flipp_pomodoro_app.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "flipp_pomodoro_app_i.h"
  2. enum
  3. {
  4. CustomEventConsumed = true,
  5. CustomEventNotConsumed = false,
  6. };
  7. static bool flipp_pomodoro_app_back_event_callback(void *ctx)
  8. {
  9. furi_assert(ctx);
  10. FlippPomodoroApp *app = ctx;
  11. return scene_manager_handle_back_event(app->scene_manager);
  12. };
  13. static void flipp_pomodoro_app_tick_event_callback(void *ctx)
  14. {
  15. furi_assert(ctx);
  16. FlippPomodoroApp *app = ctx;
  17. scene_manager_handle_custom_event(app->scene_manager, FlippPomodoroAppCustomEventTimerTick);
  18. };
  19. static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
  20. {
  21. furi_assert(ctx);
  22. FlippPomodoroApp *app = ctx;
  23. switch (event)
  24. {
  25. case FlippPomodoroAppCustomEventStageSkip:
  26. flipp_pomodoro__toggle_stage(app->state);
  27. return CustomEventConsumed;
  28. case FlippPomodoroAppCustomEventStageComplete:
  29. if (app->state->stage == Work)
  30. {
  31. // REGISTER a deed on work stage complete to get an acheivement
  32. DOLPHIN_DEED(DolphinDeedPluginGameWin);
  33. };
  34. flipp_pomodoro__toggle_stage(app->state);
  35. notification_message(app->notification_app, stage_start_notification_sequence_map[app->state->stage]);
  36. return CustomEventConsumed;
  37. default:
  38. break;
  39. }
  40. return scene_manager_handle_custom_event(app->scene_manager, event);
  41. };
  42. FlippPomodoroApp *flipp_pomodoro_app_alloc()
  43. {
  44. FlippPomodoroApp *app = malloc(sizeof(FlippPomodoroApp));
  45. app->state = flipp_pomodoro__new();
  46. app->scene_manager = scene_manager_alloc(&flipp_pomodoro_scene_handlers, app);
  47. app->gui = furi_record_open(RECORD_GUI);
  48. app->notification_app = furi_record_open(RECORD_NOTIFICATION);
  49. app->view_dispatcher = view_dispatcher_alloc();
  50. view_dispatcher_enable_queue(app->view_dispatcher);
  51. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  52. view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipp_pomodoro_app_custom_event_callback);
  53. view_dispatcher_set_tick_event_callback(app->view_dispatcher, flipp_pomodoro_app_tick_event_callback, 1000);
  54. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  55. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, flipp_pomodoro_app_back_event_callback);
  56. app->timer_view = flipp_pomodoro_view_timer_alloc();
  57. view_dispatcher_add_view(
  58. app->view_dispatcher,
  59. FlippPomodoroAppViewTimer,
  60. flipp_pomodoro_view_timer_get_view(app->timer_view));
  61. scene_manager_next_scene(app->scene_manager, FlippPomodoroSceneTimer);
  62. return app;
  63. };
  64. void flipp_pomodoro_app_free(FlippPomodoroApp *app)
  65. {
  66. view_dispatcher_remove_view(app->view_dispatcher, FlippPomodoroAppViewTimer);
  67. view_dispatcher_free(app->view_dispatcher);
  68. scene_manager_free(app->scene_manager);
  69. flipp_pomodoro_view_timer_free(app->timer_view);
  70. flipp_pomodoro__destroy(app->state);
  71. free(app);
  72. furi_record_close(RECORD_GUI);
  73. furi_record_close(RECORD_NOTIFICATION);
  74. };
  75. int32_t flipp_pomodoro_app(void *p)
  76. {
  77. UNUSED(p);
  78. FlippPomodoroApp *app = flipp_pomodoro_app_alloc();
  79. view_dispatcher_run(app->view_dispatcher);
  80. flipp_pomodoro_app_free(app);
  81. return 0;
  82. };