From 46dc098cab659538b2f229636f49b84ac8af86a1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 2 Mar 2022 00:12:30 +0100 Subject: Set anime as finished watching in ui without having to restart --- plugins/LocalAnime.hpp | 11 +++++++---- src/plugins/LocalAnime.cpp | 14 +++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/LocalAnime.hpp b/plugins/LocalAnime.hpp index 19b93e8..111d363 100644 --- a/plugins/LocalAnime.hpp +++ b/plugins/LocalAnime.hpp @@ -32,27 +32,30 @@ namespace QuickMedia { class LocalAnimeSearchPage : public LazyFetchPage { public: - LocalAnimeSearchPage(Program *program, std::vector anime_items) - : LazyFetchPage(program), anime_items(std::move(anime_items)) {} + LocalAnimeSearchPage(Program *program, std::vector anime_items, LocalAnimeSearchPage *parent_search_page = nullptr) + : LazyFetchPage(program), parent_search_page(parent_search_page), anime_items(std::move(anime_items)) {} const char* get_title() const override { return "Search"; } bool search_is_filter() override { return true; } PluginResult submit(const SubmitArgs &args, std::vector &result_tabs) override; PluginResult lazy_fetch(BodyItems &result_items) override; void toggle_read(BodyItem *selected_item) override; + + LocalAnimeSearchPage *parent_search_page; private: std::vector anime_items; }; class LocalAnimeVideoPage : public VideoPage { public: - LocalAnimeVideoPage(Program *program, std::string filepath, WatchProgress *watch_progress) - : VideoPage(program, std::move(filepath)), watch_progress(watch_progress) {} + LocalAnimeVideoPage(Program *program, LocalAnimeSearchPage *search_page, std::string filepath, WatchProgress *watch_progress) + : VideoPage(program, std::move(filepath)), search_page(search_page), watch_progress(watch_progress) {} const char* get_title() const override { return ""; } std::string get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) override; std::string get_url_timestamp() override; bool is_local() const override { return true; } void set_watch_progress(int64_t time_pos_sec) override; private: + LocalAnimeSearchPage *search_page; WatchProgress *watch_progress; }; } \ No newline at end of file diff --git a/src/plugins/LocalAnime.cpp b/src/plugins/LocalAnime.cpp index 8434810..0de33b4 100644 --- a/src/plugins/LocalAnime.cpp +++ b/src/plugins/LocalAnime.cpp @@ -321,15 +321,15 @@ namespace QuickMedia { LocalAnimeBodyItemData *item_data = static_cast(args.extra.get()); if(std::holds_alternative(*item_data->anime_item)) { const LocalAnime &anime = std::get(*item_data->anime_item); - result_tabs.push_back(Tab{ create_body(), std::make_unique(program, anime.items), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); + result_tabs.push_back(Tab{ create_body(), std::make_unique(program, anime.items, this), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); return PluginResult::OK; } else if(std::holds_alternative(*item_data->anime_item)) { const LocalAnimeSeason &season = std::get(*item_data->anime_item); - result_tabs.push_back(Tab{ create_body(), std::make_unique(program, season.episodes), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); + result_tabs.push_back(Tab{ create_body(), std::make_unique(program, season.episodes, this), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); return PluginResult::OK; } else if(std::holds_alternative(*item_data->anime_item)) { const LocalAnimeEpisode &episode = std::get(*item_data->anime_item); - result_tabs.push_back(Tab{ nullptr, std::make_unique(program, episode.path.data, &item_data->watch_progress), nullptr }); + result_tabs.push_back(Tab{ nullptr, std::make_unique(program, this, episode.path.data, &item_data->watch_progress), nullptr }); return PluginResult::OK; } return PluginResult::ERR; @@ -483,6 +483,13 @@ namespace QuickMedia { return std::to_string(watch_progress->time_pos_sec); } + static void refresh_pages_recursive(LocalAnimeSearchPage *search_page) { + while(search_page) { + search_page->needs_refresh = true; + search_page = search_page->parent_search_page; + } + } + void LocalAnimeVideoPage::set_watch_progress(int64_t time_pos_sec) { std::string filename_relative_to_anime_dir = anime_path_to_item_name(url); @@ -497,6 +504,7 @@ namespace QuickMedia { return; } + refresh_pages_recursive(search_page); watch_progress->time_pos_sec = time_pos_sec; watch_progress->duration_sec = *file_analyzer.get_duration_seconds(); set_watch_progress_for_plugin("local-anime", filename_relative_to_anime_dir, time_pos_sec, *file_analyzer.get_duration_seconds(), url); -- cgit v1.2.3