1
0
Эх сурвалжийг харах

If noVerticalPadding is set with customView(...), padding is not applied to the bottom of the scroll view if wrapInScroll is enabled. Resolves #1834.

Aidan Follestad 5 жил өмнө
parent
commit
7964a5bb50

+ 10 - 9
core/src/main/java/com/afollestad/materialdialogs/customview/DialogCustomViewExt.kt

@@ -30,9 +30,8 @@ internal const val CUSTOM_VIEW_NO_VERTICAL_PADDING = "md.custom_view_no_vertical
  * @throws IllegalStateException if there is no custom view set.
  */
 @CheckResult fun MaterialDialog.getCustomView(): View {
-  return this.view.contentLayout.customView ?: throw IllegalStateException(
-      "You have not setup this dialog as a customView dialog."
-  )
+  return this.view.contentLayout.customView
+      ?: error("You have not setup this dialog as a customView dialog.")
 }
 
 /**
@@ -62,12 +61,14 @@ fun MaterialDialog.customView(
     maxWidth(literal = 0)
   }
 
-  this.view.contentLayout.addCustomView(
-      res = viewRes,
-      view = view,
-      scrollable = scrollable,
-      horizontalPadding = horizontalPadding
-  )
+  this.view.contentLayout
+      .addCustomView(
+          res = viewRes,
+          view = view,
+          scrollable = scrollable,
+          horizontalPadding = horizontalPadding,
+          noVerticalPadding = noVerticalPadding
+      )
       .also {
         if (dialogWrapContent) {
           it.waitForWidth {

+ 11 - 3
core/src/main/java/com/afollestad/materialdialogs/internal/message/DialogContentLayout.kt

@@ -41,6 +41,7 @@ import com.afollestad.materialdialogs.internal.main.DialogLayout
 import com.afollestad.materialdialogs.internal.main.DialogScrollView
 import com.afollestad.materialdialogs.internal.main.DialogTitleLayout
 import com.afollestad.materialdialogs.message.DialogMessageSettings
+import com.afollestad.materialdialogs.utils.MDUtil.dimenPx
 import com.afollestad.materialdialogs.utils.MDUtil.maybeSetTextColor
 import com.afollestad.materialdialogs.utils.MDUtil.updatePadding
 import com.afollestad.materialdialogs.utils.inflate
@@ -78,7 +79,7 @@ class DialogContentLayout(
     typeface: Typeface?,
     applySettings: (DialogMessageSettings.() -> Unit)?
   ) {
-    addContentScrollView()
+    addContentScrollView(noVerticalPadding = false)
     if (messageTextView == null) {
       messageTextView = inflate<TextView>(R.layout.md_dialog_stub_message, scrollFrame!!).apply {
         scrollFrame!!.addView(this)
@@ -114,6 +115,7 @@ class DialogContentLayout(
     @LayoutRes res: Int?,
     view: View?,
     scrollable: Boolean,
+    noVerticalPadding: Boolean,
     horizontalPadding: Boolean
   ): View {
     check(customView == null) { "Custom view already set." }
@@ -127,7 +129,7 @@ class DialogContentLayout(
     if (scrollable) {
       // Since the view is going in the main ScrollView, apply padding to custom view.
       this.useHorizontalPadding = false
-      addContentScrollView()
+      addContentScrollView(noVerticalPadding = noVerticalPadding)
       customView = view ?: inflate(res!!, scrollFrame)
       scrollFrame!!.addView(customView?.apply {
         if (horizontalPadding) {
@@ -249,11 +251,17 @@ class DialogContentLayout(
     }
   }
 
-  private fun addContentScrollView() {
+  private fun addContentScrollView(
+    noVerticalPadding: Boolean
+  ) {
     if (scrollView == null) {
       scrollView = inflate<DialogScrollView>(R.layout.md_dialog_stub_scrollview).apply {
         this.rootView = rootLayout
         scrollFrame = this.getChildAt(0) as ViewGroup
+        if (!noVerticalPadding) {
+          val scrollBottomPadding = dimenPx(R.dimen.md_dialog_frame_margin_vertical)
+          updatePadding(bottom = scrollBottomPadding)
+        }
       }
       addView(scrollView)
     }

+ 3 - 3
core/src/main/java/com/afollestad/materialdialogs/utils/MDUtil.kt

@@ -319,9 +319,9 @@ object MDUtil {
   }
 
   @RestrictTo(LIBRARY_GROUP) fun WindowManager.getWidthAndHeight(): Pair<Int, Int> {
-    val size = Point()
-    defaultDisplay.getSize(size)
-    return Pair(size.x, size.y)
+    return Point()
+        .apply { defaultDisplay.getSize(this) }
+        .let { Pair(it.x, it.y) }
   }
 
   @RestrictTo(LIBRARY_GROUP) fun <T : View> T?.updatePadding(

+ 0 - 3
core/src/main/res/layout/md_dialog_stub_scrollview.xml

@@ -5,12 +5,9 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:clipToPadding="false"
-    android:paddingBottom="@dimen/md_dialog_frame_margin_vertical"
     >
-
   <LinearLayout
       android:id="@+id/md_scrollview_frame_content"
       style="@style/MD_Dialog_ScrollView_FrameContent"
       />
-
 </com.afollestad.materialdialogs.internal.main.DialogScrollView>