nfc_scene_delete.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../nfc_i.h"
  2. void nfc_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
  3. Nfc* nfc = context;
  4. if(type == InputTypeShort) {
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  6. }
  7. }
  8. void nfc_scene_delete_on_enter(void* context) {
  9. Nfc* nfc = context;
  10. FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
  11. // Setup Custom Widget view
  12. FuriString* temp_str;
  13. temp_str = furi_string_alloc();
  14. furi_string_printf(temp_str, "\e#Delete %s?\e#", nfc->dev->dev_name);
  15. widget_add_text_box_element(
  16. nfc->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
  17. widget_add_button_element(
  18. nfc->widget, GuiButtonTypeLeft, "Cancel", nfc_scene_delete_widget_callback, nfc);
  19. widget_add_button_element(
  20. nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
  21. furi_string_set(temp_str, "UID:");
  22. for(size_t i = 0; i < nfc_data->uid_len; i++) {
  23. furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
  24. }
  25. widget_add_string_element(
  26. nfc->widget, 64, 24, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
  27. NfcProtocol protocol = nfc->dev->dev_data.protocol;
  28. if(protocol == NfcDeviceProtocolEMV) {
  29. furi_string_set(temp_str, "EMV bank card");
  30. } else if(protocol == NfcDeviceProtocolMifareUl) {
  31. furi_string_set(temp_str, nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, true));
  32. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  33. furi_string_set(temp_str, nfc_mf_classic_type(nfc->dev->dev_data.mf_classic_data.type));
  34. } else if(protocol == NfcDeviceProtocolMifareDesfire) {
  35. furi_string_set(temp_str, "MIFARE DESFire");
  36. } else {
  37. furi_string_set(temp_str, "Unknown ISO tag");
  38. }
  39. widget_add_string_element(
  40. nfc->widget, 64, 34, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
  41. widget_add_string_element(nfc->widget, 64, 44, AlignCenter, AlignTop, FontSecondary, "NFC-A");
  42. furi_string_free(temp_str);
  43. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  44. }
  45. bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
  46. Nfc* nfc = context;
  47. bool consumed = false;
  48. if(event.type == SceneManagerEventTypeCustom) {
  49. if(event.event == GuiButtonTypeLeft) {
  50. consumed = scene_manager_previous_scene(nfc->scene_manager);
  51. } else if(event.event == GuiButtonTypeRight) {
  52. if(nfc_device_delete(nfc->dev, true)) {
  53. scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
  54. } else {
  55. scene_manager_search_and_switch_to_previous_scene(
  56. nfc->scene_manager, NfcSceneStart);
  57. }
  58. consumed = true;
  59. }
  60. }
  61. return consumed;
  62. }
  63. void nfc_scene_delete_on_exit(void* context) {
  64. Nfc* nfc = context;
  65. widget_reset(nfc->widget);
  66. }