Skip to content

Commit 6b4e120

Browse files
authored
Merge pull request #10 from CoderJava/feature/buat-pengaturan-play-sound-pada-notifikasi-screenshot
Feature - Buat pengaturan play sound pada notifikasi screenshot
2 parents c458f37 + 2fcc00e commit 6b4e120

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

assets/translations/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,6 @@
227227
"alias_minutes": "minutes",
228228
"n_minute": "{} minutes",
229229
"choose": "Choose",
230-
"finish_time_must_be_after_start_time": "Finish time must be after start time"
230+
"finish_time_must_be_after_start_time": "Finish time must be after start time",
231+
"play_sound": "Play sound"
231232
}

lib/core/util/notification_helper.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart';
2+
import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart';
13
import 'package:easy_localization/easy_localization.dart';
24
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
35

@@ -18,14 +20,19 @@ class NotificationHelper {
1820
}
1921

2022
void showScreenshotTakenNotification() {
23+
final presentSound = sharedPreferencesManager.getBool(
24+
SharedPreferencesManager.keyIsEnableSoundScreenshotNotification,
25+
defaultValue: true,
26+
) ??
27+
true;
2128
localNotification?.show(
2229
DateTime.now().millisecond,
2330
'app_name'.tr(),
2431
'screenshot_taken'.tr(),
25-
const NotificationDetails(
32+
NotificationDetails(
2633
macOS: DarwinNotificationDetails(
2734
presentAlert: true,
28-
presentSound: true,
35+
presentSound: presentSound,
2936
),
3037
),
3138
);

lib/core/util/shared_preferences_manager.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SharedPreferencesManager {
2323
static const keyFinishTimeReminderTrack = 'finish_time_reminder_track';
2424
static const keyDayReminderTrack = 'day_reminder_track';
2525
static const keyIntervalReminderTrack = 'interval_reminder_track';
26+
static const keyIsEnableSoundScreenshotNotification = 'is_enable_sound_screenshot_notification';
2627

2728
SharedPreferencesManager();
2829

lib/feature/presentation/page/home/home_page.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
9999
if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableScreenshotNotification)) {
100100
sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableScreenshotNotification, true);
101101
}
102+
if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification)) {
103+
sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification, true);
104+
}
102105
initDefaultSelectedProject();
103106
setupWindow();
104107
setupTray();

lib/feature/presentation/page/setting/setting_page.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class _SettingPageState extends State<SettingPage> {
3838
final navigationRailDestinations = <NavigationRailDestination>[];
3939
final sharedPreferencesManager = sl<SharedPreferencesManager>();
4040
final valueNotifierIsEnableScreenshotNotification = ValueNotifier(false);
41+
final valueNotifierIsEnableSoundScreenshotNotification = ValueNotifier(true);
4142
final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light);
4243
final valueNotifierLaunchAtStartup = ValueNotifier(true);
4344
final valueNotifierAlwaysOnTop = ValueNotifier(true);
@@ -258,6 +259,7 @@ class _SettingPageState extends State<SettingPage> {
258259
),
259260
children: [
260261
buildWidgetScreenshotNotification(),
262+
buildWidgetPlaySoundScreenshotNotification(),
261263
const SizedBox(height: 16),
262264
buildWidgetReminderNotTrackNotification(),
263265
const SizedBox(height: 8),
@@ -686,6 +688,8 @@ class _SettingPageState extends State<SettingPage> {
686688
void prepareData() {
687689
valueNotifierIsEnableScreenshotNotification.value =
688690
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false;
691+
valueNotifierIsEnableSoundScreenshotNotification.value =
692+
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification) ?? false;
689693
valueNotifierAlwaysOnTop.value =
690694
sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsAlwaysOnTop, defaultValue: true) ?? true;
691695

@@ -1072,6 +1076,37 @@ class _SettingPageState extends State<SettingPage> {
10721076
);
10731077
}
10741078

1079+
Widget buildWidgetPlaySoundScreenshotNotification() {
1080+
return Row(
1081+
children: [
1082+
SizedBox(
1083+
width: 24,
1084+
child: ValueListenableBuilder(
1085+
valueListenable: valueNotifierIsEnableSoundScreenshotNotification,
1086+
builder: (BuildContext context, bool isEnable, _) {
1087+
return Checkbox(
1088+
value: isEnable,
1089+
onChanged: (newValue) {
1090+
if (newValue != null) {
1091+
valueNotifierIsEnableSoundScreenshotNotification.value = newValue;
1092+
sharedPreferencesManager.putBool(
1093+
SharedPreferencesManager.keyIsEnableSoundScreenshotNotification,
1094+
newValue,
1095+
);
1096+
}
1097+
},
1098+
);
1099+
},
1100+
),
1101+
),
1102+
const SizedBox(width: 4),
1103+
Text(
1104+
'play_sound'.tr(),
1105+
),
1106+
],
1107+
);
1108+
}
1109+
10751110
Widget buildWidgetMember() {
10761111
return Row(
10771112
crossAxisAlignment: CrossAxisAlignment.start,

0 commit comments

Comments
 (0)