Skip to content

Commit 296928b

Browse files
committed
Update App Context to Add Views to Dispatcher + Add SUpport for Variable Item Lists
[Problem] Right now, I need to add views to the dispatcher in the main code, even though all of the properties are in the view when added to the app context. [Solution] Updated the app context to add views to the view dispatcher, and also added support for variable item lists. [Testing] Tested on device and confirmed everything still runs.
1 parent 7f004dc commit 296928b

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

src/app_context.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <gui/modules/menu.h>
2-
#include <gui/modules/submenu.h>
32
#include <gui/modules/popup.h>
3+
#include <gui/modules/submenu.h>
4+
#include <gui/modules/variable_item_list.h>
45

56
#include "tone_gen.h"
67
#include "app_context.h"
@@ -65,6 +66,29 @@ AppContextStatus addViewToAppContext(struct AppContext_t** context, struct View_
6566
return APP_CONTEXT_NOT_ENOUGH_VIEWS;
6667
}
6768
(*context)->activeViews[view->viewId] = view;
69+
switch(view->type) {
70+
case MENU:
71+
view_dispatcher_add_view(
72+
(*context)->view_dispatcher, view->viewId, menu_get_view(view->viewData));
73+
break;
74+
case SUBMENU:
75+
view_dispatcher_add_view(
76+
(*context)->view_dispatcher, view->viewId, submenu_get_view(view->viewData));
77+
break;
78+
case VIEW:
79+
view_dispatcher_add_view((*context)->view_dispatcher, view->viewId, view->viewData);
80+
break;
81+
case VARIABLE_ITEM_LIST:
82+
view_dispatcher_add_view(
83+
(*context)->view_dispatcher,
84+
view->viewId,
85+
variable_item_list_get_view(view->viewData));
86+
break;
87+
case POPUP:
88+
view_dispatcher_add_view(
89+
(*context)->view_dispatcher, view->viewId, popup_get_view(view->viewData));
90+
break;
91+
}
6892
return APP_CONTEXT_OK;
6993
}
7094

@@ -85,6 +109,9 @@ AppContextStatus freeAppContextViews(struct AppContext_t** context) {
85109
case VIEW:
86110
view_free(view->viewData);
87111
break;
112+
case VARIABLE_ITEM_LIST:
113+
variable_item_list_free(view->viewData);
114+
break;
88115
case POPUP:
89116
popup_free(view->viewData);
90117
break;

src/app_context.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef enum {
1111
MENU,
1212
SUBMENU,
1313
VIEW,
14+
VARIABLE_ITEM_LIST,
1415
POPUP,
1516
} ViewType;
1617

src/tone_gen.c

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <gui/canvas.h>
22
#include <gui/modules/menu.h>
33
#include <gui/modules/submenu.h>
4+
#include <gui/modules/variable_item_list.h>
45

56
/* generated by fbt from .png files in images folder */
67
#include <tone_gen_icons.h>
@@ -57,7 +58,17 @@ int setupViews(struct AppContext_t** appContext) {
5758
playbackView->viewId = ToneGenAppView_PlaybackView;
5859
playbackView->type = VIEW;
5960

60-
// Add views to the app context for management later
61+
FURI_LOG_I(TAG, "creating var-item-list view");
62+
struct View_t* variableItemListView = malloc(sizeof(struct View_t));
63+
FURI_LOG_I(TAG, "allocating view data");
64+
variableItemListView->viewData = variable_item_list_alloc();
65+
FURI_LOG_I(TAG, "setting view id");
66+
variableItemListView->viewId = ToneGenAppView_VariableItemList;
67+
FURI_LOG_I(TAG, "setting view type");
68+
variableItemListView->type = VARIABLE_ITEM_LIST;
69+
FURI_LOG_I(TAG, "moving on");
70+
71+
// Add views to the app context to be managed there
6172
FURI_LOG_I(TAG, "Adding views to app context");
6273
AppContextStatus result = addViewToAppContext(appContext, sharedMenuView);
6374
if(result != APP_CONTEXT_OK) {
@@ -77,18 +88,12 @@ int setupViews(struct AppContext_t** appContext) {
7788
return -1;
7889
}
7990

80-
// Add views to the view dispatcher for usage later
81-
FURI_LOG_I(TAG, "Adding views to view dispatcher");
82-
view_dispatcher_add_view(
83-
(*appContext)->view_dispatcher,
84-
sharedMenuView->viewId,
85-
menu_get_view(sharedMenuView->viewData));
86-
view_dispatcher_add_view(
87-
(*appContext)->view_dispatcher,
88-
submenuView->viewId,
89-
submenu_get_view(submenuView->viewData));
90-
view_dispatcher_add_view(
91-
(*appContext)->view_dispatcher, playbackView->viewId, playbackView->viewData);
91+
FURI_LOG_I(TAG, "Adding variable item list view");
92+
result = addViewToAppContext(appContext, variableItemListView);
93+
if(result != APP_CONTEXT_OK) {
94+
FURI_LOG_E(TAG, "There was a problem adding the view %d!", variableItemListView->viewId);
95+
return -1;
96+
}
9297

9398
// On the playback view, ensure we only allocate for the model once
9499
FURI_LOG_I(TAG, "allocating view model for playback");

src/tone_gen.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef enum {
1919
typedef enum {
2020
ToneGenAppView_SharedMenu,
2121
ToneGenAppView_Submenu,
22+
ToneGenAppView_VariableItemList,
2223
ToneGenAppView_PlaybackView,
2324
ToneGenAppView_Popup,
2425
ToneGenAppView_count

0 commit comments

Comments
 (0)