mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
adding an "Add new sound" button to the alarmsound picker
This commit is contained in:
@ -33,6 +33,9 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
|||||||
view.dialog_select_alarm_your_label.setTextColor(activity.getAdjustedPrimaryColor())
|
view.dialog_select_alarm_your_label.setTextColor(activity.getAdjustedPrimaryColor())
|
||||||
view.dialog_select_alarm_system_label.setTextColor(activity.getAdjustedPrimaryColor())
|
view.dialog_select_alarm_system_label.setTextColor(activity.getAdjustedPrimaryColor())
|
||||||
|
|
||||||
|
val newAlarmSound = AlarmSound(ADD_NEW_SOUND_ID, activity.getString(R.string.add_new_sound), "")
|
||||||
|
addAlarmSound(newAlarmSound, view.dialog_select_alarm_your_radio)
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setOnDismissListener { mediaPlayer.stop() }
|
.setOnDismissListener { mediaPlayer.stop() }
|
||||||
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||||
@ -56,24 +59,32 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
|||||||
id = alarmSound.id
|
id = alarmSound.id
|
||||||
setColors(config.textColor, activity.getAdjustedPrimaryColor(), config.backgroundColor)
|
setColors(config.textColor, activity.getAdjustedPrimaryColor(), config.backgroundColor)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
try {
|
alarmClicked(alarmSound)
|
||||||
mediaPlayer.stop()
|
|
||||||
mediaPlayer = MediaPlayer().apply {
|
|
||||||
setAudioStreamType(audioStream)
|
|
||||||
setDataSource(context, Uri.parse(alarmSound.uri))
|
|
||||||
isLooping = true
|
|
||||||
prepare()
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
activity.showErrorToast(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
holder.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun alarmClicked(alarmSound: AlarmSound) {
|
||||||
|
if (alarmSound.id == ADD_NEW_SOUND_ID) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
mediaPlayer.stop()
|
||||||
|
mediaPlayer = MediaPlayer().apply {
|
||||||
|
setAudioStreamType(audioStream)
|
||||||
|
setDataSource(activity, Uri.parse(alarmSound.uri))
|
||||||
|
isLooping = true
|
||||||
|
prepare()
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
activity.showErrorToast(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun dialogConfirmed() {
|
private fun dialogConfirmed() {
|
||||||
val checkedId = view.dialog_select_alarm_system_radio.checkedRadioButtonId
|
val checkedId = view.dialog_select_alarm_system_radio.checkedRadioButtonId
|
||||||
if (checkedId == -1) {
|
if (checkedId == -1) {
|
||||||
|
Reference in New Issue
Block a user