From 07f80da8f9c46c228c272e95ab88a3e098c899d9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 30 Jun 2020 02:25:10 +0200 Subject: Add infinite image scroll mode --- src/QuickMedia.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 881f2d6..9b57b0b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -12,6 +12,7 @@ #include "../include/StringUtils.hpp" #include "../include/GoogleCaptcha.hpp" #include "../include/Notification.hpp" +#include "../include/ImageViewer.hpp" #include #include @@ -234,6 +235,11 @@ namespace QuickMedia { window.setKeyRepeatEnabled(true); break; } + case Page::IMAGES_CONTINUOUS: { + body->draw_thumbnails = false; + image_continuous_page(); + break; + } case Page::CONTENT_LIST: { body->draw_thumbnails = true; content_list_page(); @@ -796,7 +802,7 @@ namespace QuickMedia { images_url = item->url; chapter_title = item->title; image_index = 0; - current_page = Page::IMAGES; + current_page = Page::IMAGES_CONTINUOUS; if(start_from_beginning) return; @@ -1181,6 +1187,66 @@ namespace QuickMedia { } } + void Program::image_continuous_page() { + search_bar->onTextUpdateCallback = nullptr; + search_bar->onTextSubmitCallback = nullptr; + + assert(current_plugin->is_manga()); + Manga *image_plugin = static_cast(current_plugin); + + content_cache_dir = get_cache_dir().join(image_plugin->name).join(manga_id_base64).join(base64_encode(chapter_title)); + if(create_directory_recursive(content_cache_dir) != 0) { + show_notification("Storage", "Failed to create directory: " + content_cache_dir.data, Urgency::CRITICAL); + current_page = Page::EPISODE_LIST; + return; + } + download_chapter_images_if_needed(image_plugin); + + Json::Value &json_chapters = content_storage_json["chapters"]; + Json::Value json_chapter; + int latest_read = 1 + image_index; + if(json_chapters.isObject()) { + json_chapter = json_chapters[chapter_title]; + if(json_chapter.isObject()) { + const Json::Value ¤t = json_chapter["current"]; + if(current.isNumeric()) + latest_read = std::max(latest_read, current.asInt()); + } else { + json_chapter = Json::Value(Json::objectValue); + } + } else { + json_chapters = Json::Value(Json::objectValue); + json_chapter = Json::Value(Json::objectValue); + } + + ImageViewer image_viewer(image_plugin, images_url, chapter_title, image_index, content_cache_dir, &font); + + json_chapter["current"] = std::min(latest_read, image_viewer.get_num_pages()); + json_chapter["total"] = image_viewer.get_num_pages(); + json_chapters[chapter_title] = json_chapter; + if(!save_manga_progress_json(content_storage_file, content_storage_json)) { + show_notification("Manga progress", "Failed to save manga progress", Urgency::CRITICAL); + } + + while(current_page == Page::IMAGES_CONTINUOUS) { + window.clear(back_color); + if(!image_viewer.draw(window)) + current_page = Page::EPISODE_LIST; + window.display(); + + int focused_page = image_viewer.get_focused_page(); + if(focused_page > latest_read) { + latest_read = focused_page; + image_index = latest_read - 1; + json_chapter["current"] = latest_read; + json_chapters[chapter_title] = json_chapter; + if(!save_manga_progress_json(content_storage_file, content_storage_json)) { + show_notification("Manga progress", "Failed to save manga progress", Urgency::CRITICAL); + } + } + } + } + void Program::content_list_page() { if(current_plugin->get_content_list(content_list_url, body->items) != PluginResult::OK) { show_notification("Content list", "Failed to get content list for url: " + content_list_url, Urgency::CRITICAL); -- cgit v1.2.3