flip_social_e.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // flip_social_e.h
  2. #ifndef FLIP_SOCIAL_E
  3. #define FLIP_SOCIAL_E
  4. #include <easy_flipper.h>
  5. #include <dialogs/dialogs.h>
  6. #include <storage/storage.h>
  7. #include <flipper_http.h>
  8. #include <input/input.h>
  9. #include <flip_social_icons.h> // add <(YOUR-APP)_icons.h> so the compiler treats the .pngs are icons
  10. #define TAG "FlipSocial"
  11. #define MAX_PRE_SAVED_MESSAGES 25 // Maximum number of pre-saved messages
  12. #define MAX_MESSAGE_LENGTH 100 // Maximum length of a message in the feed
  13. #define MAX_EXPLORE_USERS 50 // Maximum number of users to explore
  14. #define MAX_FRIENDS 50 // Maximum number of friends
  15. #define MAX_TOKENS 512 // Adjust based on expected JSON tokens
  16. #define MAX_FEED_ITEMS 128
  17. #define MAX_LINE_LENGTH 30
  18. // Define the submenu items for our Hello World application
  19. typedef enum
  20. {
  21. FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
  22. FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
  23. FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
  24. FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
  25. //
  26. FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
  27. FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
  28. FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
  29. FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
  30. FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
  31. //
  32. FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
  33. FlipSocialSubemnuComposeIndexStartIndex = 99, // starting index for the first pre saved message
  34. //
  35. FlipSocialSubmenuExploreIndex = 150, // click to go to the explore
  36. FlipSocialSubmenuExploreIndexStartIndex = 151, // starting index for the users to explore
  37. //
  38. FlipSocialSubmenuLoggedInIndexFriendsStart = 1000, // starting index for the friends
  39. } FlipSocialSubmenuIndex;
  40. typedef enum
  41. {
  42. ActionNone,
  43. ActionBack,
  44. ActionNext,
  45. ActionPrev,
  46. ActionFlip,
  47. } Action;
  48. Action action = ActionNone;
  49. // Define the ScriptPlaylist structure
  50. typedef struct
  51. {
  52. char *messages[MAX_PRE_SAVED_MESSAGES];
  53. size_t count;
  54. } PreSavedPlaylist;
  55. // Define views for our Hello World application
  56. typedef enum
  57. {
  58. FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
  59. FlipSocialViewLoggedOutLogin, // The login screen
  60. FlipSocialViewLoggedOutRegister, // The register screen
  61. FlipSocialViewLoggedOutAbout, // The about screen
  62. FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
  63. //
  64. FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
  65. FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
  66. FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
  67. FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
  68. FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
  69. FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  70. FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  71. FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
  72. FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
  73. //
  74. FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
  75. FlipSocialViewLoggedInProfile, // The profile screen
  76. FlipSocialViewLoggedInFeed, // The feed screen
  77. FlipSocialViewLoggedInCompose, // The compose screen
  78. FlipSocialViewLoggedInSettings, // The settings screen
  79. //
  80. FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
  81. FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
  82. FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
  83. FlipSocialViewLoggedInSettingsAbout, // The about screen
  84. FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
  85. FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  86. FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  87. FlipSocialViewLoggedInProcessCompose, // The dialog view to delete or send the clicked pre-saved text
  88. //
  89. FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
  90. //
  91. FlipSocialViewLoggedInExploreSubmenu, // The view after clicking the explore button
  92. FlipSocialViewLoggedInExploreProccess, // The view after clicking on a user in the explore screen
  93. FlipSocialViewLoggedInFriendsSubmenu, // The view after clicking the friends button on the profile screen
  94. FlipSocialViewLoggedInFriendsProcess, // The view after clicking on a friend in the friends screen
  95. } FlipSocialView;
  96. // Define the application structure
  97. typedef struct
  98. {
  99. ViewDispatcher *view_dispatcher; // Switches between our views
  100. Submenu *submenu_logged_out; // The application submenu (logged out)
  101. Submenu *submenu_logged_in; // The application submenu (logged in)
  102. Submenu *submenu_compose; // The application submenu (compose)
  103. Submenu *submenu_explore; // The application submenu (explore)
  104. Submenu *submenu_friends; // The application submenu (friends)
  105. Widget *widget_logged_out_about; // The about screen (logged out)
  106. Widget *widget_logged_in_about; // The about screen (logged in)
  107. View *view_process_login; // The screen displayed after clicking login
  108. View *view_process_register; // The screen displayed after clicking register
  109. View *view_process_feed; // Dialog for the feed screen
  110. View *view_process_compose; // Dialog for the compose screen (delete or send)
  111. View *view_process_explore; // Dialog for the explore screen (view user profile - add or delete friend)
  112. View *view_process_friends; // Dialog for the friends screen (view user profile - add or delete friend)
  113. VariableItemList *variable_item_list_logged_out_wifi_settings; // The wifi settings menu
  114. VariableItemList *variable_item_list_logged_out_login; // The login menu
  115. VariableItemList *variable_item_list_logged_out_register; // The register menu
  116. //
  117. VariableItemList *variable_item_list_logged_in_profile; // The profile menu
  118. VariableItemList *variable_item_list_logged_in_settings; // The settings menu
  119. VariableItemList *variable_item_list_logged_in_settings_wifi; // The wifi settings menu
  120. UART_TextInput *text_input_logged_out_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  121. UART_TextInput *text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
  122. UART_TextInput *text_input_logged_out_login_username; // Text input for username input on login screen
  123. UART_TextInput *text_input_logged_out_login_password; // Text input for password input on login screen
  124. UART_TextInput *text_input_logged_out_register_username; // Text input for username input on register screen
  125. UART_TextInput *text_input_logged_out_register_password; // Text input for password input on register screen
  126. UART_TextInput *text_input_logged_out_register_password_2; // Text input for password 2 input on register screen
  127. //
  128. UART_TextInput *text_input_logged_in_change_password; // Text input for password input on change password screen
  129. UART_TextInput *text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
  130. UART_TextInput *text_input_logged_in_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  131. UART_TextInput *text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
  132. VariableItem *variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
  133. VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
  134. VariableItem *variable_item_logged_out_login_username; // Reference to the username configuration item
  135. VariableItem *variable_item_logged_out_login_password; // Reference to the password configuration item
  136. VariableItem *variable_item_logged_out_login_button; // Reference to the login button configuration item
  137. VariableItem *variable_item_logged_out_register_username; // Reference to the username configuration item
  138. VariableItem *variable_item_logged_out_register_password; // Reference to the password configuration item
  139. VariableItem *variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
  140. VariableItem *variable_item_logged_out_register_button; // Reference to the register button configuration item
  141. //
  142. VariableItem *variable_item_logged_in_profile_username; // Reference to the username configuration item
  143. VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
  144. VariableItem *variable_item_logged_in_settings_about; // Reference to the about configuration item
  145. VariableItem *variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
  146. VariableItem *variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
  147. VariableItem *variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
  148. //
  149. VariableItem *variable_item_logged_in_profile_friends; // Reference to the friends configuration item
  150. //
  151. FuriPubSub *input_event_queue;
  152. FuriPubSubSubscription *input_event;
  153. PreSavedPlaylist pre_saved_messages; // Pre-saved messages for the feed screen
  154. char *is_logged_in; // Store the login status
  155. uint32_t is_logged_in_size; // Size of the login status buffer
  156. char *login_username_logged_in; // Store the entered login username
  157. char *login_username_logged_in_temp_buffer; // Temporary buffer for login username text input
  158. uint32_t login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
  159. char *wifi_ssid_logged_out; // Store the entered wifi ssid
  160. char *wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
  161. uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
  162. char *wifi_password_logged_out; // Store the entered wifi password
  163. char *wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
  164. uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
  165. char *login_username_logged_out; // Store the entered login username
  166. char *login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
  167. uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
  168. char *login_password_logged_out; // Store the entered login password
  169. char *login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
  170. uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
  171. char *register_username_logged_out; // Store the entered register username
  172. char *register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
  173. uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
  174. char *register_password_logged_out; // Store the entered register password
  175. char *register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
  176. uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
  177. char *register_password_2_logged_out; // Store the entered register password 2
  178. char *register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
  179. uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
  180. //
  181. char *change_password_logged_in; // Store the entered change password
  182. char *change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
  183. uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
  184. char *compose_pre_save_logged_in; // Store the entered add text
  185. char *compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
  186. uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
  187. char *wifi_ssid_logged_in; // Store the entered wifi ssid
  188. char *wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
  189. uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
  190. char *wifi_password_logged_in; // Store the entered wifi password
  191. char *wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
  192. uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
  193. } FlipSocialApp;
  194. // include strndup (otherwise NULL pointer dereference)
  195. char *strndup(const char *s, size_t n)
  196. {
  197. char *result;
  198. size_t len = strlen(s);
  199. if (n < len)
  200. len = n;
  201. result = (char *)malloc(len + 1);
  202. if (!result)
  203. return NULL;
  204. result[len] = '\0';
  205. return (char *)memcpy(result, s, len);
  206. }
  207. static FlipSocialApp *app_instance = NULL;
  208. typedef struct
  209. {
  210. char *usernames[MAX_FEED_ITEMS];
  211. char *messages[MAX_FEED_ITEMS];
  212. bool is_flipped[MAX_FEED_ITEMS];
  213. uint32_t ids[MAX_FEED_ITEMS];
  214. size_t count;
  215. size_t index;
  216. } FlipSocialFeed;
  217. typedef struct
  218. {
  219. char *usernames[MAX_EXPLORE_USERS];
  220. size_t count;
  221. size_t index;
  222. } FlipSocialModel;
  223. static FlipSocialModel flip_social_explore;
  224. static FlipSocialModel flip_social_friends;
  225. // temporary FlipSocialFeed object
  226. static FlipSocialFeed flip_social_feed = {
  227. .usernames = {"JBlanked", "FlipperKing", "FlipperQueen"},
  228. .messages = {"Welcome. This is a temp message. Either the feed didn't load or there was a server error.", "I am the Chosen Flipper.", "No one can flip like me."},
  229. .is_flipped = {false, false, true},
  230. .ids = {0, 1, 2},
  231. .count = 3,
  232. .index = 0};
  233. static void flip_social_logged_in_compose_pre_save_updated(void *context);
  234. static void flip_social_callback_submenu_choices(void *context, uint32_t index);
  235. #endif