From 6960d0c7049147567a45e09f4c41ed44c792e003 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 Apr 2024 11:37:45 +0930 Subject: [PATCH] Fix spacing when title is absent --- .../securesms/SessionDialogBuilder.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt index a99b40f36f..52c9fe760a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt @@ -7,7 +7,9 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.Button import android.widget.LinearLayout +import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.VERTICAL +import android.widget.Space import android.widget.TextView import androidx.annotation.AttrRes import androidx.annotation.LayoutRes @@ -15,13 +17,11 @@ import androidx.annotation.StringRes import androidx.annotation.StyleRes import androidx.appcompat.app.AlertDialog import androidx.core.view.setMargins -import androidx.core.view.setPadding import androidx.core.view.updateMargins import androidx.fragment.app.Fragment import network.loki.messenger.R import org.thoughtcrime.securesms.util.toPx - @DslMarker @Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE) annotation class DialogDsl @@ -37,7 +37,9 @@ class SessionDialogBuilder(val context: Context) { private var dialog: AlertDialog? = null private fun dismiss() = dialog?.dismiss() - private val topView = LinearLayout(context).apply { orientation = VERTICAL } + private val topView = LinearLayout(context) + .apply { setPadding(0, dp20, 0, 0) } + .apply { orientation = VERTICAL } .also(dialogBuilder::setCustomTitle) private val contentView = LinearLayout(context).apply { orientation = VERTICAL } private val buttonLayout = LinearLayout(context) @@ -53,18 +55,17 @@ class SessionDialogBuilder(val context: Context) { fun title(text: CharSequence?) = title(text?.toString()) fun title(text: String?) { - text(text, R.style.TextAppearance_AppCompat_Title) { setPadding(dp20) } + text(text, R.style.TextAppearance_AppCompat_Title) { setPadding(dp20, 0, dp20, 0) } } fun text(@StringRes id: Int, style: Int = 0) = text(context.getString(id), style) fun text(text: CharSequence?, @StyleRes style: Int = 0) { text(text, style) { layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) - .apply { updateMargins(dp40, 0, dp40, dp20) } + .apply { updateMargins(dp40, 0, dp40, 0) } } } - private fun text(text: CharSequence?, @StyleRes style: Int, modify: TextView.() -> Unit) { text ?: return TextView(context, null, 0, style) @@ -73,6 +74,10 @@ class SessionDialogBuilder(val context: Context) { textAlignment = View.TEXT_ALIGNMENT_CENTER modify() }.let(topView::addView) + + Space(context).apply { + layoutParams = LayoutParams(0, dp20) + }.let(topView::addView) } fun view(view: View) = contentView.addView(view) @@ -126,7 +131,7 @@ class SessionDialogBuilder(val context: Context) { setText(text) contentDescription = resources.getString(contentDescriptionRes) layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1f) - .apply { setMargins(toPx(20, resources)) } + .apply { setMargins(dp20) } setOnClickListener { listener.invoke() if (dismiss) dismiss()