Utilise dialog dsl
parent
1b88d4f950
commit
4ee68cbbb1
@ -1,21 +1,18 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2.utilities
|
package org.thoughtcrime.securesms.conversation.v2.utilities
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
|
import org.thoughtcrime.securesms.sessionDialog
|
||||||
|
|
||||||
object NotificationUtils {
|
object NotificationUtils {
|
||||||
fun showNotifyDialog(context: Context, thread: Recipient, notifyTypeHandler: (Int)->Unit) {
|
fun showNotifyDialog(context: Context, thread: Recipient, notifyTypeHandler: (Int)->Unit) {
|
||||||
val notifyTypes = context.resources.getStringArray(R.array.notify_types)
|
context.sessionDialog {
|
||||||
val currentSelected = thread.notifyType
|
title(R.string.RecipientPreferenceActivity_notification_settings)
|
||||||
|
singleChoiceItems(
|
||||||
AlertDialog.Builder(context)
|
context.resources.getStringArray(R.array.notify_types),
|
||||||
.setSingleChoiceItems(notifyTypes,currentSelected) { d, newSelection ->
|
thread.notifyType
|
||||||
notifyTypeHandler(newSelection)
|
) { notifyTypeHandler(it) }
|
||||||
d.dismiss()
|
}
|
||||||
}
|
|
||||||
.setTitle(R.string.RecipientPreferenceActivity_notification_settings)
|
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,41 +1,24 @@
|
|||||||
package org.thoughtcrime.securesms.preferences
|
package org.thoughtcrime.securesms.preferences
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import network.loki.messenger.databinding.DialogListPreferenceBinding
|
import org.thoughtcrime.securesms.sessionDialog
|
||||||
|
|
||||||
fun listPreferenceDialog(
|
fun listPreferenceDialog(
|
||||||
context: Context,
|
context: Context,
|
||||||
listPreference: ListPreference,
|
listPreference: ListPreference,
|
||||||
dialogListener: () -> Unit
|
onChange: () -> Unit
|
||||||
) : AlertDialog {
|
) : AlertDialog = listPreference.run {
|
||||||
|
context.sessionDialog {
|
||||||
val builder = AlertDialog.Builder(context)
|
val index = entryValues.indexOf(value)
|
||||||
|
val options = entries.map(CharSequence::toString).toTypedArray()
|
||||||
val binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(context))
|
|
||||||
binding.titleTextView.text = listPreference.dialogTitle
|
title(dialogTitle)
|
||||||
binding.messageTextView.text = listPreference.dialogMessage
|
text(dialogMessage)
|
||||||
|
singleChoiceItems(options, index) {
|
||||||
builder.setView(binding.root)
|
listPreference.setValueIndex(it)
|
||||||
|
onChange()
|
||||||
val dialog = builder.show()
|
|
||||||
|
|
||||||
val valueIndex = listPreference.findIndexOfValue(listPreference.value)
|
|
||||||
RadioOptionAdapter(valueIndex) {
|
|
||||||
listPreference.value = it.value
|
|
||||||
dialog.dismiss()
|
|
||||||
dialogListener()
|
|
||||||
}
|
|
||||||
.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