Skip to content

Commit

Permalink
Merge pull request #5 from beratalp/main
Browse files Browse the repository at this point in the history
Add 52/17 pomodoro timer option
  • Loading branch information
sbrin authored Nov 18, 2023
2 parents c9f45cb + e353ddb commit 7884d49
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
Binary file modified dist/pomodoro.fap
Binary file not shown.
19 changes: 19 additions & 0 deletions pomodoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum PomodoroDebugSubmenuIndex {
PomodoroSubmenuIndex10,
PomodoroSubmenuIndex25,
PomodoroSubmenuIndex50,
PomodoroSubmenuIndex52,
};

void pomodoro_submenu_callback(void* context, uint32_t index) {
Expand All @@ -24,6 +25,10 @@ void pomodoro_submenu_callback(void* context, uint32_t index) {
app->view_id = PomodoroView50;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView50);
}
if(index == PomodoroSubmenuIndex52) {
app->view_id = PomodoroView52;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView52);
}
}

void pomodoro_dialog_callback(DialogExResult result, void* context) {
Expand Down Expand Up @@ -82,6 +87,12 @@ Pomodoro* pomodoro_app_alloc() {
PomodoroSubmenuIndex10,
pomodoro_submenu_callback,
app);
submenu_add_item(
app->submenu,
"5217: 52 work 17 rest",
PomodoroSubmenuIndex52,
pomodoro_submenu_callback,
app);
view_set_previous_callback(submenu_get_view(app->submenu), pomodoro_exit);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroViewSubmenu, submenu_get_view(app->submenu));
Expand Down Expand Up @@ -115,6 +126,12 @@ Pomodoro* pomodoro_app_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView10, pomodoro_10_get_view(app->pomodoro_10));

// 52 minutes view
app->pomodoro_52 = pomodoro_52_alloc();
view_set_previous_callback(pomodoro_52_get_view(app->pomodoro_52), pomodoro_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView52, pomodoro_52_get_view(app->pomodoro_52));

// TODO switch to menu after Media is done
app->view_id = PomodoroViewSubmenu;
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
Expand All @@ -139,6 +156,8 @@ void pomodoro_app_free(Pomodoro* app) {
pomodoro_50_free(app->pomodoro_50);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView10);
pomodoro_10_free(app->pomodoro_10);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView52);
pomodoro_52_free(app->pomodoro_52);
view_dispatcher_free(app->view_dispatcher);

// Close records
Expand Down
3 changes: 3 additions & 0 deletions pomodoro.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "views/pomodoro_10.h"
#include "views/pomodoro_25.h"
#include "views/pomodoro_50.h"
#include "views/pomodoro_52.h"

typedef struct {
Gui* gui;
Expand All @@ -22,6 +23,7 @@ typedef struct {
PomodoroTimer* pomodoro_10;
PomodoroTimer* pomodoro_25;
PomodoroTimer* pomodoro_50;
PomodoroTimer* pomodoro_52;
uint32_t view_id;
} Pomodoro;

Expand All @@ -30,5 +32,6 @@ typedef enum {
PomodoroView10,
PomodoroView25,
PomodoroView50,
PomodoroView52,
PomodoroViewExitConfirm,
} PomodoroView;
46 changes: 46 additions & 0 deletions views/pomodoro_52.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "../pomodoro_timer.h"
#include "pomodoro_52.h"
#include <furi.h>
#include <furi_hal.h>
#include <gui/elements.h>
#include <notification/notification_messages.h>

static void pomodoro_52_draw_callback(Canvas* canvas, void* context) {
int max_seconds = 60 * 52;
int max_seconds_rest = 60 * 17;
pomodoro_draw_callback(canvas, context, max_seconds, max_seconds_rest);
}

static bool pomodoro_52_input_callback(InputEvent* event, void* context) {
furi_assert(context);
PomodoroTimer* pomodoro_52 = context;

if(event->type == InputTypeLong && event->key == InputKeyBack) {
return false;
} else {
pomodoro_timer_process(pomodoro_52, event);
return true;
}
}

PomodoroTimer* pomodoro_52_alloc() {
PomodoroTimer* pomodoro_52 = malloc(sizeof(PomodoroTimer));
pomodoro_52->view = view_alloc();
view_set_context(pomodoro_52->view, pomodoro_52);
view_allocate_model(pomodoro_52->view, ViewModelTypeLocking, sizeof(PomodoroTimerModel));
view_set_draw_callback(pomodoro_52->view, pomodoro_52_draw_callback);
view_set_input_callback(pomodoro_52->view, pomodoro_52_input_callback);

return pomodoro_52;
}

void pomodoro_52_free(PomodoroTimer* pomodoro_52) {
furi_assert(pomodoro_52);
view_free(pomodoro_52->view);
free(pomodoro_52);
}

View* pomodoro_52_get_view(PomodoroTimer* pomodoro_52) {
furi_assert(pomodoro_52);
return pomodoro_52->view;
}
10 changes: 10 additions & 0 deletions views/pomodoro_52.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <gui/view.h>
#include "../pomodoro_timer.h"

PomodoroTimer* pomodoro_52_alloc();

void pomodoro_52_free(PomodoroTimer* pomodoro_52);

View* pomodoro_52_get_view(PomodoroTimer* pomodoro_52);

0 comments on commit 7884d49

Please sign in to comment.