mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
avoid adding the same alarm sound multiple times
This commit is contained in:
parent
cbe2617624
commit
376cf36b8c
@ -135,10 +135,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
filename = getString(R.string.alarm)
|
filename = getString(R.string.alarm)
|
||||||
}
|
}
|
||||||
|
|
||||||
val token = object : TypeToken<LinkedHashSet<AlarmSound>>() {}.type
|
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
|
||||||
val yourAlarmSounds = Gson().fromJson<LinkedHashSet<AlarmSound>>(config.yourAlarmSounds, token) ?: LinkedHashSet()
|
val yourAlarmSounds = Gson().fromJson<ArrayList<AlarmSound>>(config.yourAlarmSounds, token) ?: ArrayList()
|
||||||
val newAlarmSoundId = (yourAlarmSounds.maxBy { it.id }?.id ?: YOUR_ALARM_SOUNDS_MIN_ID) + 1
|
val newAlarmSoundId = (yourAlarmSounds.maxBy { it.id }?.id ?: YOUR_ALARM_SOUNDS_MIN_ID) + 1
|
||||||
yourAlarmSounds.add(AlarmSound(newAlarmSoundId, filename, uri.toString()))
|
if (yourAlarmSounds.firstOrNull { it.uri == uri.toString() } == null) {
|
||||||
|
yourAlarmSounds.add(AlarmSound(newAlarmSoundId, filename, uri.toString()))
|
||||||
|
}
|
||||||
|
|
||||||
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
|
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
|
||||||
|
|
||||||
if (isKitkatPlus()) {
|
if (isKitkatPlus()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user