mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-02-02 11:36:52 +01:00
allow removing custom alarm sounds with long press
This commit is contained in:
parent
8f07546831
commit
b9adb1306b
@ -16,10 +16,12 @@ import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.getAlarmSounds
|
||||
import com.simplemobiletools.clock.helpers.PICK_AUDIO_FILE_INTENT_ID
|
||||
import com.simplemobiletools.clock.models.AlarmSound
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.isKitkatPlus
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
|
||||
|
||||
@ -55,6 +57,7 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
||||
}
|
||||
|
||||
private fun addYourAlarms() {
|
||||
view.dialog_select_alarm_your_radio.removeAllViews()
|
||||
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
|
||||
yourAlarmSounds = Gson().fromJson<ArrayList<AlarmSound>>(config.yourAlarmSounds, token) ?: ArrayList()
|
||||
yourAlarmSounds.add(AlarmSound(ADD_NEW_SOUND_ID, activity.getString(R.string.add_new_sound), ""))
|
||||
@ -84,6 +87,17 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
||||
view.dialog_select_alarm_system_radio.clearCheck()
|
||||
}
|
||||
}
|
||||
|
||||
if (alarmSound.id != -2 && holder == view.dialog_select_alarm_your_radio) {
|
||||
setOnLongClickListener {
|
||||
val items = arrayListOf(RadioItem(1, context.getString(R.string.remove)))
|
||||
|
||||
RadioGroupDialog(activity, items) {
|
||||
removeAlarmSound(alarmSound)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
@ -118,6 +132,19 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAlarmSound(alarmSound: AlarmSound) {
|
||||
val token = object : TypeToken<ArrayList<AlarmSound>>() {}.type
|
||||
yourAlarmSounds = Gson().fromJson<ArrayList<AlarmSound>>(config.yourAlarmSounds, token) ?: ArrayList()
|
||||
yourAlarmSounds.remove(alarmSound)
|
||||
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
|
||||
addYourAlarms()
|
||||
|
||||
if (alarmSound.id == view.dialog_select_alarm_your_radio.checkedRadioButtonId) {
|
||||
view.dialog_select_alarm_your_radio.clearCheck()
|
||||
view.dialog_select_alarm_system_radio.check(systemAlarmSounds.firstOrNull()?.id ?: 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
if (view.dialog_select_alarm_your_radio.checkedRadioButtonId != -1) {
|
||||
val checkedId = view.dialog_select_alarm_your_radio.checkedRadioButtonId
|
||||
|
Loading…
x
Reference in New Issue
Block a user