From 3cbf932bd13034b248b3fdafb92bdc245781110c Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 27 Jun 2023 21:35:50 +0200 Subject: [PATCH] Move clock setting to statusbar section of xfw app --- .../xtreme_app_scene_interface_statusbar.c | 18 +++++++++++ applications/services/desktop/desktop.c | 4 +-- .../services/desktop/desktop_settings.h | 1 - .../scenes/desktop_settings_scene_start.c | 32 ------------------- lib/xtreme/settings.c | 6 ++++ lib/xtreme/xtreme.h | 1 + 6 files changed, 27 insertions(+), 35 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c index 5d58472d8..50b3c14ec 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c @@ -2,6 +2,7 @@ enum VarItemListIndex { VarItemListIndexBatteryIcon, + VarItemListIndexShowClock, VarItemListIndexStatusIcons, VarItemListIndexBarBorders, VarItemListIndexBarBackground, @@ -24,6 +25,14 @@ static void xtreme_app_scene_interface_statusbar_battery_icon_changed(VariableIt furi_record_close(RECORD_POWER); } +static void xtreme_app_scene_interface_statusbar_statusbar_clock_changed(VariableItem* item) { + XtremeApp* app = variable_item_get_context(item); + bool value = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, value ? "ON" : "OFF"); + XTREME_SETTINGS()->statusbar_clock = value; + app->save_settings = true; +} + static void xtreme_app_scene_interface_statusbar_status_icons_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); bool value = variable_item_get_current_value_index(item); @@ -63,6 +72,15 @@ void xtreme_app_scene_interface_statusbar_on_enter(void* context) { variable_item_set_current_value_index(item, xtreme_settings->battery_icon); variable_item_set_current_value_text(item, battery_icon_names[xtreme_settings->battery_icon]); + item = variable_item_list_add( + var_item_list, + "Show Clock", + 2, + xtreme_app_scene_interface_statusbar_statusbar_clock_changed, + app); + variable_item_set_current_value_index(item, xtreme_settings->statusbar_clock); + variable_item_set_current_value_text(item, xtreme_settings->statusbar_clock ? "ON" : "OFF"); + item = variable_item_list_add( var_item_list, "Status Icons", diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index e2d7354d7..f78150102 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -157,7 +157,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { // locking and unlocking DESKTOP_SETTINGS_LOAD(&desktop->settings); - desktop_clock_toggle_view(desktop, desktop->settings.display_clock); + desktop_clock_toggle_view(desktop, XTREME_SETTINGS()->statusbar_clock); desktop_auto_lock_arm(desktop); return true; @@ -470,7 +470,7 @@ int32_t desktop_srv(void* p) { furi_hal_rtc_set_pin_fails(0); } - desktop_clock_toggle_view(desktop, desktop->settings.display_clock); + desktop_clock_toggle_view(desktop, XTREME_SETTINGS()->statusbar_clock); scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain); diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index 4cc07e735..fb269eaff 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -36,7 +36,6 @@ typedef struct { PinCode pin_code; uint32_t auto_lock_delay_ms; bool auto_lock_with_pin; - uint8_t display_clock; } DesktopSettings; bool DESKTOP_SETTINGS_SAVE(DesktopSettings* x); diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c index 5765963c4..baa3a9af4 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c @@ -10,7 +10,6 @@ #define SCENE_EVENT_SELECT_PIN_SETUP 2 #define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 3 #define SCENE_EVENT_SELECT_AUTO_LOCK_PIN 4 -#define SCENE_EVENT_SELECT_CLOCK_DISPLAY 5 #define AUTO_LOCK_DELAY_COUNT 9 const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = { @@ -27,27 +26,11 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = { const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] = {0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000}; -#define CLOCK_ENABLE_COUNT 2 -const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = { - "OFF", - "ON", -}; - -const uint32_t clock_enable_value[CLOCK_ENABLE_COUNT] = {0, 1}; - static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) { DesktopSettingsApp* app = context; view_dispatcher_send_custom_event(app->view_dispatcher, index); } -static void desktop_settings_scene_start_clock_enable_changed(VariableItem* item) { - DesktopSettingsApp* app = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - variable_item_set_current_value_text(item, clock_enable_text[index]); - app->settings.display_clock = index; -} - static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) { DesktopSettingsApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -99,18 +82,6 @@ void desktop_settings_scene_start_on_enter(void* context) { variable_item_set_current_value_index(item, app->settings.auto_lock_with_pin); variable_item_set_current_value_text(item, app->settings.auto_lock_with_pin ? "ON" : "OFF"); - item = variable_item_list_add( - variable_item_list, - "Show Clock", - CLOCK_ENABLE_COUNT, - desktop_settings_scene_start_clock_enable_changed, // - app); - - value_index = - value_index_uint32(app->settings.display_clock, clock_enable_value, CLOCK_ENABLE_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, clock_enable_text[value_index]); - variable_item_list_set_enter_callback( variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app); @@ -140,9 +111,6 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even case SCENE_EVENT_SELECT_AUTO_LOCK_DELAY: consumed = true; break; - case SCENE_EVENT_SELECT_CLOCK_DISPLAY: - consumed = true; - break; } } return consumed; diff --git a/lib/xtreme/settings.c b/lib/xtreme/settings.c index bdceb6900..57e5670e0 100644 --- a/lib/xtreme/settings.c +++ b/lib/xtreme/settings.c @@ -21,6 +21,7 @@ XtremeSettings xtreme_settings = { .lockscreen_statusbar = true, // ON .lockscreen_prompt = true, // ON .battery_icon = BatteryIconBarPercent, // Bar % + .statusbar_clock = false, // OFF .status_icons = true, // ON .bar_borders = true, // ON .bar_background = false, // OFF @@ -108,6 +109,10 @@ void XTREME_SETTINGS_LOAD() { x->battery_icon = CLAMP(u, BatteryIconCount - 1U, 0U); } flipper_format_rewind(file); + if(flipper_format_read_bool(file, "statusbar_clock", &b, 1)) { + x->statusbar_clock = b; + } + flipper_format_rewind(file); if(flipper_format_read_bool(file, "status_icons", &b, 1)) { x->status_icons = b; } @@ -186,6 +191,7 @@ void XTREME_SETTINGS_SAVE() { flipper_format_write_bool(file, "lockscreen_statusbar", &x->lockscreen_statusbar, 1); flipper_format_write_bool(file, "lockscreen_prompt", &x->lockscreen_prompt, 1); flipper_format_write_uint32(file, "battery_icon", &x->battery_icon, 1); + flipper_format_write_bool(file, "statusbar_clock", &x->statusbar_clock, 1); flipper_format_write_bool(file, "status_icons", &x->status_icons, 1); flipper_format_write_bool(file, "bar_borders", &x->bar_borders, 1); flipper_format_write_bool(file, "bar_background", &x->bar_background, 1); diff --git a/lib/xtreme/xtreme.h b/lib/xtreme/xtreme.h index b2a86e9c0..134f737e1 100644 --- a/lib/xtreme/xtreme.h +++ b/lib/xtreme/xtreme.h @@ -30,6 +30,7 @@ typedef struct { bool lockscreen_statusbar; bool lockscreen_prompt; uint32_t battery_icon; + bool statusbar_clock; bool status_icons; bool bar_borders; bool bar_background;