Sfoglia il codice sorgente

Option to delete saved mrz info

Eric Betts 9 mesi fa
parent
commit
35ddab5d45

BIN
images/DolphinMafia_115x62.png


+ 26 - 0
passy.c

@@ -82,6 +82,32 @@ bool passy_save_mrz_info(Passy* passy) {
     return saved;
 }
 
+bool passy_delete_mrz_info(Passy* passy) {
+    furi_assert(passy);
+
+    bool deleted = false;
+    FuriString* file_path;
+    file_path = furi_string_alloc();
+
+    do {
+        furi_string_printf(
+            file_path, "%s/%s%s", STORAGE_APP_DATA_PATH_PREFIX, PASSY_MRZ_INFO_FILENAME, ".txt");
+
+        if(!storage_simply_remove(passy->storage, furi_string_get_cstr(file_path))) break;
+        memset(passy->passport_number, 0, sizeof(passy->passport_number));
+        memset(passy->date_of_birth, 0, sizeof(passy->date_of_birth));
+        memset(passy->date_of_expiry, 0, sizeof(passy->date_of_expiry));
+        deleted = true;
+    } while(false);
+
+    if(!deleted) {
+        dialog_message_show_storage_error(passy->dialogs, "Can not remove file");
+    }
+
+    furi_string_free(file_path);
+    return deleted;
+}
+
 bool passy_custom_event_callback(void* context, uint32_t event) {
     furi_assert(context);
     Passy* passy = context;

+ 1 - 0
passy.h

@@ -3,3 +3,4 @@
 typedef struct Passy Passy;
 
 bool passy_save_mrz_info(Passy* passy);
+bool passy_delete_mrz_info(Passy* passy);

+ 0 - 1
readme.md

@@ -8,6 +8,5 @@
  - Only requests DG1, the contents of the MRZ
 
 ## To do
- - Menu to delete cached MRZ
  - Support other country passports
  - Support DG2, the photo

+ 2 - 0
scenes/passy_scene_config.h

@@ -5,3 +5,5 @@ ADD_SCENE(passy, read_success, ReadSuccess)
 ADD_SCENE(passy, passport_number_input, PassportNumberInput)
 ADD_SCENE(passy, dob_input, DoBInput)
 ADD_SCENE(passy, doe_input, DoEInput)
+ADD_SCENE(passy, delete, Delete)
+ADD_SCENE(passy, delete_success, DeleteSuccess)

+ 50 - 0
scenes/passy_scene_delete.c

@@ -0,0 +1,50 @@
+#include "../passy_i.h"
+
+void passy_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
+    Passy* passy = context;
+    if(type == InputTypeShort) {
+        view_dispatcher_send_custom_event(passy->view_dispatcher, result);
+    }
+}
+
+void passy_scene_delete_on_enter(void* context) {
+    Passy* passy = context;
+
+    // Setup Custom Widget view
+    char temp_str[64];
+    snprintf(temp_str, sizeof(temp_str), "\e#Delete MRZ info?\e#");
+    widget_add_text_box_element(
+        passy->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, temp_str, false);
+    widget_add_button_element(
+        passy->widget, GuiButtonTypeLeft, "Back", passy_scene_delete_widget_callback, passy);
+    widget_add_button_element(
+        passy->widget, GuiButtonTypeRight, "Delete", passy_scene_delete_widget_callback, passy);
+
+    view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewWidget);
+}
+
+bool passy_scene_delete_on_event(void* context, SceneManagerEvent event) {
+    Passy* passy = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == GuiButtonTypeLeft) {
+            return scene_manager_previous_scene(passy->scene_manager);
+        } else if(event.event == GuiButtonTypeRight) {
+            if(passy_delete_mrz_info(passy)) {
+                scene_manager_next_scene(passy->scene_manager, PassySceneDeleteSuccess);
+            } else {
+                scene_manager_search_and_switch_to_previous_scene(
+                    passy->scene_manager, PassySceneMainMenu);
+            }
+            consumed = true;
+        }
+    }
+    return consumed;
+}
+
+void passy_scene_delete_on_exit(void* context) {
+    Passy* passy = context;
+
+    widget_reset(passy->widget);
+}

+ 40 - 0
scenes/passy_scene_delete_success.c

@@ -0,0 +1,40 @@
+#include "../passy_i.h"
+
+void passy_scene_delete_success_popup_callback(void* context) {
+    Passy* passy = context;
+    view_dispatcher_send_custom_event(passy->view_dispatcher, PassyCustomEventViewExit);
+}
+
+void passy_scene_delete_success_on_enter(void* context) {
+    Passy* passy = context;
+
+    // Setup view
+    Popup* popup = passy->popup;
+    popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
+    popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
+    popup_set_timeout(popup, 1500);
+    popup_set_context(popup, passy);
+    popup_set_callback(popup, passy_scene_delete_success_popup_callback);
+    popup_enable_timeout(popup);
+    view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewPopup);
+}
+
+bool passy_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
+    Passy* passy = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == PassyCustomEventViewExit) {
+            consumed = scene_manager_search_and_switch_to_previous_scene(
+                passy->scene_manager, PassySceneMainMenu);
+        }
+    }
+    return consumed;
+}
+
+void passy_scene_delete_success_on_exit(void* context) {
+    Passy* passy = context;
+
+    // Clear view
+    popup_reset(passy->popup);
+}

+ 15 - 0
scenes/passy_scene_main_menu.c

@@ -4,6 +4,7 @@
 
 enum SubmenuIndex {
     SubmenuIndexRead,
+    SubmenuIndexDeleteMRZInfo,
 };
 
 void passy_scene_main_menu_submenu_callback(void* context, uint32_t index) {
@@ -18,6 +19,15 @@ void passy_scene_main_menu_on_enter(void* context) {
 
     submenu_add_item(
         submenu, "Read", SubmenuIndexRead, passy_scene_main_menu_submenu_callback, passy);
+    if(strlen(passy->passport_number) > 0 && strlen(passy->date_of_birth) > 0 &&
+       strlen(passy->date_of_expiry) > 0) {
+        submenu_add_item(
+            submenu,
+            "Delete MRZ Info",
+            SubmenuIndexDeleteMRZInfo,
+            passy_scene_main_menu_submenu_callback,
+            passy);
+    }
 
     view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewMenu);
 }
@@ -38,6 +48,11 @@ bool passy_scene_main_menu_on_event(void* context, SceneManagerEvent event) {
                 scene_manager_next_scene(passy->scene_manager, PassyScenePassportNumberInput);
             }
             consumed = true;
+        } else if(event.event == SubmenuIndexDeleteMRZInfo) {
+            scene_manager_set_scene_state(
+                passy->scene_manager, PassySceneMainMenu, SubmenuIndexDeleteMRZInfo);
+            scene_manager_next_scene(passy->scene_manager, PassySceneDelete);
+            consumed = true;
         }
     }