|
@@ -1,20 +1,25 @@
|
|
|
#include "totp_app_settings.h"
|
|
#include "totp_app_settings.h"
|
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
|
|
+#include <totp_icons.h>
|
|
|
#include "../../ui_controls.h"
|
|
#include "../../ui_controls.h"
|
|
|
#include "../../scene_director.h"
|
|
#include "../../scene_director.h"
|
|
|
#include "../token_menu/totp_scene_token_menu.h"
|
|
#include "../token_menu/totp_scene_token_menu.h"
|
|
|
#include "../../constants.h"
|
|
#include "../../constants.h"
|
|
|
#include "../../../services/config/config.h"
|
|
#include "../../../services/config/config.h"
|
|
|
|
|
+#include "../../../services/convert/convert.h"
|
|
|
#include "../../../lib/roll_value/roll_value.h"
|
|
#include "../../../lib/roll_value/roll_value.h"
|
|
|
#include "../../../types/nullable.h"
|
|
#include "../../../types/nullable.h"
|
|
|
|
|
|
|
|
-#define DIGIT_TO_CHAR(digit) ((digit) + '0')
|
|
|
|
|
|
|
+char* YES_NO_LIST[] = {"NO", "YES"};
|
|
|
|
|
|
|
|
-typedef enum { HoursInput, MinutesInput, ConfirmButton } Control;
|
|
|
|
|
|
|
+typedef enum { HoursInput, MinutesInput, Sound, Vibro, ConfirmButton } Control;
|
|
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
|
int8_t tz_offset_hours;
|
|
int8_t tz_offset_hours;
|
|
|
uint8_t tz_offset_minutes;
|
|
uint8_t tz_offset_minutes;
|
|
|
|
|
+ bool notification_sound;
|
|
|
|
|
+ bool notification_vibro;
|
|
|
|
|
+ uint8_t y_offset;
|
|
|
TotpNullable_uint16_t current_token_index;
|
|
TotpNullable_uint16_t current_token_index;
|
|
|
Control selected_control;
|
|
Control selected_control;
|
|
|
} SceneState;
|
|
} SceneState;
|
|
@@ -39,55 +44,87 @@ void totp_scene_app_settings_activate(
|
|
|
float off_dec = modff(plugin_state->timezone_offset, &off_int);
|
|
float off_dec = modff(plugin_state->timezone_offset, &off_int);
|
|
|
scene_state->tz_offset_hours = off_int;
|
|
scene_state->tz_offset_hours = off_int;
|
|
|
scene_state->tz_offset_minutes = 60.0f * off_dec;
|
|
scene_state->tz_offset_minutes = 60.0f * off_dec;
|
|
|
|
|
+ scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound;
|
|
|
|
|
+ scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void two_digit_to_str(int8_t num, char* str) {
|
|
static void two_digit_to_str(int8_t num, char* str) {
|
|
|
uint8_t index = 0;
|
|
uint8_t index = 0;
|
|
|
if(num < 0) {
|
|
if(num < 0) {
|
|
|
- str[0] = '-';
|
|
|
|
|
- index++;
|
|
|
|
|
|
|
+ str[index++] = '-';
|
|
|
num = -num;
|
|
num = -num;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
uint8_t d1 = (num / 10) % 10;
|
|
uint8_t d1 = (num / 10) % 10;
|
|
|
uint8_t d2 = num % 10;
|
|
uint8_t d2 = num % 10;
|
|
|
- str[index] = DIGIT_TO_CHAR(d1);
|
|
|
|
|
- str[index + 1] = DIGIT_TO_CHAR(d2);
|
|
|
|
|
- str[index + 2] = '\0';
|
|
|
|
|
|
|
+ str[index++] = CONVERT_DIGIT_TO_CHAR(d1);
|
|
|
|
|
+ str[index++] = CONVERT_DIGIT_TO_CHAR(d2);
|
|
|
|
|
+ str[index++] = '\0';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void totp_scene_app_settings_render(Canvas* const canvas, PluginState* plugin_state) {
|
|
|
|
|
- const SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
|
|
|
|
|
|
+void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state) {
|
|
|
|
|
+ const SceneState* scene_state = plugin_state->current_scene_state;
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, "Timezone offset");
|
|
|
|
|
|
|
+ canvas_draw_str_aligned(
|
|
|
|
|
+ canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset");
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
|
|
|
|
char tmp_str[4];
|
|
char tmp_str[4];
|
|
|
two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]);
|
|
two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]);
|
|
|
- canvas_draw_str_aligned(canvas, 0, 16, AlignLeft, AlignTop, "Hours:");
|
|
|
|
|
|
|
+ canvas_draw_str_aligned(canvas, 0, 16 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:");
|
|
|
ui_control_select_render(
|
|
ui_control_select_render(
|
|
|
canvas,
|
|
canvas,
|
|
|
36,
|
|
36,
|
|
|
- 10,
|
|
|
|
|
|
|
+ 10 - scene_state->y_offset,
|
|
|
SCREEN_WIDTH - 36,
|
|
SCREEN_WIDTH - 36,
|
|
|
&tmp_str[0],
|
|
&tmp_str[0],
|
|
|
scene_state->selected_control == HoursInput);
|
|
scene_state->selected_control == HoursInput);
|
|
|
|
|
|
|
|
two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]);
|
|
two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]);
|
|
|
- canvas_draw_str_aligned(canvas, 0, 34, AlignLeft, AlignTop, "Minutes:");
|
|
|
|
|
|
|
+ canvas_draw_str_aligned(
|
|
|
|
|
+ canvas, 0, 34 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:");
|
|
|
ui_control_select_render(
|
|
ui_control_select_render(
|
|
|
canvas,
|
|
canvas,
|
|
|
36,
|
|
36,
|
|
|
- 28,
|
|
|
|
|
|
|
+ 28 - scene_state->y_offset,
|
|
|
SCREEN_WIDTH - 36,
|
|
SCREEN_WIDTH - 36,
|
|
|
&tmp_str[0],
|
|
&tmp_str[0],
|
|
|
scene_state->selected_control == MinutesInput);
|
|
scene_state->selected_control == MinutesInput);
|
|
|
|
|
|
|
|
|
|
+ canvas_draw_icon(
|
|
|
|
|
+ canvas,
|
|
|
|
|
+ SCREEN_WIDTH_CENTER - 5,
|
|
|
|
|
+ SCREEN_HEIGHT - 5 - scene_state->y_offset,
|
|
|
|
|
+ &I_totp_arrow_bottom_10x5);
|
|
|
|
|
+
|
|
|
|
|
+ canvas_set_font(canvas, FontPrimary);
|
|
|
|
|
+ canvas_draw_str_aligned(
|
|
|
|
|
+ canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications");
|
|
|
|
|
+ canvas_set_font(canvas, FontSecondary);
|
|
|
|
|
+
|
|
|
|
|
+ canvas_draw_str_aligned(canvas, 0, 80 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
|
|
|
|
|
+ ui_control_select_render(
|
|
|
|
|
+ canvas,
|
|
|
|
|
+ 36,
|
|
|
|
|
+ 74 - scene_state->y_offset,
|
|
|
|
|
+ SCREEN_WIDTH - 36,
|
|
|
|
|
+ YES_NO_LIST[scene_state->notification_sound],
|
|
|
|
|
+ scene_state->selected_control == Sound);
|
|
|
|
|
+
|
|
|
|
|
+ canvas_draw_str_aligned(canvas, 0, 98 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
|
|
|
|
|
+ ui_control_select_render(
|
|
|
|
|
+ canvas,
|
|
|
|
|
+ 36,
|
|
|
|
|
+ 92 - scene_state->y_offset,
|
|
|
|
|
+ SCREEN_WIDTH - 36,
|
|
|
|
|
+ YES_NO_LIST[scene_state->notification_vibro],
|
|
|
|
|
+ scene_state->selected_control == Vibro);
|
|
|
|
|
+
|
|
|
ui_control_button_render(
|
|
ui_control_button_render(
|
|
|
canvas,
|
|
canvas,
|
|
|
SCREEN_WIDTH_CENTER - 24,
|
|
SCREEN_WIDTH_CENTER - 24,
|
|
|
- 50,
|
|
|
|
|
|
|
+ 115 - scene_state->y_offset,
|
|
|
48,
|
|
48,
|
|
|
13,
|
|
13,
|
|
|
"Confirm",
|
|
"Confirm",
|
|
@@ -114,10 +151,20 @@ bool totp_scene_app_settings_handle_event(
|
|
|
HoursInput,
|
|
HoursInput,
|
|
|
ConfirmButton,
|
|
ConfirmButton,
|
|
|
RollOverflowBehaviorStop);
|
|
RollOverflowBehaviorStop);
|
|
|
|
|
+ if(scene_state->selected_control > MinutesInput) {
|
|
|
|
|
+ scene_state->y_offset = 64;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ scene_state->y_offset = 0;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case InputKeyDown:
|
|
case InputKeyDown:
|
|
|
totp_roll_value_uint8_t(
|
|
totp_roll_value_uint8_t(
|
|
|
&scene_state->selected_control, 1, HoursInput, ConfirmButton, RollOverflowBehaviorStop);
|
|
&scene_state->selected_control, 1, HoursInput, ConfirmButton, RollOverflowBehaviorStop);
|
|
|
|
|
+ if(scene_state->selected_control > MinutesInput) {
|
|
|
|
|
+ scene_state->y_offset = 64;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ scene_state->y_offset = 0;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case InputKeyRight:
|
|
case InputKeyRight:
|
|
|
if(scene_state->selected_control == HoursInput) {
|
|
if(scene_state->selected_control == HoursInput) {
|
|
@@ -126,6 +173,10 @@ bool totp_scene_app_settings_handle_event(
|
|
|
} else if(scene_state->selected_control == MinutesInput) {
|
|
} else if(scene_state->selected_control == MinutesInput) {
|
|
|
totp_roll_value_uint8_t(
|
|
totp_roll_value_uint8_t(
|
|
|
&scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll);
|
|
&scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll);
|
|
|
|
|
+ } else if(scene_state->selected_control == Sound) {
|
|
|
|
|
+ scene_state->notification_sound = !scene_state->notification_sound;
|
|
|
|
|
+ } else if(scene_state->selected_control == Vibro) {
|
|
|
|
|
+ scene_state->notification_vibro = !scene_state->notification_vibro;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case InputKeyLeft:
|
|
case InputKeyLeft:
|
|
@@ -135,13 +186,23 @@ bool totp_scene_app_settings_handle_event(
|
|
|
} else if(scene_state->selected_control == MinutesInput) {
|
|
} else if(scene_state->selected_control == MinutesInput) {
|
|
|
totp_roll_value_uint8_t(
|
|
totp_roll_value_uint8_t(
|
|
|
&scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll);
|
|
&scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll);
|
|
|
|
|
+ } else if(scene_state->selected_control == Sound) {
|
|
|
|
|
+ scene_state->notification_sound = !scene_state->notification_sound;
|
|
|
|
|
+ } else if(scene_state->selected_control == Vibro) {
|
|
|
|
|
+ scene_state->notification_vibro = !scene_state->notification_vibro;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case InputKeyOk:
|
|
case InputKeyOk:
|
|
|
if(scene_state->selected_control == ConfirmButton) {
|
|
if(scene_state->selected_control == ConfirmButton) {
|
|
|
plugin_state->timezone_offset = (float)scene_state->tz_offset_hours +
|
|
plugin_state->timezone_offset = (float)scene_state->tz_offset_hours +
|
|
|
(float)scene_state->tz_offset_minutes / 60.0f;
|
|
(float)scene_state->tz_offset_minutes / 60.0f;
|
|
|
- totp_config_file_update_timezone_offset(plugin_state->timezone_offset);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ plugin_state->notification_method =
|
|
|
|
|
+ (scene_state->notification_sound ? NotificationMethodSound :
|
|
|
|
|
+ NotificationMethodNone) |
|
|
|
|
|
+ (scene_state->notification_vibro ? NotificationMethodVibro :
|
|
|
|
|
+ NotificationMethodNone);
|
|
|
|
|
+ totp_config_file_update_user_settings(plugin_state);
|
|
|
|
|
|
|
|
if(!scene_state->current_token_index.is_null) {
|
|
if(!scene_state->current_token_index.is_null) {
|
|
|
TokenMenuSceneContext generate_scene_context = {
|
|
TokenMenuSceneContext generate_scene_context = {
|