mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-15 00:38:35 -07:00
Xfw app initial custom app manager interface
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
ADD_SCENE(xtreme_app, start, Start)
|
||||
ADD_SCENE(xtreme_app, graphics, Graphics)
|
||||
ADD_SCENE(xtreme_app, mainmenu, Mainmenu)
|
||||
ADD_SCENE(xtreme_app, mainmenu_add, MainmenuAdd)
|
||||
ADD_SCENE(xtreme_app, statusbar, Statusbar)
|
||||
ADD_SCENE(xtreme_app, protocols, Protocols)
|
||||
ADD_SCENE(xtreme_app, protocols_frequencies, ProtocolsFrequencies)
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
enum VarItemListIndex {
|
||||
VarItemListIndexApp,
|
||||
VarItemListIndexRemoveApp,
|
||||
VarItemListIndexAddApp,
|
||||
};
|
||||
|
||||
void xtreme_app_scene_mainmenu_var_item_list_callback(
|
||||
void* context,
|
||||
uint32_t index) {
|
||||
XtremeApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
static void xtreme_app_scene_mainmenu_app_changed(VariableItem* item) {
|
||||
XtremeApp* app = variable_item_get_context(item);
|
||||
app->mainmenu_app_index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, *CharList_get(app->mainmenu_apps, app->mainmenu_app_index));
|
||||
}
|
||||
|
||||
void xtreme_app_scene_mainmenu_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"App",
|
||||
CharList_size(app->mainmenu_apps),
|
||||
xtreme_app_scene_mainmenu_app_changed,
|
||||
app);
|
||||
app->mainmenu_app_index = 0;
|
||||
variable_item_set_current_value_index(item, app->mainmenu_app_index);
|
||||
if(CharList_size(app->mainmenu_apps)) {
|
||||
variable_item_set_current_value_text(item, *CharList_get(app->mainmenu_apps, app->mainmenu_app_index));
|
||||
} else {
|
||||
variable_item_set_current_value_text(item, "None");
|
||||
}
|
||||
|
||||
variable_item_list_add(var_item_list, "Remove App", 0, NULL, app);
|
||||
|
||||
variable_item_list_add(var_item_list, "Add App", 0, NULL, app);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
var_item_list, xtreme_app_scene_mainmenu_var_item_list_callback, app);
|
||||
|
||||
variable_item_list_set_selected_item(
|
||||
var_item_list,
|
||||
scene_manager_get_scene_state(
|
||||
app->scene_manager, XtremeAppSceneMainmenu));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_mainmenu_on_event(void* context, SceneManagerEvent event) {
|
||||
XtremeApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, XtremeAppSceneMainmenu, event.event);
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case VarItemListIndexRemoveApp:
|
||||
if(!CharList_size(app->mainmenu_apps)) break;
|
||||
char* value =
|
||||
*CharList_get(app->mainmenu_apps, app->mainmenu_app_index);
|
||||
CharList_it_t it;
|
||||
CharList_it(it, app->mainmenu_apps);
|
||||
while(!CharList_end_p(it)) {
|
||||
if(strcmp(*CharList_ref(it), value) == 0) {
|
||||
CharList_remove(app->mainmenu_apps, it);
|
||||
} else {
|
||||
CharList_next(it);
|
||||
}
|
||||
}
|
||||
app->save_mainmenu_apps = true;
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMainmenu);
|
||||
break;
|
||||
case VarItemListIndexAddApp:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMainmenuAdd);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_mainmenu_on_exit(void* context) {
|
||||
XtremeApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "../xtreme_app.h"
|
||||
|
||||
enum FileBrowserResult {
|
||||
FileBrowserResultOk,
|
||||
};
|
||||
|
||||
static bool xtreme_app_scene_mainmenu_add_file_browser_callback(
|
||||
FuriString* file_path,
|
||||
void* context,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name) {
|
||||
UNUSED(context);
|
||||
// #ifndef APP_FAP_LOADER
|
||||
// Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
// bool success = fap_loader_load_name_and_icon(file_path, storage, icon_ptr, item_name);
|
||||
// furi_record_close(RECORD_STORAGE);
|
||||
// #else
|
||||
UNUSED(file_path);
|
||||
UNUSED(icon_ptr);
|
||||
UNUSED(item_name);
|
||||
bool success = false;
|
||||
// #endif
|
||||
return success;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_mainmenu_add_on_enter(void* context) {
|
||||
XtremeApp* app = context;
|
||||
FuriString* file_path = furi_string_alloc_set_str(EXT_PATH("apps"));
|
||||
|
||||
const DialogsFileBrowserOptions browser_options = {
|
||||
.extension = ".fap",
|
||||
.skip_assets = true,
|
||||
.hide_ext = true,
|
||||
.item_loader_callback = xtreme_app_scene_mainmenu_add_file_browser_callback,
|
||||
.item_loader_context = app,
|
||||
.base_path = EXT_PATH("apps"),
|
||||
};
|
||||
|
||||
if(dialog_file_browser_show(app->dialogs, file_path, file_path, &browser_options)) {
|
||||
CharList_push_back(app->mainmenu_apps, strdup(furi_string_get_cstr(file_path)));
|
||||
app->save_mainmenu_apps = true;
|
||||
}
|
||||
|
||||
furi_string_free(file_path);
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, FileBrowserResultOk);
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_mainmenu_add_on_event(void* context, SceneManagerEvent event) {
|
||||
XtremeApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case FileBrowserResultOk:
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_app_scene_mainmenu_add_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
enum VarItemListIndex {
|
||||
VarItemListIndexGraphics,
|
||||
VarItemListIndexMainmenu,
|
||||
VarItemListIndexStatusbar,
|
||||
VarItemListIndexProtocols,
|
||||
VarItemListIndexDolphin,
|
||||
@@ -18,6 +19,7 @@ void xtreme_app_scene_start_on_enter(void* context) {
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
|
||||
variable_item_list_add(var_item_list, "Graphics", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Mainmenu", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Statusbar", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Protocols", 0, NULL, app);
|
||||
variable_item_list_add(var_item_list, "Dolphin", 0, NULL, app);
|
||||
@@ -45,6 +47,9 @@ bool xtreme_app_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
case VarItemListIndexGraphics:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneGraphics);
|
||||
break;
|
||||
case VarItemListIndexMainmenu:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMainmenu);
|
||||
break;
|
||||
case VarItemListIndexStatusbar:
|
||||
scene_manager_next_scene(app->scene_manager, XtremeAppSceneStatusbar);
|
||||
break;
|
||||
|
||||
@@ -125,6 +125,7 @@ static bool xtreme_app_back_event_callback(void* context) {
|
||||
XtremeApp* xtreme_app_alloc() {
|
||||
XtremeApp* app = malloc(sizeof(XtremeApp));
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
@@ -260,6 +261,7 @@ void xtreme_app_free(XtremeApp* app) {
|
||||
furi_string_free(app->version_tag);
|
||||
|
||||
// Records
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(app);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
@@ -27,11 +28,16 @@ ARRAY_DEF(CharList, char*)
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
DialogsApp* dialogs;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
VariableItemList* var_item_list;
|
||||
TextInput* text_input;
|
||||
Popup* popup;
|
||||
uint asset_pack;
|
||||
CharList_t asset_packs;
|
||||
CharList_t mainmenu_apps;
|
||||
uint8_t mainmenu_app_index;
|
||||
bool subghz_use_defaults;
|
||||
FrequencyList_t subghz_static_frequencies;
|
||||
uint8_t subghz_static_index;
|
||||
@@ -42,9 +48,8 @@ typedef struct {
|
||||
bool subghz_bypass;
|
||||
int dolphin_level;
|
||||
char device_name[NAMECHANGER_TEXT_STORE_SIZE];
|
||||
uint asset_pack;
|
||||
CharList_t asset_packs;
|
||||
FuriString* version_tag;
|
||||
bool save_mainmenu_apps;
|
||||
bool save_subghz;
|
||||
bool save_subghz_frequencies;
|
||||
bool save_level;
|
||||
|
||||
Reference in New Issue
Block a user