metroflip_scene_read_success.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../metroflip_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define TAG "Metroflip:Scene:ReadSuccess"
  4. void metroflip_success_widget_callback(GuiButtonType result, InputType type, void* context) {
  5. Metroflip* app = context;
  6. UNUSED(result);
  7. if(type == InputTypeShort) {
  8. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, MetroflipSceneStart);
  9. }
  10. }
  11. void metroflip_scene_read_success_on_enter(void* context) {
  12. Metroflip* app = context;
  13. Widget* widget = app->widget;
  14. dolphin_deed(DolphinDeedNfcReadSuccess);
  15. furi_string_reset(app->text_box_store);
  16. FuriString* str = furi_string_alloc();
  17. if(strcmp(app->card_type, "Metromoney") == 0) {
  18. FURI_LOG_I(TAG, "Metromoney card detected");
  19. furi_string_printf(
  20. str,
  21. "\e#Metromoney\nCard number: %lu\nBalance: %lu.%02u GEL",
  22. app->card_number,
  23. app->balance_lari,
  24. app->balance_tetri);
  25. } else {
  26. FURI_LOG_I(TAG, "Unknown card type");
  27. furi_string_printf(str, "\e#Unknown card\n");
  28. }
  29. widget_add_text_scroll_element(widget, 0, 0, 128, 64, furi_string_get_cstr(str));
  30. widget_add_button_element(
  31. widget, GuiButtonTypeRight, "Exit", metroflip_success_widget_callback, app);
  32. furi_string_free(str);
  33. view_dispatcher_switch_to_view(app->view_dispatcher, MetroflipViewWidget);
  34. }
  35. bool metroflip_scene_read_success_on_event(void* context, SceneManagerEvent event) {
  36. Metroflip* app = context;
  37. bool consumed = false;
  38. if(event.type == SceneManagerEventTypeCustom) {
  39. if(event.event == GuiButtonTypeLeft) {
  40. consumed = scene_manager_previous_scene(app->scene_manager);
  41. }
  42. } else if(event.type == SceneManagerEventTypeBack) {
  43. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, MetroflipSceneStart);
  44. consumed = true;
  45. }
  46. return consumed;
  47. }
  48. void metroflip_scene_read_success_on_exit(void* context) {
  49. Metroflip* app = context;
  50. widget_reset(app->widget);
  51. UNUSED(context);
  52. }