|
|
@@ -509,183 +509,6 @@ void flip_social_callback_draw_feed(Canvas *canvas, void *model)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// function to draw the dialog canvas
|
|
|
-void flip_social_canvas_draw_explore(Canvas *canvas, char *user_username, char *content)
|
|
|
-{
|
|
|
- canvas_set_color(canvas, ColorBlack);
|
|
|
- canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(canvas, 64, 5, AlignCenter, AlignCenter, user_username);
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
-
|
|
|
- draw_user_message(canvas, content, 0, 12);
|
|
|
-
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
- canvas_draw_icon(canvas, 0, 53, &I_ButtonLeft_4x7);
|
|
|
- canvas_draw_str_aligned(canvas, 9, 54, AlignLeft, AlignTop, "Remove");
|
|
|
- canvas_draw_icon(canvas, 98, 53, &I_ButtonRight_4x7);
|
|
|
- canvas_draw_str_aligned(canvas, 107, 54, AlignLeft, AlignTop, "Add");
|
|
|
-
|
|
|
- if (strlen(content) > 0)
|
|
|
- {
|
|
|
- last_explore_response = content;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// Callback function to handle the explore dialog
|
|
|
-void flip_social_callback_draw_explore(Canvas *canvas, void *model)
|
|
|
-{
|
|
|
- UNUSED(model);
|
|
|
- if (!canvas)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Canvas is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!app_instance)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "FlipSocialApp is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!flip_social_dialog_shown)
|
|
|
- {
|
|
|
- flip_social_dialog_shown = true;
|
|
|
- app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
|
|
|
- app_instance->input_event = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
|
|
|
- auth_headers_alloc();
|
|
|
- }
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], last_explore_response);
|
|
|
-
|
|
|
- // handle action
|
|
|
- switch (action)
|
|
|
- {
|
|
|
- case ActionNext:
|
|
|
- // add friend
|
|
|
- char add_payload[128];
|
|
|
- snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
|
|
|
- flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload);
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Added!");
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- case ActionPrev:
|
|
|
- // remove friend
|
|
|
- char remove_payload[128];
|
|
|
- snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
|
|
|
- flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Removed!");
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- case ActionBack:
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_dialog_stop = true;
|
|
|
- last_explore_response = "";
|
|
|
- flip_social_dialog_shown = false;
|
|
|
- flip_social_explore->index = 0;
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (flip_social_dialog_stop)
|
|
|
- {
|
|
|
- furi_pubsub_unsubscribe(app_instance->input_event_queue, app_instance->input_event);
|
|
|
- flip_social_dialog_shown = false;
|
|
|
- flip_social_dialog_stop = false;
|
|
|
- action = ActionNone;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// Callback function to handle the friends dialog
|
|
|
-void flip_social_callback_draw_friends(Canvas *canvas, void *model)
|
|
|
-{
|
|
|
- UNUSED(model);
|
|
|
- if (!canvas)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Canvas is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!app_instance)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "FlipSocialApp is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!flip_social_dialog_shown)
|
|
|
- {
|
|
|
- flip_social_dialog_shown = true;
|
|
|
- app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
|
|
|
- app_instance->input_event = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
|
|
|
- auth_headers_alloc();
|
|
|
- }
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], last_explore_response);
|
|
|
-
|
|
|
- // handle action
|
|
|
- switch (action)
|
|
|
- {
|
|
|
- case ActionNext:
|
|
|
- // add friend
|
|
|
- char add_payload[128];
|
|
|
- snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
|
|
|
- if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload))
|
|
|
- {
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Added!");
|
|
|
-
|
|
|
- // add the friend to the friends list
|
|
|
- flip_social_friends->usernames[flip_social_friends->count] = flip_social_friends->usernames[flip_social_friends->index];
|
|
|
- flip_social_friends->count++;
|
|
|
- if (!flip_social_update_friends())
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to update friends");
|
|
|
- }
|
|
|
- }
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- case ActionPrev:
|
|
|
- // remove friend
|
|
|
- char remove_payload[128];
|
|
|
- snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
|
|
|
- if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload))
|
|
|
- {
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Removed!");
|
|
|
-
|
|
|
- // remove the friend from the friends list
|
|
|
- for (int i = flip_social_friends->index; i < flip_social_friends->count - 1; i++)
|
|
|
- {
|
|
|
- flip_social_friends->usernames[i] = flip_social_friends->usernames[i + 1];
|
|
|
- }
|
|
|
- flip_social_friends->count--;
|
|
|
- if (!flip_social_update_friends())
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to update friends");
|
|
|
- }
|
|
|
- }
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- case ActionBack:
|
|
|
- canvas_clear(canvas);
|
|
|
- flip_social_dialog_stop = true;
|
|
|
- last_explore_response = "";
|
|
|
- flip_social_dialog_shown = false;
|
|
|
- flip_social_friends->index = 0;
|
|
|
- action = ActionNone;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (flip_social_dialog_stop)
|
|
|
- {
|
|
|
- furi_pubsub_unsubscribe(app_instance->input_event_queue, app_instance->input_event);
|
|
|
- flip_social_dialog_shown = false;
|
|
|
- flip_social_dialog_stop = false;
|
|
|
- action = ActionNone;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void flip_social_canvas_draw_user_message(Canvas *canvas, char *user_username, char *user_message, bool show_prev, bool show_next)
|
|
|
{
|
|
|
canvas_set_color(canvas, ColorBlack);
|