From 86cab0e11e4871ec2258c2099d8634a91a2f9bea Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 30 Aug 2024 10:17:04 +1000 Subject: [PATCH] Bringing my xml dialog styling from my 'Standardise message deletion' branch --- .../securesms/SessionDialogBuilder.kt | 49 +++++++++++++------ .../preferences/ClearAllDataDialog.kt | 1 - .../drawable/default_dialog_background.xml | 2 +- .../main/res/drawable/dialog_background.xml | 11 ----- .../main/res/drawable/ic_radio_selected.xml | 13 +++++ .../main/res/drawable/ic_radio_unselected.xml | 11 +++++ .../drawable/padded_circle_accent_select.xml | 8 +-- .../main/res/drawable/radial_multi_select.xml | 2 +- app/src/main/res/drawable/radio_states.xml | 9 ++++ .../main/res/layout/dialog_clear_all_data.xml | 8 +-- app/src/main/res/layout/item_selectable.xml | 2 +- .../layout/view_dialog_single_choice_item.xml | 11 +++++ app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/dimens.xml | 7 ++- app/src/main/res/values/styles.xml | 9 ++++ app/src/main/res/values/themes.xml | 5 ++ 16 files changed, 111 insertions(+), 38 deletions(-) delete mode 100644 app/src/main/res/drawable/dialog_background.xml create mode 100644 app/src/main/res/drawable/ic_radio_selected.xml create mode 100644 app/src/main/res/drawable/ic_radio_unselected.xml create mode 100644 app/src/main/res/drawable/radio_states.xml create mode 100644 app/src/main/res/layout/view_dialog_single_choice_item.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt index f780c80870..69d58411f3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt @@ -9,12 +9,14 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import android.widget.ArrayAdapter import android.widget.Button import android.widget.LinearLayout import android.widget.LinearLayout.VERTICAL import android.widget.Space import android.widget.TextView import androidx.annotation.AttrRes +import androidx.annotation.ColorRes import androidx.annotation.LayoutRes import androidx.annotation.StringRes import androidx.annotation.StyleRes @@ -32,9 +34,10 @@ annotation class DialogDsl @DialogDsl class SessionDialogBuilder(val context: Context) { - val dp20 = toPx(20, context.resources) - val dp40 = toPx(40, context.resources) - val dp60 = toPx(60, context.resources) + private val dp8 = toPx(8, context.resources) + private val dp20 = toPx(20, context.resources) + private val dp40 = toPx(40, context.resources) + private val dp60 = toPx(60, context.resources) private val dialogBuilder: AlertDialog.Builder = AlertDialog.Builder(context) @@ -59,7 +62,7 @@ class SessionDialogBuilder(val context: Context) { // Main title entry point fun title(text: String?) { - text(text, R.style.TextAppearance_AppCompat_Title) { setPadding(dp20, 0, dp20, 0) } + text(text, R.style.TextAppearance_Session_Dialog_Title) { setPadding(dp20, 0, dp20, 0) } } // Convenience assessor for title that takes a string resource @@ -68,18 +71,18 @@ class SessionDialogBuilder(val context: Context) { // Convenience accessor for title that takes a CharSequence fun title(text: CharSequence?) = title(text?.toString()) - fun text(@StringRes id: Int, style: Int = 0) = text(context.getString(id), style) + fun text(@StringRes id: Int, style: Int? = null) = text(context.getString(id), style) - fun text(text: CharSequence?, @StyleRes style: Int = 0) { + fun text(text: CharSequence?, @StyleRes style: Int? = null) { text(text, style) { layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) .apply { updateMargins(dp40, 0, dp40, 0) } } } - private fun text(text: CharSequence?, @StyleRes style: Int, modify: TextView.() -> Unit) { + private fun text(text: CharSequence?, @StyleRes style: Int? = null, modify: TextView.() -> Unit) { text ?: return - TextView(context, null, 0, style) + TextView(context, null, 0, style ?: R.style.TextAppearance_Session_Dialog_Message) .apply { setText(text) textAlignment = View.TEXT_ALIGNMENT_CENTER @@ -87,7 +90,7 @@ class SessionDialogBuilder(val context: Context) { }.let(topView::addView) Space(context).apply { - layoutParams = LinearLayout.LayoutParams(0, dp20) + layoutParams = LinearLayout.LayoutParams(0, dp8) }.let(topView::addView) } @@ -104,17 +107,31 @@ class SessionDialogBuilder(val context: Context) { fun singleChoiceItems( options: Collection, currentSelected: Int = 0, + dismissOnRadioSelect: Boolean = true, onSelect: (Int) -> Unit - ) = singleChoiceItems(options.toTypedArray(), currentSelected, onSelect) + ) = singleChoiceItems( + options.toTypedArray(), + currentSelected, + dismissOnRadioSelect, + onSelect + ) fun singleChoiceItems( options: Array, currentSelected: Int = 0, + dismissOnRadioSelect: Boolean = true, onSelect: (Int) -> Unit - ): AlertDialog.Builder = dialogBuilder.setSingleChoiceItems( - options, - currentSelected - ) { dialog, it -> onSelect(it); dialog.dismiss() } + ): AlertDialog.Builder{ + val adapter = ArrayAdapter(context, R.layout.view_dialog_single_choice_item, options) + + return dialogBuilder.setSingleChoiceItems( + adapter, + currentSelected + ) { dialog, it -> + onSelect(it) + if(dismissOnRadioSelect) dialog.dismiss() + } + } fun items( options: Array, @@ -141,10 +158,14 @@ class SessionDialogBuilder(val context: Context) { @StringRes text: Int, @StringRes contentDescriptionRes: Int = text, @StyleRes style: Int = R.style.Widget_Session_Button_Dialog_UnimportantText, + @ColorRes textColor: Int? = null, dismiss: Boolean = true, listener: (() -> Unit) = {} ) = Button(context, null, 0, style).apply { setText(text) + textColor?.let{ + setTextColor(it) + } contentDescription = resources.getString(contentDescriptionRes) layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, dp60, 1f) setOnClickListener { 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 a4579f1415..98ad62dcb3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt @@ -63,7 +63,6 @@ class ClearAllDataDialog : DialogFragment() { binding.recyclerView.apply { itemAnimator = null adapter = optionAdapter - addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)) setHasFixedSize(true) } optionAdapter.submitList(listOf(device, network)) diff --git a/app/src/main/res/drawable/default_dialog_background.xml b/app/src/main/res/drawable/default_dialog_background.xml index d2e3dfbfa7..01ae255c9f 100644 --- a/app/src/main/res/drawable/default_dialog_background.xml +++ b/app/src/main/res/drawable/default_dialog_background.xml @@ -4,7 +4,7 @@ android:shape="rectangle"> - + \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_background.xml b/app/src/main/res/drawable/dialog_background.xml deleted file mode 100644 index e546e1f84c..0000000000 --- a/app/src/main/res/drawable/dialog_background.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_radio_selected.xml b/app/src/main/res/drawable/ic_radio_selected.xml new file mode 100644 index 0000000000..82021810e9 --- /dev/null +++ b/app/src/main/res/drawable/ic_radio_selected.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_radio_unselected.xml b/app/src/main/res/drawable/ic_radio_unselected.xml new file mode 100644 index 0000000000..285dbb276e --- /dev/null +++ b/app/src/main/res/drawable/ic_radio_unselected.xml @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/padded_circle_accent_select.xml b/app/src/main/res/drawable/padded_circle_accent_select.xml index 0d384e658f..ba8e121e16 100644 --- a/app/src/main/res/drawable/padded_circle_accent_select.xml +++ b/app/src/main/res/drawable/padded_circle_accent_select.xml @@ -2,10 +2,10 @@ - + diff --git a/app/src/main/res/drawable/radial_multi_select.xml b/app/src/main/res/drawable/radial_multi_select.xml index c05af4e763..5b2144e897 100644 --- a/app/src/main/res/drawable/radial_multi_select.xml +++ b/app/src/main/res/drawable/radial_multi_select.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/radio_states.xml b/app/src/main/res/drawable/radio_states.xml new file mode 100644 index 0000000000..4d20610ca2 --- /dev/null +++ b/app/src/main/res/drawable/radio_states.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_clear_all_data.xml b/app/src/main/res/layout/dialog_clear_all_data.xml index e25d699fa5..ba8bf82283 100644 --- a/app/src/main/res/layout/dialog_clear_all_data.xml +++ b/app/src/main/res/layout/dialog_clear_all_data.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:text="@string/clearDataAll" android:textColor="?android:textColorPrimary" - android:textStyle="bold" + style="@style/TextAppearance.Session.Dialog.Title" android:textSize="@dimen/medium_font_size" /> + style="@style/TextAppearance.Session.Dialog.Message" /> diff --git a/app/src/main/res/layout/item_selectable.xml b/app/src/main/res/layout/item_selectable.xml index 0dcb4d526a..28a5bf8495 100644 --- a/app/src/main/res/layout/item_selectable.xml +++ b/app/src/main/res/layout/item_selectable.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?selectableItemBackground" - android:paddingHorizontal="@dimen/medium_spacing" + android:paddingHorizontal="@dimen/large_spacing" android:paddingVertical="@dimen/small_spacing"> + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 75a3459f09..b55d951473 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -34,6 +34,7 @@ + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 3ec6cd1990..81cca8417e 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -9,6 +9,10 @@ 20sp 26sp + + 16sp + 18sp + 60dp 34dp @@ -36,6 +40,7 @@ 56dp 40dp 48dp + 42dp 4dp @@ -120,6 +125,6 @@ 40dp 200dp 34dp - 24dp + 26dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 38bfe08865..339139e8fc 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -23,6 +23,15 @@ @dimen/very_large_font_size + + + +