aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp128
1 files changed, 99 insertions, 29 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index a9956d3..13361c6 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1482,6 +1482,15 @@ namespace QuickMedia {
window.draw(tab_associated_data.search_result_text);
}
+ if(!tabs[selected_tab].page->is_ready()) {
+ sf::Text loading_text("Loading...", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(30 * get_ui_scale()));
+ auto text_bounds = loading_text.getLocalBounds();
+ loading_text.setPosition(
+ std::floor(body_pos.x + body_size.x * 0.5f - text_bounds.width * 0.5f),
+ std::floor(body_pos.y + body_size.y * 0.5f - text_bounds.height * 0.5f));
+ window.draw(loading_text);
+ }
+
if(matrix)
matrix->update();
@@ -1518,6 +1527,8 @@ namespace QuickMedia {
bool redraw = true;
for(Tab &tab : tabs) {
+ if(tab.body->attach_side == AttachSide::BOTTOM)
+ tab.body->select_last_item();
tab.body->thumbnail_max_size = tab.page->get_thumbnail_max_size();
tab.page->on_navigate_to_page(tab.body.get());
}
@@ -1591,9 +1602,9 @@ namespace QuickMedia {
tabs[selected_tab].search_bar->clear();
tabs[selected_tab].search_bar->onTextUpdateCallback("");
} else {
- int selected_item_index = tabs[selected_tab].body->get_selected_item();
- tabs[selected_tab].body->select_first_item();
- tabs[selected_tab].body->set_selected_item(selected_item_index, false);
+ //int selected_item_index = tabs[selected_tab].body->get_selected_item();
+ //tabs[selected_tab].body->select_first_item();
+ //tabs[selected_tab].body->set_selected_item(selected_item_index, false);
}
}
@@ -1716,13 +1727,14 @@ namespace QuickMedia {
hide_virtual_keyboard();
};
- std::function<void()> on_bottom_reached = [&ui_tabs, &tabs, &tab_associated_data, &gradient_inc] {
+ std::function<void()> on_reached_end = [&ui_tabs, &tabs, &tab_associated_data, &gradient_inc] {
const int selected_tab = ui_tabs.get_selected();
if(tab_associated_data[selected_tab].fetch_status == FetchStatus::NONE
&& !tab_associated_data[selected_tab].fetching_next_page_running
&& !tab_associated_data[selected_tab].fetching_next_page_failed
- && !tabs[selected_tab].body->items.empty()
- && tabs[selected_tab].page
+ && (!tabs[selected_tab].search_bar || tabs[selected_tab].search_bar->is_empty())
+ && tabs[selected_tab].body->get_num_visible_items() > 0
+ && tabs[selected_tab].page->is_ready()
&& (!tabs[selected_tab].page->is_lazy_fetch_page() || tab_associated_data[selected_tab].lazy_fetch_finished))
{
gradient_inc = 0.0;
@@ -1746,7 +1758,10 @@ namespace QuickMedia {
submit_handler(body_item->get_title());
};
- tab.body->on_bottom_reached = on_bottom_reached;
+ if(tab.body->attach_side == AttachSide::TOP)
+ tab.body->on_bottom_reached = on_reached_end;
+ else if(tab.body->attach_side == AttachSide::BOTTOM)
+ tab.body->on_top_reached = on_reached_end;
TabAssociatedData &associated_data = tab_associated_data[i];
if(tab.search_bar) {
@@ -1762,7 +1777,10 @@ namespace QuickMedia {
associated_data.search_text_updated = true;
} else {
tabs[i].body->filter_search_fuzzy(text);
- tabs[i].body->select_first_item();
+ if(tabs[i].body->attach_side == AttachSide::TOP)
+ tabs[i].body->select_first_item();
+ else if(tabs[i].body->attach_side == AttachSide::BOTTOM)
+ tabs[i].body->select_last_item();
}
associated_data.typing = false;
};
@@ -1816,7 +1834,7 @@ namespace QuickMedia {
}
} else if(event.key.code == sf::Keyboard::T && event.key.control) {
BodyItem *selected_item = tabs[selected_tab].body->get_selected();
- if(selected_item && tabs[selected_tab].page && tabs[selected_tab].page->is_trackable()) {
+ if(selected_item && tabs[selected_tab].page->is_trackable()) {
TrackablePage *trackable_page = dynamic_cast<TrackablePage*>(tabs[selected_tab].page.get());
run_task_with_loading_screen([trackable_page, selected_item](){
return trackable_page->track(selected_item->get_title()) == TrackResult::OK;
@@ -1857,17 +1875,31 @@ namespace QuickMedia {
// TODO: Dont show tabs if there is only one tab
get_body_dimensions(window_size, tabs[selected_tab].search_bar.get(), body_pos, body_size, true);
- gradient_points[0].position.x = 0.0f;
- gradient_points[0].position.y = window_size.y - gradient_height;
+ if(tabs[selected_tab].body->attach_side == AttachSide::TOP) {
+ gradient_points[0].position.x = 0.0f;
+ gradient_points[0].position.y = window_size.y - gradient_height;
- gradient_points[1].position.x = window_size.x;
- gradient_points[1].position.y = window_size.y - gradient_height;
+ gradient_points[1].position.x = window_size.x;
+ gradient_points[1].position.y = window_size.y - gradient_height;
- gradient_points[2].position.x = window_size.x;
- gradient_points[2].position.y = window_size.y;
+ gradient_points[2].position.x = window_size.x;
+ gradient_points[2].position.y = window_size.y;
+
+ gradient_points[3].position.x = 0.0f;
+ gradient_points[3].position.y = window_size.y;
+ } else if(tabs[selected_tab].body->attach_side == AttachSide::BOTTOM) {
+ gradient_points[0].position.x = 0.0f;
+ gradient_points[0].position.y = body_pos.y;
- gradient_points[3].position.x = 0.0f;
- gradient_points[3].position.y = window_size.y;
+ gradient_points[1].position.x = window_size.x;
+ gradient_points[1].position.y = body_pos.y;
+
+ gradient_points[2].position.x = window_size.x;
+ gradient_points[2].position.y = body_pos.y + gradient_height;
+
+ gradient_points[3].position.x = 0.0f;
+ gradient_points[3].position.y = body_pos.y + gradient_height;
+ }
}
if(tab_associated_data[selected_tab].fetching_next_page_running) {
@@ -1875,15 +1907,22 @@ namespace QuickMedia {
gradient_inc += (frame_time_ms * 0.5);
sf::Color bottom_color = interpolate_colors(back_color, sf::Color(175, 180, 188), progress);
- gradient_points[0].color = back_color;
- gradient_points[1].color = back_color;
- gradient_points[2].color = bottom_color;
- gradient_points[3].color = bottom_color;
+ if(tabs[selected_tab].body->attach_side == AttachSide::TOP) {
+ gradient_points[0].color = back_color;
+ gradient_points[1].color = back_color;
+ gradient_points[2].color = bottom_color;
+ gradient_points[3].color = bottom_color;
+ } else if(tabs[selected_tab].body->attach_side == AttachSide::BOTTOM) {
+ gradient_points[0].color = bottom_color;
+ gradient_points[1].color = bottom_color;
+ gradient_points[2].color = back_color;
+ gradient_points[3].color = back_color;
+ }
}
if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->update();
- if(tabs[selected_tab].page->is_lazy_fetch_page() && tab_associated_data[selected_tab].fetch_status == FetchStatus::NONE && !tab_associated_data[selected_tab].lazy_fetch_finished) {
+ if(tabs[selected_tab].page->is_ready() && tabs[selected_tab].page->is_lazy_fetch_page() && tab_associated_data[selected_tab].fetch_status == FetchStatus::NONE && !tab_associated_data[selected_tab].lazy_fetch_finished) {
tab_associated_data[selected_tab].fetch_status = FetchStatus::LOADING;
tab_associated_data[selected_tab].fetch_type = FetchType::LAZY;
tab_associated_data[selected_tab].search_result_text.setString("Loading...");
@@ -1897,18 +1936,33 @@ namespace QuickMedia {
for(size_t i = 0; i < tabs.size(); ++i) {
TabAssociatedData &associated_data = tab_associated_data[i];
+ if(!tabs[i].page->is_ready())
+ continue;
if(associated_data.fetching_next_page_running && associated_data.next_page_future.ready()) {
+ const bool body_was_empty = tabs[i].body->items.empty();
BodyItems new_body_items = associated_data.next_page_future.get();
fprintf(stderr, "Finished fetching page %d, num new items: %zu\n", associated_data.fetched_page + 1, new_body_items.size());
+ int prev_selected_item = tabs[i].body->get_selected_item();
size_t num_new_messages = new_body_items.size();
if(num_new_messages > 0) {
- tabs[i].body->append_items(std::move(new_body_items));
+ if(tabs[i].body->attach_side == AttachSide::TOP)
+ tabs[i].body->append_items(std::move(new_body_items));
+ else if(tabs[i].body->attach_side == AttachSide::BOTTOM)
+ tabs[i].body->prepend_items_reverse(std::move(new_body_items));
associated_data.fetched_page++;
} else {
associated_data.fetching_next_page_failed = true;
}
associated_data.fetching_next_page_running = false;
+
+ if(tabs[i].body->attach_side == AttachSide::BOTTOM) {
+ if(body_was_empty) {
+ tabs[i].body->select_last_item();
+ } else {
+ tabs[i].body->set_selected_item(prev_selected_item + num_new_messages, true);
+ }
+ }
}
if(associated_data.search_text_updated && associated_data.fetch_status == FetchStatus::NONE && !associated_data.fetching_next_page_running) {
@@ -1929,7 +1983,12 @@ namespace QuickMedia {
if(!associated_data.search_text_updated) {
FetchResult fetch_result = associated_data.fetch_future.get();
tabs[i].body->items = std::move(fetch_result.body_items);
- tabs[i].body->select_first_item();
+ if(tabs[i].body->attach_side == AttachSide::TOP) {
+ tabs[i].body->select_first_item();
+ } else if(tabs[i].body->attach_side == AttachSide::BOTTOM) {
+ std::reverse(tabs[i].body->items.begin(), tabs[i].body->items.end());
+ tabs[i].body->select_last_item();
+ }
associated_data.fetched_page = 0;
associated_data.fetching_next_page_failed = false;
if(fetch_result.result != PluginResult::OK)
@@ -1949,6 +2008,10 @@ namespace QuickMedia {
FetchResult fetch_result = associated_data.fetch_future.get();
tabs[i].body->items = std::move(fetch_result.body_items);
if(tabs[i].search_bar) tabs[i].body->filter_search_fuzzy(tabs[i].search_bar->get_text());
+ if(tabs[i].body->attach_side == AttachSide::BOTTOM) {
+ std::reverse(tabs[i].body->items.begin(), tabs[i].body->items.end());
+ tabs[i].body->select_last_item();
+ }
LazyFetchPage *lazy_fetch_page = static_cast<LazyFetchPage*>(tabs[i].page.get());
if(fetch_result.result != PluginResult::OK)
associated_data.search_result_text.setString("Failed to fetch page!");
@@ -1984,8 +2047,12 @@ namespace QuickMedia {
AsyncImageLoader::get_instance().update();
window.display();
- if(!tabs[selected_tab].body->items.empty() && tabs[selected_tab].body->is_last_item_fully_visible())
- on_bottom_reached();
+ if(!tabs[selected_tab].body->items.empty()) {
+ if(tabs[selected_tab].body->attach_side == AttachSide::TOP && tabs[selected_tab].body->is_last_item_fully_visible())
+ on_reached_end();
+ else if(tabs[selected_tab].body->attach_side == AttachSide::BOTTOM && tabs[selected_tab].body->is_first_item_fully_visible())
+ on_reached_end();
+ }
if(go_to_previous_page) {
go_to_previous_page = false;
@@ -3373,7 +3440,7 @@ namespace QuickMedia {
//thread_body->clamp_selection();
//thread_body->set_page_scroll(0.0f);
int prev_sel = thread_body->get_selected_item();
- thread_body->select_last_item();
+ thread_body->select_first_item();
thread_body->set_selected_item(prev_sel, false);
} else if(event.key.code == sf::Keyboard::BackSpace && !comment_navigation_stack.empty()) {
size_t previous_selected = comment_navigation_stack.top();
@@ -5692,6 +5759,8 @@ namespace QuickMedia {
// TODO: Maybe set this instead when the mention is visible on the screen?
current_room->unread_notification_count = 0;
+ matrix_chat_page->set_room_as_read(current_room);
+
Message *read_message = last_visible_timeline_message;
if(read_message->replaced_by)
read_message = read_message->replaced_by.get();
@@ -5825,7 +5894,8 @@ namespace QuickMedia {
exit(exit_code);
auto notifications_body = create_body();
- auto matrix_notifications_page = std::make_unique<MatrixNotificationsPage>(this, notifications_body.get());
+ //notifications_body->attach_side = AttachSide::BOTTOM;
+ auto matrix_notifications_page = std::make_unique<MatrixNotificationsPage>(this, matrix, notifications_body.get());
auto rooms_tags_body = create_body();
auto matrix_rooms_tag_page = std::make_unique<MatrixRoomTagsPage>(this, rooms_tags_body.get());
@@ -5854,7 +5924,7 @@ namespace QuickMedia {
add_body_item_unique_title(room_directory_body->items, "jupiterbroadcasting.com");
auto matrix_room_directory_page = std::make_unique<MatrixRoomDirectoryPage>(this, matrix);
- MatrixQuickMedia matrix_handler(this, matrix, matrix_rooms_page.get(), matrix_rooms_tag_page.get(), matrix_invites_page.get());
+ MatrixQuickMedia matrix_handler(this, matrix, matrix_rooms_page.get(), matrix_rooms_tag_page.get(), matrix_invites_page.get(), matrix_notifications_page.get());
bool sync_cached = false;
if(!matrix->start_sync(&matrix_handler, sync_cached)) {
show_notification("QuickMedia", "Failed to start sync", Urgency::CRITICAL);