Просмотр исходного кода

Implements move feature in editor

- This adds the ability to rearrange the playlist from within the app
- Updates the readme to show new feature
- Bumps the app version
acegoal07 1 год назад
Родитель
Сommit
18bd245697

+ 1 - 0
README.md

@@ -27,6 +27,7 @@ As i know these firmwares are supported and working if you know any more please
 - Rename playlist (Renames the selected playlist to the new name provided)
 - Add NFC Item (Adds the selected nfc item to the currently selected playlist)
 - Remove NFC Item (Opens a menu allowing you to select a line to remove from the playlist)
+- Move NFC Item (Allows you to change the order of the NFC items in the playlist)
 - View playlist content (Allows you to view the contents of the playlist)
 ## Feature ideas:
 - A function to allow you to add multiple nfc items to a playlist at once

+ 1 - 1
application.fam

@@ -8,7 +8,7 @@ App(
     fap_category="NFC",
     fap_author="@acegoal07",
     fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
-    fap_version="2.4",
+    fap_version="2.5",
     fap_icon_assets="assets",
     fap_icon="assets/Playlist_10px.png",
     fap_private_libs=[

+ 1 - 0
scenes/nfc_playlist_scene_config.h

@@ -4,6 +4,7 @@ ADD_SCENE(nfc_playlist, main_menu, MainMenu)
 ADD_SCENE(nfc_playlist, name_new_playlist, NameNewPlaylist)
 ADD_SCENE(nfc_playlist, nfc_add, NfcAdd)
 ADD_SCENE(nfc_playlist, nfc_remove, NfcRemove)
+ADD_SCENE(nfc_playlist, nfc_move_item, NfcMoveItem)
 ADD_SCENE(nfc_playlist, playlist_edit, PlaylistEdit)
 ADD_SCENE(nfc_playlist, playlist_rename, PlaylistRename)
 ADD_SCENE(nfc_playlist, playlist_select, PlaylistSelect)

+ 25 - 29
scenes/nfc_playlist_scene_nfc_move_item → scenes/nfc_playlist_scene_nfc_move_item.c

@@ -1,6 +1,3 @@
-// This is currently not working so its not included at the moment
-
-
 #include "../nfc_playlist.h"
 
 typedef enum {
@@ -48,8 +45,8 @@ void nfc_playlist_nfc_move_item_options_change_callback(VariableItem* item) {
 void nfc_playlist_nfc_move_item_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
 
-   selected_target = 0;
-   selected_destination = 0;
+   selected_target = 1;
+   selected_destination = 1;
 
    variable_item_list_set_header(nfc_playlist->variable_item_list, "Move NFC Item");
 
@@ -83,8 +80,6 @@ void nfc_playlist_nfc_move_item_scene_on_enter(void* context) {
 
 bool nfc_playlist_nfc_move_item_scene_on_event(void* context, SceneManagerEvent event) {
    NfcPlaylist* nfc_playlist = context;
-   UNUSED(nfc_playlist);
-
    bool consumed = false;
 
    if(event.type == SceneManagerEventTypeCustom) {
@@ -94,49 +89,50 @@ bool nfc_playlist_nfc_move_item_scene_on_event(void* context, SceneManagerEvent
             Stream* stream = file_stream_alloc(storage);
 
             if(file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.playlist_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
-               int counter = 0;
-               FuriString* tmp_target_line = furi_string_alloc();
+               FuriString* tmp_target_str = furi_string_alloc();
                FuriString* line = furi_string_alloc();
+               uint8_t counter = 0;
 
                while(stream_read_line(stream, line)) {
                   counter++;
-                  if (counter == selected_target) {
-                     furi_string_set(tmp_target_line, line);
+                  if(counter == selected_target) {
+                     furi_string_trim(line);
+                     furi_string_cat_printf(tmp_target_str, "%s", furi_string_get_cstr(line));
+                     furi_string_reset(line);
+                     stream_rewind(stream);
+                     counter = 0;
+                     break;
                   }
                }
-               furi_string_reset(line);
-               stream_rewind(stream);
 
-               counter = 0;
-               FuriString* tmp_new_playlist_order = furi_string_alloc();
+               FuriString* tmp_new_order_str = furi_string_alloc();
 
                while(stream_read_line(stream, line)) {
                   counter++;
-
                   if(counter == selected_target) {
                      continue;
                   }
-
                   furi_string_trim(line);
-
-                  if(!furi_string_empty(tmp_new_playlist_order)) {
-                     furi_string_cat_printf(tmp_new_playlist_order, "\n");
+                  if(!furi_string_empty(tmp_new_order_str)) {
+                     furi_string_cat_printf(tmp_new_order_str, "%s", "\n");
                   }
-                  if(counter == selected_destination) {
-                     furi_string_cat_printf(tmp_new_playlist_order, "%s\n%s", furi_string_get_cstr(tmp_target_line), furi_string_get_cstr(line));
+                  if(counter == selected_destination && counter == nfc_playlist->settings.playlist_length) {
+                     furi_string_cat_printf(tmp_new_order_str, "%s\n%s", furi_string_get_cstr(line), furi_string_get_cstr(tmp_target_str));
+                     furi_string_free(tmp_target_str);
                   } else {
-                     furi_string_cat_printf(tmp_new_playlist_order, "%s", furi_string_get_cstr(line));
+                     if(counter == selected_destination) {
+                        furi_string_cat_printf(tmp_new_order_str, "%s\n", furi_string_get_cstr(tmp_target_str));
+                        furi_string_reset(tmp_target_str);
+                     }
+                     furi_string_cat_printf(tmp_new_order_str, "%s", furi_string_get_cstr(line));
                   }
                }
 
-               FURI_LOG_RAW_I("New playlist order: %s\n", furi_string_get_cstr(tmp_new_playlist_order));
-
+               furi_string_free(line);
                stream_clean(stream);
-               stream_write_string(stream, tmp_new_playlist_order);
+               stream_write_string(stream, tmp_new_order_str);
+               furi_string_free(tmp_new_order_str);
                file_stream_close(stream);
-               furi_string_free(tmp_new_playlist_order);
-               furi_string_free(tmp_target_line);
-               furi_string_free(line);
             }
 
             stream_free(stream);

+ 14 - 0
scenes/nfc_playlist_scene_playlist_edit.c

@@ -6,6 +6,7 @@ typedef enum {
    NfcPlaylistFileEdit_RenamePlaylist,
    NfcPlaylistFileEdit_AddNfcItem,
    NfcPlaylistFileEdit_RemoveNfcItem,
+   NfcPlaylistFileEdit_MoveNfcItem,
    NfcPlaylistFileEdit_ViewPlaylistContent
 } NfcPlaylistFileEditMenuSelection;
 
@@ -64,6 +65,15 @@ void nfc_playlist_playlist_edit_scene_on_enter(void* context) {
       playlist_path_empty,
       "No\nplaylist\nselected");
 
+   submenu_add_lockable_item(
+      nfc_playlist->submenu,
+      "Move NFC Item",
+      NfcPlaylistFileEdit_MoveNfcItem,
+      nfc_playlist_playlist_edit_menu_callback,
+      nfc_playlist,
+      playlist_path_empty,
+      "No\nplaylist\nselected");
+
    submenu_add_lockable_item(
       nfc_playlist->submenu,
       "View Playlist Content",
@@ -101,6 +111,10 @@ bool nfc_playlist_playlist_edit_scene_on_event(void* context, SceneManagerEvent
             scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NfcRemove);
             consumed = true;
             break;
+         case NfcPlaylistFileEdit_MoveNfcItem:
+            scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NfcMoveItem);
+            consumed = true;
+            break;
          case NfcPlaylistFileEdit_ViewPlaylistContent:
             scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ViewPlaylistContent);
             consumed = true;