From b63fe76a71805a217d0d66f624bc3c1e982dc9bc Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 4 Jun 2023 18:54:39 +0100 Subject: [PATCH] Properly hide favs tab when no favs are set --- applications/main/archive/helpers/archive_browser.c | 4 +++- applications/main/archive/helpers/archive_favorites.c | 4 +--- applications/main/archive/helpers/archive_favorites.h | 2 +- applications/main/archive/scenes/archive_scene_browser.c | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/applications/main/archive/helpers/archive_browser.c b/applications/main/archive/helpers/archive_browser.c index b0781d843..43ab8c950 100644 --- a/applications/main/archive/helpers/archive_browser.c +++ b/applications/main/archive/helpers/archive_browser.c @@ -484,7 +484,9 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) { bool tab_empty = true; bool is_app_tab = furi_string_start_with_str(browser->path, "/app:"); if(tab == ArchiveTabFavorites) { - tab_empty = false; + if(archive_favorites_count() > 0) { + tab_empty = false; + } } else if(is_app_tab) { char* app_name = strchr(furi_string_get_cstr(browser->path), ':'); if(app_name != NULL) { diff --git a/applications/main/archive/helpers/archive_favorites.c b/applications/main/archive/helpers/archive_favorites.c index 7e3229283..7efeeb4d1 100644 --- a/applications/main/archive/helpers/archive_favorites.c +++ b/applications/main/archive/helpers/archive_favorites.c @@ -46,9 +46,7 @@ static bool archive_favorites_read_line(File* file, FuriString* str_result) { return result; } -uint16_t archive_favorites_count(void* context) { - furi_assert(context); - +uint16_t archive_favorites_count() { Storage* fs_api = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(fs_api); diff --git a/applications/main/archive/helpers/archive_favorites.h b/applications/main/archive/helpers/archive_favorites.h index e45af92e7..dfeb18e76 100644 --- a/applications/main/archive/helpers/archive_favorites.h +++ b/applications/main/archive/helpers/archive_favorites.h @@ -6,7 +6,7 @@ #define ARCHIVE_FAV_PATH CFG_PATH("favorites.txt") #define ARCHIVE_FAV_TEMP_PATH CFG_PATH("favorites.tmp") -uint16_t archive_favorites_count(void* context); +uint16_t archive_favorites_count(); bool archive_favorites_read(void* context); bool archive_favorites_delete(const char* format, ...) _ATTRIBUTE((__format__(__printf__, 1, 2))); bool archive_is_favorite(const char* format, ...) _ATTRIBUTE((__format__(__printf__, 1, 2))); diff --git a/applications/main/archive/scenes/archive_scene_browser.c b/applications/main/archive/scenes/archive_scene_browser.c index bf9079be4..0854c2d3f 100644 --- a/applications/main/archive/scenes/archive_scene_browser.c +++ b/applications/main/archive/scenes/archive_scene_browser.c @@ -77,6 +77,9 @@ void archive_scene_browser_on_enter(void* context) { browser->is_root = true; archive_browser_set_callback(browser, archive_scene_browser_callback, archive); + if(archive_get_tab(browser) == ArchiveTabFavorites && archive_favorites_count() < 1) { + archive_switch_tab(browser, TAB_LEFT); + } archive_update_focus(browser, archive->text_store); view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser);