Initial lock menu rework

This commit is contained in:
Willy-JL
2023-03-23 03:33:13 +00:00
parent 217a37515c
commit 3b71b8596c
12 changed files with 256 additions and 96 deletions

View File

@@ -4,6 +4,8 @@
#include <toolbox/saved_struct.h>
#include <stdbool.h>
#include <loader/loader.h>
// #include <loader/loader_i.h>
#include <xtreme/settings.h>
#include "../desktop_i.h"
#include <desktop/desktop_settings.h>
@@ -26,7 +28,7 @@ void desktop_scene_lock_menu_on_enter(void* context) {
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
desktop_lock_menu_set_pin_state(desktop->lock_menu, desktop->settings.pin_code.length > 0);
desktop_lock_menu_set_idx(desktop->lock_menu, 0);
desktop_lock_menu_set_idx(desktop->lock_menu, 3);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
}
@@ -55,52 +57,59 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
}
} else if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
// case DesktopLockMenuEventPinLock:
// if(desktop->settings.pin_code.length > 0) {
// desktop_pin_lock(&desktop->settings);
// desktop_lock(desktop);
// } else {
// LoaderStatus status =
// loader_start(desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
// if(status == LoaderStatusOk) {
// scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 1);
// } else {
// FURI_LOG_E(TAG, "Unable to start desktop settings");
// }
// }
// consumed = true;
// break;
// case DesktopLockMenuEventPinLockShutdown:
// if(desktop->settings.pin_code.length > 0) {
// desktop_pin_lock(&desktop->settings);
// desktop_lock(desktop);
// Power* power = furi_record_open(RECORD_POWER);
// furi_delay_ms(666);
// power_off(power);
// furi_record_close(RECORD_POWER);
// } else {
// LoaderStatus status =
// loader_start(desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
// if(status == LoaderStatusOk) {
// scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 2);
// } else {
// FURI_LOG_E(TAG, "Unable to start desktop settings");
// }
// }
// consumed = true;
// break;
case DesktopLockMenuEventSettings:
// loader_start(desktop->loader, "Settings", NULL);
// view_dispatcher_switch_to_view(desktop->loader->view_dispatcher, LoaderMenuViewSettings);
consumed = true;
break;
case DesktopLockMenuEventLock:
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock(desktop);
consumed = true;
break;
case DesktopLockMenuEventPinLock:
if(desktop->settings.pin_code.length > 0) {
desktop_pin_lock(&desktop->settings);
desktop_lock(desktop);
} else {
LoaderStatus status =
loader_start(desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
if(status == LoaderStatusOk) {
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 1);
} else {
FURI_LOG_E(TAG, "Unable to start desktop settings");
}
}
case DesktopLockMenuEventXtreme:
loader_start(desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("apps/.Main/xtreme_app.fap"));
consumed = true;
break;
case DesktopLockMenuEventPinLockShutdown:
if(desktop->settings.pin_code.length > 0) {
desktop_pin_lock(&desktop->settings);
desktop_lock(desktop);
Power* power = furi_record_open(RECORD_POWER);
furi_delay_ms(666);
power_off(power);
furi_record_close(RECORD_POWER);
} else {
LoaderStatus status =
loader_start(desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
if(status == LoaderStatusOk) {
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 2);
} else {
FURI_LOG_E(TAG, "Unable to start desktop settings");
}
}
consumed = true;
break;
case DesktopLockMenuEventXtremeSettings:
loader_start(
desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("apps/.Main/xtreme_app.fap"));
break;
default:
break;
}

View File

@@ -39,11 +39,9 @@ typedef enum {
DesktopDebugEventSaveState,
DesktopDebugEventExit,
DesktopLockMenuEventSettings,
DesktopLockMenuEventLock,
DesktopLockMenuEventPinLock,
DesktopLockMenuEventPinLockShutdown,
DesktopLockMenuEventExit,
DesktopLockMenuEventXtremeSettings,
DesktopLockMenuEventXtreme,
DesktopAnimationEventCheckAnimation,
DesktopAnimationEventNewIdleAnimation,

View File

@@ -1,15 +1,28 @@
#include <furi.h>
#include <gui/elements.h>
#include <assets_icons.h>
#include <xtreme/settings.h>
#include <furi_hal_rtc.h>
#include "../desktop_i.h"
#include "desktop_view_lock_menu.h"
static const NotificationSequence sequence_note_c = {
&message_note_c5,
&message_delay_100,
&message_sound_off,
NULL,
};
typedef enum {
DesktopLockMenuIndexLefthandedMode,
DesktopLockMenuIndexSettings,
DesktopLockMenuIndexDarkMode,
DesktopLockMenuIndexLock,
DesktopLockMenuIndexPinLock,
DesktopLockMenuIndexPinLockShutdown,
DesktopLockMenuIndexXtremeSettings,
DesktopLockMenuIndexBluetooth,
DesktopLockMenuIndexXtreme,
DesktopLockMenuIndexBrightness,
DesktopLockMenuIndexVolume,
DesktopLockMenuIndexTotalCount
} DesktopLockMenuIndex;
@@ -42,36 +55,96 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
DesktopLockMenuViewModel* m = model;
canvas_set_color(canvas, ColorBlack);
canvas_draw_icon(canvas, -57, 0 + STATUS_BAR_Y_SHIFT, &I_DoorLeft_70x55);
canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55);
canvas_set_font(canvas, FontBatteryPercent);
int x, y, w, h;
bool selected, toggle;
bool enabled = false;
uint value = 0;
int total = 58;
const Icon* icon = NULL;
for(size_t i = 0; i < DesktopLockMenuIndexTotalCount; ++i) {
const char* str = NULL;
if(i == DesktopLockMenuIndexLock) {
str = "Lock";
} else if(i == DesktopLockMenuIndexPinLock) {
if(m->pin_is_set) {
str = "Lock with PIN";
} else {
str = "Set PIN";
}
} else if(i == DesktopLockMenuIndexPinLockShutdown) {
if(m->pin_is_set) {
str = "Lock with PIN + Off";
} else {
str = "Set PIN + Off";
}
} else if(i == DesktopLockMenuIndexXtremeSettings) {
str = "Xtreme Settings";
selected = m->idx == i;
toggle = i < 6;
if(toggle) {
x = 2 + 32 * (i / 2);
y = 2 + 32 * (i % 2);
w = 28;
h = 28;
enabled = false;
} else {
x = 98 + 16 * (i % 2);
y = 2;
w = 12;
h = 60;
value = 0;
}
if(str) //-V547
canvas_draw_str_aligned(
canvas, 64, 9 + (i * 12) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str);
switch(i) {
case DesktopLockMenuIndexLefthandedMode:
icon = &I_CC_LefthandedMode_16x16;
enabled = furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient);
break;
case DesktopLockMenuIndexSettings:
icon = &I_CC_Settings_16x16;
break;
case DesktopLockMenuIndexDarkMode:
icon = &I_CC_DarkMode_16x16;
enabled = XTREME_SETTINGS()->dark_mode;
break;
case DesktopLockMenuIndexLock:
icon = &I_CC_Lock_16x16;
break;
case DesktopLockMenuIndexBluetooth:
icon = &I_CC_Bluetooth_16x16;
enabled = m->lock_menu->bt->bt_settings.enabled;
break;
case DesktopLockMenuIndexXtreme:
icon = &I_CC_Xtreme_16x16;
break;
case DesktopLockMenuIndexBrightness:
icon = &I_Pin_star_7x7;
value = total - m->lock_menu->notification->settings.display_brightness * total;
break;
case DesktopLockMenuIndexVolume:
icon = &I_Volup_8x6;
value = total - m->lock_menu->notification->settings.speaker_volume * total;
break;
default:
break;
}
if(m->idx == i) elements_frame(canvas, 15, 1 + (i * 12) + STATUS_BAR_Y_SHIFT, 98, 15);
if(selected) {
elements_bold_rounded_frame(canvas, x - 1, y - 1, w + 1, h + 1);
} else {
canvas_draw_rframe(canvas, x, y, w, h, 5);
}
if(toggle) {
if(enabled) {
canvas_draw_rbox(canvas, x, y, w, h, 5);
canvas_set_color(canvas, ColorWhite);
}
canvas_draw_icon(canvas, x + (w - icon_get_width(icon)) / 2, y + (h - icon_get_height(icon)) / 2, icon);
if(enabled) {
canvas_set_color(canvas, ColorBlack);
}
} else {
canvas_draw_icon(canvas, x + (w - icon_get_width(icon)) / 2, y + (h - icon_get_height(icon)) / 2, icon);
canvas_set_color(canvas, ColorXOR);
canvas_draw_box(canvas, x + 1, y + 1 + value, w - 2, h - 2 - value);
if(selected) {
canvas_set_color(canvas, ColorBlack);
} else {
canvas_set_color(canvas, ColorWhite);
}
canvas_draw_dot(canvas, x + 1, y + 1);
canvas_draw_dot(canvas, x + 1, y + h - 2);
canvas_draw_dot(canvas, x + w - 2, y + 1);
canvas_draw_dot(canvas, x + w - 2, y + h - 2);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, x, y, w, h, 5);
}
}
}
@@ -86,47 +159,113 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
DesktopLockMenuView* lock_menu = context;
uint8_t idx = 0;
bool consumed = false;
bool update = false;
bool consumed = true;
with_view_model(
lock_menu->view,
DesktopLockMenuViewModel * model,
{
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
if(event->key == InputKeyUp) {
if(model->idx == 0) {
model->idx = DesktopLockMenuIndexTotalCount - 1;
} else {
model->idx = CLAMP(model->idx - 1, DesktopLockMenuIndexTotalCount - 1, 0);
if(model->idx < 6) {
if(event->key == InputKeyUp || event->key == InputKeyDown) {
if(model->idx % 2) {
model->idx--;
} else {
model->idx++;
}
} else if(event->key == InputKeyLeft) {
if(model->idx < 2) {
model->idx = 7;
} else {
model->idx -= 2;
}
} else if(event->key == InputKeyRight) {
if(model->idx >= 4) {
model->idx = 6;
} else {
model->idx += 2;
}
}
update = true;
consumed = true;
} else if(event->key == InputKeyDown) {
if(model->idx == DesktopLockMenuIndexTotalCount - 1) {
model->idx = 0;
} else {
model->idx = CLAMP(model->idx + 1, DesktopLockMenuIndexTotalCount - 1, 0);
} else {
if(event->key == InputKeyLeft) {
model->idx--;
} else if(event->key == InputKeyRight) {
if(model->idx >= 7) {
model->idx = 1;
} else {
model->idx++;
}
}
update = true;
consumed = true;
}
}
idx = model->idx;
},
update);
true);
if(event->key == InputKeyOk) {
if((idx == DesktopLockMenuIndexLock) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventLock, lock_menu->context);
} else if((idx == DesktopLockMenuIndexPinLock) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventPinLock, lock_menu->context);
} else if((idx == DesktopLockMenuIndexPinLockShutdown) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventPinLockShutdown, lock_menu->context);
} else if((idx == DesktopLockMenuIndexXtremeSettings) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventXtremeSettings, lock_menu->context);
UNUSED(idx);
if(event->key == InputKeyBack) {
consumed = false;
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
DesktopEvent event = 0;
switch(idx) {
case DesktopLockMenuIndexLefthandedMode:
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient)) {
furi_hal_rtc_reset_flag(FuriHalRtcFlagHandOrient);
} else {
furi_hal_rtc_set_flag(FuriHalRtcFlagHandOrient);
}
break;
case DesktopLockMenuIndexSettings:
event = DesktopLockMenuEventSettings;
break;
case DesktopLockMenuIndexDarkMode:
XTREME_SETTINGS()->dark_mode = !XTREME_SETTINGS()->dark_mode;
XTREME_SETTINGS_SAVE();
break;
case DesktopLockMenuIndexLock:
event = DesktopLockMenuEventLock;
break;
case DesktopLockMenuIndexBluetooth:
lock_menu->bt->bt_settings.enabled = !lock_menu->bt->bt_settings.enabled;
bt_settings_save(&lock_menu->bt->bt_settings);
break;
case DesktopLockMenuIndexXtreme:
event = DesktopLockMenuEventXtreme;
break;
default:
break;
}
if(event) {
lock_menu->callback(event, lock_menu->context);
}
} else if(idx >= 6) {
int8_t offset = 0;
if(event->key == InputKeyUp) {
offset = 1;
} else if(event->key == InputKeyDown) {
offset = -1;
}
if(offset) {
float value;
switch(idx) {
case DesktopLockMenuIndexBrightness:
value = lock_menu->notification->settings.display_brightness + 0.05 * offset;
lock_menu->notification->settings.display_brightness = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value);
notification_message_save_settings(lock_menu->notification);
notification_message(lock_menu->notification, &sequence_display_backlight_on);
break;
case DesktopLockMenuIndexVolume:
value = lock_menu->notification->settings.speaker_volume + 0.05 * offset;
lock_menu->notification->settings.speaker_volume = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value);
notification_message_save_settings(lock_menu->notification);
notification_message(lock_menu->notification, &sequence_note_c);
break;
default:
break;
}
}
}
consumed = true;
}
return consumed;
@@ -134,8 +273,15 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
DesktopLockMenuView* desktop_lock_menu_alloc() {
DesktopLockMenuView* lock_menu = malloc(sizeof(DesktopLockMenuView));
lock_menu->bt = furi_record_open(RECORD_BT);
lock_menu->notification = furi_record_open(RECORD_NOTIFICATION);
lock_menu->view = view_alloc();
view_allocate_model(lock_menu->view, ViewModelTypeLocking, sizeof(DesktopLockMenuViewModel));
with_view_model(
lock_menu->view,
DesktopLockMenuViewModel * model,
{ model->lock_menu = lock_menu; },
false);
view_set_context(lock_menu->view, lock_menu);
view_set_draw_callback(lock_menu->view, (ViewDrawCallback)desktop_lock_menu_draw_callback);
view_set_input_callback(lock_menu->view, desktop_lock_menu_input_callback);
@@ -147,5 +293,7 @@ void desktop_lock_menu_free(DesktopLockMenuView* lock_menu_view) {
furi_assert(lock_menu_view);
view_free(lock_menu_view->view);
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_BT);
free(lock_menu_view);
}

View File

@@ -2,6 +2,8 @@
#include <gui/view.h>
#include "desktop_events.h"
#include <bt/bt_service/bt.h>
#include <bt/bt_service/bt_i.h>
#define HINT_TIMEOUT 2
@@ -12,12 +14,15 @@ typedef void (*DesktopLockMenuViewCallback)(DesktopEvent event, void* context);
struct DesktopLockMenuView {
View* view;
DesktopLockMenuViewCallback callback;
NotificationApp* notification;
Bt* bt;
void* context;
};
typedef struct {
uint8_t idx;
bool pin_is_set;
DesktopLockMenuView* lock_menu;
} DesktopLockMenuViewModel;
void desktop_lock_menu_set_callback(

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 570 B