From eae4eff92f59ef1d093e93bd50560248c8058d95 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 6 Dec 2019 20:34:25 +0100 Subject: [PATCH] Fixed custom dialog behaving oddly while displaying scrollable content --- .../com/topjohnwu/magisk/view/MagiskDialog.kt | 29 +++++++-- .../main/res/layout/dialog_magisk_base.xml | 63 ++++++++++--------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt index b2a088cf5..30107bfbf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt @@ -9,9 +9,12 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.WindowManager import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatDialog +import androidx.core.view.ViewCompat +import androidx.core.view.updatePadding import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -26,7 +29,7 @@ import me.tatarka.bindingcollectionadapter2.ItemBinding class MagiskDialog @JvmOverloads constructor( context: Context, theme: Int = 0 -) : AlertDialog(context, theme) { +) : AppCompatDialog(context, theme) { private val binding: DialogMagiskBaseBinding = DialogMagiskBaseBinding.inflate(LayoutInflater.from(context)) @@ -34,12 +37,30 @@ class MagiskDialog @JvmOverloads constructor( init { binding.setVariable(BR.data, data) - super.setView(binding.root) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + super.setContentView(binding.root) + window?.apply { + setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + setLayout( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.MATCH_PARENT + ) + } + + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, insets -> + view.updatePadding( + top = view.paddingTop + insets.systemWindowInsetTop, + bottom = view.paddingBottom + insets.systemWindowInsetBottom + ) + insets + } + + binding.dialogBaseOutsideContainer.setOnClickListener { + setCanceledOnTouchOutside(true) + } } inner class Data { diff --git a/app/src/main/res/layout/dialog_magisk_base.xml b/app/src/main/res/layout/dialog_magisk_base.xml index 7fa4bb7a3..e2d752533 100644 --- a/app/src/main/res/layout/dialog_magisk_base.xml +++ b/app/src/main/res/layout/dialog_magisk_base.xml @@ -13,6 +13,7 @@ - - + android:layout_height="wrap_content"> - + - + - + + app:layout_constraintBottom_toTopOf="@+id/dialog_base_buttons" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent"> - +