mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Bringing my xml dialog styling from my 'Standardise message deletion' branch
This commit is contained in:
parent
706d1aadd8
commit
86cab0e11e
@ -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<String>,
|
||||
currentSelected: Int = 0,
|
||||
dismissOnRadioSelect: Boolean = true,
|
||||
onSelect: (Int) -> Unit
|
||||
) = singleChoiceItems(options.toTypedArray(), currentSelected, onSelect)
|
||||
) = singleChoiceItems(
|
||||
options.toTypedArray(),
|
||||
currentSelected,
|
||||
dismissOnRadioSelect,
|
||||
onSelect
|
||||
)
|
||||
|
||||
fun singleChoiceItems(
|
||||
options: Array<String>,
|
||||
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<CharSequence>(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<String>,
|
||||
@ -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 {
|
||||
|
@ -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))
|
||||
|
@ -4,7 +4,7 @@
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="?backgroundSecondary" />
|
||||
|
||||
<stroke android:width="1dp" android:color="?elementBorderColor" />
|
||||
<corners android:radius="?dialogCornerRadius" />
|
||||
|
||||
</shape>
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="16dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="16dp">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="2dp" />
|
||||
<solid android:color="?backgroundSecondary" />
|
||||
</shape>
|
||||
</inset>
|
13
app/src/main/res/drawable/ic_radio_selected.xml
Normal file
13
app/src/main/res/drawable/ic_radio_selected.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="27dp"
|
||||
android:height="27dp"
|
||||
android:viewportWidth="27"
|
||||
android:viewportHeight="27">
|
||||
<path
|
||||
android:pathData="M13.567,13.714m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0"
|
||||
android:fillColor="?accentColor"/>
|
||||
<path
|
||||
android:strokeWidth="1"
|
||||
android:pathData="M13.567,13.713m-12.5,0a12.5,12.5 0,1 1,25 0a12.5,12.5 0,1 1,-25 0"
|
||||
android:strokeColor="?textColorAlert"/>
|
||||
</vector>
|
11
app/src/main/res/drawable/ic_radio_unselected.xml
Normal file
11
app/src/main/res/drawable/ic_radio_unselected.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="27dp"
|
||||
android:height="27dp"
|
||||
android:viewportWidth="27"
|
||||
android:viewportHeight="27">
|
||||
<path
|
||||
android:strokeWidth="1"
|
||||
android:pathData="M13.567,13.713m-12.5,0a12.5,12.5 0,1 1,25 0a12.5,12.5 0,1 1,-25 0"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?textColorAlert"/>
|
||||
</vector>
|
@ -2,10 +2,10 @@
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true">
|
||||
<layer-list>
|
||||
<item android:right="4dp"
|
||||
android:top="4dp"
|
||||
android:left="4dp"
|
||||
android:bottom="4dp">
|
||||
<item android:right="3dp"
|
||||
android:top="3dp"
|
||||
android:left="3dp"
|
||||
android:bottom="3dp">
|
||||
<shape
|
||||
android:shape="oval">
|
||||
<solid android:color="?colorAccent" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape android:shape="oval"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<stroke android:width="1dp" android:color="?android:textColorPrimary"/>
|
||||
<stroke android:width="1dp" android:color="?textColorAlert"/>
|
||||
</shape>
|
9
app/src/main/res/drawable/radio_states.xml
Normal file
9
app/src/main/res/drawable/radio_states.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="true"
|
||||
android:drawable="@drawable/ic_radio_selected" /> <!-- checked -->
|
||||
<item android:state_selected="true"
|
||||
android:drawable="@drawable/ic_radio_selected" /> <!-- selected -->
|
||||
<item
|
||||
android:drawable="@drawable/ic_radio_unselected" /> <!-- unchecked-->
|
||||
</selector>
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
@ -22,17 +22,17 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginTop="@dimen/large_spacing"
|
||||
android:layout_marginTop="@dimen/small_spacing"
|
||||
android:text="@string/clearDataAllDescription"
|
||||
android:textAlignment="center"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/small_font_size" />
|
||||
style="@style/TextAppearance.Session.Dialog.Message" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="@dimen/small_spacing"
|
||||
android:layout_marginTop="@dimen/small_spacing"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:itemCount="2"
|
||||
tools:listitem="@layout/item_selectable"/>
|
||||
|
@ -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">
|
||||
|
||||
<TextView
|
||||
|
11
app/src/main/res/layout/view_dialog_single_choice_item.xml
Normal file
11
app/src/main/res/layout/view_dialog_single_choice_item.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checkMark="@drawable/radio_states"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/dialog_radio_height"
|
||||
android:paddingEnd="@dimen/large_spacing"
|
||||
android:paddingStart="@dimen/large_spacing"
|
||||
android:textAppearance="@style/TextAppearance.Session.Dialog.Message"/>
|
@ -34,6 +34,7 @@
|
||||
<attr name="danger" format="reference|color"/>
|
||||
<attr name="backgroundSecondary" format="reference|color"/>
|
||||
<attr name="prominentButtonColor" format="reference|color"/>
|
||||
<attr name="textColorAlert" format="reference|color"/>
|
||||
<attr name="elementBorderColor" format="reference|color"/>
|
||||
<attr name="conversation_background" format="reference|color"/>
|
||||
<attr name="conversation_editor_background" format="reference|color"/>
|
||||
|
@ -9,6 +9,10 @@
|
||||
<dimen name="large_font_size">20sp</dimen>
|
||||
<dimen name="very_large_font_size">26sp</dimen>
|
||||
|
||||
<!-- Need to be temporary added until the theming is properly centralised in Compose -->
|
||||
<dimen name="small2_font_size">16sp</dimen>
|
||||
<dimen name="medium2_font_size">18sp</dimen>
|
||||
|
||||
<!-- Element Sizes -->
|
||||
<dimen name="dialog_button_height">60dp</dimen>
|
||||
<dimen name="small_button_height">34dp</dimen>
|
||||
@ -36,6 +40,7 @@
|
||||
<dimen name="input_bar_height">56dp</dimen>
|
||||
<dimen name="input_bar_button_collapsed_size">40dp</dimen>
|
||||
<dimen name="input_bar_button_expanded_size">48dp</dimen>
|
||||
<dimen name="dialog_radio_height">42dp</dimen>
|
||||
|
||||
<!-- Distances -->
|
||||
<dimen name="very_small_spacing">4dp</dimen>
|
||||
@ -120,6 +125,6 @@
|
||||
<dimen name="react_with_any_emoji_bottom_sheet_dialog_fragment_tabs_height">40dp</dimen>
|
||||
<dimen name="max_text_width">200dp</dimen>
|
||||
<dimen name="radial_size">34dp</dimen>
|
||||
<dimen name="small_radial_size">24dp</dimen>
|
||||
<dimen name="small_radial_size">26dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
@ -23,6 +23,15 @@
|
||||
<item name="android:textSize">@dimen/very_large_font_size</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Session.Dialog.Title" parent="TextAppearance.AppCompat.Title">
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:textSize">@dimen/medium2_font_size</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Session.Dialog.Message" parent="TextAppearance.AppCompat.Body1">
|
||||
<item name="android:textSize">@dimen/small2_font_size</item>
|
||||
</style>
|
||||
|
||||
<style name="ThemeOverlay.Session.AlertDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
|
||||
<item name="android:windowBackground">@drawable/default_dialog_background</item>
|
||||
<item name="android:colorBackground">?backgroundSecondary</item>
|
||||
|
@ -317,6 +317,7 @@
|
||||
<item name="android:textColorTertiary">@color/classic_dark_5</item>
|
||||
<item name="android:textColor">?android:textColorPrimary</item>
|
||||
<item name="android:textColorHint">@color/gray27</item>
|
||||
<item name="textColorAlert">@color/classic_dark_6</item>
|
||||
<item name="android:windowBackground">?colorPrimary</item>
|
||||
<item name="android:navigationBarColor">@color/navigation_bar</item>
|
||||
<item name="bottomSheetDialogTheme">@style/Classic.Dark.BottomSheet</item>
|
||||
@ -399,6 +400,7 @@
|
||||
<item name="android:textColorTertiary">@color/classic_light_1</item>
|
||||
<item name="android:textColor">?android:textColorPrimary</item>
|
||||
<item name="android:textColorHint">@color/gray27</item>
|
||||
<item name="textColorAlert">@color/classic_light_0</item>
|
||||
<item name="android:windowBackground">?colorPrimary</item>
|
||||
<item name="android:navigationBarColor">@color/classic_light_navigation_bar</item>
|
||||
<item name="colorCellBackground">@color/classic_light_6</item>
|
||||
@ -489,6 +491,7 @@
|
||||
<item name="android:textColorTertiary">@color/ocean_dark_5</item>
|
||||
<item name="android:textColor">?android:textColorPrimary</item>
|
||||
<item name="android:textColorHint">@color/ocean_dark_5</item>
|
||||
<item name="textColorAlert">@color/ocean_dark_7</item>
|
||||
<item name="android:windowBackground">?colorPrimary</item>
|
||||
<item name="android:navigationBarColor">@color/navigation_bar</item>
|
||||
<item name="colorCellBackground">@color/ocean_dark_3</item>
|
||||
@ -574,6 +577,7 @@
|
||||
<item name="android:textColorTertiary">@color/ocean_light_2</item>
|
||||
<item name="android:textColor">?android:textColorPrimary</item>
|
||||
<item name="android:textColorHint">@color/ocean_light_6</item>
|
||||
<item name="textColorAlert">@color/ocean_light_0</item>
|
||||
<item name="android:navigationBarColor">@color/ocean_light_navigation_bar</item>
|
||||
<item name="android:windowBackground">?colorPrimary</item>
|
||||
<item name="colorCellBackground">@color/ocean_light_5</item>
|
||||
@ -680,6 +684,7 @@
|
||||
<item name="prominentButtonColor">?colorAccent</item>
|
||||
<item name="elementBorderColor">@color/classic_dark_3</item>
|
||||
<item name="danger">@color/danger_dark</item>
|
||||
<item name="textColorAlert">@color/classic_dark_6</item>
|
||||
|
||||
<!-- Home screen -->
|
||||
<item name="searchBackgroundColor">#1B1B1B</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user