Skip to content

Commit

Permalink
Merge pull request #10 from CoderJava/feature/buat-pengaturan-play-so…
Browse files Browse the repository at this point in the history
…und-pada-notifikasi-screenshot

Feature - Buat pengaturan play sound pada notifikasi screenshot
  • Loading branch information
CoderJava authored Jul 24, 2023
2 parents c458f37 + 2fcc00e commit 6b4e120
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
3 changes: 2 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@
"alias_minutes": "minutes",
"n_minute": "{} minutes",
"choose": "Choose",
"finish_time_must_be_after_start_time": "Finish time must be after start time"
"finish_time_must_be_after_start_time": "Finish time must be after start time",
"play_sound": "Play sound"
}
11 changes: 9 additions & 2 deletions lib/core/util/notification_helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart';
import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

Expand All @@ -18,14 +20,19 @@ class NotificationHelper {
}

void showScreenshotTakenNotification() {
final presentSound = sharedPreferencesManager.getBool(
SharedPreferencesManager.keyIsEnableSoundScreenshotNotification,
defaultValue: true,
) ??
true;
localNotification?.show(
DateTime.now().millisecond,
'app_name'.tr(),
'screenshot_taken'.tr(),
const NotificationDetails(
NotificationDetails(
macOS: DarwinNotificationDetails(
presentAlert: true,
presentSound: true,
presentSound: presentSound,
),
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/core/util/shared_preferences_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SharedPreferencesManager {
static const keyFinishTimeReminderTrack = 'finish_time_reminder_track';
static const keyDayReminderTrack = 'day_reminder_track';
static const keyIntervalReminderTrack = 'interval_reminder_track';
static const keyIsEnableSoundScreenshotNotification = 'is_enable_sound_screenshot_notification';

SharedPreferencesManager();

Expand Down
3 changes: 3 additions & 0 deletions lib/feature/presentation/page/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableScreenshotNotification)) {
sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableScreenshotNotification, true);
}
if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification)) {
sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification, true);
}
initDefaultSelectedProject();
setupWindow();
setupTray();
Expand Down
35 changes: 35 additions & 0 deletions lib/feature/presentation/page/setting/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _SettingPageState extends State<SettingPage> {
final navigationRailDestinations = <NavigationRailDestination>[];
final sharedPreferencesManager = sl<SharedPreferencesManager>();
final valueNotifierIsEnableScreenshotNotification = ValueNotifier(false);
final valueNotifierIsEnableSoundScreenshotNotification = ValueNotifier(true);
final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light);
final valueNotifierLaunchAtStartup = ValueNotifier(true);
final valueNotifierAlwaysOnTop = ValueNotifier(true);
Expand Down Expand Up @@ -258,6 +259,7 @@ class _SettingPageState extends State<SettingPage> {
),
children: [
buildWidgetScreenshotNotification(),
buildWidgetPlaySoundScreenshotNotification(),
const SizedBox(height: 16),
buildWidgetReminderNotTrackNotification(),
const SizedBox(height: 8),
Expand Down Expand Up @@ -686,6 +688,8 @@ class _SettingPageState extends State<SettingPage> {
void prepareData() {
valueNotifierIsEnableScreenshotNotification.value =
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false;
valueNotifierIsEnableSoundScreenshotNotification.value =
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification) ?? false;
valueNotifierAlwaysOnTop.value =
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsAlwaysOnTop, defaultValue: true) ?? true;

Expand Down Expand Up @@ -1072,6 +1076,37 @@ class _SettingPageState extends State<SettingPage> {
);
}

Widget buildWidgetPlaySoundScreenshotNotification() {
return Row(
children: [
SizedBox(
width: 24,
child: ValueListenableBuilder(
valueListenable: valueNotifierIsEnableSoundScreenshotNotification,
builder: (BuildContext context, bool isEnable, _) {
return Checkbox(
value: isEnable,
onChanged: (newValue) {
if (newValue != null) {
valueNotifierIsEnableSoundScreenshotNotification.value = newValue;
sharedPreferencesManager.putBool(
SharedPreferencesManager.keyIsEnableSoundScreenshotNotification,
newValue,
);
}
},
);
},
),
),
const SizedBox(width: 4),
Text(
'play_sound'.tr(),
),
],
);
}

Widget buildWidgetMember() {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down

0 comments on commit 6b4e120

Please sign in to comment.