From da32d252db503a54234d32169e7bc7495d0a536b Mon Sep 17 00:00:00 2001
From: MX <10697207+xMasterX@users.noreply.github.com>
Date: Mon, 19 Dec 2022 17:54:59 +0300
Subject: [PATCH] Clock - use system locale settings
---
applications/main/clock_app/application.fam | 13 ---
applications/main/clock_app/clock_app.c | 25 +++--
applications/main/clock_app/clock_app.h | 5 +-
applications/main/clock_app/clock_settings.h | 36 -------
.../main/clock_app/clock_settings_app.c | 102 ------------------
.../main/clock_app/clock_settings_filename.h | 3 -
6 files changed, 15 insertions(+), 169 deletions(-)
delete mode 100644 applications/main/clock_app/clock_settings.h
delete mode 100644 applications/main/clock_app/clock_settings_app.c
delete mode 100644 applications/main/clock_app/clock_settings_filename.h
diff --git a/applications/main/clock_app/application.fam b/applications/main/clock_app/application.fam
index 245307368..9016973c5 100644
--- a/applications/main/clock_app/application.fam
+++ b/applications/main/clock_app/application.fam
@@ -5,21 +5,8 @@ App(
entry_point="clock_app",
cdefines=["APP_CLOCK"],
requires=["gui"],
- provides=["clock_settings"],
icon="A_Clock_14",
stack_size=2 * 1024,
order=81,
)
-
-App(
- appid="clock_settings",
- name="Clock",
- apptype=FlipperAppType.SETTINGS,
- entry_point="clock_settings_app",
- requires=["gui","clock"],
- stack_size=1 * 1024,
- order=20,
-)
-
-
diff --git a/applications/main/clock_app/clock_app.c b/applications/main/clock_app/clock_app.c
index c5b4dd9e8..47b2ba8bd 100644
--- a/applications/main/clock_app/clock_app.c
+++ b/applications/main/clock_app/clock_app.c
@@ -33,7 +33,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
char meridian_string[MERIDIAN_LEN];
char timer_string[20];
- if(state->settings.time_format == H24) {
+ if(state->time_format == LocaleTimeFormat24h) {
snprintf(
time_string, TIME_LEN, CLOCK_TIME_FORMAT, curr_dt.hour, curr_dt.minute, curr_dt.second);
} else {
@@ -54,9 +54,12 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
pm12 ? MERIDIAN_STRING_PM : MERIDIAN_STRING_AM);
}
- if(state->settings.date_format == Iso) {
+ if(state->date_format == LocaleDateFormatYMD) {
snprintf(
date_string, DATE_LEN, CLOCK_ISO_DATE_FORMAT, curr_dt.year, curr_dt.month, curr_dt.day);
+ } else if(state->date_format == LocaleDateFormatMDY) {
+ snprintf(
+ date_string, DATE_LEN, CLOCK_RFC_DATE_FORMAT, curr_dt.month, curr_dt.day, curr_dt.year);
} else {
snprintf(
date_string, DATE_LEN, CLOCK_RFC_DATE_FORMAT, curr_dt.day, curr_dt.month, curr_dt.year);
@@ -84,7 +87,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, date_string);
- if(state->settings.time_format == H12)
+ if(state->time_format == LocaleTimeFormat12h)
canvas_draw_str_aligned(canvas, 65, 12, AlignCenter, AlignCenter, meridian_string);
}
if(timer_running) {
@@ -95,16 +98,12 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
}
static void clock_state_init(ClockState* const state) {
- LOAD_CLOCK_SETTINGS(&state->settings);
- if(state->settings.time_format != H12 && state->settings.time_format != H24) {
- state->settings.time_format = H12;
- }
- if(state->settings.date_format != Iso && state->settings.date_format != Rfc) {
- state->settings.date_format = Iso;
- }
- FURI_LOG_D(TAG, "Time format: %s", state->settings.time_format == H12 ? "12h" : "24h");
- FURI_LOG_D(
- TAG, "Date format: %s", state->settings.date_format == Iso ? "ISO 8601" : "RFC 5322");
+ state->time_format = locale_get_time_format();
+
+ state->date_format = locale_get_date_format();
+
+ //FURI_LOG_D(TAG, "Time format: %s", state->settings.time_format == H12 ? "12h" : "24h");
+ //FURI_LOG_D(TAG, "Date format: %s", state->settings.date_format == Iso ? "ISO 8601" : "RFC 5322");
//furi_hal_rtc_get_datetime(&state->datetime);
}
diff --git a/applications/main/clock_app/clock_app.h b/applications/main/clock_app/clock_app.h
index c0c7436c8..693bdfac0 100644
--- a/applications/main/clock_app/clock_app.h
+++ b/applications/main/clock_app/clock_app.h
@@ -1,7 +1,7 @@
#pragma once
#include
-#include "clock_settings.h"
+#include
#define TAG "Clock"
@@ -28,7 +28,8 @@ typedef struct {
} PluginEvent;
typedef struct {
- ClockSettings settings;
+ LocaleDateFormat date_format;
+ LocaleTimeFormat time_format;
FuriHalRtcDateTime datetime;
FuriMutex* mutex;
FuriMessageQueue* event_queue;
diff --git a/applications/main/clock_app/clock_settings.h b/applications/main/clock_app/clock_settings.h
deleted file mode 100644
index b2970f659..000000000
--- a/applications/main/clock_app/clock_settings.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-
-#include "clock_settings_filename.h"
-
-#include
-#include
-#include
-#include
-#include
-
-#define CLOCK_SETTINGS_VER (1)
-#define CLOCK_SETTINGS_PATH EXT_PATH(CLOCK_SETTINGS_FILE_NAME)
-#define CLOCK_SETTINGS_MAGIC (0xC1)
-
-#define SAVE_CLOCK_SETTINGS(x) \
- saved_struct_save( \
- CLOCK_SETTINGS_PATH, (x), sizeof(ClockSettings), CLOCK_SETTINGS_MAGIC, CLOCK_SETTINGS_VER)
-
-#define LOAD_CLOCK_SETTINGS(x) \
- saved_struct_load( \
- CLOCK_SETTINGS_PATH, (x), sizeof(ClockSettings), CLOCK_SETTINGS_MAGIC, CLOCK_SETTINGS_VER)
-
-typedef enum {
- H12 = 1,
- H24 = 2,
-} TimeFormat;
-
-typedef enum {
- Iso = 1, // ISO 8601: yyyy-mm-dd
- Rfc = 2, // RFC 5322: dd-mm-yyyy
-} DateFormat;
-
-typedef struct {
- TimeFormat time_format;
- DateFormat date_format;
-} ClockSettings;
\ No newline at end of file
diff --git a/applications/main/clock_app/clock_settings_app.c b/applications/main/clock_app/clock_settings_app.c
deleted file mode 100644
index c9fd87eda..000000000
--- a/applications/main/clock_app/clock_settings_app.c
+++ /dev/null
@@ -1,102 +0,0 @@
-#include
-#include
-#include
-#include
-#include "clock_settings.h"
-
-#define TAG "Clock"
-
-typedef struct {
- ClockSettings clock_settings;
- Gui* gui;
- ViewDispatcher* view_dispatcher;
- VariableItemList* variable_item_list;
-} ClockAppSettings;
-
-static uint32_t clock_app_settings_exit(void* context) {
- UNUSED(context);
- return VIEW_NONE;
-}
-
-#define TIME_FORMAT_COUNT 2
-const char* const time_format_text[TIME_FORMAT_COUNT] = {
- "12h",
- "24h",
-};
-
-const uint32_t time_format_value[TIME_FORMAT_COUNT] = {H12, H24};
-
-#define DATE_FORMAT_COUNT 2
-const char* const date_format_text[DATE_FORMAT_COUNT] = {
- "mm-dd", // ISO 8601
- "dd-mm", // RFC 5322
-};
-
-const uint32_t date_format_value[DATE_FORMAT_COUNT] = {Iso, Rfc};
-
-static void time_format_changed(VariableItem* item) {
- ClockAppSettings* app = variable_item_get_context(item);
- uint8_t index = variable_item_get_current_value_index(item);
- variable_item_set_current_value_text(item, time_format_text[index]);
- app->clock_settings.time_format = time_format_value[index];
-}
-
-static void date_format_changed(VariableItem* item) {
- ClockAppSettings* app = variable_item_get_context(item);
- uint8_t index = variable_item_get_current_value_index(item);
- variable_item_set_current_value_text(item, date_format_text[index]);
- app->clock_settings.date_format = date_format_value[index];
-}
-
-static ClockAppSettings* alloc_settings() {
- ClockAppSettings* app = malloc(sizeof(ClockAppSettings));
- LOAD_CLOCK_SETTINGS(&app->clock_settings);
- app->gui = furi_record_open(RECORD_GUI);
- app->variable_item_list = variable_item_list_alloc();
- View* view = variable_item_list_get_view(app->variable_item_list);
- view_set_previous_callback(view, clock_app_settings_exit);
-
- VariableItem* item;
- uint8_t value_index;
-
- item = variable_item_list_add(
- app->variable_item_list, "Clock format", TIME_FORMAT_COUNT, time_format_changed, app);
- value_index = value_index_uint32(
- (uint32_t)(app->clock_settings.time_format), time_format_value, TIME_FORMAT_COUNT);
- //FURI_LOG_T(TAG, "Time format index: %u", value_index);
- variable_item_set_current_value_index(item, value_index);
- variable_item_set_current_value_text(item, time_format_text[value_index]);
-
- item = variable_item_list_add(
- app->variable_item_list, "Date format", DATE_FORMAT_COUNT, date_format_changed, app);
- value_index = value_index_uint32(
- (uint32_t)(app->clock_settings.date_format), date_format_value, DATE_FORMAT_COUNT);
- //FURI_LOG_T(TAG, "Date format index: %u", value_index);
- variable_item_set_current_value_index(item, value_index);
- variable_item_set_current_value_text(item, date_format_text[value_index]);
-
- app->view_dispatcher = view_dispatcher_alloc();
- view_dispatcher_enable_queue(app->view_dispatcher);
- view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
- view_dispatcher_add_view(app->view_dispatcher, 0, view);
- view_dispatcher_switch_to_view(app->view_dispatcher, 0);
-
- return app;
-}
-
-static void free_settings(ClockAppSettings* app) {
- view_dispatcher_remove_view(app->view_dispatcher, 0);
- variable_item_list_free(app->variable_item_list);
- view_dispatcher_free(app->view_dispatcher);
- furi_record_close(RECORD_GUI);
- SAVE_CLOCK_SETTINGS(&app->clock_settings);
- free(app);
-}
-
-extern int32_t clock_settings_app(void* p) {
- UNUSED(p);
- ClockAppSettings* app = alloc_settings();
- view_dispatcher_run(app->view_dispatcher);
- free_settings(app);
- return 0;
-}
diff --git a/applications/main/clock_app/clock_settings_filename.h b/applications/main/clock_app/clock_settings_filename.h
deleted file mode 100644
index 7097134dc..000000000
--- a/applications/main/clock_app/clock_settings_filename.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-#define CLOCK_SETTINGS_FILE_NAME ".clock.settings"