flip_social_e.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 the submenu items for our Hello World application
  14. typedef enum
  15. {
  16. FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
  17. FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
  18. FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
  19. FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
  20. //
  21. FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
  22. FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
  23. FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
  24. FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
  25. FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
  26. //
  27. FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
  28. FlipSocialSubemnuComposeIndexStartIndex = 99, // starting index for the first pre saved message
  29. } FlipSocialSubmenuIndex;
  30. typedef enum
  31. {
  32. ActionNone,
  33. ActionBack,
  34. ActionNext,
  35. ActionPrev,
  36. ActionFlip,
  37. } Action;
  38. Action action = ActionNone;
  39. // Define the ScriptPlaylist structure
  40. typedef struct
  41. {
  42. char *messages[MAX_PRE_SAVED_MESSAGES];
  43. size_t count;
  44. } PreSavedPlaylist;
  45. // Define views for our Hello World application
  46. typedef enum
  47. {
  48. FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
  49. FlipSocialViewLoggedOutLogin, // The login screen
  50. FlipSocialViewLoggedOutRegister, // The register screen
  51. FlipSocialViewLoggedOutAbout, // The about screen
  52. FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
  53. //
  54. FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
  55. FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
  56. FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
  57. FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
  58. FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
  59. FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  60. FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  61. FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
  62. FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
  63. //
  64. FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
  65. FlipSocialViewLoggedInProfile, // The profile screen
  66. FlipSocialViewLoggedInFeed, // The feed screen
  67. FlipSocialViewLoggedInCompose, // The compose screen
  68. FlipSocialViewLoggedInSettings, // The settings screen
  69. //
  70. FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
  71. FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
  72. FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
  73. FlipSocialViewLoggedInSettingsAbout, // The about screen
  74. FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
  75. FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  76. FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  77. FlipSocialViewLoggedInProcessCompose, // The dialog view to delete or send the clicked pre-saved text
  78. //
  79. FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
  80. } FlipSocialView;
  81. // Define the application structure
  82. typedef struct
  83. {
  84. ViewDispatcher *view_dispatcher; // Switches between our views
  85. Submenu *submenu_logged_out; // The application submenu (logged out)
  86. Submenu *submenu_logged_in; // The application submenu (logged in)
  87. Submenu *submenu_compose; // The application submenu (compose)
  88. Widget *widget_logged_out_about; // The about screen (logged out)
  89. Widget *widget_logged_in_about; // The about screen (logged in)
  90. View *view_process_login; // The screen displayed after clicking login
  91. View *view_process_register; // The screen displayed after clicking register
  92. View *view_process_feed; // Dialog for the feed screen
  93. View *view_process_compose; // Dialog for the compose screen (delete or send)
  94. VariableItemList *variable_item_list_logged_out_wifi_settings; // The wifi settings menu
  95. VariableItemList *variable_item_list_logged_out_login; // The login menu
  96. VariableItemList *variable_item_list_logged_out_register; // The register menu
  97. //
  98. VariableItemList *variable_item_list_logged_in_profile; // The profile menu
  99. VariableItemList *variable_item_list_logged_in_settings; // The settings menu
  100. VariableItemList *variable_item_list_logged_in_settings_wifi; // The wifi settings menu
  101. UART_TextInput *text_input_logged_out_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  102. UART_TextInput *text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
  103. UART_TextInput *text_input_logged_out_login_username; // Text input for username input on login screen
  104. UART_TextInput *text_input_logged_out_login_password; // Text input for password input on login screen
  105. UART_TextInput *text_input_logged_out_register_username; // Text input for username input on register screen
  106. UART_TextInput *text_input_logged_out_register_password; // Text input for password input on register screen
  107. UART_TextInput *text_input_logged_out_register_password_2; // Text input for password 2 input on register screen
  108. //
  109. UART_TextInput *text_input_logged_in_change_password; // Text input for password input on change password screen
  110. UART_TextInput *text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
  111. UART_TextInput *text_input_logged_in_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  112. UART_TextInput *text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
  113. VariableItem *variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
  114. VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
  115. VariableItem *variable_item_logged_out_login_username; // Reference to the username configuration item
  116. VariableItem *variable_item_logged_out_login_password; // Reference to the password configuration item
  117. VariableItem *variable_item_logged_out_login_button; // Reference to the login button configuration item
  118. VariableItem *variable_item_logged_out_register_username; // Reference to the username configuration item
  119. VariableItem *variable_item_logged_out_register_password; // Reference to the password configuration item
  120. VariableItem *variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
  121. VariableItem *variable_item_logged_out_register_button; // Reference to the register button configuration item
  122. //
  123. VariableItem *variable_item_logged_in_profile_username; // Reference to the username configuration item
  124. VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
  125. VariableItem *variable_item_logged_in_settings_about; // Reference to the about configuration item
  126. VariableItem *variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
  127. VariableItem *variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
  128. VariableItem *variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
  129. //
  130. FuriPubSub *input_event_queue;
  131. FuriPubSubSubscription *input_event;
  132. char *is_logged_in; // Store the login status
  133. uint32_t is_logged_in_size; // Size of the login status buffer
  134. char *login_username_logged_in; // Store the entered login username
  135. char *login_username_logged_in_temp_buffer; // Temporary buffer for login username text input
  136. uint32_t login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
  137. PreSavedPlaylist pre_saved_messages; // Pre-saved messages for the feed screen
  138. char *wifi_ssid_logged_out; // Store the entered wifi ssid
  139. char *wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
  140. uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
  141. char *wifi_password_logged_out; // Store the entered wifi password
  142. char *wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
  143. uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
  144. char *login_username_logged_out; // Store the entered login username
  145. char *login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
  146. uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
  147. char *login_password_logged_out; // Store the entered login password
  148. char *login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
  149. uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
  150. char *register_username_logged_out; // Store the entered register username
  151. char *register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
  152. uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
  153. char *register_password_logged_out; // Store the entered register password
  154. char *register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
  155. uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
  156. char *register_password_2_logged_out; // Store the entered register password 2
  157. char *register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
  158. uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
  159. //
  160. char *change_password_logged_in; // Store the entered change password
  161. char *change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
  162. uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
  163. char *compose_pre_save_logged_in; // Store the entered add text
  164. char *compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
  165. uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
  166. char *wifi_ssid_logged_in; // Store the entered wifi ssid
  167. char *wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
  168. uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
  169. char *wifi_password_logged_in; // Store the entered wifi password
  170. char *wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
  171. uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
  172. } FlipSocialApp;
  173. // include strndup (otherwise NULL pointer dereference)
  174. char *strndup(const char *s, size_t n)
  175. {
  176. char *result;
  177. size_t len = strlen(s);
  178. if (n < len)
  179. len = n;
  180. result = (char *)malloc(len + 1);
  181. if (!result)
  182. return NULL;
  183. result[len] = '\0';
  184. return (char *)memcpy(result, s, len);
  185. }
  186. #endif