flip_social_e.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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>
  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_USER_LENGTH 32 // Maximum length of a username
  15. #define MAX_FRIENDS 50 // Maximum number of friends
  16. #define MAX_TOKENS 450 // Adjust based on expected JSON tokens
  17. #define MAX_FEED_ITEMS 41 // Maximum number of feed items
  18. #define MAX_LINE_LENGTH 30
  19. #define MAX_MESSAGE_USERS 20 // Maximum number of users to display in the submenu
  20. #define MAX_MESSAGES 20 // Maximum number of meesages between each user
  21. // Define the submenu items for our Hello World application
  22. typedef enum
  23. {
  24. FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
  25. FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
  26. FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
  27. FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
  28. //
  29. FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
  30. FlipSocialSubmenuExploreIndex, // click to go to the explore
  31. FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
  32. FlipSocialSubmenuLoggedInIndexMessages, // click to go to the messages screen
  33. FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
  34. FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
  35. FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
  36. //
  37. FlipSocialSubmenuLoggedInIndexMessagesNewMessage, // click to add a new message
  38. //
  39. FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
  40. FlipSocialSubemnuComposeIndexStartIndex = 100, // starting index for the first pre saved message
  41. //
  42. FlipSocialSubmenuExploreIndexStartIndex = 150, // starting index for the users to explore
  43. //
  44. FlipSocialSubmenuLoggedInIndexFriendsStart = 200, // starting index for the friends
  45. //
  46. FlipSocialSubmenuLoggedInIndexMessagesUsersStart = 250, // starting index for the messages
  47. //
  48. FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart = 300, // click to select a user to message
  49. } FlipSocialSubmenuIndex;
  50. typedef enum
  51. {
  52. ActionNone,
  53. ActionBack,
  54. ActionNext,
  55. ActionPrev,
  56. ActionFlip,
  57. } Action;
  58. static Action action = ActionNone;
  59. // Define the ScriptPlaylist structure
  60. typedef struct
  61. {
  62. char *messages[MAX_PRE_SAVED_MESSAGES];
  63. size_t count;
  64. } PreSavedPlaylist;
  65. typedef struct
  66. {
  67. char *usernames[MAX_FEED_ITEMS];
  68. char *messages[MAX_FEED_ITEMS];
  69. bool is_flipped[MAX_FEED_ITEMS];
  70. int ids[MAX_FEED_ITEMS];
  71. int flips[MAX_FEED_ITEMS];
  72. size_t count;
  73. size_t index;
  74. } FlipSocialFeed;
  75. typedef struct
  76. {
  77. char *usernames[MAX_EXPLORE_USERS];
  78. int count;
  79. int index;
  80. } FlipSocialModel;
  81. typedef struct
  82. {
  83. char *usernames[MAX_MESSAGE_USERS];
  84. int count;
  85. int index;
  86. } FlipSocialModel2;
  87. typedef struct
  88. {
  89. char *usernames[MAX_MESSAGES];
  90. char *messages[MAX_MESSAGES];
  91. int count;
  92. int index;
  93. } FlipSocialMessage;
  94. // Define views for our Hello World application
  95. typedef enum
  96. {
  97. FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
  98. FlipSocialViewLoggedOutLogin, // The login screen
  99. FlipSocialViewLoggedOutRegister, // The register screen
  100. FlipSocialViewLoggedOutAbout, // The about screen
  101. FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
  102. //
  103. FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
  104. FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
  105. FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
  106. FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
  107. FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
  108. FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  109. FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  110. FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
  111. FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
  112. //
  113. FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
  114. FlipSocialViewLoggedInProfile, // The profile screen
  115. FlipSocialViewLoggedInFeed, // The feed screen
  116. FlipSocialViewLoggedInCompose, // The compose screen
  117. FlipSocialViewLoggedInSettings, // The settings screen
  118. //
  119. FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
  120. FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
  121. //
  122. FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
  123. FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput, // Text input screen for new message input on messages screen
  124. FlipSocialViewLoggedInMessagesUserChoices, // the view after clicking [New Message] - select a user to message, then direct to input view
  125. //
  126. FlipSocialViewLoggedInSettingsAbout, // The about screen
  127. FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
  128. FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  129. FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  130. FlipSocialViewLoggedInProcessCompose, // The dialog view to delete or send the clicked pre-saved text
  131. //
  132. FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
  133. //
  134. FlipSocialViewLoggedInExploreSubmenu, // The view after clicking the explore button
  135. FlipSocialViewLoggedInExploreProccess, // The view after clicking on a user in the explore screen
  136. FlipSocialViewLoggedInFriendsSubmenu, // The view after clicking the friends button on the profile screen
  137. FlipSocialViewLoggedInFriendsProcess, // The view after clicking on a friend in the friends screen
  138. FlipSocialViewLoggedInMessagesSubmenu, // The view after clicking the messages button on the profile screen
  139. FlipSocialViewLoggedInMessagesProcess, // The view after clicking on a user in the messages screen
  140. } FlipSocialView;
  141. // Define the application structure
  142. typedef struct
  143. {
  144. ViewDispatcher *view_dispatcher; // Switches between our views
  145. Submenu *submenu_logged_out; // The application submenu (logged out)
  146. Submenu *submenu_logged_in; // The application submenu (logged in)
  147. Submenu *submenu_compose; // The application submenu (compose)
  148. Submenu *submenu_explore; // The application submenu (explore)
  149. Submenu *submenu_friends; // The application submenu (friends)
  150. Submenu *submenu_messages; // The application submenu (messages)
  151. Submenu *submenu_messages_user_choices; // The application submenu (messages user choices)
  152. Widget *widget_logged_out_about; // The about screen (logged out)
  153. Widget *widget_logged_in_about; // The about screen (logged in)
  154. View *view_process_login; // The screen displayed after clicking login
  155. View *view_process_register; // The screen displayed after clicking register
  156. View *view_process_feed; // Dialog for the feed screen
  157. View *view_process_compose; // Dialog for the compose screen (delete or send)
  158. View *view_process_explore; // Dialog for the explore screen (view user profile - add or delete friend)
  159. View *view_process_friends; // Dialog for the friends screen (view user profile - add or delete friend)
  160. View *view_process_messages; // Dialog for the messages screen (next, previous, send message)
  161. VariableItemList *variable_item_list_logged_out_wifi_settings; // The wifi settings menu
  162. VariableItemList *variable_item_list_logged_out_login; // The login menu
  163. VariableItemList *variable_item_list_logged_out_register; // The register menu
  164. //
  165. VariableItemList *variable_item_list_logged_in_profile; // The profile menu
  166. VariableItemList *variable_item_list_logged_in_settings; // The settings menu
  167. VariableItemList *variable_item_list_logged_in_settings_wifi; // The wifi settings menu
  168. UART_TextInput *text_input_logged_out_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  169. UART_TextInput *text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
  170. UART_TextInput *text_input_logged_out_login_username; // Text input for username input on login screen
  171. UART_TextInput *text_input_logged_out_login_password; // Text input for password input on login screen
  172. UART_TextInput *text_input_logged_out_register_username; // Text input for username input on register screen
  173. UART_TextInput *text_input_logged_out_register_password; // Text input for password input on register screen
  174. UART_TextInput *text_input_logged_out_register_password_2; // Text input for password 2 input on register screen
  175. //
  176. UART_TextInput *text_input_logged_in_change_password; // Text input for password input on change password screen
  177. UART_TextInput *text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
  178. UART_TextInput *text_input_logged_in_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  179. UART_TextInput *text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
  180. //
  181. UART_TextInput *text_input_logged_in_messages_new_message; // Text input for new message input on messages screen
  182. UART_TextInput *text_input_logged_in_messages_new_message_user_choices; //
  183. VariableItem *variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
  184. VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
  185. VariableItem *variable_item_logged_out_login_username; // Reference to the username configuration item
  186. VariableItem *variable_item_logged_out_login_password; // Reference to the password configuration item
  187. VariableItem *variable_item_logged_out_login_button; // Reference to the login button configuration item
  188. VariableItem *variable_item_logged_out_register_username; // Reference to the username configuration item
  189. VariableItem *variable_item_logged_out_register_password; // Reference to the password configuration item
  190. VariableItem *variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
  191. VariableItem *variable_item_logged_out_register_button; // Reference to the register button configuration item
  192. //
  193. VariableItem *variable_item_logged_in_profile_username; // Reference to the username configuration item
  194. VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
  195. VariableItem *variable_item_logged_in_settings_about; // Reference to the about configuration item
  196. VariableItem *variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
  197. VariableItem *variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
  198. VariableItem *variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
  199. //
  200. VariableItem *variable_item_logged_in_profile_friends; // Reference to the friends configuration item
  201. //
  202. FuriPubSub *input_event_queue;
  203. FuriPubSubSubscription *input_event;
  204. PreSavedPlaylist pre_saved_messages; // Pre-saved messages for the feed screen
  205. char *is_logged_in; // Store the login status
  206. uint32_t is_logged_in_size; // Size of the login status buffer
  207. char *login_username_logged_in; // Store the entered login username
  208. char *login_username_logged_in_temp_buffer; // Temporary buffer for login username text input
  209. uint32_t login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
  210. char *wifi_ssid_logged_out; // Store the entered wifi ssid
  211. char *wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
  212. uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
  213. char *wifi_password_logged_out; // Store the entered wifi password
  214. char *wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
  215. uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
  216. char *login_username_logged_out; // Store the entered login username
  217. char *login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
  218. uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
  219. char *login_password_logged_out; // Store the entered login password
  220. char *login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
  221. uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
  222. char *register_username_logged_out; // Store the entered register username
  223. char *register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
  224. uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
  225. char *register_password_logged_out; // Store the entered register password
  226. char *register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
  227. uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
  228. char *register_password_2_logged_out; // Store the entered register password 2
  229. char *register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
  230. uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
  231. //
  232. char *change_password_logged_in; // Store the entered change password
  233. char *change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
  234. uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
  235. char *compose_pre_save_logged_in; // Store the entered add text
  236. char *compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
  237. uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
  238. char *wifi_ssid_logged_in; // Store the entered wifi ssid
  239. char *wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
  240. uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
  241. char *wifi_password_logged_in; // Store the entered wifi password
  242. char *wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
  243. uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
  244. //
  245. char *messages_new_message_logged_in; // Store the entered new message
  246. char *messages_new_message_logged_in_temp_buffer; // Temporary buffer for new message text input
  247. uint32_t messages_new_message_logged_in_temp_buffer_size; // Size of the new message temporary buffer
  248. char *message_user_choice_logged_in; // Store the entered message to send to the selected user
  249. char *message_user_choice_logged_in_temp_buffer; // Temporary buffer for message to send to the selected user
  250. uint32_t message_user_choice_logged_in_temp_buffer_size; // Size of the message to send to the selected user temporary buffer
  251. } FlipSocialApp;
  252. static FlipSocialFeed *flip_social_feed = NULL; // Store the feed
  253. static FlipSocialModel *flip_social_friends = NULL; // Store the friends
  254. static FlipSocialModel2 *flip_social_message_users = NULL; // Store the users that have sent messages to the logged in user
  255. static FlipSocialModel *flip_social_explore = NULL; // Store the users to explore
  256. static FlipSocialMessage *flip_social_messages = NULL; // Store the messages between the logged in user and the selected user
  257. // include strndup (otherwise NULL pointer dereference)
  258. char *strndup(const char *s, size_t n)
  259. {
  260. char *result;
  261. size_t len = strlen(s);
  262. if (n < len)
  263. len = n;
  264. result = (char *)malloc(len + 1);
  265. if (!result)
  266. return NULL;
  267. result[len] = '\0';
  268. return (char *)memcpy(result, s, len);
  269. }
  270. static FlipSocialApp *app_instance = NULL;
  271. static void flip_social_logged_in_compose_pre_save_updated(void *context);
  272. static void flip_social_callback_submenu_choices(void *context, uint32_t index);
  273. #endif