Skip to content

Commit

Permalink
feat: animated stage background (#39)(#32)
Browse files Browse the repository at this point in the history
* wip encapsulate current stage mechanism

* add animations for stages

* fix incorrect documentation commit

* remove duplications in view

* enable re-render after animation is assigned
  • Loading branch information
Th3Un1q3 authored Jan 29, 2023
1 parent 70e3a71 commit 925ebc6
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 13 deletions.
10 changes: 8 additions & 2 deletions flipp_pomodoro_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
{
case FlippPomodoroAppCustomEventStageSkip:
flipp_pomodoro__toggle_stage(app->state);
view_dispatcher_send_custom_event(
app->view_dispatcher,
FlippPomodoroAppCustomEventStateUpdated);
return CustomEventConsumed;
case FlippPomodoroAppCustomEventStageComplete:
if (app->state->stage == Work)
if (flipp_pomodoro__get_stage(app->state) == Work)
{
// REGISTER a deed on work stage complete to get an acheivement
DOLPHIN_DEED(DolphinDeedPluginGameWin);
};

flipp_pomodoro__toggle_stage(app->state);
notification_message(app->notification_app, stage_start_notification_sequence_map[app->state->stage]);
notification_message(app->notification_app, stage_start_notification_sequence_map[flipp_pomodoro__get_stage(app->state)]);
view_dispatcher_send_custom_event(
app->view_dispatcher,
FlippPomodoroAppCustomEventStateUpdated);
return CustomEventConsumed;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions flipp_pomodoro_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum
FlippPomodoroAppCustomEventStageSkip = 100,
FlippPomodoroAppCustomEventStageComplete, // By Expiration
FlippPomodoroAppCustomEventTimerTick,
FlippPomodoroAppCustomEventStateUpdated,
} FlippPomodoroAppCustomEvent;

typedef struct
Expand Down
Binary file added images/flipp_pomodoro_focus_64/frame_00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
1 change: 1 addition & 0 deletions images/flipp_pomodoro_focus_64/frame_rate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
File renamed without changes
Binary file added images/flipp_pomodoro_rest_64/frame_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/flipp_pomodoro_rest_64/frame_rate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
12 changes: 9 additions & 3 deletions modules/flipp_pomodoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ const PomodoroStage default_stage = Work;
void flipp_pomodoro__toggle_stage(FlippPomodoroState *state)
{
furi_assert(state);
state->stage = stage_rotaion_map[state->stage];
state->stage = stage_rotaion_map[flipp_pomodoro__get_stage(state)];
state->started_at_timestamp = time_now();
};

PomodoroStage flipp_pomodoro__get_stage(FlippPomodoroState *state)
{
furi_assert(state);
return state->stage;
};

char *flipp_pomodoro__next_stage_label(FlippPomodoroState *state)
{
furi_assert(state);
return next_stage_label[state->stage];
return next_stage_label[flipp_pomodoro__get_stage(state)];
};

void flipp_pomodoro__destroy(FlippPomodoroState *state)
Expand All @@ -41,7 +47,7 @@ uint32_t flipp_pomodoro__current_stage_total_duration(FlippPomodoroState *state)
[Rest] = 5 * TIME_SECONDS_IN_MINUTE,
};

return stage_duration_seconds_map[state->stage];
return stage_duration_seconds_map[flipp_pomodoro__get_stage(state)];
};

uint32_t flipp_pomodoro__stage_expires_timestamp(FlippPomodoroState *state)
Expand Down
8 changes: 6 additions & 2 deletions modules/flipp_pomodoro.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ typedef struct
} FlippPomodoroState;

/// @brief Generates initial state
/// @param state - pointer to the state of pomorodo.
/// @returns A new pre-populated state for pomodoro timer
FlippPomodoroState *flipp_pomodoro__new();

/// @brief Extract current stage of pomodoro
/// @param state - pointer to the state of pomorodo
/// @returns Current stage value
PomodoroStage flipp_pomodoro__get_stage(FlippPomodoroState *state);

/// @brief Destroys state of timer and it's dependencies
void flipp_pomodoro__destroy(FlippPomodoroState *state);

/// @brief Get remaining stage time.
/// @param state - pointer to the state of pomorodo.
/// @param state - pointer to the state of pomorodo
/// @returns Time difference to the end of current stage
TimeDifference flipp_pomodoro__stage_remaining_duration(FlippPomodoroState *state);

Expand Down
20 changes: 17 additions & 3 deletions scenes/flipp_pomodoro_scene_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ enum

uint8_t ExitSignal = 0;

void flipp_pomodoro_scene_timer_sync_view_state(void *context)
{
furi_assert(context);

FlippPomodoroApp *app = context;

flipp_pomodoro_view_timer_set_state(
flipp_pomodoro_view_timer_get_view(app->timer_view),
app->state);
};

void flipp_pomodoro_scene_timer_on_next_stage(void *ctx)
{
furi_assert(ctx);
Expand All @@ -30,9 +41,7 @@ void flipp_pomodoro_scene_timer_on_enter(void *context)
FlippPomodoroApp *app = context;

view_dispatcher_switch_to_view(app->view_dispatcher, FlippPomodoroAppViewTimer);
flipp_pomodoro_view_timer_set_state(
flipp_pomodoro_view_timer_get_view(app->timer_view),
app->state);
flipp_pomodoro_scene_timer_sync_view_state(app);
flipp_pomodoro_view_timer_set_on_right_cb(
app->timer_view,
flipp_pomodoro_scene_timer_on_next_stage,
Expand All @@ -47,6 +56,11 @@ void flipp_pomodoro_scene_timer_handle_custom_event(FlippPomodoroApp *app, Flipp
app->view_dispatcher,
FlippPomodoroAppCustomEventStageComplete);
}

if (custom_event == FlippPomodoroAppCustomEventStateUpdated)
{
flipp_pomodoro_scene_timer_sync_view_state(app);
}
};

bool flipp_pomodoro_scene_timer_on_event(void *ctx, SceneManagerEvent event)
Expand Down
39 changes: 36 additions & 3 deletions views/flipp_pomodoro_timer_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ struct FlippPomodoroTimerView

typedef struct
{
IconAnimation *icon;
FlippPomodoroState *state;
} FlippPomodoroTimerViewModel;

static const Icon *stage_background_image[] = {
[Work] = &I_flipp_pomodoro_work_64,
[Rest] = &I_flipp_pomodoro_rest_64,
[Work] = &A_flipp_pomodoro_focus_64,
[Rest] = &A_flipp_pomodoro_rest_64,
};

static void flipp_pomodoro_view_timer_draw_countdown(Canvas *canvas, TimeDifference remaining_time)
Expand Down Expand Up @@ -73,7 +74,11 @@ static void flipp_pomodoro_view_timer_draw_callback(Canvas *canvas, void *_model
FlippPomodoroTimerViewModel *model = _model;

canvas_clear(canvas);
canvas_draw_icon(canvas, 0, 0, stage_background_image[model->state->stage]);
if (model->icon)
{
canvas_draw_icon_animation(canvas, 0, 0, model->icon);
}

flipp_pomodoro_view_timer_draw_countdown(
canvas,
flipp_pomodoro__stage_remaining_duration(model->state));
Expand Down Expand Up @@ -109,6 +114,25 @@ View *flipp_pomodoro_view_timer_get_view(FlippPomodoroTimerView *timer)
return timer->view;
};

void flipp_pomodoro_view_timer_assign_animation(View *view)
{
with_view_model(
view,
FlippPomodoroTimerViewModel * model,
{
furi_assert(model->state);
if (model->icon)
{
icon_animation_free(model->icon);
}
model->icon = icon_animation_alloc(
stage_background_image[flipp_pomodoro__get_stage(model->state)]);
view_tie_icon_animation(view, model->icon);
icon_animation_start(model->icon);
},
true);
}

FlippPomodoroTimerView *flipp_pomodoro_view_timer_alloc()
{
FlippPomodoroTimerView *timer = malloc(sizeof(FlippPomodoroTimerView));
Expand Down Expand Up @@ -141,11 +165,20 @@ void flipp_pomodoro_view_timer_set_state(View *view, FlippPomodoroState *state)
model->state = state;
},
false);
flipp_pomodoro_view_timer_assign_animation(view);
};

void flipp_pomodoro_view_timer_free(FlippPomodoroTimerView *timer)
{
furi_assert(timer);
with_view_model(
timer->view,
FlippPomodoroTimerViewModel * model,
{
icon_animation_free(model->icon);
},
false);
view_free(timer->view);

free(timer);
};

0 comments on commit 925ebc6

Please sign in to comment.