Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pmodore/pmodore-application
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud-eslami committed Jun 2, 2023
2 parents 30290fb + 3ab5d4a commit 1a21555
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: [main, develop]
branches: [main, develop, hotfix/timer-issue]

jobs:
build_android:
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
4 changes: 2 additions & 2 deletions lib/core/resources/params/timer_state_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "package:pomodore/features/task_management/domain/entities/task_entity.da
class TimerStateParams extends Equatable {
final int duration;
final int baseDuration;
final TaskEntity task;
final TaskEntity? task;
final bool timerDone;

const TimerStateParams({
Expand All @@ -26,7 +26,7 @@ class TimerStateParams extends Equatable {
class TimerStateRestoreParams extends Equatable {
final int duration;
final int baseDuration;
final Map<String, dynamic> task;
final Map<String, dynamic>? task;
final bool timerDone;

const TimerStateRestoreParams({
Expand Down
4 changes: 0 additions & 4 deletions lib/features/configuration/presentation/pages/base_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BasePage extends StatelessWidget {
const HomePage(),
const TasksPage(),
const SettingsPage(),
const UserPage(),
const TimerPage(),
];

Expand Down Expand Up @@ -49,9 +48,6 @@ class BasePage extends StatelessWidget {
BottomNavigationBarItem(
icon: const Icon(Ionicons.settings_outline),
label: localization.settingTab),
BottomNavigationBarItem(
icon: const Icon(Ionicons.person),
label: localization.settingTab),
BottomNavigationBarItem(
icon: Container(
width: 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,4 @@ class TasksLocalDataSource {

return result;
}

getTaskById(String id) {}

getCompletedTask() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ class TimerLocalDataSource {
FStorage.timerStateDateTimeKey, DateTime.now().toString());
await FStorage.write(FStorage.timerStateBaseDurationKey,
stateParams.baseDuration.toString());
await FStorage.write(FStorage.taskIdKey, stateParams.task.id);
if (stateParams.task != null) {
await FStorage.write(FStorage.taskIdKey, stateParams.task!.id);
}
result = stateParams.duration;
} catch (e) {
rethrow;
}
return result;
}

Future<Map<String, dynamic>> getTaskById(String id) async {
Future<Map<String, dynamic>?> getTaskById(String? id) async {
if (id == null) return null;
final List<Map<String, dynamic>> result = await db.query(
"tasks",
where: "uid = ?",
Expand All @@ -64,14 +67,11 @@ class TimerLocalDataSource {
await FStorage.read(FStorage.timerStateBaseDurationKey);
final id = await FStorage.read(FStorage.taskIdKey);

if (state != null &&
dateTimeState != null &&
baseStateDuration != null &&
id != null) {
if (state != null && dateTimeState != null && baseStateDuration != null) {
final DateTime restoredDateTime = DateTime.parse(dateTimeState);
final DateTime now = DateTime.now();
final Duration remainDuration = now.difference(restoredDateTime);
final Map<String, dynamic> task = await getTaskById(id);
final Map<String, dynamic>? task = await getTaskById(id);

if (remainDuration.inSeconds < int.parse(state)) {
result = TimerStateRestoreParams(
Expand All @@ -89,11 +89,12 @@ class TimerLocalDataSource {
);
}
} else {
dPrint("All values are null so we can not restore timer");
result = null;
}
} catch (e) {
dPrint(e.toString());
rethrow;
} catch (e, s) {
dPrint("$e $s");
result = null;
}

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "package:dartz/dartz.dart";
import "package:pomodore/core/utils/debug_print.dart";
import "package:pomodore/features/task_management/data/data_sources/timer_local_data_source.dart";
import "package:pomodore/features/task_management/data/models/task_model.dart";
import "package:pomodore/features/task_management/domain/repositories/timer_repository.dart";
Expand Down Expand Up @@ -30,24 +31,31 @@ class TimerRepositoryImpl extends TimerRepository {
Future<Either<String, TimerStateParams>> restoreTimerState() async {
late Either<String, TimerStateParams> result;

final TimerStateRestoreParams? restoredState =
await timerLocalDataSource.restoreTimerState();

if (restoredState != null) {
result = Right(
TimerStateParams(
duration: restoredState.duration,
baseDuration: restoredState.baseDuration,
task: TaskModel.fromJson(restoredState.task),
timerDone: restoredState.timerDone,
),
);
} else {
try {
final TimerStateRestoreParams? restoredState =
await timerLocalDataSource.restoreTimerState();

if (restoredState != null) {
result = Right(
TimerStateParams(
duration: restoredState.duration,
baseDuration: restoredState.baseDuration,
task: restoredState.task != null
? TaskModel.fromJson(restoredState.task!)
: null,
timerDone: restoredState.timerDone,
),
);
} else {
result = const Left("error");
}

timerLocalDataSource.removeTimerState();
} catch (e, s) {
dPrint("$e $s");
result = const Left("error");
}

timerLocalDataSource.removeTimerState();

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
void _timerStateSaved(TimerStateSaved event, Emitter emit) async {
emit(SaveTimerLoading(state.duration));

if (taskItem == null) {
emit(SaveTimerFailure(state.duration));
} else {
final Either<String, int> result = await saveTimerStateUseCase.call(
params: TimerStateParams(
duration: state.duration,
baseDuration: getDurationInMinutes,
task: taskItem!,
timerDone: false,
),
);

result.fold((l) => emit(SaveTimerFailure(state.duration)),
(r) => emit(SaveTimerSuccess(state.duration)));
}
final Either<String, int> result = await saveTimerStateUseCase.call(
params: TimerStateParams(
duration: state.duration,
baseDuration: getDurationInMinutes,
task: taskItem,
timerDone: false,
),
);

result.fold(
(l) => emit(
SaveTimerFailure(state.duration),
),
(r) => emit(
SaveTimerSuccess(state.duration),
),
);
}

void _timerStateRestored(TimerStateRestored event, Emitter emit) async {
Expand All @@ -105,8 +107,14 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
final Either<String, TimerStateParams> result =
await restoreTimerStateUseCase.call();

result.fold((l) => emit(RestoreTimerFailure(state.duration)),
(r) => emit(RestoreTimerSuccess(state.duration, r)));
result.fold(
(l) => emit(
RestoreTimerFailure(state.duration),
),
(r) => emit(
RestoreTimerSuccess(state.duration, r),
),
);
}

void _timerDurationSet(TimerDurationSet event, Emitter emit) {
Expand All @@ -117,7 +125,9 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {

void _timerTaskSelected(TimerTaskSelected event, Emitter emit) {
selectTask(event.taskItem);
emit(SelectTaskSuccess(state.duration, taskItem!));
if (event.taskItem != null) {
emit(SelectTaskSuccess(state.duration, taskItem!));
}
}

void _timerTaskDeSelected(TimerTaskDeSelected event, Emitter emit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SaveCurrentTimerStateDialogShowed extends TimerEvent {
}

class TimerTaskSelected extends TimerEvent {
final TaskEntity taskItem;
final TaskEntity? taskItem;

const TimerTaskSelected(this.taskItem);

Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "package:flutter_localizations/flutter_localizations.dart";
import "package:pomodore/core/constant/constant.dart";
import "package:pomodore/core/router/router.dart";
import "package:pomodore/core/services/notification/local_notification.dart";
import "package:pomodore/core/shared_widgets/global_snack.dart";
import "package:pomodore/core/utils/debug_print.dart";
import "package:pomodore/di.dart";
import "package:pomodore/features/configuration/presentation/blocs/base_bloc/base_bloc.dart";
Expand Down Expand Up @@ -105,7 +106,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
BlocListener<TimerBloc, TimerState>(
listener: (context, state) {
final TimerBloc bloc = context.read<TimerBloc>();
dPrint(state.toString());
if (state is RestoreTimerSuccess) {
if (state.timerStateParams.timerDone) {
getIt.get<AppLocalNotification>().sendCustomNotification(
Expand Down

0 comments on commit 1a21555

Please sign in to comment.