diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt index 7874fb17..0d06dc8d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt @@ -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>() {}.type yourAlarmSounds = Gson().fromJson>(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>() {}.type + yourAlarmSounds = Gson().fromJson>(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