mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Improve notification content dialog (#1211)
This commit is contained in:
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
|
|
||||||
|
|
||||||
class ListPreferenceDialog(
|
fun listPreferenceDialog(
|
||||||
private val listPreference: ListPreference,
|
context: Context,
|
||||||
private val dialogListener: () -> Unit
|
listPreference: ListPreference,
|
||||||
) : BaseDialog() {
|
dialogListener: () -> Unit
|
||||||
private lateinit var binding: DialogListPreferenceBinding
|
) : AlertDialog {
|
||||||
|
|
||||||
override fun setContentView(builder: AlertDialog.Builder) {
|
val builder = AlertDialog.Builder(context)
|
||||||
binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(requireContext()))
|
|
||||||
binding.titleTextView.text = listPreference.dialogTitle
|
val binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(context))
|
||||||
binding.messageTextView.text = listPreference.dialogMessage
|
binding.titleTextView.text = listPreference.dialogTitle
|
||||||
binding.closeButton.setOnClickListener {
|
binding.messageTextView.text = listPreference.dialogMessage
|
||||||
dismiss()
|
|
||||||
}
|
builder.setView(binding.root)
|
||||||
val options = listPreference.entryValues.zip(listPreference.entries) { value, title ->
|
|
||||||
RadioOption(value.toString(), title.toString())
|
val dialog = builder.show()
|
||||||
}
|
|
||||||
val valueIndex = listPreference.findIndexOfValue(listPreference.value)
|
val valueIndex = listPreference.findIndexOfValue(listPreference.value)
|
||||||
val optionAdapter = RadioOptionAdapter(valueIndex) {
|
RadioOptionAdapter(valueIndex) {
|
||||||
listPreference.value = it.value
|
listPreference.value = it.value
|
||||||
dismiss()
|
dialog.dismiss()
|
||||||
dialogListener.invoke()
|
dialogListener()
|
||||||
}
|
|
||||||
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
|
||||||
|
}
|
||||||
|
@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.preferences;
|
|||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
|
import static org.thoughtcrime.securesms.preferences.ListPreferenceDialogKt.listPreferenceDialog;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -77,10 +79,10 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
.setOnPreferenceClickListener(preference -> {
|
.setOnPreferenceClickListener(preference -> {
|
||||||
ListPreference listPreference = (ListPreference) preference;
|
ListPreference listPreference = (ListPreference) preference;
|
||||||
listPreference.setDialogMessage(R.string.preferences_notifications__content_message);
|
listPreference.setDialogMessage(R.string.preferences_notifications__content_message);
|
||||||
new ListPreferenceDialog(listPreference, () -> {
|
listPreferenceDialog(getContext(), listPreference, () -> {
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF));
|
initializeListSummary(findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF));
|
||||||
return null;
|
return null;
|
||||||
}).show(getChildFragmentManager(), "ListPreferenceDialog");
|
});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:background="?dialog_background_color">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/titleTextView"
|
android:id="@+id/titleTextView"
|
||||||
@ -21,11 +20,10 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/closeButton"
|
android:id="@+id/closeButton"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="@dimen/medium_spacing"
|
android:layout_marginEnd="@dimen/medium_spacing"
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:src="@drawable/ic_baseline_close_24"
|
android:src="@drawable/ic_baseline_close_24"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/titleTextView"
|
app:layout_constraintBottom_toBottomOf="@id/titleTextView"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
@ -36,7 +34,6 @@
|
|||||||
android:id="@+id/messageTextView"
|
android:id="@+id/messageTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?dialog_background_color"
|
|
||||||
android:drawablePadding="@dimen/large_spacing"
|
android:drawablePadding="@dimen/large_spacing"
|
||||||
android:gravity="center_horizontal|center_vertical"
|
android:gravity="center_horizontal|center_vertical"
|
||||||
android:paddingHorizontal="@dimen/large_spacing"
|
android:paddingHorizontal="@dimen/large_spacing"
|
||||||
|
Loading…
Reference in New Issue
Block a user