metroflip_scene_read_success.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, "Rav-Kav") == 0) {
  18. FURI_LOG_I(TAG, "Rav Kav card detected");
  19. furi_string_printf(str, "\e#Rav-Kav:\n");
  20. furi_string_cat_printf(str, "Balance: %.2f\n", (double)app->value);
  21. furi_string_cat_printf(str, "Currency: %s\n", app->currency);
  22. } else if(strcmp(app->card_type, "Metromoney") == 0) {
  23. FURI_LOG_I(TAG, "Metromoney card detected");
  24. furi_string_printf(
  25. str,
  26. "\e#Metromoney\nCard number: %lu\nBalance: %lu.%02u GEL",
  27. app->card_number,
  28. app->balance_lari,
  29. app->balance_tetri);
  30. } else {
  31. FURI_LOG_I(TAG, "Unknown card type");
  32. furi_string_printf(str, "\e#Unknown card\n");
  33. }
  34. widget_add_text_scroll_element(widget, 0, 0, 128, 64, furi_string_get_cstr(str));
  35. widget_add_button_element(
  36. widget, GuiButtonTypeRight, "Exit", metroflip_success_widget_callback, app);
  37. furi_string_free(str);
  38. view_dispatcher_switch_to_view(app->view_dispatcher, MetroflipViewWidget);
  39. }
  40. bool metroflip_scene_read_success_on_event(void* context, SceneManagerEvent event) {
  41. Metroflip* app = context;
  42. bool consumed = false;
  43. if(event.type == SceneManagerEventTypeCustom) {
  44. if(event.event == GuiButtonTypeLeft) {
  45. consumed = scene_manager_previous_scene(app->scene_manager);
  46. }
  47. } else if(event.type == SceneManagerEventTypeBack) {
  48. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, MetroflipSceneStart);
  49. consumed = true;
  50. }
  51. return consumed;
  52. }
  53. void metroflip_scene_read_success_on_exit(void* context) {
  54. Metroflip* app = context;
  55. widget_reset(app->widget);
  56. UNUSED(context);
  57. }