Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit 7964a5b

Browse files
committed
If noVerticalPadding is set with customView(...), padding is not applied to the bottom of the scroll view if wrapInScroll is enabled. Resolves #1834.
1 parent 35ea27d commit 7964a5b

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

core/src/main/java/com/afollestad/materialdialogs/customview/DialogCustomViewExt.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ internal const val CUSTOM_VIEW_NO_VERTICAL_PADDING = "md.custom_view_no_vertical
3030
* @throws IllegalStateException if there is no custom view set.
3131
*/
3232
@CheckResult fun MaterialDialog.getCustomView(): View {
33-
return this.view.contentLayout.customView ?: throw IllegalStateException(
34-
"You have not setup this dialog as a customView dialog."
35-
)
33+
return this.view.contentLayout.customView
34+
?: error("You have not setup this dialog as a customView dialog.")
3635
}
3736

3837
/**
@@ -62,12 +61,14 @@ fun MaterialDialog.customView(
6261
maxWidth(literal = 0)
6362
}
6463

65-
this.view.contentLayout.addCustomView(
66-
res = viewRes,
67-
view = view,
68-
scrollable = scrollable,
69-
horizontalPadding = horizontalPadding
70-
)
64+
this.view.contentLayout
65+
.addCustomView(
66+
res = viewRes,
67+
view = view,
68+
scrollable = scrollable,
69+
horizontalPadding = horizontalPadding,
70+
noVerticalPadding = noVerticalPadding
71+
)
7172
.also {
7273
if (dialogWrapContent) {
7374
it.waitForWidth {

core/src/main/java/com/afollestad/materialdialogs/internal/message/DialogContentLayout.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.afollestad.materialdialogs.internal.main.DialogLayout
4141
import com.afollestad.materialdialogs.internal.main.DialogScrollView
4242
import com.afollestad.materialdialogs.internal.main.DialogTitleLayout
4343
import com.afollestad.materialdialogs.message.DialogMessageSettings
44+
import com.afollestad.materialdialogs.utils.MDUtil.dimenPx
4445
import com.afollestad.materialdialogs.utils.MDUtil.maybeSetTextColor
4546
import com.afollestad.materialdialogs.utils.MDUtil.updatePadding
4647
import com.afollestad.materialdialogs.utils.inflate
@@ -78,7 +79,7 @@ class DialogContentLayout(
7879
typeface: Typeface?,
7980
applySettings: (DialogMessageSettings.() -> Unit)?
8081
) {
81-
addContentScrollView()
82+
addContentScrollView(noVerticalPadding = false)
8283
if (messageTextView == null) {
8384
messageTextView = inflate<TextView>(R.layout.md_dialog_stub_message, scrollFrame!!).apply {
8485
scrollFrame!!.addView(this)
@@ -114,6 +115,7 @@ class DialogContentLayout(
114115
@LayoutRes res: Int?,
115116
view: View?,
116117
scrollable: Boolean,
118+
noVerticalPadding: Boolean,
117119
horizontalPadding: Boolean
118120
): View {
119121
check(customView == null) { "Custom view already set." }
@@ -127,7 +129,7 @@ class DialogContentLayout(
127129
if (scrollable) {
128130
// Since the view is going in the main ScrollView, apply padding to custom view.
129131
this.useHorizontalPadding = false
130-
addContentScrollView()
132+
addContentScrollView(noVerticalPadding = noVerticalPadding)
131133
customView = view ?: inflate(res!!, scrollFrame)
132134
scrollFrame!!.addView(customView?.apply {
133135
if (horizontalPadding) {
@@ -249,11 +251,17 @@ class DialogContentLayout(
249251
}
250252
}
251253

252-
private fun addContentScrollView() {
254+
private fun addContentScrollView(
255+
noVerticalPadding: Boolean
256+
) {
253257
if (scrollView == null) {
254258
scrollView = inflate<DialogScrollView>(R.layout.md_dialog_stub_scrollview).apply {
255259
this.rootView = rootLayout
256260
scrollFrame = this.getChildAt(0) as ViewGroup
261+
if (!noVerticalPadding) {
262+
val scrollBottomPadding = dimenPx(R.dimen.md_dialog_frame_margin_vertical)
263+
updatePadding(bottom = scrollBottomPadding)
264+
}
257265
}
258266
addView(scrollView)
259267
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ object MDUtil {
319319
}
320320

321321
@RestrictTo(LIBRARY_GROUP) fun WindowManager.getWidthAndHeight(): Pair<Int, Int> {
322-
val size = Point()
323-
defaultDisplay.getSize(size)
324-
return Pair(size.x, size.y)
322+
return Point()
323+
.apply { defaultDisplay.getSize(this) }
324+
.let { Pair(it.x, it.y) }
325325
}
326326

327327
@RestrictTo(LIBRARY_GROUP) fun <T : View> T?.updatePadding(

core/src/main/res/layout/md_dialog_stub_scrollview.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
77
android:clipToPadding="false"
8-
android:paddingBottom="@dimen/md_dialog_frame_margin_vertical"
98
>
10-
119
<LinearLayout
1210
android:id="@+id/md_scrollview_frame_content"
1311
style="@style/MD_Dialog_ScrollView_FrameContent"
1412
/>
15-
1613
</com.afollestad.materialdialogs.internal.main.DialogScrollView>

0 commit comments

Comments
 (0)