acegoal07 пре 1 година
родитељ
комит
86dd162941
9 измењених фајлова са 83 додато и 7 уклоњено
  1. 3 2
      README.md
  2. 8 3
      nfc_playlist.c
  3. 2 0
      nfc_playlist.h
  4. 2 1
      nfc_playlist_i.h
  5. 11 0
      scences/file_edit.c
  6. 1 0
      scences/file_edit.h
  7. 41 0
      scences/name_new_file.c
  8. 10 0
      scences/name_new_file.h
  9. 5 1
      scences/nfc_select.c

+ 3 - 2
README.md

@@ -22,10 +22,11 @@ As i know these firmwares are supported and working if you know any more please
 - LED indicator (Whether or not the LED's will be on)
 - Reset settings (Puts all the settings back to the defaults)
 ## Playlist editor:
+- Create PLaylist (Creates a new playlist with the given name)
 - Delete playlist (Deletes the selected playlist)
 - Rename playlist (Renames the selected playlist to the new name provided)
-- View playlist content (Allows you to view the items in the playlist)
-- Add NFC Item (Allows you to select a NFC item to add to the end of playlist)
+- View playlist content (Allows you to view the contents of the playlist)
+- Add NFC Item (Adds the selected nfc item to the currently selected playlist)
 ## Development plans/ideas:
 Things i would like to add:
 - Ability to remove cards from the playlist

+ 8 - 3
nfc_playlist.c

@@ -10,7 +10,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
    nfc_playlist_file_rename_scene_on_enter,
    nfc_playlist_confirm_delete_scene_on_enter,
    nfc_playlist_view_playlist_content_scene_on_enter,
-   nfc_playlist_nfc_select_scene_on_enter
+   nfc_playlist_nfc_select_scene_on_enter,
+   nfc_playlist_name_new_file_scene_on_enter
 };
 
 static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
@@ -22,7 +23,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE
    nfc_playlist_file_rename_scene_on_event,
    nfc_playlist_confirm_delete_scene_on_event,
    nfc_playlist_view_playlist_content_scene_on_event,
-   nfc_playlist_nfc_select_scene_on_event
+   nfc_playlist_nfc_select_scene_on_event,
+   nfc_playlist_name_new_file_scene_on_event
 };
 
 static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
@@ -34,7 +36,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
    nfc_playlist_file_rename_scene_on_exit,
    nfc_playlist_confirm_delete_scene_on_exit,
    nfc_playlist_view_playlist_content_scene_on_exit,
-   nfc_playlist_nfc_select_scene_on_exit
+   nfc_playlist_nfc_select_scene_on_exit,
+   nfc_playlist_name_new_file_scene_on_exit
 };
 
 static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
@@ -92,6 +95,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget));
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent, widget_get_view(nfc_playlist->widget));
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect, file_browser_get_view(nfc_playlist->nfc_file_browser));
+   view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile, text_input_get_view(nfc_playlist->text_input));
 
    Storage* storage = furi_record_open(RECORD_STORAGE);
    if (!storage_common_exists(storage, PLAYLIST_DIR)) {
@@ -114,6 +118,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect);
+   view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile);
 
    scene_manager_free(nfc_playlist->scene_manager);
    view_dispatcher_free(nfc_playlist->view_dispatcher);

+ 2 - 0
nfc_playlist.h

@@ -26,6 +26,7 @@ typedef enum {
    NfcPlaylistView_ConfirmDelete,
    NfcPlaylistView_ViewPlaylistContent,
    NfcPlaylistView_NfcSelect,
+   NfcPlaylistView_NameNewFile
 } NfcPlayScenesView;
 
 typedef enum {
@@ -38,6 +39,7 @@ typedef enum {
    NfcPlaylistScene_ConfirmDelete,
    NfcPlaylistScene_ViewPlaylistContent,
    NfcPlaylistScene_NfcSelect,
+   NfcPlaylistScene_NameNewFile,
    NfcPlaylistScene_count
 } NfcPlaylistScene;
 

+ 2 - 1
nfc_playlist_i.h

@@ -7,4 +7,5 @@
 #include "scences/file_rename.h"
 #include "scences/confirm_delete.h"
 #include "scences/view_playlist_content.h"
-#include "scences/nfc_select.h"
+#include "scences/nfc_select.h"
+#include "scences/name_new_file.h"

+ 11 - 0
scences/file_edit.c

@@ -11,6 +11,13 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
 
    submenu_set_header(nfc_playlist->submenu, "Edit Playlist");
 
+   submenu_add_item(
+      nfc_playlist->submenu,
+      "Create Playlist",
+      NfcPlaylistMenuSelection_CreatePlaylist,
+      nfc_playlist_file_edit_menu_callback,
+      nfc_playlist);
+
    submenu_add_lockable_item(
       nfc_playlist->submenu,
       "Delete Playlist",
@@ -55,6 +62,10 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
    bool consumed = false;
    if(event.type == SceneManagerEventTypeCustom) {
       switch(event.event) {
+         case NfcPlaylistMenuSelection_CreatePlaylist:
+            scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NameNewFile);
+            consumed = true;
+            break;
          case NfcPlaylistMenuSelection_DeletePlaylist:
             scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete);
             consumed = true;

+ 1 - 0
scences/file_edit.h

@@ -9,6 +9,7 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
 void nfc_playlist_file_edit_scene_on_exit(void* context);
 
 typedef enum {
+   NfcPlaylistMenuSelection_CreatePlaylist,
    NfcPlaylistMenuSelection_DeletePlaylist,
    NfcPlaylistMenuSelection_RenamePlaylist,
    NfcPlaylistMenuSelection_ViewPlaylistContent,

+ 41 - 0
scences/name_new_file.c

@@ -0,0 +1,41 @@
+#include "nfc_playlist.h"
+#include "scences/name_new_file.h"
+
+void nfc_playlist_name_new_file_menu_callback(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   Storage* storage = furi_record_open(RECORD_STORAGE);
+   FuriString* file_name = furi_string_alloc();
+   furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
+   FURI_LOG_I("Creating file: %s", furi_string_get_cstr(file_name));
+   if (!storage_common_exists(storage, furi_string_get_cstr(file_name))) {
+      File* file = storage_file_alloc(storage);
+      storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW);
+      storage_file_close(file);
+      storage_file_free(file);
+   }
+   furi_string_move(nfc_playlist->settings.file_path, file_name);
+   furi_string_free(file_name);
+   furi_record_close(RECORD_STORAGE);
+   scene_manager_previous_scene(nfc_playlist->scene_manager);
+}
+
+void nfc_playlist_name_new_file_scene_on_enter(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   nfc_playlist->text_input_output = (char*)malloc(50);
+   text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
+   text_input_set_minimum_length(nfc_playlist->text_input, 1);
+   text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
+   view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
+}
+
+bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event) {
+   UNUSED(context);
+   UNUSED(event);
+   return false;
+}
+
+void nfc_playlist_name_new_file_scene_on_exit(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   text_input_reset(nfc_playlist->text_input);
+   free(nfc_playlist->text_input_output);
+}

+ 10 - 0
scences/name_new_file.h

@@ -0,0 +1,10 @@
+#pragma once
+#include <furi.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/text_input.h>
+#include <storage/storage.h>
+
+void nfc_playlist_name_new_file_scene_on_enter(void* context);
+bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event);
+void nfc_playlist_name_new_file_scene_on_exit(void* context);

+ 5 - 1
scences/nfc_select.c

@@ -15,7 +15,11 @@ void nfc_playlist_nfc_select_menu_callback(void* context) {
       furi_string_push_back(playlist_content, buffer[i]);
    }
 
-   furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
+   if (read_count > 0) {
+      furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
+   } else {
+      furi_string_printf(playlist_content, "%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
+   }
 
    storage_file_write(file, furi_string_get_cstr(playlist_content), sizeof(char) * furi_string_utf8_length(playlist_content));