Skip to content

Commit

Permalink
Squashed 'pomodoro/' changes from d329978..b408703
Browse files Browse the repository at this point in the history
b408703 fix catalog versions
2f006ba bump version
e4d9959 Update apps
7bfa94d bump versions
5cee3bd fix cnt down timer & update pomodoro
793f8fa categories part 1
63f561c more manifestos, xbox controller and videopoker ufbt fixes
a7b41b1 Add Screenshots
0a1b42c API 31 / unzip sources
REVERT: d329978 feat: on-demand contextual chatting (#211)
REVERT: 52cc11a feat: display stats (#97)
REVERT: ddda80f ci(build): fix missing deed method (#198)
REVERT: 2f2962d feat: long cycle (#42) (#45)
REVERT: 925ebc6 feat: animated stage background (#39)(#32)
REVERT: 70e3a71 refactor: modules structure (#11)
REVERT: fa63582 feat: add happiness management (#10)
REVERT: 57b1487 update images art
REVERT: 621c6fd complete MVP
REVERT: b3f442d add timer stage toggl
REVERT: f49e172 add build infrastructure

git-subtree-dir: pomodoro
git-subtree-split: b408703
  • Loading branch information
Willy-JL committed Nov 12, 2023
1 parent d329978 commit b7ca82a
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 373 deletions.
6 changes: 5 additions & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ App(
entry_point="flipp_pomodoro_app",
requires=["gui", "notification", "dolphin"],
stack_size=1 * 1024,
fap_category="Productivity",
fap_category="Tools",
fap_icon_assets="images",
fap_icon="flipp_pomodoro_10.png",
fap_author="@Th3Un1q3",
fap_weburl="https://github.com/Th3Un1q3/flipp_pomodoro",
fap_version="1.3",
fap_description="Boost Your Productivity with the Pomodoro Timer",
)
56 changes: 25 additions & 31 deletions flipp_pomodoro_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,36 @@

#define TAG "FlippPomodoro"

enum
{
enum {
CustomEventConsumed = true,
CustomEventNotConsumed = false,
};

static bool flipp_pomodoro_app_back_event_callback(void *ctx)
{
static bool flipp_pomodoro_app_back_event_callback(void* ctx) {
furi_assert(ctx);
FlippPomodoroApp *app = ctx;
FlippPomodoroApp* app = ctx;
return scene_manager_handle_back_event(app->scene_manager);
};

static void flipp_pomodoro_app_tick_event_callback(void *ctx)
{
static void flipp_pomodoro_app_tick_event_callback(void* ctx) {
furi_assert(ctx);
FlippPomodoroApp *app = ctx;
FlippPomodoroApp* app = ctx;

scene_manager_handle_custom_event(app->scene_manager, FlippPomodoroAppCustomEventTimerTick);
};

static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
{
static bool flipp_pomodoro_app_custom_event_callback(void* ctx, uint32_t event) {
furi_assert(ctx);
FlippPomodoroApp *app = ctx;
FlippPomodoroApp* app = ctx;

switch (event)
{
switch(event) {
case FlippPomodoroAppCustomEventStageSkip:
flipp_pomodoro__toggle_stage(app->state);
view_dispatcher_send_custom_event(
app->view_dispatcher,
FlippPomodoroAppCustomEventStateUpdated);
app->view_dispatcher, FlippPomodoroAppCustomEventStateUpdated);
return CustomEventConsumed;
case FlippPomodoroAppCustomEventStageComplete:
if (flipp_pomodoro__get_stage(app->state) == FlippPomodoroStageFocus)
{
if(flipp_pomodoro__get_stage(app->state) == FlippPomodoroStageFocus) {
// REGISTER a deed on work stage complete to get an acheivement
dolphin_deed(DolphinDeedPluginGameWin);
FURI_LOG_I(TAG, "Focus stage reward added");
Expand All @@ -47,20 +40,20 @@ static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
};

flipp_pomodoro__toggle_stage(app->state);
notification_message(app->notification_app, stage_start_notification_sequence_map[flipp_pomodoro__get_stage(app->state)]);
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);
app->view_dispatcher, FlippPomodoroAppCustomEventStateUpdated);
return CustomEventConsumed;
default:
break;
}
return scene_manager_handle_custom_event(app->scene_manager, event);
};

FlippPomodoroApp *flipp_pomodoro_app_alloc()
{
FlippPomodoroApp *app = malloc(sizeof(FlippPomodoroApp));
FlippPomodoroApp* flipp_pomodoro_app_alloc() {
FlippPomodoroApp* app = malloc(sizeof(FlippPomodoroApp));
app->state = flipp_pomodoro__new();

app->scene_manager = scene_manager_alloc(&flipp_pomodoro_scene_handlers, app);
Expand All @@ -72,10 +65,13 @@ FlippPomodoroApp *flipp_pomodoro_app_alloc()

view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipp_pomodoro_app_custom_event_callback);
view_dispatcher_set_tick_event_callback(app->view_dispatcher, flipp_pomodoro_app_tick_event_callback, 1000);
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, flipp_pomodoro_app_custom_event_callback);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, flipp_pomodoro_app_tick_event_callback, 1000);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
view_dispatcher_set_navigation_event_callback(app->view_dispatcher, flipp_pomodoro_app_back_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, flipp_pomodoro_app_back_event_callback);

app->timer_view = flipp_pomodoro_view_timer_alloc();
app->info_view = flipp_pomodoro_info_view_alloc();
Expand All @@ -95,8 +91,7 @@ FlippPomodoroApp *flipp_pomodoro_app_alloc()
return app;
};

void flipp_pomodoro_app_free(FlippPomodoroApp *app)
{
void flipp_pomodoro_app_free(FlippPomodoroApp* app) {
view_dispatcher_remove_view(app->view_dispatcher, FlippPomodoroAppViewTimer);
view_dispatcher_remove_view(app->view_dispatcher, FlippPomodoroAppViewInfo);
view_dispatcher_free(app->view_dispatcher);
Expand All @@ -110,11 +105,10 @@ void flipp_pomodoro_app_free(FlippPomodoroApp *app)
furi_record_close(RECORD_NOTIFICATION);
};

int32_t flipp_pomodoro_app(void *p)
{
int32_t flipp_pomodoro_app(void* p) {
UNUSED(p);
FURI_LOG_I(TAG, "Initial");
FlippPomodoroApp *app = flipp_pomodoro_app_alloc();
FlippPomodoroApp* app = flipp_pomodoro_app_alloc();

FURI_LOG_I(TAG, "Run deed added");
dolphin_deed(DolphinDeedPluginGameStart);
Expand Down
25 changes: 11 additions & 14 deletions flipp_pomodoro_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#include "modules/flipp_pomodoro.h"
#include "modules/flipp_pomodoro_statistics.h"

typedef enum
{
typedef enum {
// Reserve first 100 events for button types and indexes, starting from 0
FlippPomodoroAppCustomEventStageSkip = 100,
FlippPomodoroAppCustomEventStageComplete, // By Expiration
Expand All @@ -23,20 +22,18 @@ typedef enum
FlippPomodoroAppCustomEventResumeTimer,
} FlippPomodoroAppCustomEvent;

typedef struct
{
SceneManager *scene_manager;
ViewDispatcher *view_dispatcher;
Gui *gui;
NotificationApp *notification_app;
FlippPomodoroTimerView *timer_view;
FlippPomodoroInfoView *info_view;
FlippPomodoroState *state;
FlippPomodoroStatistics *statistics;
typedef struct {
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Gui* gui;
NotificationApp* notification_app;
FlippPomodoroTimerView* timer_view;
FlippPomodoroInfoView* info_view;
FlippPomodoroState* state;
FlippPomodoroStatistics* statistics;
} FlippPomodoroApp;

typedef enum
{
typedef enum {
FlippPomodoroAppViewTimer,
FlippPomodoroAppViewInfo,
} FlippPomodoroAppView;
2 changes: 1 addition & 1 deletion helpers/notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern const NotificationSequence work_start_notification;
extern const NotificationSequence rest_start_notification;

/// @brief Defines a notification sequence that should indicate start of specific pomodoro stage.
const NotificationSequence *stage_start_notification_sequence_map[] = {
const NotificationSequence* stage_start_notification_sequence_map[] = {
[FlippPomodoroStageFocus] = &work_start_notification,
[FlippPomodoroStageRest] = &rest_start_notification,
[FlippPomodoroStageLongBreak] = &rest_start_notification,
Expand Down
9 changes: 4 additions & 5 deletions helpers/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
const int TIME_SECONDS_IN_MINUTE = 60;
const int TIME_MINUTES_IN_HOUR = 60;

uint32_t time_now()
{
uint32_t time_now() {
return furi_hal_rtc_get_timestamp();
};

TimeDifference time_difference_seconds(uint32_t begin, uint32_t end)
{
TimeDifference time_difference_seconds(uint32_t begin, uint32_t end) {
const uint32_t duration_seconds = end - begin;

uint32_t minutes = (duration_seconds / TIME_MINUTES_IN_HOUR) % TIME_MINUTES_IN_HOUR;
uint32_t seconds = duration_seconds % TIME_SECONDS_IN_MINUTE;

return (TimeDifference){.total_seconds = duration_seconds, .minutes = minutes, .seconds = seconds};
return (
TimeDifference){.total_seconds = duration_seconds, .minutes = minutes, .seconds = seconds};
};
3 changes: 1 addition & 2 deletions helpers/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ extern const int TIME_SECONDS_IN_MINUTE;
extern const int TIME_MINUTES_IN_HOUR;

/// @brief Container for a time period
typedef struct
{
typedef struct {
uint8_t seconds;
uint8_t minutes;
uint32_t total_seconds;
Expand Down
Binary file added img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 13 additions & 23 deletions modules/flipp_pomodoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ PomodoroStage stages_sequence[] = {
FlippPomodoroStageLongBreak,
};

char *current_stage_label[] = {
char* current_stage_label[] = {
[FlippPomodoroStageFocus] = "Focusing...",
[FlippPomodoroStageRest] = "Short Break...",
[FlippPomodoroStageLongBreak] = "Long Break...",
};

char *next_stage_label[] = {
char* next_stage_label[] = {
[FlippPomodoroStageFocus] = "Focus",
[FlippPomodoroStageRest] = "Short Break",
[FlippPomodoroStageLongBreak] = "Long Break",
Expand All @@ -34,39 +34,33 @@ PomodoroStage flipp_pomodoro__stage_by_index(int index) {
return stages_sequence[index % one_loop_size];
}

void flipp_pomodoro__toggle_stage(FlippPomodoroState *state)
{
void flipp_pomodoro__toggle_stage(FlippPomodoroState* state) {
furi_assert(state);
state->current_stage_index = state->current_stage_index + 1;
state->started_at_timestamp = time_now();
};

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

char *flipp_pomodoro__current_stage_label(FlippPomodoroState *state)
{
char* flipp_pomodoro__current_stage_label(FlippPomodoroState* state) {
furi_assert(state);
return current_stage_label[flipp_pomodoro__get_stage(state)];
};

char *flipp_pomodoro__next_stage_label(FlippPomodoroState *state)
{
char* flipp_pomodoro__next_stage_label(FlippPomodoroState* state) {
furi_assert(state);
return next_stage_label[flipp_pomodoro__stage_by_index(state->current_stage_index + 1)];
};

void flipp_pomodoro__destroy(FlippPomodoroState *state)
{
void flipp_pomodoro__destroy(FlippPomodoroState* state) {
furi_assert(state);
free(state);
};

uint32_t flipp_pomodoro__current_stage_total_duration(FlippPomodoroState *state)
{
uint32_t flipp_pomodoro__current_stage_total_duration(FlippPomodoroState* state) {
const int32_t stage_duration_seconds_map[] = {
[FlippPomodoroStageFocus] = 25 * TIME_SECONDS_IN_MINUTE,
[FlippPomodoroStageRest] = 5 * TIME_SECONDS_IN_MINUTE,
Expand All @@ -76,27 +70,23 @@ uint32_t flipp_pomodoro__current_stage_total_duration(FlippPomodoroState *state)
return stage_duration_seconds_map[flipp_pomodoro__get_stage(state)];
};

uint32_t flipp_pomodoro__stage_expires_timestamp(FlippPomodoroState *state)
{
uint32_t flipp_pomodoro__stage_expires_timestamp(FlippPomodoroState* state) {
return state->started_at_timestamp + flipp_pomodoro__current_stage_total_duration(state);
};

TimeDifference flipp_pomodoro__stage_remaining_duration(FlippPomodoroState *state)
{
TimeDifference flipp_pomodoro__stage_remaining_duration(FlippPomodoroState* state) {
const uint32_t stage_ends_at = flipp_pomodoro__stage_expires_timestamp(state);
return time_difference_seconds(time_now(), stage_ends_at);
};

bool flipp_pomodoro__is_stage_expired(FlippPomodoroState *state)
{
bool flipp_pomodoro__is_stage_expired(FlippPomodoroState* state) {
const uint32_t expired_by = flipp_pomodoro__stage_expires_timestamp(state);
const uint8_t seamless_change_span_seconds = 1;
return (time_now() - seamless_change_span_seconds) >= expired_by;
};

FlippPomodoroState *flipp_pomodoro__new()
{
FlippPomodoroState *state = malloc(sizeof(FlippPomodoroState));
FlippPomodoroState* flipp_pomodoro__new() {
FlippPomodoroState* state = malloc(sizeof(FlippPomodoroState));
const uint32_t now = time_now();
state->started_at_timestamp = now;
state->current_stage_index = 0;
Expand Down
22 changes: 10 additions & 12 deletions modules/flipp_pomodoro.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,50 @@
#include "../helpers/time.h"

/// @brief Options of pomodoro stages
typedef enum
{
typedef enum {
FlippPomodoroStageFocus,
FlippPomodoroStageRest,
FlippPomodoroStageLongBreak,
} PomodoroStage;

/// @brief State of the pomodoro timer
typedef struct
{
typedef struct {
uint8_t current_stage_index;
uint32_t started_at_timestamp;
} FlippPomodoroState;

/// @brief Generates initial state
/// @returns A new pre-populated state for pomodoro timer
FlippPomodoroState *flipp_pomodoro__new();
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);
PomodoroStage flipp_pomodoro__get_stage(FlippPomodoroState* state);

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

/// @brief Get remaining stage time.
/// @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);
TimeDifference flipp_pomodoro__stage_remaining_duration(FlippPomodoroState* state);

/// @brief Label of currently active stage
/// @param state - pointer to the state of pomorodo
/// @returns A string that explains current stage
char *flipp_pomodoro__current_stage_label(FlippPomodoroState *state);
char* flipp_pomodoro__current_stage_label(FlippPomodoroState* state);

/// @brief Label of transition to the next stage
/// @param state - pointer to the state of pomorodo.
/// @returns string with the label of the "skipp" button
char *flipp_pomodoro__next_stage_label(FlippPomodoroState *state);
char* flipp_pomodoro__next_stage_label(FlippPomodoroState* state);

/// @brief Check if current stage is expired
/// @param state - pointer to the state of pomorodo.
/// @returns expriations status - true means stage is expired
bool flipp_pomodoro__is_stage_expired(FlippPomodoroState *state);
bool flipp_pomodoro__is_stage_expired(FlippPomodoroState* state);

/// @brief Rotate stage of the timer
/// @param state - pointer to the state of pomorodo.
void flipp_pomodoro__toggle_stage(FlippPomodoroState *state);
void flipp_pomodoro__toggle_stage(FlippPomodoroState* state);
Loading

0 comments on commit b7ca82a

Please sign in to comment.