Improve notification content dialog (#1211)
parent
47d5b242ca
commit
331d523c45
@ -1,42 +1,41 @@
|
|||||||
package org.thoughtcrime.securesms.preferences
|
package org.thoughtcrime.securesms.preferences
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
|
||||||
import network.loki.messenger.databinding.DialogListPreferenceBinding
|
import network.loki.messenger.databinding.DialogListPreferenceBinding
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
|
||||||
|
fun listPreferenceDialog(
|
||||||
class ListPreferenceDialog(
|
context: Context,
|
||||||
private val listPreference: ListPreference,
|
listPreference: ListPreference,
|
||||||
private val dialogListener: () -> Unit
|
dialogListener: () -> Unit
|
||||||
) : BaseDialog() {
|
) : AlertDialog {
|
||||||
private lateinit var binding: DialogListPreferenceBinding
|
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
override fun setContentView(builder: AlertDialog.Builder) {
|
|
||||||
binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(requireContext()))
|
val binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(context))
|
||||||
binding.titleTextView.text = listPreference.dialogTitle
|
binding.titleTextView.text = listPreference.dialogTitle
|
||||||
binding.messageTextView.text = listPreference.dialogMessage
|
binding.messageTextView.text = listPreference.dialogMessage
|
||||||
binding.closeButton.setOnClickListener {
|
|
||||||
dismiss()
|
builder.setView(binding.root)
|
||||||
}
|
|
||||||
val options = listPreference.entryValues.zip(listPreference.entries) { value, title ->
|
val dialog = builder.show()
|
||||||
RadioOption(value.toString(), title.toString())
|
|
||||||
}
|
val valueIndex = listPreference.findIndexOfValue(listPreference.value)
|
||||||
val valueIndex = listPreference.findIndexOfValue(listPreference.value)
|
RadioOptionAdapter(valueIndex) {
|
||||||
val optionAdapter = RadioOptionAdapter(valueIndex) {
|
listPreference.value = it.value
|
||||||
listPreference.value = it.value
|
dialog.dismiss()
|
||||||
dismiss()
|
dialogListener()
|
||||||
dialogListener.invoke()
|
|
||||||
}
|
|
||||||
binding.recyclerView.apply {
|
|
||||||
adapter = optionAdapter
|
|
||||||
addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
|
|
||||||
setHasFixedSize(true)
|
|
||||||
}
|
|
||||||
optionAdapter.submitList(options)
|
|
||||||
builder.setView(binding.root)
|
|
||||||
builder.setCancelable(false)
|
|
||||||
}
|
}
|
||||||
|
.apply {
|
||||||
|
listPreference.entryValues.zip(listPreference.entries) { value, title ->
|
||||||
|
RadioOption(value.toString(), title.toString())
|
||||||
|
}.let(this::submitList)
|
||||||
|
}
|
||||||
|
.let { binding.recyclerView.adapter = it }
|
||||||
|
|
||||||
|
binding.closeButton.setOnClickListener { dialog.dismiss() }
|
||||||
|
|
||||||
|
return dialog
|
||||||
}
|
}
|
Loading…
Reference in New Issue