[FL-2748] disabled automatic poweroff for single-frame slideshows #1621

This commit is contained in:
hedger 2022-08-18 19:46:43 +03:00 committed by GitHub
parent e243a0e0e4
commit 2e993b0a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -94,6 +94,10 @@ bool slideshow_is_loaded(Slideshow* slideshow) {
return slideshow->loaded; return slideshow->loaded;
} }
bool slideshow_is_one_page(Slideshow* slideshow) {
return slideshow->loaded && (slideshow->icon.frame_count == 1);
}
bool slideshow_advance(Slideshow* slideshow) { bool slideshow_advance(Slideshow* slideshow) {
uint8_t next_frame = slideshow->current_frame + 1; uint8_t next_frame = slideshow->current_frame + 1;
if(next_frame < slideshow->icon.frame_count) { if(next_frame < slideshow->icon.frame_count) {

View File

@ -9,6 +9,7 @@ Slideshow* slideshow_alloc();
void slideshow_free(Slideshow* slideshow); void slideshow_free(Slideshow* slideshow);
bool slideshow_load(Slideshow* slideshow, const char* fspath); bool slideshow_load(Slideshow* slideshow, const char* fspath);
bool slideshow_is_loaded(Slideshow* slideshow); bool slideshow_is_loaded(Slideshow* slideshow);
bool slideshow_is_one_page(Slideshow* slideshow);
void slideshow_goback(Slideshow* slideshow); void slideshow_goback(Slideshow* slideshow);
bool slideshow_advance(Slideshow* slideshow); bool slideshow_advance(Slideshow* slideshow);
void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y); void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y);

View File

@ -35,8 +35,9 @@ static bool desktop_view_slideshow_input(InputEvent* event, void* context) {
furi_assert(event); furi_assert(event);
DesktopSlideshowView* instance = context; DesktopSlideshowView* instance = context;
DesktopSlideshowViewModel* model = view_get_model(instance->view);
bool update_view = false;
if(event->type == InputTypeShort) { if(event->type == InputTypeShort) {
DesktopSlideshowViewModel* model = view_get_model(instance->view);
bool end_slideshow = false; bool end_slideshow = false;
switch(event->key) { switch(event->key) {
case InputKeyLeft: case InputKeyLeft:
@ -54,15 +55,18 @@ static bool desktop_view_slideshow_input(InputEvent* event, void* context) {
if(end_slideshow) { if(end_slideshow) {
instance->callback(DesktopSlideshowCompleted, instance->context); instance->callback(DesktopSlideshowCompleted, instance->context);
} }
view_commit_model(instance->view, true); update_view = true;
} else if(event->key == InputKeyOk) { } else if(event->key == InputKeyOk) {
if(event->type == InputTypePress) { if(event->type == InputTypePress) {
furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_SHORT); furi_timer_start(instance->timer, DESKTOP_SLIDESHOW_POWEROFF_SHORT);
} else if(event->type == InputTypeRelease) { } else if(event->type == InputTypeRelease) {
furi_timer_stop(instance->timer); 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; return true;
} }
@ -79,12 +83,12 @@ static void desktop_view_slideshow_enter(void* context) {
instance->timer = instance->timer =
furi_timer_alloc(desktop_first_start_timer_callback, FuriTimerTypeOnce, instance); 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); DesktopSlideshowViewModel* model = view_get_model(instance->view);
model->slideshow = slideshow_alloc(); model->slideshow = slideshow_alloc();
if(!slideshow_load(model->slideshow, SLIDESHOW_FS_PATH)) { if(!slideshow_load(model->slideshow, SLIDESHOW_FS_PATH)) {
instance->callback(DesktopSlideshowCompleted, instance->context); 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); view_commit_model(instance->view, false);
} }