avoid adding the same alarm sound multiple times

This commit is contained in:
tibbi 2018-03-29 16:48:31 +02:00
parent cbe2617624
commit 376cf36b8c
1 changed files with 6 additions and 3 deletions

View File

@ -135,10 +135,13 @@ class MainActivity : SimpleActivity() {
filename = getString(R.string.alarm)
}
val token = object : TypeToken<LinkedHashSet<AlarmSound>>() {}.type
val yourAlarmSounds = Gson().fromJson<LinkedHashSet<AlarmSound>>(config.yourAlarmSounds, token) ?: LinkedHashSet()
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
val yourAlarmSounds = Gson().fromJson<ArrayList<AlarmSound>>(config.yourAlarmSounds, token) ?: ArrayList()
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)
if (isKitkatPlus()) {