Kaynağa Gözat

Add invalid file popup

TollyH 2 yıl önce
ebeveyn
işleme
39f91d4340

+ 7 - 0
mfc_editor_app.c

@@ -47,6 +47,10 @@ MfcEditorApp* mfc_editor_app_alloc() {
     view_dispatcher_add_view(
         instance->view_dispatcher, MfcEditorAppViewSubmenu, submenu_get_view(instance->submenu));
 
+    instance->popup = popup_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher, MfcEditorAppViewPopup, popup_get_view(instance->popup));
+
     return instance;
 }
 
@@ -56,6 +60,9 @@ void mfc_editor_app_free(MfcEditorApp* instance) {
     view_dispatcher_remove_view(instance->view_dispatcher, MfcEditorAppViewSubmenu);
     submenu_free(instance->submenu);
 
+    view_dispatcher_remove_view(instance->view_dispatcher, MfcEditorAppViewPopup);
+    popup_free(instance->popup);
+
     view_dispatcher_free(instance->view_dispatcher);
     scene_manager_free(instance->scene_manager);
 

+ 11 - 0
mfc_editor_app_i.h

@@ -8,10 +8,12 @@
 #include <gui/scene_manager.h>
 #include <gui/view_dispatcher.h>
 
+#include <gui/modules/popup.h>
 #include <gui/modules/submenu.h>
 
 #include <nfc/nfc.h>
 #include <nfc/nfc_device.h>
+#include <nfc/protocols/mf_classic/mf_classic.h>
 
 #include <storage/storage.h>
 
@@ -25,6 +27,13 @@
 #define NFC_APP_EXTENSION ".nfc"
 #define NFC_APP_SHADOW_EXTENSION ".shd"
 
+enum MfcEditorCustomEvent {
+    // Reserve first 100 events for button types and indexes, starting from 0
+    MfcEditorCustomEventReserved = 100,
+
+    MfcEditorCustomEventViewExit,
+};
+
 struct MfcEditorApp {
     ViewDispatcher* view_dispatcher;
     SceneManager* scene_manager;
@@ -34,6 +43,7 @@ struct MfcEditorApp {
     DialogsApp* dialogs;
 
     Submenu* submenu;
+    Popup* popup;
 
     NfcDevice* nfc_device;
 
@@ -42,6 +52,7 @@ struct MfcEditorApp {
 
 typedef enum {
     MfcEditorAppViewSubmenu,
+    MfcEditorAppViewPopup,
 } MfcEditorAppView;
 
 bool mfc_editor_prompt_load_file(MfcEditorApp* instance);

+ 1 - 0
scenes/mfc_editor_scene_config.h

@@ -1,2 +1,3 @@
 ADD_SCENE(mfc_editor, start, Start)
 ADD_SCENE(mfc_editor, file_select, FileSelect)
+ADD_SCENE(mfc_editor, invalid_file, InvalidFile)

+ 4 - 5
scenes/mfc_editor_scene_file_select.c

@@ -7,14 +7,13 @@ void mfc_editor_scene_file_select_on_enter(void* context) {
         if(nfc_device_get_protocol(instance->nfc_device) == NfcProtocolMfClassic) {
             FURI_LOG_I(
                 TAG, "Valid MFC file selected at '%s'", furi_string_get_cstr(instance->file_path));
+            scene_manager_previous_scene(instance->scene_manager);
         } else {
-            FURI_LOG_I(
-                TAG,
-                "Invalid MFC file selected at '%s'",
-                furi_string_get_cstr(instance->file_path));
+            scene_manager_next_scene(instance->scene_manager, MfcEditorSceneInvalidFile);
         }
+    } else {
+        scene_manager_previous_scene(instance->scene_manager);
     }
-    scene_manager_previous_scene(instance->scene_manager);
 }
 
 bool mfc_editor_scene_file_select_on_event(void* context, SceneManagerEvent event) {

+ 38 - 0
scenes/mfc_editor_scene_invalid_file.c

@@ -0,0 +1,38 @@
+#include "../mfc_editor_app_i.h"
+
+void mfc_editor_scene_invalid_file_popup_callback(void* context) {
+    MfcEditorApp* instance = context;
+    view_dispatcher_send_custom_event(instance->view_dispatcher, MfcEditorCustomEventViewExit);
+}
+
+void mfc_editor_scene_invalid_file_on_enter(void* context) {
+    MfcEditorApp* instance = context;
+
+    Popup* popup = instance->popup;
+    popup_set_header(popup, "Invalid file", 63, 10, AlignCenter, AlignTop);
+    popup_set_text(popup, "Only MIFARE Classic files\nare supported", 63, 40, AlignCenter, AlignCenter);
+    popup_set_context(popup, instance);
+    popup_set_callback(popup, mfc_editor_scene_invalid_file_popup_callback);
+
+    view_dispatcher_switch_to_view(instance->view_dispatcher, MfcEditorAppViewPopup);
+}
+
+bool mfc_editor_scene_invalid_file_on_event(void* context, SceneManagerEvent event) {
+    MfcEditorApp* instance = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == MfcEditorCustomEventViewExit) {
+            consumed = scene_manager_search_and_switch_to_previous_scene(
+                instance->scene_manager, MfcEditorSceneStart);
+        }
+    }
+
+    return consumed;
+}
+
+void mfc_editor_scene_invalid_file_on_exit(void* context) {
+    MfcEditorApp* instance = context;
+
+    popup_reset(instance->popup);
+}