Skip to content

Commit 2f2962d

Browse files
authored
feat: long cycle (#42) (#45)
* add current stage labels * add drop loop * add long sequence * add docs for current label method * unified context references
1 parent 925ebc6 commit 2f2962d

9 files changed

+114
-34
lines changed

flipp_pomodoro_app.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
3535
FlippPomodoroAppCustomEventStateUpdated);
3636
return CustomEventConsumed;
3737
case FlippPomodoroAppCustomEventStageComplete:
38-
if (flipp_pomodoro__get_stage(app->state) == Work)
38+
if (flipp_pomodoro__get_stage(app->state) == FlippPomodoroStageFocus)
3939
{
4040
// REGISTER a deed on work stage complete to get an acheivement
4141
DOLPHIN_DEED(DolphinDeedPluginGameWin);

helpers/notifications.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern const NotificationSequence rest_start_notification;
88

99
/// @brief Defines a notification sequence that should indicate start of specific pomodoro stage.
1010
const NotificationSequence *stage_start_notification_sequence_map[] = {
11-
[Work] = &work_start_notification,
12-
[Rest] = &rest_start_notification,
11+
[FlippPomodoroStageFocus] = &work_start_notification,
12+
[FlippPomodoroStageRest] = &rest_start_notification,
13+
[FlippPomodoroStageLongBreak] = &rest_start_notification,
1314
};

modules/flipp_pomodoro.c

+39-13
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,60 @@
33
#include "../helpers/time.h"
44
#include "flipp_pomodoro.h"
55

6-
char *next_stage_label[] = {
7-
[Work] = "Get Rest",
8-
[Rest] = "Start Work",
6+
PomodoroStage stages_sequence[] = {
7+
FlippPomodoroStageFocus,
8+
FlippPomodoroStageRest,
9+
10+
FlippPomodoroStageFocus,
11+
FlippPomodoroStageRest,
12+
13+
FlippPomodoroStageFocus,
14+
FlippPomodoroStageRest,
15+
16+
FlippPomodoroStageFocus,
17+
FlippPomodoroStageLongBreak,
918
};
1019

11-
const PomodoroStage stage_rotaion_map[] = {
12-
[Work] = Rest,
13-
[Rest] = Work,
20+
char *current_stage_label[] = {
21+
[FlippPomodoroStageFocus] = "Continue focus for:",
22+
[FlippPomodoroStageRest] = "Keep rest for:",
23+
[FlippPomodoroStageLongBreak] = "Long Break for:",
1424
};
1525

16-
const PomodoroStage default_stage = Work;
26+
char *next_stage_label[] = {
27+
[FlippPomodoroStageFocus] = "Focus",
28+
[FlippPomodoroStageRest] = "Short Break",
29+
[FlippPomodoroStageLongBreak] = "Long Break",
30+
};
31+
32+
PomodoroStage flipp_pomodoro__stage_by_index(int index) {
33+
const int one_loop_size = sizeof(stages_sequence);
34+
return stages_sequence[index % one_loop_size];
35+
}
1736

1837
void flipp_pomodoro__toggle_stage(FlippPomodoroState *state)
1938
{
2039
furi_assert(state);
21-
state->stage = stage_rotaion_map[flipp_pomodoro__get_stage(state)];
40+
state->current_stage_index = state->current_stage_index + 1;
2241
state->started_at_timestamp = time_now();
2342
};
2443

2544
PomodoroStage flipp_pomodoro__get_stage(FlippPomodoroState *state)
2645
{
2746
furi_assert(state);
28-
return state->stage;
47+
return flipp_pomodoro__stage_by_index(state->current_stage_index);
48+
};
49+
50+
char *flipp_pomodoro__current_stage_label(FlippPomodoroState *state)
51+
{
52+
furi_assert(state);
53+
return current_stage_label[flipp_pomodoro__get_stage(state)];
2954
};
3055

3156
char *flipp_pomodoro__next_stage_label(FlippPomodoroState *state)
3257
{
3358
furi_assert(state);
34-
return next_stage_label[flipp_pomodoro__get_stage(state)];
59+
return next_stage_label[flipp_pomodoro__stage_by_index(state->current_stage_index + 1)];
3560
};
3661

3762
void flipp_pomodoro__destroy(FlippPomodoroState *state)
@@ -43,8 +68,9 @@ void flipp_pomodoro__destroy(FlippPomodoroState *state)
4368
uint32_t flipp_pomodoro__current_stage_total_duration(FlippPomodoroState *state)
4469
{
4570
const int32_t stage_duration_seconds_map[] = {
46-
[Work] = 25 * TIME_SECONDS_IN_MINUTE,
47-
[Rest] = 5 * TIME_SECONDS_IN_MINUTE,
71+
[FlippPomodoroStageFocus] = 25 * TIME_SECONDS_IN_MINUTE,
72+
[FlippPomodoroStageRest] = 5 * TIME_SECONDS_IN_MINUTE,
73+
[FlippPomodoroStageLongBreak] = 30 * TIME_SECONDS_IN_MINUTE,
4874
};
4975

5076
return stage_duration_seconds_map[flipp_pomodoro__get_stage(state)];
@@ -73,6 +99,6 @@ FlippPomodoroState *flipp_pomodoro__new()
7399
FlippPomodoroState *state = malloc(sizeof(FlippPomodoroState));
74100
const uint32_t now = time_now();
75101
state->started_at_timestamp = now;
76-
state->stage = default_stage;
102+
state->current_stage_index = 0;
77103
return state;
78104
};

modules/flipp_pomodoro.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
/// @brief Options of pomodoro stages
77
typedef enum
88
{
9-
Work,
10-
Rest,
9+
FlippPomodoroStageFocus,
10+
FlippPomodoroStageRest,
11+
FlippPomodoroStageLongBreak,
1112
} PomodoroStage;
1213

1314
/// @brief State of the pomodoro timer
1415
typedef struct
1516
{
1617
PomodoroStage stage;
18+
uint8_t current_stage_index;
1719
uint32_t started_at_timestamp;
1820
} FlippPomodoroState;
1921

@@ -34,6 +36,11 @@ void flipp_pomodoro__destroy(FlippPomodoroState *state);
3436
/// @returns Time difference to the end of current stage
3537
TimeDifference flipp_pomodoro__stage_remaining_duration(FlippPomodoroState *state);
3638

39+
/// @brief Label of currently active stage
40+
/// @param state - pointer to the state of pomorodo
41+
/// @returns A string that explains current stage
42+
char *flipp_pomodoro__current_stage_label(FlippPomodoroState *state);
43+
3744
/// @brief Label of transition to the next stage
3845
/// @param state - pointer to the state of pomorodo.
3946
/// @returns string with the label of the "skipp" button

scenes/flipp_pomodoro_scene.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ void (*const flipp_pomodoro_scene_on_enter_handlers[])(void*) = {
99

1010
// Generate scene on_event handlers array
1111
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
12-
bool (*const flipp_pomodoro_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
12+
bool (*const flipp_pomodoro_scene_on_event_handlers[])(void* ctx, SceneManagerEvent event) = {
1313
#include "config/flipp_pomodoro_scene_config.h"
1414
};
1515
#undef ADD_SCENE
1616

1717
// Generate scene on_exit handlers array
1818
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
19-
void (*const flipp_pomodoro_scene_on_exit_handlers[])(void* context) = {
19+
void (*const flipp_pomodoro_scene_on_exit_handlers[])(void* ctx) = {
2020
#include "config/flipp_pomodoro_scene_config.h"
2121
};
2222
#undef ADD_SCENE

scenes/flipp_pomodoro_scene.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ extern const SceneManagerHandlers flipp_pomodoro_scene_handlers;
1818

1919
// Generate scene on_event handlers declaration
2020
#define ADD_SCENE(prefix, name, id) \
21-
bool prefix##_scene_##name##_on_event(void *context, SceneManagerEvent event);
21+
bool prefix##_scene_##name##_on_event(void *ctx, SceneManagerEvent event);
2222
#include "config/flipp_pomodoro_scene_config.h"
2323
#undef ADD_SCENE
2424

2525
// Generate scene on_exit handlers declaration
26-
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void *context);
26+
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void *ctx);
2727
#include "config/flipp_pomodoro_scene_config.h"
2828
#undef ADD_SCENE

scenes/flipp_pomodoro_scene_timer.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ enum
1212

1313
uint8_t ExitSignal = 0;
1414

15-
void flipp_pomodoro_scene_timer_sync_view_state(void *context)
15+
void flipp_pomodoro_scene_timer_sync_view_state(void *ctx)
1616
{
17-
furi_assert(context);
17+
furi_assert(ctx);
1818

19-
FlippPomodoroApp *app = context;
19+
FlippPomodoroApp *app = ctx;
2020

2121
flipp_pomodoro_view_timer_set_state(
2222
flipp_pomodoro_view_timer_get_view(app->timer_view),
@@ -34,11 +34,11 @@ void flipp_pomodoro_scene_timer_on_next_stage(void *ctx)
3434
FlippPomodoroAppCustomEventStageSkip);
3535
};
3636

37-
void flipp_pomodoro_scene_timer_on_enter(void *context)
37+
void flipp_pomodoro_scene_timer_on_enter(void *ctx)
3838
{
39-
furi_assert(context);
39+
furi_assert(ctx);
4040

41-
FlippPomodoroApp *app = context;
41+
FlippPomodoroApp *app = ctx;
4242

4343
view_dispatcher_switch_to_view(app->view_dispatcher, FlippPomodoroAppViewTimer);
4444
flipp_pomodoro_scene_timer_sync_view_state(app);
@@ -83,7 +83,7 @@ bool flipp_pomodoro_scene_timer_on_event(void *ctx, SceneManagerEvent event)
8383
return SceneEventNotConusmed;
8484
};
8585

86-
void flipp_pomodoro_scene_timer_on_exit(void *context)
86+
void flipp_pomodoro_scene_timer_on_exit(void *ctx)
8787
{
88-
UNUSED(context);
88+
UNUSED(ctx);
8989
};

views/flipp_pomodoro_timer_view.c

+49-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ typedef struct
3030
} FlippPomodoroTimerViewModel;
3131

3232
static const Icon *stage_background_image[] = {
33-
[Work] = &A_flipp_pomodoro_focus_64,
34-
[Rest] = &A_flipp_pomodoro_rest_64,
33+
[FlippPomodoroStageFocus] = &A_flipp_pomodoro_focus_64,
34+
[FlippPomodoroStageRest] = &A_flipp_pomodoro_rest_64,
35+
[FlippPomodoroStageLongBreak] = &A_flipp_pomodoro_rest_64,
3536
};
3637

3738
static void flipp_pomodoro_view_timer_draw_countdown(Canvas *canvas, TimeDifference remaining_time)
@@ -42,7 +43,7 @@ static void flipp_pomodoro_view_timer_draw_countdown(Canvas *canvas, TimeDiffere
4243
const uint8_t countdown_box_height = canvas_height(canvas) * 0.4;
4344
const uint8_t countdown_box_width = canvas_width(canvas) * 0.5;
4445
const uint8_t countdown_box_x = canvas_width(canvas) - countdown_box_width - right_border_margin;
45-
const uint8_t countdown_box_y = 0;
46+
const uint8_t countdown_box_y = 15;
4647

4748
elements_bold_rounded_frame(canvas,
4849
countdown_box_x,
@@ -64,6 +65,48 @@ static void flipp_pomodoro_view_timer_draw_countdown(Canvas *canvas, TimeDiffere
6465
furi_string_free(timer_string);
6566
};
6667

68+
static void draw_str_with_drop_shadow(
69+
Canvas *canvas, uint8_t x,
70+
uint8_t y,
71+
Align horizontal,
72+
Align vertical,
73+
const char* str
74+
) {
75+
canvas_set_color(canvas, ColorWhite);
76+
for (int x_off = -2; x_off <= 2; x_off++)
77+
{
78+
for (int y_off = -2; y_off <= 2; y_off++)
79+
{
80+
canvas_draw_str_aligned(
81+
canvas,
82+
x + x_off,
83+
y + y_off,
84+
horizontal,
85+
vertical,
86+
str);
87+
}
88+
}
89+
canvas_set_color(canvas, ColorBlack);
90+
canvas_draw_str_aligned(
91+
canvas,
92+
x,
93+
y,
94+
horizontal,
95+
vertical,
96+
str);
97+
}
98+
99+
static void flipp_pomodoro_view_timer_draw_current_stage_label(Canvas *canvas, FlippPomodoroState *state) {
100+
canvas_set_font(canvas, FontPrimary);
101+
draw_str_with_drop_shadow(
102+
canvas,
103+
canvas_width(canvas),
104+
0,
105+
AlignRight,
106+
AlignTop,
107+
flipp_pomodoro__current_stage_label(state));
108+
}
109+
67110
static void flipp_pomodoro_view_timer_draw_callback(Canvas *canvas, void *_model)
68111
{
69112
if (!_model)
@@ -83,6 +126,9 @@ static void flipp_pomodoro_view_timer_draw_callback(Canvas *canvas, void *_model
83126
canvas,
84127
flipp_pomodoro__stage_remaining_duration(model->state));
85128

129+
flipp_pomodoro_view_timer_draw_current_stage_label(canvas, model->state);
130+
canvas_set_color(canvas, ColorBlack);
131+
86132
canvas_set_font(canvas, FontSecondary);
87133
elements_button_right(canvas, flipp_pomodoro__next_stage_label(model->state));
88134
};

views/flipp_pomodoro_timer_view.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
typedef struct FlippPomodoroTimerView FlippPomodoroTimerView;
77

8-
typedef void (*FlippPomodoroTimerViewInputCb)(void *context);
8+
typedef void (*FlippPomodoroTimerViewInputCb)(void *ctx);
99

1010
FlippPomodoroTimerView *flipp_pomodoro_view_timer_alloc();
1111

0 commit comments

Comments
 (0)