| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #include <furi.h>
- #include <gui/gui.h>
- #include <gui/elements.h>
- #include <gui/view.h>
- #include "flipp_pomodoro_info_view.h"
- // Auto-compiled icons
- #include "flipp_pomodoro_icons.h"
- enum
- {
- ViewInputConsumed = true,
- ViewInputNotConusmed = false,
- };
- struct FlippPomodoroInfoView
- {
- View *view;
- FlippPomodoroInfoViewUserActionCb resume_timer_cb;
- void *user_action_cb_ctx;
- };
- typedef struct
- {
- uint8_t pomodoros_completed;
- FlippPomodoroInfoViewMode mode;
- } FlippPomodoroInfoViewModel;
- static void flipp_pomodoro_info_view_draw_statistics(Canvas *canvas, FlippPomodoroInfoViewModel *model)
- {
- FuriString *stats_string = furi_string_alloc();
- furi_string_printf(stats_string, "So Long,\nand Thanks for All the Focus...\nand for completing\n\e#%i\e# pomodoro(s)", model->pomodoros_completed);
- const char *stats_string_formatted = furi_string_get_cstr(stats_string);
- elements_text_box(
- canvas,
- 0,
- 0,
- canvas_width(canvas),
- canvas_height(canvas) - 10,
- AlignCenter,
- AlignCenter,
- stats_string_formatted,
- true);
- furi_string_free(stats_string);
- elements_button_left(canvas, "Guide");
- }
- static void flipp_pomodoro_info_view_draw_about(Canvas *canvas, FlippPomodoroInfoViewModel *model)
- {
- UNUSED(model);
- canvas_draw_icon(canvas, 0, 0, &I_flipp_pomodoro_learn_50x128);
- elements_button_left(canvas, "Stats");
- }
- static void flipp_pomodoro_info_view_draw_callback(Canvas *canvas, void *_model)
- {
- if (!_model)
- {
- return;
- };
- FlippPomodoroInfoViewModel *model = _model;
- canvas_clear(canvas);
- if (model->mode == FlippPomodoroInfoViewModeStats)
- {
- flipp_pomodoro_info_view_draw_statistics(canvas, model);
- }
- else
- {
- flipp_pomodoro_info_view_draw_about(canvas, model);
- }
- elements_button_right(canvas, "Resume");
- }
- void flipp_pomodoro_info_view_set_mode(View *view, FlippPomodoroInfoViewMode desired_mode)
- {
- with_view_model(
- view,
- FlippPomodoroInfoViewModel * model,
- {
- model->mode = desired_mode;
- },
- false);
- }
- void flipp_pomodoro_info_view_toggle_mode(FlippPomodoroInfoView *info_view)
- {
- with_view_model(
- flipp_pomodoro_info_view_get_view(info_view),
- FlippPomodoroInfoViewModel * model,
- {
- flipp_pomodoro_info_view_set_mode(
- flipp_pomodoro_info_view_get_view(info_view),
- (model->mode == FlippPomodoroInfoViewModeStats) ? FlippPomodoroInfoViewModeAbout : FlippPomodoroInfoViewModeStats);
- },
- true);
- }
- bool flipp_pomodoro_info_view_input_callback(InputEvent *event, void *ctx)
- {
- FlippPomodoroInfoView *info_view = ctx;
- if (event->type == InputTypePress)
- {
- if (event->key == InputKeyRight && info_view->resume_timer_cb != NULL)
- {
- info_view->resume_timer_cb(info_view->user_action_cb_ctx);
- return ViewInputConsumed;
- }
- else if (event->key == InputKeyLeft)
- {
- flipp_pomodoro_info_view_toggle_mode(info_view);
- return ViewInputConsumed;
- }
- }
- return ViewInputNotConusmed;
- }
- FlippPomodoroInfoView *flipp_pomodoro_info_view_alloc()
- {
- FlippPomodoroInfoView *info_view = malloc(sizeof(FlippPomodoroInfoView));
- info_view->view = view_alloc();
- view_allocate_model(flipp_pomodoro_info_view_get_view(info_view), ViewModelTypeLockFree, sizeof(FlippPomodoroInfoViewModel));
- view_set_context(flipp_pomodoro_info_view_get_view(info_view), info_view);
- view_set_draw_callback(flipp_pomodoro_info_view_get_view(info_view), flipp_pomodoro_info_view_draw_callback);
- view_set_input_callback(flipp_pomodoro_info_view_get_view(info_view), flipp_pomodoro_info_view_input_callback);
- return info_view;
- }
- View *flipp_pomodoro_info_view_get_view(FlippPomodoroInfoView *info_view)
- {
- return info_view->view;
- }
- void flipp_pomodoro_info_view_free(FlippPomodoroInfoView *info_view)
- {
- furi_assert(info_view);
- view_free(info_view->view);
- free(info_view);
- }
- void flipp_pomodoro_info_view_set_pomodoros_completed(View *view, uint8_t pomodoros_completed)
- {
- with_view_model(
- view,
- FlippPomodoroInfoViewModel * model,
- {
- model->pomodoros_completed = pomodoros_completed;
- },
- false);
- }
- void flipp_pomodoro_info_view_set_resume_timer_cb(FlippPomodoroInfoView *info_view, FlippPomodoroInfoViewUserActionCb user_action_cb, void *user_action_cb_ctx)
- {
- info_view->resume_timer_cb = user_action_cb;
- info_view->user_action_cb_ctx = user_action_cb_ctx;
- }
|