improve error handling at SelectAlarmSound dialog

This commit is contained in:
tibbi 2018-03-28 23:38:26 +02:00
parent 2d4ea903d1
commit 87c1b0ea08
3 changed files with 16 additions and 8 deletions

View File

@ -31,9 +31,11 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
edit_alarm_sound.text = alarm.soundTitle
edit_alarm_sound.setOnClickListener {
SelectAlarmSoundDialog(activity, alarm.soundUri, AudioManager.STREAM_ALARM) {
alarm.soundTitle = it.title
alarm.soundUri = it.uri
edit_alarm_sound.text = it.title
if (it != null) {
alarm.soundTitle = it.title
alarm.soundUri = it.uri
edit_alarm_sound.text = it.title
}
}
}

View File

@ -14,7 +14,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showErrorToast
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: String, val audioStream: Int, val callback: (alarmSound: AlarmSound) -> Unit) {
class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: String, val audioStream: Int, val callback: (alarmSound: AlarmSound?) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_alarm_sound, null)
private val alarms = activity.getAlarms()
private var mediaPlayer = MediaPlayer()
@ -58,6 +58,10 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
private fun dialogConfirmed() {
val checkedId = view.dialog_select_alarm_radio.checkedRadioButtonId
callback(alarms[checkedId])
if (checkedId == -1) {
callback(null)
} else {
callback(alarms[checkedId])
}
}
}

View File

@ -66,9 +66,11 @@ class TimerFragment : Fragment() {
timer_sound.setOnClickListener {
SelectAlarmSoundDialog(activity as SimpleActivity, config.timerSoundUri, AudioManager.STREAM_SYSTEM) {
config.timerSoundTitle = it.title
config.timerSoundUri = it.uri
timer_sound.text = it.title
if (it != null) {
config.timerSoundTitle = it.title
config.timerSoundUri = it.uri
timer_sound.text = it.title
}
}
}
}