mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 05:18:35 -07:00
Update apps
This commit is contained in:
152
applications/external/pomodoro/views/flipp_pomodoro_info_view.c
vendored
Normal file
152
applications/external/pomodoro/views/flipp_pomodoro_info_view.c
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
#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%i 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;
|
||||
}
|
||||
71
applications/external/pomodoro/views/flipp_pomodoro_info_view.h
vendored
Normal file
71
applications/external/pomodoro/views/flipp_pomodoro_info_view.h
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
/** @brief Mode types for FlippPomodoroInfoView
|
||||
*
|
||||
* These are the modes that can be used in the FlippPomodoroInfoView
|
||||
*/
|
||||
typedef enum {
|
||||
FlippPomodoroInfoViewModeStats,
|
||||
FlippPomodoroInfoViewModeAbout,
|
||||
} FlippPomodoroInfoViewMode;
|
||||
|
||||
/** @brief Forward declaration of the FlippPomodoroInfoView struct */
|
||||
typedef struct FlippPomodoroInfoView FlippPomodoroInfoView;
|
||||
|
||||
/** @brief User action callback function type
|
||||
*
|
||||
* Callback functions of this type are called when a user action is performed.
|
||||
*/
|
||||
typedef void (*FlippPomodoroInfoViewUserActionCb)(void* ctx);
|
||||
|
||||
/** @brief Allocate a new FlippPomodoroInfoView
|
||||
*
|
||||
* Allocates a new FlippPomodoroInfoView and returns a pointer to it.
|
||||
* @return A pointer to a new FlippPomodoroInfoView
|
||||
*/
|
||||
FlippPomodoroInfoView* flipp_pomodoro_info_view_alloc();
|
||||
|
||||
/** @brief Get the view from a FlippPomodoroInfoView
|
||||
*
|
||||
* Returns a pointer to the view associated with a FlippPomodoroInfoView.
|
||||
* @param info_view A pointer to a FlippPomodoroInfoView
|
||||
* @return A pointer to the view of the FlippPomodoroInfoView
|
||||
*/
|
||||
View* flipp_pomodoro_info_view_get_view(FlippPomodoroInfoView* info_view);
|
||||
|
||||
/** @brief Free a FlippPomodoroInfoView
|
||||
*
|
||||
* Frees the memory used by a FlippPomodoroInfoView.
|
||||
* @param info_view A pointer to a FlippPomodoroInfoView
|
||||
*/
|
||||
void flipp_pomodoro_info_view_free(FlippPomodoroInfoView* info_view);
|
||||
|
||||
/** @brief Set the number of completed pomodoros in the view
|
||||
*
|
||||
* Sets the number of completed pomodoros that should be displayed in the view.
|
||||
* @param info_view A pointer to the view
|
||||
* @param pomodoros_completed The number of completed pomodoros
|
||||
*/
|
||||
void flipp_pomodoro_info_view_set_pomodoros_completed(View* info_view, uint8_t pomodoros_completed);
|
||||
|
||||
/** @brief Set the callback function to be called when the timer should be resumed
|
||||
*
|
||||
* Sets the callback function that will be called when the timer should be resumed.
|
||||
* @param info_view A pointer to the FlippPomodoroInfoView
|
||||
* @param user_action_cb The callback function
|
||||
* @param user_action_cb_ctx The context to be passed to the callback function
|
||||
*/
|
||||
void flipp_pomodoro_info_view_set_resume_timer_cb(
|
||||
FlippPomodoroInfoView* info_view,
|
||||
FlippPomodoroInfoViewUserActionCb user_action_cb,
|
||||
void* user_action_cb_ctx);
|
||||
|
||||
/** @brief Set the mode of the view
|
||||
*
|
||||
* Sets the mode that should be used in the view.
|
||||
* @param view A pointer to the view
|
||||
* @param desired_mode The desired mode
|
||||
*/
|
||||
void flipp_pomodoro_info_view_set_mode(View* view, FlippPomodoroInfoViewMode desired_mode);
|
||||
@@ -156,7 +156,10 @@ FlippPomodoroTimerView* flipp_pomodoro_view_timer_alloc() {
|
||||
FlippPomodoroTimerView* timer = malloc(sizeof(FlippPomodoroTimerView));
|
||||
timer->view = view_alloc();
|
||||
|
||||
view_allocate_model(timer->view, ViewModelTypeLockFree, sizeof(FlippPomodoroTimerViewModel));
|
||||
view_allocate_model(
|
||||
flipp_pomodoro_view_timer_get_view(timer),
|
||||
ViewModelTypeLockFree,
|
||||
sizeof(FlippPomodoroTimerViewModel));
|
||||
view_set_context(flipp_pomodoro_view_timer_get_view(timer), timer);
|
||||
view_set_draw_callback(timer->view, flipp_pomodoro_view_timer_draw_callback);
|
||||
view_set_input_callback(timer->view, flipp_pomodoro_view_timer_input_callback);
|
||||
|
||||
Reference in New Issue
Block a user