flip_social.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. #ifndef FLIP_SOCIAL_H
  2. #define FLIP_SOCIAL_H
  3. #include <easy_flipper/easy_flipper.h>
  4. #include <dialogs/dialogs.h>
  5. #include <storage/storage.h>
  6. #include <flipper_http/flipper_http.h>
  7. #include <input/input.h>
  8. #include <flip_social_icons.h>
  9. #include <font/font.h>
  10. #define TAG "FlipSocial"
  11. #define VERSION "1.1"
  12. #define VERSION_TAG TAG " v" VERSION
  13. #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
  14. #define MAX_MESSAGE_LENGTH 100 // Maximum length of a message in the feed
  15. #define MAX_EXPLORE_USERS 50 // Maximum number of users to explore
  16. #define MAX_USER_LENGTH 32 // Maximum length of a username
  17. #define MAX_FRIENDS 50 // Maximum number of friends
  18. #define MAX_FEED_ITEMS 20 // Maximum number of feed items
  19. #define MAX_LINE_LENGTH 27
  20. #define MAX_MESSAGE_USERS 40 // Maximum number of users to display in the submenu
  21. #define MAX_MESSAGES 20 // Maximum number of meesages between each user
  22. #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/settings.bin"
  23. #define PRE_SAVED_MESSAGES_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/pre_saved_messages.txt"
  24. // Define the submenu items for our Hello World application
  25. typedef enum
  26. {
  27. FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
  28. FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
  29. //
  30. FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
  31. FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
  32. FlipSocialSubmenuLoggedInIndexUserSettings, // click to go to the user settings screen
  33. //
  34. FlipSocialSubmenuLoggedInIndexAbout, // click to go to the about screen
  35. FlipSocialSubmenuLoggedInIndexWifiSettings, // click to go to the wifi settings screen
  36. //
  37. FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
  38. FlipSocialSubmenuExploreIndex, // click to go to the explore
  39. FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
  40. FlipSocialSubmenuLoggedInIndexMessages, // click to go to the messages screen
  41. FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
  42. FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
  43. FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
  44. //
  45. FlipSocialSubmenuLoggedInIndexMessagesNewMessage, // click to add a new message
  46. //
  47. FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
  48. FlipSocialSubemnuComposeIndexStartIndex = 100, // starting index for the first pre saved message
  49. //
  50. FlipSocialSubmenuExploreIndexStartIndex = 200, // starting index for the users to explore
  51. //
  52. FlipSocialSubmenuLoggedInIndexFriendsStart = 400, // starting index for the friends
  53. //
  54. FlipSocialSubmenuLoggedInIndexMessagesUsersStart = 600, // starting index for the messages
  55. //
  56. FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart = 800, // click to select a user to message
  57. } FlipSocialSubmenuIndex;
  58. // Define the ScriptPlaylist structure
  59. typedef struct
  60. {
  61. char messages[MAX_PRE_SAVED_MESSAGES][MAX_MESSAGE_LENGTH];
  62. size_t count;
  63. size_t index;
  64. } PreSavedPlaylist;
  65. // Define a FlipSocialFeed individual item
  66. typedef struct
  67. {
  68. char username[MAX_USER_LENGTH];
  69. char message[MAX_MESSAGE_LENGTH];
  70. char date_created[MAX_LINE_LENGTH];
  71. bool is_flipped;
  72. int id;
  73. int flips;
  74. } FlipSocialFeedItem;
  75. typedef struct
  76. {
  77. int ids[MAX_FEED_ITEMS];
  78. size_t count;
  79. size_t index;
  80. int series_index;
  81. } FlipSocialFeedMini;
  82. typedef struct
  83. {
  84. char usernames[MAX_EXPLORE_USERS][MAX_USER_LENGTH];
  85. int count;
  86. int index;
  87. } FlipSocialModel;
  88. typedef struct
  89. {
  90. char usernames[MAX_MESSAGE_USERS][MAX_USER_LENGTH];
  91. int count;
  92. int index;
  93. } FlipSocialModel2;
  94. typedef struct
  95. {
  96. char usernames[MAX_MESSAGES][MAX_USER_LENGTH];
  97. char messages[MAX_MESSAGES][MAX_MESSAGE_LENGTH];
  98. int count;
  99. int index;
  100. } FlipSocialMessage;
  101. // Define views for our Hello World application
  102. typedef enum
  103. {
  104. FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
  105. FlipSocialViewLoggedOutLogin, // The login screen
  106. FlipSocialViewLoggedOutRegister, // The register screen
  107. FlipSocialViewLoggedOutAbout, // The about screen
  108. FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
  109. //
  110. FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
  111. FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
  112. FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
  113. FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
  114. FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
  115. FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  116. FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  117. FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
  118. FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
  119. //
  120. FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
  121. FlipSocialViewLoggedInProfile, // The profile screen
  122. FlipSocialViewLoggedInFeed, // The feed screen
  123. FlipSocialViewLoggedInCompose, // The compose screen
  124. FlipSocialViewLoggedInSettings, // The settings screen
  125. //
  126. FlipSocialViewLoggedInChangeBioInput, // Text input screen for bio input on profile screen
  127. FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
  128. FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
  129. //
  130. FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
  131. FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput, // Text input screen for new message input on messages screen
  132. FlipSocialViewLoggedInMessagesUserChoices, // the view after clicking [New Message] - select a user to message, then direct to input view
  133. FlipSocialViewLoggedInExploreInput, // Text input screen for explore input on explore screen
  134. FlipSocialViewLoggedInMessageUsersInput,
  135. //
  136. FlipSocialViewLoggedInSettingsAbout, // The about screen
  137. FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
  138. FlipSocialViewLoggedInSettingsUser, // The user settings screen
  139. FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  140. FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  141. //
  142. FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
  143. //
  144. FlipSocialViewLoggedInExploreSubmenu, // The view after clicking the explore button
  145. FlipSocialViewLoggedInFriendsSubmenu, // The view after clicking the friends button on the profile screen
  146. FlipSocialViewLoggedInMessagesSubmenu, // The view after clicking the messages button on the profile screen
  147. //
  148. FlipSocialViewLoading, // The loading screen
  149. //
  150. FlipSocialViewWidgetResult, // The text box that displays the random fact
  151. FlipSocialViewLoader, // The loader screen retrieves data from the internet
  152. //
  153. FlipSocialViewExploreDialog, // The dialog for the explore screen
  154. FlipSocialViewFriendsDialog, // The dialog for the friends screen
  155. FlipSocialViewMessagesDialog, // The dialog for the messages screen
  156. FlipSocialViewComposeDialog, // The dialog for the compose screen
  157. //
  158. FlipSocialViewTextInput, // The text input screen
  159. FlipSocialViewVariableItemList,
  160. //
  161. FlipSocialViewSubmenu,
  162. } FlipSocialView;
  163. // Define the application structure
  164. typedef struct
  165. {
  166. FlipperHTTP *fhttp; // The HTTP client
  167. View *view_loader;
  168. Widget *widget_result;
  169. //
  170. ViewDispatcher *view_dispatcher; // Switches between our views
  171. Submenu *submenu_logged_out; // The application submenu (logged out)
  172. Submenu *submenu_logged_in; // The application submenu (logged in)
  173. //
  174. Submenu *submenu;
  175. //
  176. Widget *widget_logged_out_about; // The about screen (logged out)
  177. Widget *widget_logged_in_about; // The about screen (logged in)
  178. VariableItemList *variable_item_list; // The main menu
  179. UART_TextInput *text_input; // The text input
  180. VariableItem *variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
  181. VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
  182. VariableItem *variable_item_logged_out_login_username; // Reference to the username configuration item
  183. VariableItem *variable_item_logged_out_login_password; // Reference to the password configuration item
  184. VariableItem *variable_item_logged_out_login_button; // Reference to the login button configuration item
  185. VariableItem *variable_item_logged_out_register_username; // Reference to the username configuration item
  186. VariableItem *variable_item_logged_out_register_password; // Reference to the password configuration item
  187. VariableItem *variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
  188. VariableItem *variable_item_logged_out_register_button; // Reference to the register button configuration item
  189. //
  190. VariableItem *variable_item_logged_in_profile_username; // Reference to the username configuration item
  191. VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
  192. VariableItem *variable_item_logged_in_profile_change_bio; // Reference to the change bio configuration item
  193. //
  194. VariableItem *variable_item_logged_in_settings_about; // Reference to the about configuration item
  195. VariableItem *variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
  196. VariableItem *variable_item_logged_in_settings_user; // Reference to the user settings configuration item
  197. VariableItem *variable_item_logged_in_user_settings_feed_type; // Reference to the feed type configuration item
  198. VariableItem *variable_item_logged_in_user_settings_notifications; // Reference to the notifications configuration item
  199. VariableItem *variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
  200. VariableItem *variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
  201. //
  202. VariableItem *variable_item_logged_in_profile_friends; // Reference to the friends configuration item
  203. //
  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 *change_bio_logged_in; // Store the entered bio
  211. char *change_bio_logged_in_temp_buffer; // Temporary buffer for bio text input
  212. uint32_t change_bio_logged_in_temp_buffer_size; // Size of the bio temporary buffer
  213. //
  214. char *wifi_ssid_logged_out; // Store the entered wifi ssid
  215. char *wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
  216. uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
  217. char *wifi_password_logged_out; // Store the entered wifi password
  218. char *wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
  219. uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
  220. char *login_username_logged_out; // Store the entered login username
  221. char *login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
  222. uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
  223. char *login_password_logged_out; // Store the entered login password
  224. char *login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
  225. uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
  226. char *register_username_logged_out; // Store the entered register username
  227. char *register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
  228. uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
  229. char *register_password_logged_out; // Store the entered register password
  230. char *register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
  231. uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
  232. char *register_password_2_logged_out; // Store the entered register password 2
  233. char *register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
  234. uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
  235. //
  236. char *change_password_logged_in; // Store the entered change password
  237. char *change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
  238. uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
  239. char *compose_pre_save_logged_in; // Store the entered add text
  240. char *compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
  241. uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
  242. char *wifi_ssid_logged_in; // Store the entered wifi ssid
  243. char *wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
  244. uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
  245. char *wifi_password_logged_in; // Store the entered wifi password
  246. char *wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
  247. uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
  248. //
  249. char *messages_new_message_logged_in; // Store the entered new message
  250. char *messages_new_message_logged_in_temp_buffer; // Temporary buffer for new message text input
  251. uint32_t messages_new_message_logged_in_temp_buffer_size; // Size of the new message temporary buffer
  252. char *message_user_choice_logged_in; // Store the entered message to send to the selected user
  253. char *message_user_choice_logged_in_temp_buffer; // Temporary buffer for message to send to the selected user
  254. uint32_t message_user_choice_logged_in_temp_buffer_size; // Size of the message to send to the selected user temporary buffer
  255. //
  256. char *explore_logged_in; // Store the entered explore
  257. char *explore_logged_in_temp_buffer; // Temporary buffer for explore text input
  258. uint32_t explore_logged_in_temp_buffer_size; // Size of the explore temporary buffer
  259. char *message_users_logged_in; // Store the entered message users
  260. char *message_users_logged_in_temp_buffer; // Temporary buffer for message users text input
  261. uint32_t message_users_logged_in_temp_buffer_size; // Size of the message users temporary buffer
  262. DialogEx *dialog_explore;
  263. DialogEx *dialog_friends;
  264. DialogEx *dialog_messages;
  265. DialogEx *dialog_compose;
  266. View *view_feed;
  267. char *explore_user_bio; // Store the bio of the selected user
  268. } FlipSocialApp;
  269. void flip_social_app_free(FlipSocialApp *app);
  270. extern FlipSocialModel *flip_social_friends; // Store the friends
  271. extern FlipSocialModel2 *flip_social_message_users; // Store the users that have sent messages to the logged in user
  272. extern FlipSocialModel *flip_social_explore; // Store the users to explore
  273. extern FlipSocialMessage *flip_social_messages; // Store the messages between the logged in user and the selected user
  274. extern FlipSocialFeedMini *flip_feed_info; // Store the feed info
  275. extern FlipSocialFeedItem *flip_feed_item; // Store a feed item
  276. extern FlipSocialApp *app_instance;
  277. extern bool flip_social_sent_login_request;
  278. extern bool flip_social_sent_register_request;
  279. extern bool flip_social_login_success;
  280. extern bool flip_social_register_success;
  281. extern bool flip_social_dialog_shown;
  282. extern bool flip_social_dialog_stop;
  283. extern bool flip_social_send_message;
  284. extern char *selected_message;
  285. extern char auth_headers[256];
  286. //
  287. extern char *flip_social_feed_type[];
  288. extern uint8_t flip_social_feed_type_index;
  289. //
  290. extern char *flip_social_notification_type[];
  291. extern uint8_t flip_social_notification_type_index;
  292. //
  293. extern bool went_to_friends;
  294. #endif