Skip to content

Commit

Permalink
feat: display stats (#97)
Browse files Browse the repository at this point in the history
1. A new feature to display statistics has been added. This includes the creation of new files `flipp_pomodoro_statistics.c` and `flipp_pomodoro_statistics.h` in the `modules` directory, and changes to `flipp_pomodoro_app.c` and `flipp_pomodoro_app.h` to incorporate the statistics functionality.

2. The `.vscode/settings.json` file has been updated with new entries.

3. The `flipp_pomodoro_app.c` file has been updated with new functions and modifications to existing ones to accommodate the new statistics feature.

4. New scenes have been added for displaying information and statistics, as seen in the `flipp_pomodoro_scene_info.c` and `flipp_pomodoro_scene_timer.c` files.

5. A new view `flipp_pomodoro_info_view.c` has been created to display the statistics and information.

6. An image file `flipp_pomodoro_learn_50x128.png` has been added to the `images` directory.

7. A new shell script `files-list.sh` has been added to the `tools` directory.
  • Loading branch information
Th3Un1q3 authored Jun 21, 2023
1 parent ddda80f commit 52cc11a
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 25 deletions.
20 changes: 19 additions & 1 deletion flipp_pomodoro_app.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "flipp_pomodoro_app_i.h"

#define TAG "FlippPomodoro"

enum
{
CustomEventConsumed = true,
Expand Down Expand Up @@ -39,6 +41,9 @@ static bool flipp_pomodoro_app_custom_event_callback(void *ctx, uint32_t event)
{
// REGISTER a deed on work stage complete to get an acheivement
dolphin_deed(DolphinDeedPluginGameWin);
FURI_LOG_I(TAG, "Focus stage reward added");

flipp_pomodoro_statistics__increase_focus_stages_completed(app->statistics);
};

flipp_pomodoro__toggle_stage(app->state);
Expand All @@ -63,6 +68,8 @@ FlippPomodoroApp *flipp_pomodoro_app_alloc()
app->notification_app = furi_record_open(RECORD_NOTIFICATION);

app->view_dispatcher = view_dispatcher_alloc();
app->statistics = flipp_pomodoro_statistics__new();

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);
Expand All @@ -71,23 +78,32 @@ FlippPomodoroApp *flipp_pomodoro_app_alloc()
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();

view_dispatcher_add_view(
app->view_dispatcher,
FlippPomodoroAppViewTimer,
flipp_pomodoro_view_timer_get_view(app->timer_view));

scene_manager_next_scene(app->scene_manager, FlippPomodoroSceneTimer);
view_dispatcher_add_view(
app->view_dispatcher,
FlippPomodoroAppViewInfo,
flipp_pomodoro_info_view_get_view(app->info_view));

scene_manager_next_scene(app->scene_manager, FlippPomodoroSceneTimer);
FURI_LOG_I(TAG, "Alloc complete");
return 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);
scene_manager_free(app->scene_manager);
flipp_pomodoro_view_timer_free(app->timer_view);
flipp_pomodoro_info_view_free(app->info_view);
flipp_pomodoro_statistics__destroy(app->statistics);
flipp_pomodoro__destroy(app->state);
free(app);
furi_record_close(RECORD_GUI);
Expand All @@ -97,8 +113,10 @@ void flipp_pomodoro_app_free(FlippPomodoroApp *app)
int32_t flipp_pomodoro_app(void *p)
{
UNUSED(p);
FURI_LOG_I(TAG, "Initial");
FlippPomodoroApp *app = flipp_pomodoro_app_alloc();

FURI_LOG_I(TAG, "Run deed added");
dolphin_deed(DolphinDeedPluginGameStart);

view_dispatcher_run(app->view_dispatcher);
Expand Down
6 changes: 6 additions & 0 deletions flipp_pomodoro_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <gui/scene_manager.h>
#include <notification/notification_messages.h>
#include "views/flipp_pomodoro_timer_view.h"
#include "views/flipp_pomodoro_info_view.h"

#include "modules/flipp_pomodoro.h"
#include "modules/flipp_pomodoro_statistics.h"

typedef enum
{
Expand All @@ -17,6 +19,7 @@ typedef enum
FlippPomodoroAppCustomEventStageComplete, // By Expiration
FlippPomodoroAppCustomEventTimerTick,
FlippPomodoroAppCustomEventStateUpdated,
FlippPomodoroAppCustomEventResumeTimer,
} FlippPomodoroAppCustomEvent;

typedef struct
Expand All @@ -26,10 +29,13 @@ typedef struct
Gui *gui;
NotificationApp *notification_app;
FlippPomodoroTimerView *timer_view;
FlippPomodoroInfoView *info_view;
FlippPomodoroState *state;
FlippPomodoroStatistics *statistics;
} FlippPomodoroApp;

typedef enum
{
FlippPomodoroAppViewTimer,
FlippPomodoroAppViewInfo,
} FlippPomodoroAppView;
2 changes: 1 addition & 1 deletion flipp_pomodoro_app_i.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define FURI_DEBUG 1
// #define FURI_DEBUG 1

/**
* Index of dependencies for the main app
Expand Down
Binary file added images/flipp_pomodoro_learn_50x128.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: 0 additions & 1 deletion modules/flipp_pomodoro.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ typedef enum
/// @brief State of the pomodoro timer
typedef struct
{
PomodoroStage stage;
uint8_t current_stage_index;
uint32_t started_at_timestamp;
} FlippPomodoroState;
Expand Down
28 changes: 28 additions & 0 deletions modules/flipp_pomodoro_statistics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "flipp_pomodoro_statistics.h"

FlippPomodoroStatistics *flipp_pomodoro_statistics__new()
{
FlippPomodoroStatistics *statistics = malloc(sizeof(FlippPomodoroStatistics));

statistics->focus_stages_completed = 0;

return statistics;
}

// Return the number of completed focus stages
uint8_t flipp_pomodoro_statistics__get_focus_stages_completed(FlippPomodoroStatistics *statistics)
{
return statistics->focus_stages_completed;
}

// Increase the number of completed focus stages by one
void flipp_pomodoro_statistics__increase_focus_stages_completed(FlippPomodoroStatistics *statistics)
{
statistics->focus_stages_completed++;
}

void flipp_pomodoro_statistics__destroy(FlippPomodoroStatistics *statistics)
{
furi_assert(statistics);
free(statistics);
};
45 changes: 45 additions & 0 deletions modules/flipp_pomodoro_statistics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include <furi_hal.h>

/** @brief FlippPomodoroStatistics structure
*
* This structure is used to keep track of completed focus stages.
*/
typedef struct
{
uint8_t focus_stages_completed;
} FlippPomodoroStatistics;

/** @brief Allocate and initialize a new FlippPomodoroStatistics
*
* This function allocates a new FlippPomodoroStatistics structure, initializes its members
* and returns a pointer to it.
*
* @return A pointer to a new FlippPomodoroStatistics structure
*/
FlippPomodoroStatistics *flipp_pomodoro_statistics__new();

/** @brief Get the number of completed focus stages
*
* This function retrieves the number of completed focus stages in a FlippPomodoroStatistics structure.
*
* @param statistics A pointer to a FlippPomodoroStatistics structure
* @return The number of completed focus stages
*/
uint8_t flipp_pomodoro_statistics__get_focus_stages_completed(FlippPomodoroStatistics *statistics);

/** @brief Increase the number of completed focus stages
*
* This function increases the count of the completed focus stages by one in a FlippPomodoroStatistics structure.
*
* @param statistics A pointer to a FlippPomodoroStatistics structure
*/
void flipp_pomodoro_statistics__increase_focus_stages_completed(FlippPomodoroStatistics *statistics);

/** @brief Free a FlippPomodoroStatistics structure
*
* This function frees the memory used by a FlippPomodoroStatistics structure.
*
* @param statistics A pointer to a FlippPomodoroStatistics structure
*/
void flipp_pomodoro_statistics__destroy(FlippPomodoroStatistics *state);
1 change: 1 addition & 0 deletions scenes/config/flipp_pomodoro_scene_config.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ADD_SCENE(flipp_pomodoro, info, Info)
ADD_SCENE(flipp_pomodoro, timer, Timer)
1 change: 1 addition & 0 deletions scenes/flipp_pomodoro_scene.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <gui/scene_manager.h>

// Generate scene id and total number
Expand Down
67 changes: 67 additions & 0 deletions scenes/flipp_pomodoro_scene_info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <furi.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include "flipp_pomodoro_scene.h"
#include "../flipp_pomodoro_app.h"
#include "../views/flipp_pomodoro_info_view.h"

enum
{
SceneEventConusmed = true,
SceneEventNotConusmed = false
};

void flipp_pomodoro_scene_info_on_back_to_timer(void *ctx)
{
furi_assert(ctx);
FlippPomodoroApp *app = ctx;

view_dispatcher_send_custom_event(
app->view_dispatcher,
FlippPomodoroAppCustomEventResumeTimer);
};

void flipp_pomodoro_scene_info_on_enter(void *ctx)
{
furi_assert(ctx);
FlippPomodoroApp *app = ctx;

view_dispatcher_switch_to_view(app->view_dispatcher, FlippPomodoroAppViewInfo);
flipp_pomodoro_info_view_set_pomodoros_completed(
flipp_pomodoro_info_view_get_view(app->info_view),
flipp_pomodoro_statistics__get_focus_stages_completed(app->statistics));
flipp_pomodoro_info_view_set_mode(flipp_pomodoro_info_view_get_view(app->info_view), FlippPomodoroInfoViewModeStats);
flipp_pomodoro_info_view_set_resume_timer_cb(app->info_view, flipp_pomodoro_scene_info_on_back_to_timer, app);
};

void flipp_pomodoro_scene_info_handle_custom_event(FlippPomodoroApp *app, FlippPomodoroAppCustomEvent custom_event)
{
if (custom_event == FlippPomodoroAppCustomEventResumeTimer)
{
scene_manager_next_scene(app->scene_manager, FlippPomodoroSceneTimer);
}
};

bool flipp_pomodoro_scene_info_on_event(void *ctx, SceneManagerEvent event)
{
furi_assert(ctx);
FlippPomodoroApp *app = ctx;

switch (event.type)
{
case SceneManagerEventTypeBack:
view_dispatcher_stop(app->view_dispatcher);
return SceneEventConusmed;
case SceneManagerEventTypeCustom:
flipp_pomodoro_scene_info_handle_custom_event(app, event.event);
return SceneEventConusmed;
default:
break;
};
return SceneEventNotConusmed;
};

void flipp_pomodoro_scene_info_on_exit(void *ctx)
{
UNUSED(ctx);
};
13 changes: 10 additions & 3 deletions scenes/flipp_pomodoro_scene_timer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <furi.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include "flipp_pomodoro_scene.h"
#include "../flipp_pomodoro_app.h"
#include "../views/flipp_pomodoro_timer_view.h"

Expand All @@ -10,8 +12,6 @@ enum
SceneEventNotConusmed = false
};

uint8_t ExitSignal = 0;

void flipp_pomodoro_scene_timer_sync_view_state(void *ctx)
{
furi_assert(ctx);
Expand Down Expand Up @@ -40,6 +40,12 @@ void flipp_pomodoro_scene_timer_on_enter(void *ctx)

FlippPomodoroApp *app = ctx;

if (flipp_pomodoro__is_stage_expired(app->state))
{
flipp_pomodoro__destroy(app->state);
app->state = flipp_pomodoro__new();
}

view_dispatcher_switch_to_view(app->view_dispatcher, FlippPomodoroAppViewTimer);
flipp_pomodoro_scene_timer_sync_view_state(app);
flipp_pomodoro_view_timer_set_on_right_cb(
Expand Down Expand Up @@ -76,7 +82,8 @@ bool flipp_pomodoro_scene_timer_on_event(void *ctx, SceneManagerEvent event)
event.event);
return SceneEventConusmed;
case SceneManagerEventTypeBack:
return ExitSignal;
scene_manager_next_scene(app->scene_manager, FlippPomodoroSceneInfo);
return SceneEventConusmed;
default:
break;
};
Expand Down
Loading

0 comments on commit 52cc11a

Please sign in to comment.