2021-07-22 06:05:07 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
2021-09-15 15:24:19 +00:00
|
|
|
void nfc_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-09-15 15:24:19 +00:00
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_delete_on_enter(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-08-17 15:08:13 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
|
2021-07-22 06:05:07 +00:00
|
|
|
|
|
|
|
// Setup Custom Widget view
|
2022-08-17 15:08:13 +00:00
|
|
|
string_t temp_str;
|
|
|
|
string_init(temp_str);
|
|
|
|
|
|
|
|
string_printf(temp_str, "\e#Delete %s?\e#", nfc->dev->dev_name);
|
2022-04-19 19:23:50 +00:00
|
|
|
widget_add_text_box_element(
|
2022-08-17 15:08:13 +00:00
|
|
|
nfc->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, string_get_cstr(temp_str), false);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_button_element(
|
2022-08-17 15:08:13 +00:00
|
|
|
nfc->widget, GuiButtonTypeLeft, "Cancel", nfc_scene_delete_widget_callback, nfc);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_button_element(
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
|
2022-08-17 15:08:13 +00:00
|
|
|
|
|
|
|
string_set_str(temp_str, "UID:");
|
|
|
|
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
|
|
|
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
widget_add_string_element(
|
|
|
|
nfc->widget, 64, 24, AlignCenter, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
NfcProtocol protocol = nfc->dev->dev_data.protocol;
|
|
|
|
if(protocol == NfcDeviceProtocolEMV) {
|
2022-08-17 15:08:13 +00:00
|
|
|
string_set_str(temp_str, "EMV bank card");
|
2022-04-19 15:23:58 +00:00
|
|
|
} else if(protocol == NfcDeviceProtocolMifareUl) {
|
2022-08-17 15:08:13 +00:00
|
|
|
string_set_str(temp_str, nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, true));
|
|
|
|
} else if(protocol == NfcDeviceProtocolMifareClassic) {
|
|
|
|
string_set_str(temp_str, nfc_mf_classic_type(nfc->dev->dev_data.mf_classic_data.type));
|
|
|
|
} else if(protocol == NfcDeviceProtocolMifareDesfire) {
|
|
|
|
string_set_str(temp_str, "MIFARE DESFire");
|
|
|
|
} else {
|
|
|
|
string_set_str(temp_str, "Unknown ISO tag");
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
widget_add_string_element(
|
|
|
|
nfc->widget, 64, 34, AlignCenter, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
|
|
|
widget_add_string_element(nfc->widget, 64, 44, AlignCenter, AlignTop, FontSecondary, "NFC-A");
|
|
|
|
string_clear(temp_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
2021-07-22 06:05:07 +00:00
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == GuiButtonTypeLeft) {
|
2022-08-17 15:08:13 +00:00
|
|
|
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
2021-07-22 06:05:07 +00:00
|
|
|
} else if(event.event == GuiButtonTypeRight) {
|
2022-05-27 11:19:21 +00:00
|
|
|
if(nfc_device_delete(nfc->dev, true)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
|
|
|
|
} else {
|
2021-07-28 14:52:00 +00:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
nfc->scene_manager, NfcSceneStart);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = true;
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
return consumed;
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_delete_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
widget_reset(nfc->widget);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|