From 2e993b0a58153b0848387783761d1e3be0116eef Mon Sep 17 00:00:00 2001 From: hedger Date: Thu, 18 Aug 2022 19:46:43 +0300 Subject: [PATCH] [FL-2748] disabled automatic poweroff for single-frame slideshows #1621 --- applications/desktop/helpers/slideshow.c | 4 ++++ applications/desktop/helpers/slideshow.h | 1 + .../desktop/views/desktop_view_slideshow.c | 14 +++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/applications/desktop/helpers/slideshow.c b/applications/desktop/helpers/slideshow.c index 63bd42b55..b4d85cb90 100644 --- a/applications/desktop/helpers/slideshow.c +++ b/applications/desktop/helpers/slideshow.c @@ -94,6 +94,10 @@ bool slideshow_is_loaded(Slideshow* slideshow) { return slideshow->loaded; } +bool slideshow_is_one_page(Slideshow* slideshow) { + return slideshow->loaded && (slideshow->icon.frame_count == 1); +} + bool slideshow_advance(Slideshow* slideshow) { uint8_t next_frame = slideshow->current_frame + 1; if(next_frame < slideshow->icon.frame_count) { diff --git a/applications/desktop/helpers/slideshow.h b/applications/desktop/helpers/slideshow.h index eeaac0e8b..9083e0dcf 100644 --- a/applications/desktop/helpers/slideshow.h +++ b/applications/desktop/helpers/slideshow.h @@ -9,6 +9,7 @@ Slideshow* slideshow_alloc(); void slideshow_free(Slideshow* slideshow); bool slideshow_load(Slideshow* slideshow, const char* fspath); bool slideshow_is_loaded(Slideshow* slideshow); +bool slideshow_is_one_page(Slideshow* slideshow); void slideshow_goback(Slideshow* slideshow); bool slideshow_advance(Slideshow* slideshow); void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y); diff --git a/applications/desktop/views/desktop_view_slideshow.c b/applications/desktop/views/desktop_view_slideshow.c index 26ae95eae..58a8f6d0c 100644 --- a/applications/desktop/views/desktop_view_slideshow.c +++ b/applications/desktop/views/desktop_view_slideshow.c @@ -35,8 +35,9 @@ static bool desktop_view_slideshow_input(InputEvent* event, void* context) { furi_assert(event); DesktopSlideshowView* instance = context; + DesktopSlideshowViewModel* model = view_get_model(instance->view); + bool update_view = false; if(event->type == InputTypeShort) { - DesktopSlideshowViewModel* model = view_get_model(instance->view); bool end_slideshow = false; switch(event->key) { case InputKeyLeft: @@ -54,15 +55,18 @@ static bool desktop_view_slideshow_input(InputEvent* event, void* context) { if(end_slideshow) { instance->callback(DesktopSlideshowCompleted, instance->context); } - view_commit_model(instance->view, true); + update_view = true; } else if(event->key == InputKeyOk) { if(event->type == InputTypePress) { furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_SHORT); } else if(event->type == InputTypeRelease) { furi_timer_stop(instance->timer); - furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_LONG); + if(!slideshow_is_one_page(model->slideshow)) { + furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_LONG); + } } } + view_commit_model(instance->view, update_view); return true; } @@ -79,12 +83,12 @@ static void desktop_view_slideshow_enter(void* context) { instance->timer = furi_timer_alloc(desktop_first_start_timer_callback, FuriTimerTypeOnce, instance); - furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_LONG); - DesktopSlideshowViewModel* model = view_get_model(instance->view); model->slideshow = slideshow_alloc(); if(!slideshow_load(model->slideshow, SLIDESHOW_FS_PATH)) { instance->callback(DesktopSlideshowCompleted, instance->context); + } else if(!slideshow_is_one_page(model->slideshow)) { + furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_LONG); } view_commit_model(instance->view, false); }