diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt index 560c137104..fa3be71307 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt @@ -42,6 +42,7 @@ class ClearAllDataDialog : BaseDialog() { var selectedOption = device val optionAdapter = RadioOptionAdapter { selectedOption = it } binding.recyclerView.apply { + itemAnimator = null adapter = optionAdapter addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)) setHasFixedSize(true) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ListPreferenceDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ListPreferenceDialog.kt index e407c67774..2ba48f6e41 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ListPreferenceDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ListPreferenceDialog.kt @@ -1,42 +1,41 @@ package org.thoughtcrime.securesms.preferences +import android.content.Context import android.view.LayoutInflater import androidx.appcompat.app.AlertDialog import androidx.preference.ListPreference -import androidx.recyclerview.widget.DividerItemDecoration import network.loki.messenger.databinding.DialogListPreferenceBinding -import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog -class ListPreferenceDialog( - private val listPreference: ListPreference, - private val dialogListener: () -> Unit -) : BaseDialog() { - private lateinit var binding: DialogListPreferenceBinding +fun listPreferenceDialog( + context: Context, + listPreference: ListPreference, + dialogListener: () -> Unit +) : AlertDialog { - override fun setContentView(builder: AlertDialog.Builder) { - binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(requireContext())) - binding.titleTextView.text = listPreference.dialogTitle - binding.messageTextView.text = listPreference.dialogMessage - binding.closeButton.setOnClickListener { - dismiss() - } - val options = listPreference.entryValues.zip(listPreference.entries) { value, title -> - RadioOption(value.toString(), title.toString()) - } - val valueIndex = listPreference.findIndexOfValue(listPreference.value) - val optionAdapter = RadioOptionAdapter(valueIndex) { - listPreference.value = it.value - dismiss() - dialogListener.invoke() - } - binding.recyclerView.apply { - adapter = optionAdapter - addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)) - setHasFixedSize(true) - } - optionAdapter.submitList(options) - builder.setView(binding.root) - builder.setCancelable(false) + val builder = AlertDialog.Builder(context) + + val binding = DialogListPreferenceBinding.inflate(LayoutInflater.from(context)) + binding.titleTextView.text = listPreference.dialogTitle + binding.messageTextView.text = listPreference.dialogMessage + + builder.setView(binding.root) + + 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 } -} \ No newline at end of file + binding.closeButton.setOnClickListener { dialog.dismiss() } + + return dialog +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index 9ae78fc5cf..4eaa58e815 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.preferences; import static android.app.Activity.RESULT_OK; +import static org.thoughtcrime.securesms.preferences.ListPreferenceDialogKt.listPreferenceDialog; + import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; @@ -77,10 +79,10 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme .setOnPreferenceClickListener(preference -> { ListPreference listPreference = (ListPreference) preference; listPreference.setDialogMessage(R.string.preferences_notifications__content_message); - new ListPreferenceDialog(listPreference, () -> { - initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF)); + listPreferenceDialog(getContext(), listPreference, () -> { + initializeListSummary(findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF)); return null; - }).show(getChildFragmentManager(), "ListPreferenceDialog"); + }); return true; }); diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt index 2cb61a0e82..4bb69c4c14 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt @@ -16,8 +16,8 @@ class RadioOptionAdapter( ) : ListAdapter(RadioOptionDiffer()) { class RadioOptionDiffer: DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem === newItem - override fun areContentsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem == newItem + override fun areItemsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem.title == newItem.title + override fun areContentsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem.value == newItem.value } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -31,7 +31,7 @@ class RadioOptionAdapter( holder.bind(option, isSelected) { onClickListener(it) selectedOptionPosition = position - notifyDataSetChanged() + notifyItemRangeChanged(0, itemCount) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt index 1e44574925..9bfc5d57b2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt @@ -32,11 +32,8 @@ import nl.komponents.kovenant.ui.alwaysUi import nl.komponents.kovenant.ui.successUi import org.session.libsession.avatars.AvatarHelper import org.session.libsession.messaging.MessagingModuleConfiguration -import org.session.libsession.utilities.Address -import org.session.libsession.utilities.ProfileKeyUtil -import org.session.libsession.utilities.ProfilePictureUtilities +import org.session.libsession.utilities.* import org.session.libsession.utilities.SSKEnvironment.ProfileManagerProtocol -import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.avatar.AvatarSelection import org.thoughtcrime.securesms.components.ProfilePictureView @@ -85,7 +82,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { super.onCreate(savedInstanceState, isReady) binding = ActivitySettingsBinding.inflate(layoutInflater) setContentView(binding.root) - val displayName = TextSecurePreferences.getProfileName(this) ?: hexEncodedPublicKey + val displayName = getDisplayName() glide = GlideApp.with(this) with(binding) { setupProfilePictureView(profilePictureView.root) @@ -112,10 +109,13 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { } } + private fun getDisplayName(): String = + TextSecurePreferences.getProfileName(this) ?: truncateIdForDisplay(hexEncodedPublicKey) + private fun setupProfilePictureView(view: ProfilePictureView) { view.glide = glide view.publicKey = hexEncodedPublicKey - view.displayName = TextSecurePreferences.getProfileName(this) ?: hexEncodedPublicKey + view.displayName = getDisplayName() view.isLarge = true view.update() } diff --git a/app/src/main/res/layout/activity_join_public_chat.xml b/app/src/main/res/layout/activity_join_public_chat.xml index d437a230fc..e4d5fb433b 100644 --- a/app/src/main/res/layout/activity_join_public_chat.xml +++ b/app/src/main/res/layout/activity_join_public_chat.xml @@ -11,7 +11,6 @@ android:layout_height="match_parent" > diff --git a/app/src/main/res/layout/activity_link_device.xml b/app/src/main/res/layout/activity_link_device.xml index 4c5df3b6f2..b267c08ac8 100644 --- a/app/src/main/res/layout/activity_link_device.xml +++ b/app/src/main/res/layout/activity_link_device.xml @@ -12,7 +12,6 @@ android:layout_height="match_parent" > diff --git a/app/src/main/res/layout/activity_qr_code.xml b/app/src/main/res/layout/activity_qr_code.xml index 6a1229648e..58c7e40c82 100644 --- a/app/src/main/res/layout/activity_qr_code.xml +++ b/app/src/main/res/layout/activity_qr_code.xml @@ -6,7 +6,6 @@ android:layout_height="match_parent" > diff --git a/app/src/main/res/layout/dialog_blocked.xml b/app/src/main/res/layout/dialog_blocked.xml index 479210f1df..4ad01ec8ee 100644 --- a/app/src/main/res/layout/dialog_blocked.xml +++ b/app/src/main/res/layout/dialog_blocked.xml @@ -35,7 +35,7 @@ android:orientation="horizontal">