Explorar el Código

Merge pull request #22 from jblanked/dev_1.0

fix item index, add flip status, bump to 1.0.2
JBlanked hace 1 año
padre
commit
b9aee23f11

+ 17 - 3
alloc/alloc.c

@@ -340,7 +340,10 @@ static void flip_social_feed_draw_callback(Canvas *canvas, void *model)
     canvas_set_font_custom(canvas, FONT_SIZE_SMALL);
     canvas_set_font_custom(canvas, FONT_SIZE_SMALL);
     char flip_message[32];
     char flip_message[32];
     snprintf(flip_message, sizeof(flip_message), "%u %s", flip_feed_item->flips, flip_feed_item->flips == 1 ? "flip" : "flips");
     snprintf(flip_message, sizeof(flip_message), "%u %s", flip_feed_item->flips, flip_feed_item->flips == 1 ? "flip" : "flips");
-    canvas_draw_str(canvas, 0, 60, flip_message);                  // Draw the number of flips
+    canvas_draw_str(canvas, 0, 60, flip_message); // Draw the number of flips
+    char flip_status[16];
+    snprintf(flip_status, sizeof(flip_status), flip_feed_item->is_flipped ? "Unflip" : "Flip");
+    canvas_draw_str(canvas, 32, 60, flip_status);                  // Draw the flip status
     canvas_draw_str(canvas, 64, 60, flip_feed_item->date_created); // Draw the date
     canvas_draw_str(canvas, 64, 60, flip_feed_item->date_created); // Draw the date
 }
 }
 
 
@@ -393,7 +396,7 @@ static bool flip_social_feed_input_callback(InputEvent *event, void *context)
             flip_feed_info->series_index = atoi(series_index) + 1;
             flip_feed_info->series_index = atoi(series_index) + 1;
             char new_series_index[16];
             char new_series_index[16];
             snprintf(new_series_index, sizeof(new_series_index), "%d", flip_feed_info->series_index);
             snprintf(new_series_index, sizeof(new_series_index), "%d", flip_feed_info->series_index);
-            FURI_LOG_I(TAG, "New series index: %s", new_series_index);
+
             save_char("series_index", new_series_index);
             save_char("series_index", new_series_index);
 
 
             if (!flip_social_load_initial_feed(true, flip_feed_info->series_index))
             if (!flip_social_load_initial_feed(true, flip_feed_info->series_index))
@@ -464,6 +467,7 @@ static bool flip_social_feed_input_callback(InputEvent *event, void *context)
         }
         }
         // change the flip status
         // change the flip status
         flip_feed_item->is_flipped = !flip_feed_item->is_flipped;
         flip_feed_item->is_flipped = !flip_feed_item->is_flipped;
+
         // send post request to flip the message
         // send post request to flip the message
         if (app_instance->login_username_logged_in == NULL)
         if (app_instance->login_username_logged_in == NULL)
         {
         {
@@ -496,6 +500,13 @@ static bool flip_social_feed_input_callback(InputEvent *event, void *context)
         // switch view, free dialog, re-alloc dialog, switch back to dialog
         // switch view, free dialog, re-alloc dialog, switch back to dialog
         view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
         view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
         flip_social_free_feed_view();
         flip_social_free_feed_view();
+        // load feed item
+        if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
+        {
+            FURI_LOG_E(TAG, "Failed to load nexy feed post");
+            fhttp.state = ISSUE;
+            return false;
+        }
         if (feed_view_alloc())
         if (feed_view_alloc())
         {
         {
             view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInFeed);
             view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInFeed);
@@ -504,7 +515,6 @@ static bool flip_social_feed_input_callback(InputEvent *event, void *context)
         {
         {
             FURI_LOG_E(TAG, "Failed to allocate feed dialog");
             FURI_LOG_E(TAG, "Failed to allocate feed dialog");
         }
         }
-        furi_delay_ms(1000);
         flipper_http_deinit();
         flipper_http_deinit();
     }
     }
     return false;
     return false;
@@ -768,6 +778,8 @@ static void flip_social_feed_type_change(VariableItem *item)
 {
 {
     uint8_t index = variable_item_get_current_value_index(item);
     uint8_t index = variable_item_get_current_value_index(item);
     variable_item_set_current_value_text(item, flip_social_feed_type[index]);
     variable_item_set_current_value_text(item, flip_social_feed_type[index]);
+    flip_social_feed_type_index = index;
+    variable_item_set_current_value_index(item, index);
 
 
     // save the feed type
     // save the feed type
     save_char("user_feed_type", strstr(flip_social_feed_type[index], "Global") ? "global" : "friends");
     save_char("user_feed_type", strstr(flip_social_feed_type[index], "Global") ? "global" : "friends");
@@ -776,6 +788,8 @@ static void flip_social_notification_type_change(VariableItem *item)
 {
 {
     uint8_t index = variable_item_get_current_value_index(item);
     uint8_t index = variable_item_get_current_value_index(item);
     variable_item_set_current_value_text(item, flip_social_notification_type[index]);
     variable_item_set_current_value_text(item, flip_social_notification_type[index]);
+    flip_social_notification_type_index = index;
+    variable_item_set_current_value_index(item, index);
 
 
     // save the notification type
     // save the notification type
     save_char("user_notifications", strstr(flip_social_notification_type[index], "ON") ? "on" : "off");
     save_char("user_notifications", strstr(flip_social_notification_type[index], "ON") ? "on" : "off");

+ 1 - 1
application.fam

@@ -9,6 +9,6 @@ App(
     fap_icon_assets="assets",
     fap_icon_assets="assets",
     fap_author="JBlanked",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipSocial",
     fap_weburl="https://github.com/jblanked/FlipSocial",
-    fap_version="1.0.1",
+    fap_version="1.0.2",
     fap_description="Social media platform for the Flipper Zero.",
     fap_description="Social media platform for the Flipper Zero.",
 )
 )

+ 4 - 0
assets/CHANGELOG.md

@@ -1,3 +1,7 @@
+## 1.0.2
+- Fixed the Feed Type and Notifications toggles, in the User Settings, to work as intended. 
+- Added flip status to each feed post.
+
 ## 1.0.1  
 ## 1.0.1  
 - Fixed a freeze that occurred when sending a direct message.
 - Fixed a freeze that occurred when sending a direct message.
 
 

BIN
assets/flip-social-main-menu.png


+ 2 - 115
callback/flip_social_callback.c

@@ -613,121 +613,6 @@ static void compose_dialog_callback(DialogExResult result, void *context)
         }
         }
     }
     }
 }
 }
-void feed_dialog_callback(DialogExResult result, void *context)
-{
-    furi_assert(context);
-    FlipSocialApp *app = (FlipSocialApp *)context;
-    if (result == DialogExResultLeft) // Previous message
-    {
-        if (flip_feed_info->index > 0)
-        {
-            flip_feed_info->index--;
-        }
-        // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
-        flip_social_free_feed_view();
-        // load feed item
-        if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
-        {
-            FURI_LOG_E(TAG, "Failed to load nexy feed post");
-            fhttp.state = ISSUE;
-            return;
-        }
-        if (feed_view_alloc())
-        {
-            view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
-        }
-        else
-        {
-            FURI_LOG_E(TAG, "Failed to allocate feed dialog");
-            fhttp.state = ISSUE;
-            return;
-        }
-    }
-    else if (result == DialogExResultRight) // Next message
-    {
-        if (flip_feed_info->index < flip_feed_info->count - 1)
-        {
-            flip_feed_info->index++;
-        }
-        // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
-        flip_social_free_feed_view();
-        // load feed item
-        if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
-        {
-            FURI_LOG_E(TAG, "Failed to load nexy feed post");
-            fhttp.state = ISSUE;
-            return;
-        }
-        if (feed_view_alloc())
-        {
-            view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
-        }
-        else
-        {
-            FURI_LOG_E(TAG, "Failed to allocate feed dialog");
-            fhttp.state = ISSUE;
-            return;
-        }
-    }
-    else if (result == DialogExResultCenter) // Flip/Unflip
-    {
-        // Moved to above the is_flipped check
-        if (!flip_feed_item->is_flipped)
-        {
-            // increase the flip count
-            flip_feed_item->flips++;
-        }
-        else
-        {
-            // decrease the flip count
-            flip_feed_item->flips--;
-        }
-        // change the flip status
-        flip_feed_item->is_flipped = !flip_feed_item->is_flipped;
-        // send post request to flip the message
-        if (app_instance->login_username_logged_in == NULL)
-        {
-            FURI_LOG_E(TAG, "Username is NULL");
-            return;
-        }
-        if (!flipper_http_init(flipper_http_rx_callback, app_instance))
-        {
-            FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
-            return;
-        }
-        auth_headers_alloc();
-        char payload[256];
-        snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"post_id\":\"%u\"}", app_instance->login_username_logged_in, flip_feed_item->id);
-        if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/feed/flip/", auth_headers, payload))
-        {
-            // save feed item
-            char new_save[256];
-            snprintf(new_save, sizeof(new_save), "{\"id\":%u,\"username\":\"%s\",\"message\":\"%s\",\"flip_count\":%u,\"flipped\":%s}",
-                     flip_feed_item->id, flip_feed_item->username, flip_feed_item->message, flip_feed_item->flips, flip_feed_item->is_flipped ? "true" : "false");
-            // if (!flip_social_save_post((char *)flip_feed_item->id, new_save))
-            // {
-            //     FURI_LOG_E(TAG, "Failed to save the feed post");
-            //     fhttp.state = ISSUE;
-            //     return;
-            // }
-        }
-        // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
-        flip_social_free_feed_view();
-        if (feed_view_alloc())
-        {
-            view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
-        }
-        else
-        {
-            FURI_LOG_E(TAG, "Failed to allocate feed dialog");
-        }
-        furi_delay_ms(1000);
-        flipper_http_deinit();
-    }
-}
 
 
 static bool flip_social_get_user_info()
 static bool flip_social_get_user_info()
 {
 {
@@ -1700,6 +1585,8 @@ void flip_social_logged_in_user_settings_item_selected(void *context, uint32_t i
     {
     {
     case 0: // Feed Type
     case 0: // Feed Type
         break;
         break;
+    case 1: // Notifications
+        break;
     }
     }
 }
 }
 
 

+ 1 - 1
flip_social.h

@@ -10,7 +10,7 @@
 #include <font/font.h>
 #include <font/font.h>
 
 
 #define TAG "FlipSocial"
 #define TAG "FlipSocial"
-#define VERSION_TAG TAG " v1.0.1"
+#define VERSION_TAG TAG " v1.0.2"
 
 
 #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
 #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
 #define MAX_MESSAGE_LENGTH 100    // Maximum length of a message in the feed
 #define MAX_MESSAGE_LENGTH 100    // Maximum length of a message in the feed

+ 1 - 1
flip_storage/flip_social_storage.c

@@ -506,5 +506,5 @@ bool load_char(
     storage_file_free(file);
     storage_file_free(file);
     furi_record_close(RECORD_STORAGE);
     furi_record_close(RECORD_STORAGE);
 
 
-    return true;
+    return strlen(value) > 0;
 }
 }