From 4175dce635e6ec90c57f637265719138be3da29f Mon Sep 17 00:00:00 2001 From: CoderJava Date: Mon, 24 Jul 2023 21:53:23 +0700 Subject: [PATCH 1/4] Set default pengaturan reminder track --- lib/main.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index ade5729..d1aee3f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -286,6 +286,7 @@ class _MyAppState extends State { }; } + // set default launch at startup final isLaunchAtStartupExists = sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsLaunchAtStartup); if (!isLaunchAtStartupExists) { @@ -293,9 +294,35 @@ class _MyAppState extends State { sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsLaunchAtStartup, true); } + // set default value always on top final isAlwaysOnTop = sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsAlwaysOnTop, defaultValue: true) ?? true; windowManager.setAlwaysOnTop(isAlwaysOnTop); + + // set default value reminder not track + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableReminderTrack)) { + sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableReminderTrack, false); + } + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyStartTimeReminderTrack)) { + sharedPreferencesManager.putString(SharedPreferencesManager.keyStartTimeReminderTrack, '08:30'); + } + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyFinishTimeReminderTrack)) { + sharedPreferencesManager.putString(SharedPreferencesManager.keyFinishTimeReminderTrack, '17:00'); + } + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyDayReminderTrack)) { + final defaultDays = [ + DateTime.monday.toString(), + DateTime.tuesday.toString(), + DateTime.wednesday.toString(), + DateTime.thursday.toString(), + DateTime.friday.toString(), + ]; + sharedPreferencesManager.putStringList(SharedPreferencesManager.keyDayReminderTrack, defaultDays); + } + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIntervalReminderTrack)) { + // 15 menit + sharedPreferencesManager.putInt(SharedPreferencesManager.keyIntervalReminderTrack, 15); + } }); super.initState(); } From 773cfe6f7f1493a99baec70b28bf1a5a3efe0a5d Mon Sep 17 00:00:00 2001 From: CoderJava Date: Mon, 24 Jul 2023 21:57:40 +0700 Subject: [PATCH 2/4] feat: Buat pengaturan reminder track time --- lib/core/util/shared_preferences_manager.dart | 5 + .../page/setting/setting_page.dart | 582 +++++++++++++++--- 2 files changed, 503 insertions(+), 84 deletions(-) diff --git a/lib/core/util/shared_preferences_manager.dart b/lib/core/util/shared_preferences_manager.dart index fcb4930..e047035 100644 --- a/lib/core/util/shared_preferences_manager.dart +++ b/lib/core/util/shared_preferences_manager.dart @@ -18,6 +18,11 @@ class SharedPreferencesManager { static const keyBaseFilePathScreenshot = 'base_file_path_screenshot'; static const keyIsLaunchAtStartup = 'is_launch_at_startup'; static const keyIsAlwaysOnTop = 'is_always_on_top'; + static const keyIsEnableReminderTrack = 'is_enable_reminder_track'; + static const keyStartTimeReminderTrack = 'start_time_reminder_track'; + static const keyFinishTimeReminderTrack = 'finish_time_reminder_track'; + static const keyDayReminderTrack = 'day_reminder_track'; + static const keyIntervalReminderTrack = 'interval_reminder_track'; SharedPreferencesManager(); diff --git a/lib/feature/presentation/page/setting/setting_page.dart b/lib/feature/presentation/page/setting/setting_page.dart index faf3aa4..4c503b8 100644 --- a/lib/feature/presentation/page/setting/setting_page.dart +++ b/lib/feature/presentation/page/setting/setting_page.dart @@ -6,6 +6,7 @@ import 'package:dipantau_desktop_client/core/util/helper.dart'; import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart'; import 'package:dipantau_desktop_client/core/util/widget_helper.dart'; import 'package:dipantau_desktop_client/feature/presentation/bloc/appearance/appearance_bloc.dart'; +import 'package:dipantau_desktop_client/feature/presentation/page/home/home_page.dart'; import 'package:dipantau_desktop_client/feature/presentation/page/member_setting/member_setting_page.dart'; import 'package:dipantau_desktop_client/feature/presentation/page/setting_discord/setting_discord_page.dart'; import 'package:dipantau_desktop_client/feature/presentation/page/setup_credential/setup_credential_page.dart'; @@ -14,6 +15,7 @@ import 'package:dipantau_desktop_client/feature/presentation/widget/widget_prima import 'package:dipantau_desktop_client/feature/presentation/widget/widget_theme_container.dart'; import 'package:dipantau_desktop_client/injection_container.dart'; import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -39,12 +41,23 @@ class _SettingPageState extends State { final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light); final valueNotifierLaunchAtStartup = ValueNotifier(true); final valueNotifierAlwaysOnTop = ValueNotifier(true); + final valueNotifierIsEnableReminderTrack = ValueNotifier(false); final widgetHelper = WidgetHelper(); + final controllerStartTimeReminderTrackNotification = TextEditingController(); + final controllerFinishTimeReminderTrackNotification = TextEditingController(); + final controllerIntervalReminderTrackNotification = TextEditingController(); var selectedIndexNavigationRail = 0; UserRole? userRole; var hostname = ''; late AppearanceBloc appearanceBloc; + var isEnableReminderTrackMon = true; + var isEnableReminderTrackTue = true; + var isEnableReminderTrackWed = true; + var isEnableReminderTrackThu = true; + var isEnableReminderTrackFri = true; + var isEnableReminderTrackSat = false; + var isEnableReminderTrackSun = false; @override void setState(VoidCallback fn) { @@ -245,6 +258,407 @@ class _SettingPageState extends State { ), children: [ buildWidgetScreenshotNotification(), + const SizedBox(height: 16), + buildWidgetReminderNotTrackNotification(), + const SizedBox(height: 8), + buildWidgetSetupReminderNotTrackNotification(), + ], + ); + } + + Widget buildWidgetSetupReminderNotTrackNotification() { + final isEnabled = valueNotifierIsEnableReminderTrack.value; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + 'from'.tr(), + ), + const SizedBox(width: 8), + SizedBox( + width: 64, + height: 24, + child: TextField( + controller: controllerStartTimeReminderTrackNotification, + decoration: widgetHelper.setDefaultTextFieldDecoration().copyWith( + isDense: true, + counterText: '', + contentPadding: const EdgeInsets.only( + top: 8, + ), + ), + enabled: isEnabled, + textAlign: TextAlign.center, + maxLines: 1, + maxLength: 5, + readOnly: true, + onTap: !isEnabled + ? null + : () async { + final strStart = controllerStartTimeReminderTrackNotification.text.trim(); + var initialTime = TimeOfDay.now(); + if (strStart.contains(':')) { + final strStartHour = strStart.split(':').first; + final strStartMinute = strStart.split(':').last; + final startHour = int.tryParse(strStartHour); + final startMinute = int.tryParse(strStartMinute); + if (startHour != null && startMinute != null) { + initialTime = TimeOfDay(hour: startHour, minute: startMinute); + } + } + final result = await showTimePicker( + context: context, + initialTime: initialTime, + initialEntryMode: TimePickerEntryMode.input, + ); + if (result != null) { + final hour = result.hour; + final minute = result.minute; + var strResult = hour < 10 ? '0$hour' : hour.toString(); + strResult += ':'; + strResult += minute < 10 ? '0$minute' : minute.toString(); + controllerStartTimeReminderTrackNotification.text = strResult; + updateReminderTrack(); + setState(() {}); + } + }, + ), + ), + const SizedBox(width: 8), + Text( + 'to'.tr(), + ), + const SizedBox(width: 8), + SizedBox( + width: 64, + height: 24, + child: TextField( + controller: controllerFinishTimeReminderTrackNotification, + decoration: widgetHelper.setDefaultTextFieldDecoration().copyWith( + isDense: true, + counterText: '', + contentPadding: const EdgeInsets.only( + top: 8, + ), + ), + enabled: isEnabled, + textAlign: TextAlign.center, + maxLines: 1, + maxLength: 5, + readOnly: true, + onTap: !isEnabled + ? null + : () async { + final strFinish = controllerFinishTimeReminderTrackNotification.text.trim(); + var initialTime = TimeOfDay.now(); + if (strFinish.contains(':')) { + final strFinishHour = strFinish.split(':').first; + final strFinishMinute = strFinish.split(':').last; + final finishHour = int.tryParse(strFinishHour); + final finishMinute = int.tryParse(strFinishMinute); + if (finishHour != null && finishMinute != null) { + initialTime = TimeOfDay(hour: finishHour, minute: finishMinute); + } + } + final result = await showTimePicker( + context: context, + initialTime: initialTime, + initialEntryMode: TimePickerEntryMode.input, + ); + if (result != null) { + final finishHour = result.hour; + final finishMinute = result.minute; + final now = DateTime.now(); + final strStart = controllerStartTimeReminderTrackNotification.text.trim(); + if (strStart.contains(':')) { + final strStartHour = strStart.split(':').first; + final strStartMinute = strStart.split(':').last; + final startHour = int.tryParse(strStartHour); + final startMinute = int.tryParse(strStartMinute); + if (startHour != null && startMinute != null) { + final startReminderDateTime = DateTime( + now.year, + now.month, + now.day, + startHour, + startMinute, + ); + final finishReminderDateTime = DateTime( + now.year, + now.month, + now.day, + finishHour, + finishMinute, + ); + if ((finishReminderDateTime.isBefore(startReminderDateTime) || + finishReminderDateTime.isAtSameMomentAs(startReminderDateTime)) && + mounted) { + widgetHelper.showSnackBar(context, 'finish_time_must_be_after_start_time'.tr()); + return; + } + } + } + + var strResult = finishHour < 10 ? '0$finishHour' : finishHour.toString(); + strResult += ':'; + strResult += finishMinute < 10 ? '0$finishMinute' : finishMinute.toString(); + controllerFinishTimeReminderTrackNotification.text = strResult; + updateReminderTrack(); + setState(() {}); + } + }, + ), + ), + const SizedBox(width: 8), + ], + ), + const SizedBox(height: 8), + Text( + 'on_these_days'.tr(), + ), + Wrap( + spacing: 8, + children: [ + buildWidgetItemDay( + 'mon'.tr(), + isEnableReminderTrackMon, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackMon = newValue); + } + }, + ), + buildWidgetItemDay( + 'tue'.tr(), + isEnableReminderTrackTue, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackTue = newValue); + } + }, + ), + buildWidgetItemDay( + 'wed'.tr(), + isEnableReminderTrackWed, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackWed = newValue); + } + }, + ), + buildWidgetItemDay( + 'thu'.tr(), + isEnableReminderTrackThu, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackThu = newValue); + } + }, + ), + buildWidgetItemDay( + 'fri'.tr(), + isEnableReminderTrackFri, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackFri = newValue); + } + }, + ), + buildWidgetItemDay( + 'sat'.tr(), + isEnableReminderTrackSat, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackSat = newValue); + } + }, + ), + buildWidgetItemDay( + 'sun'.tr(), + isEnableReminderTrackSun, + onChanged: (newValue) { + if (newValue != null) { + setState(() => isEnableReminderTrackSun = newValue); + } + }, + ), + ], + ), + Row( + children: [ + Text( + 'if_i_havent_tracked_time_in'.tr(), + ), + const SizedBox(width: 8), + SizedBox( + width: 36, + height: 24, + child: TextField( + controller: controllerIntervalReminderTrackNotification, + decoration: widgetHelper.setDefaultTextFieldDecoration().copyWith( + isDense: true, + counterText: '', + contentPadding: const EdgeInsets.only( + top: 8, + ), + ), + enabled: isEnabled, + textAlign: TextAlign.center, + maxLines: 1, + maxLength: 2, + keyboardType: TextInputType.number, + readOnly: true, + onTap: !isEnabled + ? null + : () async { + final elements = []; + var counter = 0; + for (var number = 1; number <= 12; number++) { + counter += 5; + elements.add(counter); + } + final result = await showCupertinoModalPopup( + context: context, + builder: (context) { + final strInterval = controllerIntervalReminderTrackNotification.text.trim(); + var indexSelected = elements.indexWhere((element) => element.toString() == strInterval); + if (indexSelected == -1) { + indexSelected = 0; + } + return Container( + height: 192, + padding: const EdgeInsets.all(16), + color: CupertinoColors.systemBackground.resolveFrom(context), + child: Column( + children: [ + Expanded( + child: CupertinoPicker( + squeeze: 1, + itemExtent: 28, + useMagnifier: true, + scrollController: FixedExtentScrollController( + initialItem: indexSelected, + ), + onSelectedItemChanged: (int value) { + indexSelected = value; + }, + children: elements.map( + (e) { + return Text( + 'n_minute'.tr( + args: [ + e.toString(), + ], + ), + ); + }, + ).toList(), + ), + ), + const SizedBox(height: 16), + SizedBox( + width: double.infinity, + child: WidgetPrimaryButton( + onPressed: () => context.pop(elements[indexSelected]), + child: Text('choose'.tr()), + ), + ), + ], + ), + ); + }, + ); + if (result != null) { + controllerIntervalReminderTrackNotification.text = result.toString(); + updateReminderTrack(); + setState(() {}); + } + }, + ), + ), + const SizedBox(width: 8), + Text( + 'alias_minutes'.tr(), + ), + ], + ), + ], + ); + } + + Widget buildWidgetItemDay(String label, bool value, {ValueChanged? onChanged}) { + final isEnabled = valueNotifierIsEnableReminderTrack.value; + return SizedBox( + width: 60, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + width: 24, + child: Checkbox( + value: value, + onChanged: !isEnabled + ? null + : (newValue) { + onChanged?.call(newValue); + updateReminderTrack(); + }, + ), + ), + const SizedBox(width: 4), + Text( + label, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Colors.grey, + ), + ), + ], + ), + ); + } + + Widget buildWidgetReminderNotTrackNotification() { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'remind_me_to_track_time'.tr(), + style: Theme.of(context).textTheme.bodyLarge, + ), + Text( + 'subtitle_remind_me_to_track_time'.tr(), + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Colors.grey, + ), + ), + ], + ), + ), + const SizedBox(width: 16), + ValueListenableBuilder( + valueListenable: valueNotifierIsEnableReminderTrack, + builder: (BuildContext context, bool value, _) { + return Switch.adaptive( + value: value, + onChanged: (newValue) { + sharedPreferencesManager.putBool( + SharedPreferencesManager.keyIsEnableReminderTrack, + newValue, + ); + valueNotifierIsEnableReminderTrack.value = newValue; + updateReminderTrack(); + setState(() {}); + }, + activeColor: Theme.of(context).colorScheme.primary, + ); + }, + ), ], ); } @@ -289,6 +703,20 @@ class _SettingPageState extends State { if (appearanceMode != null) { valueNotifierAppearanceMode.value = appearanceMode; } + + valueNotifierIsEnableReminderTrack.value = + sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableReminderTrack) ?? false; + controllerStartTimeReminderTrackNotification.text = + sharedPreferencesManager.getString(SharedPreferencesManager.keyStartTimeReminderTrack, defaultValue: '08:30') ?? + '08:30'; + controllerFinishTimeReminderTrackNotification.text = sharedPreferencesManager + .getString(SharedPreferencesManager.keyFinishTimeReminderTrack, defaultValue: '17:00') ?? + '17:00'; + controllerIntervalReminderTrackNotification.text = (sharedPreferencesManager.getInt( + SharedPreferencesManager.keyIntervalReminderTrack, + ) ?? + 15) + .toString(); } Widget buildWidgetSetHostName() { @@ -825,96 +1253,82 @@ class _SettingPageState extends State { ], ); } -} -/*class _SettingPageState extends State { - final helper = sl(); - final valueNotifierIsEnableScreenshotNotification = ValueNotifier(false); - final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light); - final valueNotifierLaunchAtStartup = ValueNotifier(true); - final widgetHelper = WidgetHelper(); - final sharedPreferencesManager = sl(); - - var hostname = ''; - late AppearanceBloc appearanceBloc; - UserRole? userRole; + void updateReminderTrack() async { + final isEnableReminderNotTrack = valueNotifierIsEnableReminderTrack.value; + await sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableReminderTrack, isEnableReminderNotTrack); - @override - void setState(VoidCallback fn) { - if (mounted) { - super.setState(fn); + final strStart = controllerStartTimeReminderTrackNotification.text.trim(); + if (strStart.contains(':') && strStart.split(':').length == 2) { + final splitStrStart = strStart.split(':'); + final strStartHour = splitStrStart.first; + final strStartMinute = splitStrStart.last; + final startHour = int.tryParse(strStartHour); + final startMinute = int.tryParse(strStartMinute); + if (startHour != null && startMinute != null) { + var formattedStart = startHour < 10 ? '0$startHour' : startHour.toString(); + formattedStart += ':'; + formattedStart += startMinute < 10 ? '0$startMinute' : startMinute.toString(); + await sharedPreferencesManager.putString( + SharedPreferencesManager.keyStartTimeReminderTrack, + formattedStart, + ); + } } - } - @override - void initState() { - launchAtStartup.isEnabled().then((value) { - valueNotifierLaunchAtStartup.value = value; - }); - appearanceBloc = BlocProvider.of(context); - final strUserRole = sharedPreferencesManager.getString(SharedPreferencesManager.keyUserRole) ?? ''; - userRole = strUserRole.fromStringUserRole; - prepareData(); - super.initState(); - } - - void prepareData() { - valueNotifierIsEnableScreenshotNotification.value = - sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false; - - hostname = sharedPreferencesManager.getString( - SharedPreferencesManager.keyDomainApi, - ) ?? - ''; - if (hostname.isEmpty) { - hostname = '-'; + final strFinish = controllerFinishTimeReminderTrackNotification.text.trim(); + if (strFinish.contains(':') && strFinish.split(':').length == 2) { + final splitStrFinish = strFinish.split(':'); + final strFinishHour = splitStrFinish.first; + final strFinishMinute = splitStrFinish.last; + final finishHour = int.tryParse(strFinishHour); + final finishMinute = int.tryParse(strFinishMinute); + if (finishHour != null && finishMinute != null) { + var formattedFinish = finishHour < 10 ? '0$finishHour' : finishHour.toString(); + formattedFinish += ':'; + formattedFinish += finishMinute < 10 ? '0$finishMinute' : finishMinute.toString(); + await sharedPreferencesManager.putString( + SharedPreferencesManager.keyFinishTimeReminderTrack, + formattedFinish, + ); + } } - final strAppearanceMode = - sharedPreferencesManager.getString(SharedPreferencesManager.keyAppearanceMode) ?? AppearanceMode.light.name; - final appearanceMode = strAppearanceMode.fromStringAppearanceMode; - if (appearanceMode != null) { - valueNotifierAppearanceMode.value = appearanceMode; + final reminderDays = []; + if (isEnableReminderTrackMon) { + reminderDays.add(DateTime.monday.toString()); } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('setting'.tr()), - centerTitle: false, - ), - body: SizedBox( - width: double.infinity, - child: ListView( - padding: EdgeInsets.only( - left: helper.getDefaultPaddingLayout, - top: helper.getDefaultPaddingLayoutTop, - right: helper.getDefaultPaddingLayout, - bottom: helper.getDefaultPaddingLayout + 8, - ), - children: [ - Text( - 'general'.tr(), - style: Theme.of(context).textTheme.titleLarge, - ), - const SizedBox(height: 8), - buildWidgetScreenshotNotification(), - const SizedBox(height: 16), - buildWidgetLaunchAtStartup(), - const SizedBox(height: 16), - buildWidgetSetHostName(), - const SizedBox(height: 16), - buildWidgetCheckForUpdate(), - const SizedBox(height: 16), - buildWidgetChooseAppearance(), - buildWidgetCompanySetting(), - const SizedBox(height: 24), - buildWidgetButtonLogout(), - ], - ), - ), + if (isEnableReminderTrackTue) { + reminderDays.add(DateTime.tuesday.toString()); + } + if (isEnableReminderTrackWed) { + reminderDays.add(DateTime.wednesday.toString()); + } + if (isEnableReminderTrackThu) { + reminderDays.add(DateTime.thursday.toString()); + } + if (isEnableReminderTrackFri) { + reminderDays.add(DateTime.friday.toString()); + } + if (isEnableReminderTrackSat) { + reminderDays.add(DateTime.saturday.toString()); + } + if (isEnableReminderTrackSun) { + reminderDays.add(DateTime.sunday.toString()); + } + await sharedPreferencesManager.putStringList( + SharedPreferencesManager.keyDayReminderTrack, + reminderDays, ); + + final strIntervalReminderTrack = controllerIntervalReminderTrackNotification.text.trim(); + final intervalReminderTrack = int.tryParse(strIntervalReminderTrack); + if (intervalReminderTrack != null) { + await sharedPreferencesManager.putInt( + SharedPreferencesManager.keyIntervalReminderTrack, + intervalReminderTrack, + ); + } + countTimeReminderTrackInSeconds = 0; } -}*/ +} From e6c581235c9ffdb66587797305c5805c51a0ee83 Mon Sep 17 00:00:00 2001 From: CoderJava Date: Mon, 24 Jul 2023 21:59:13 +0700 Subject: [PATCH 3/4] feat: Buat fitur pengaturan reminder track time berdasarkan pengaturan yang tersimpan di lokal --- .../presentation/page/home/home_page.dart | 99 +++++++++++++++++-- 1 file changed, 89 insertions(+), 10 deletions(-) diff --git a/lib/feature/presentation/page/home/home_page.dart b/lib/feature/presentation/page/home/home_page.dart index 4a7def3..a75cc70 100644 --- a/lib/feature/presentation/page/home/home_page.dart +++ b/lib/feature/presentation/page/home/home_page.dart @@ -38,6 +38,8 @@ import 'package:path_provider/path_provider.dart'; import 'package:tray_manager/tray_manager.dart'; import 'package:window_manager/window_manager.dart'; +var countTimeReminderTrackInSeconds = 0; + class HomePage extends StatefulWidget { static const routePath = '/home'; static const routeName = 'home'; @@ -65,7 +67,6 @@ class _HomePageState extends State with TrayListener, WindowListener { final notificationHelper = sl(); final intervalScreenshot = 60 * 5; // 300 detik (5 menit) final listTrackLocal = []; - final intervalReminderNotTrack = 60 * 10; // 600 detik (10 menit) var isWindowVisible = true; var userId = ''; @@ -76,7 +77,6 @@ class _HomePageState extends State with TrayListener, WindowListener { TrackTask? selectedTask; Timer? timeTrack, timerCronTrack, timerDate; var countTimerInSeconds = 0; - var countTimerReminderNotTrack = 0; var isHaveActivity = false; var counterActivity = 0; DateTime? startTime; @@ -127,13 +127,93 @@ class _HomePageState extends State with TrayListener, WindowListener { ); timerDate = Timer.periodic(const Duration(seconds: 1), (_) { if (!isTimerStart) { - countTimerReminderNotTrack += 1; - if (countTimerReminderNotTrack == intervalReminderNotTrack) { - countTimerReminderNotTrack = 0; - notificationHelper.showReminderNotTrackNotification(); + // reminder track + var isShowReminderTrack = false; + final now = DateTime.now(); + countTimeReminderTrackInSeconds += 1; + final isEnableReminderTrack = + sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableReminderTrack) ?? false; + if (isEnableReminderTrack) { + DateTime? startReminderTrack, finishReminderTrack; + final strStartReminderTrack = sharedPreferencesManager.getString( + SharedPreferencesManager.keyStartTimeReminderTrack, + ) ?? + ''; + if (strStartReminderTrack.contains(':') && strStartReminderTrack.split(':').length == 2) { + final splitStrStartReminderTrack = strStartReminderTrack.split(':'); + final strStartHourReminderTrack = splitStrStartReminderTrack.first; + final strStartMinuteReminderTrack = splitStrStartReminderTrack.last; + final startHourReminderTrack = int.tryParse(strStartHourReminderTrack); + final startMinuteReminderTrack = int.tryParse(strStartMinuteReminderTrack); + if (startHourReminderTrack != null && startMinuteReminderTrack != null) { + startReminderTrack = DateTime( + now.year, + now.month, + now.day, + startHourReminderTrack, + startMinuteReminderTrack, + ); + } + } + + final strFinishReminderTrack = sharedPreferencesManager.getString( + SharedPreferencesManager.keyFinishTimeReminderTrack, + ) ?? + ''; + if (strFinishReminderTrack.contains(':') && strFinishReminderTrack.split(':').length == 2) { + final splitStrFinishReminderTrack = strFinishReminderTrack.split(':'); + final strFinishHourReminderTrack = splitStrFinishReminderTrack.first; + final strFinishMinuteReminderTrack = splitStrFinishReminderTrack.last; + final finishHourReminderTrack = int.tryParse(strFinishHourReminderTrack); + final finishMinuteReminderTrack = int.tryParse(strFinishMinuteReminderTrack); + if (finishHourReminderTrack != null && finishMinuteReminderTrack != null) { + finishReminderTrack = DateTime( + now.year, + now.month, + now.day, + finishHourReminderTrack, + finishMinuteReminderTrack, + ); + } + } + + final daysReminderTrack = + sharedPreferencesManager.getStringList(SharedPreferencesManager.keyDayReminderTrack) ?? []; + final nowWeekday = now.weekday; + final isTodayReminderTrackEnabled = + daysReminderTrack.where((element) => element == nowWeekday.toString()).isNotEmpty; + + int? intervalReminderTrackInSeconds; + final intervalReminderTrackInMinutes = + sharedPreferencesManager.getInt(SharedPreferencesManager.keyIntervalReminderTrack) ?? -1; + if (intervalReminderTrackInMinutes != -1 && intervalReminderTrackInMinutes > 0) { + intervalReminderTrackInSeconds = intervalReminderTrackInMinutes * 60; + } + + if (startReminderTrack != null && + finishReminderTrack != null && + isTodayReminderTrackEnabled && + countTimeReminderTrackInSeconds == intervalReminderTrackInSeconds) { + if (now.isAfter(startReminderTrack) && now.isBefore(finishReminderTrack) || + (now.isAtSameMomentAs(startReminderTrack) || now.isAtSameMomentAs(finishReminderTrack))) { + isShowReminderTrack = true; + } + } + + if (countTimeReminderTrackInSeconds == intervalReminderTrackInSeconds || + intervalReminderTrackInSeconds == null) { + countTimeReminderTrackInSeconds = 0; + } + + if (isShowReminderTrack) { + notificationHelper.showReminderNotTrackNotification(); + } + } else { + countTimeReminderTrackInSeconds = 0; } } + // reset timer jika berpindah hari final now = DateTime.now(); final dateTimeNow = DateTime( now.year, @@ -965,8 +1045,7 @@ class _HomePageState extends State with TrayListener, WindowListener { final activity = percentActivity.round(); final listPathScreenshots = await platformChannelHelper.doTakeScreenshot(); - final isPermissionScreenRecordingGranted = - await platformChannelHelper.checkPermissionScreenRecording(); + final isPermissionScreenRecordingGranted = await platformChannelHelper.checkPermissionScreenRecording(); if (isPermissionScreenRecordingGranted != null && !isPermissionScreenRecordingGranted) { debugPrint('screen recording not granted'); notificationHelper.showPermissionScreenRecordingIssuedNotification(); @@ -1047,7 +1126,7 @@ class _HomePageState extends State with TrayListener, WindowListener { } void startTimer() { - countTimerReminderNotTrack = 0; + countTimeReminderTrackInSeconds = 0; stopTimer(); timeTrack = Timer.periodic(const Duration(seconds: 1), (_) { increaseTimerTray(); @@ -1055,7 +1134,7 @@ class _HomePageState extends State with TrayListener, WindowListener { } void stopTimer() { - countTimerReminderNotTrack = 0; + countTimeReminderTrackInSeconds = 0; if (timeTrack != null && timeTrack!.isActive) { timeTrack!.cancel(); } From 109e43630b823996736d8c0b1303949e8b3544a3 Mon Sep 17 00:00:00 2001 From: CoderJava Date: Mon, 24 Jul 2023 21:59:50 +0700 Subject: [PATCH 4/4] feat(ui): Update localization bahasa English untuk pengaturan reminder track time --- assets/translations/en-US.json | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index 19755d6..8336d7c 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -84,7 +84,7 @@ "try_changing_it": "Try changing it", "example_hostname": "e.g. https://dipantau.id", "screenshot_notification": "Screenshot Notification", - "subtitle_screenshot_notification": "Show notification while capture screenshot", + "subtitle_screenshot_notification": "Show notification while capture screenshot.", "setting": "Setting", "current": "Current", "warning_change_hostname": "Make sure your data has been synced. This change requires restarting the app.", @@ -147,11 +147,11 @@ "general": "General", "company": "Company", "members": "Members", - "add_edit_or_remove_member": "Add, edit, or remove member", + "add_edit_or_remove_member": "Add, edit, or remove member.", "projects": "Projects", - "add_edit_or_remove_project": "Add, edit, or remove project", + "add_edit_or_remove_project": "Add, edit, or remove project.", "tasks_2": "Tasks", - "add_edit_or_remove_task": "Add, edit, or remove task", + "add_edit_or_remove_task": "Add, edit, or remove task.", "member_setting": "Member Setting", "name": "Name", "role": "Role", @@ -185,7 +185,7 @@ "avg_activity": "Avg. Activity", "idle_time": "Idle Time", "discord_channel_id": "Discord Channel ID", - "subtitle_discord_channel_id": "It's used as cloud storage for all screenshots members", + "subtitle_discord_channel_id": "It's used as cloud storage for all screenshots members.", "discord_channel_id_sucessfully_updated": "Discord channel ID successfully updated", "set_discord_channel_id": "Set Discord Channel ID", "cannot_be_empty": "Cannot be empty", @@ -208,7 +208,24 @@ "check": "Check", "version_app": "Version App", "always_on_top": "Always on Top", - "subtitle_always_on_top": "Set Dipantau window always on top of other windows", + "subtitle_always_on_top": "Set Dipantau window always on top of other windows.", "back_to_main_menu": "Back to Main Menu", - "screenshot": "Screenshot" + "screenshot": "Screenshot", + "remind_me_to_track_time": "Reminder Not Track", + "subtitle_remind_me_to_track_time": "Show notification for remind me to track time.", + "from": "From", + "to": "to", + "on_these_days": "On these days", + "mon": "Mon", + "tue": "Tue", + "wed": "Wed", + "thu": "Thu", + "fri": "Fri", + "sat": "Sat", + "sun": "Sun", + "if_i_havent_tracked_time_in": "If I haven't tracked time in", + "alias_minutes": "minutes", + "n_minute": "{} minutes", + "choose": "Choose", + "finish_time_must_be_after_start_time": "Finish time must be after start time" } \ No newline at end of file