nfc_magic_scene_magic_info.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "../nfc_magic_i.h"
  2. #include "../lib/magic/types.h"
  3. void nfc_magic_scene_magic_info_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. NfcMagic* nfc_magic = context;
  8. if(type == InputTypeShort) {
  9. view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
  10. }
  11. }
  12. void nfc_magic_scene_magic_info_on_enter(void* context) {
  13. NfcMagic* nfc_magic = context;
  14. Widget* widget = nfc_magic->widget;
  15. const char* card_type = nfc_magic_type(nfc_magic->dev->type);
  16. notification_message(nfc_magic->notifications, &sequence_success);
  17. widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
  18. widget_add_string_element(
  19. widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "Magic card detected");
  20. widget_add_string_element(widget, 3, 17, AlignLeft, AlignTop, FontSecondary, card_type);
  21. widget_add_button_element(
  22. widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
  23. widget_add_button_element(
  24. widget, GuiButtonTypeRight, "More", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
  25. // Setup and start worker
  26. view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
  27. }
  28. bool nfc_magic_scene_magic_info_on_event(void* context, SceneManagerEvent event) {
  29. NfcMagic* nfc_magic = context;
  30. bool consumed = false;
  31. if(event.type == SceneManagerEventTypeCustom) {
  32. if(event.event == GuiButtonTypeLeft) {
  33. consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
  34. } else if(event.event == GuiButtonTypeRight) {
  35. MagicType type = nfc_magic->dev->type;
  36. if(type == MagicTypeGen4) {
  37. scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneGen4Actions);
  38. consumed = true;
  39. } else {
  40. scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneActions);
  41. consumed = true;
  42. }
  43. }
  44. }
  45. return consumed;
  46. }
  47. void nfc_magic_scene_magic_info_on_exit(void* context) {
  48. NfcMagic* nfc_magic = context;
  49. widget_reset(nfc_magic->widget);
  50. }