Skip to content

Commit b636880

Browse files
authored
fixed issue #262 (#421)
1 parent c30a89b commit b636880

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class AddOrUpdateAlarmController extends GetxController {
7979
final RxInt snoozeDuration = 1.obs;
8080
var customRingtoneName = 'Default'.obs;
8181
var customRingtoneNames = [].obs;
82+
var previousRingtone='';
8283
final noteController = TextEditingController();
8384
final RxString note = ''.obs;
8485
final deleteAfterGoesOff = false.obs;
@@ -842,7 +843,7 @@ class AddOrUpdateAlarmController extends GetxController {
842843
RingtoneModel customRingtone = RingtoneModel(
843844
ringtoneName: customRingtoneName.value,
844845
ringtonePath: savedFilePath,
845-
currentCounterOfUsage: 0,
846+
currentCounterOfUsage: 1,
846847
);
847848
await IsarDb.addCustomRingtone(customRingtone);
848849
}

lib/app/modules/addOrUpdateAlarm/views/choose_ringtone_tile.dart

+24-5
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,33 @@ class ChooseRingtoneTile extends StatelessWidget {
9999
itemBuilder: (context, index) {
100100
return Obx(
101101
() => ListTile(
102-
onTap: () {
102+
onTap: () async {
103+
controller.previousRingtone =
104+
controller.customRingtoneName.value;
105+
103106
controller.customRingtoneName.value =
104107
controller
105108
.customRingtoneNames[index];
109+
110+
if (controller
111+
.customRingtoneName.value !=
112+
controller.previousRingtone) {
113+
await AudioUtils
114+
.updateRingtoneCounterOfUsage(
115+
customRingtoneName: controller
116+
.customRingtoneName.value,
117+
counterUpdate:
118+
CounterUpdate.increment,
119+
);
120+
121+
await AudioUtils
122+
.updateRingtoneCounterOfUsage(
123+
customRingtoneName:
124+
controller.previousRingtone,
125+
counterUpdate:
126+
CounterUpdate.decrement,
127+
);
128+
}
106129
},
107130
tileColor: controller
108131
.customRingtoneName ==
@@ -208,10 +231,6 @@ class ChooseRingtoneTile extends StatelessWidget {
208231
ElevatedButton(
209232
onPressed: () async {
210233
Utils.hapticFeedback();
211-
await AudioUtils.updateRingtoneCounterOfUsage(
212-
customRingtoneName: controller.customRingtoneName.value,
213-
counterUpdate: CounterUpdate.increment,
214-
);
215234
Get.back();
216235
},
217236
style: ElevatedButton.styleFrom(

0 commit comments

Comments
 (0)