瀏覽代碼

Revert "ui: Improve window inset calculation"

This reverts commit aca541593c62a48882adbd11178fb729922a0d57.
Peter Cai 1 月之前
父節點
當前提交
19b127df3f

+ 1 - 1
app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt

@@ -109,7 +109,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
         val origFabMarginRight = (fab.layoutParams as ViewGroup.MarginLayoutParams).rightMargin
         val origFabMarginBottom = (fab.layoutParams as ViewGroup.MarginLayoutParams).bottomMargin
         ViewCompat.setOnApplyWindowInsetsListener(fab) { v, insets ->
-            val bars = insets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.systemBars())
+            val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
 
             v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
                 rightMargin = origFabMarginRight + bars.right

+ 5 - 6
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

@@ -24,7 +24,6 @@ import im.angry.openeuicc.util.OpenEuiccContextMarker
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
 import net.typeblog.lpac_jni.LocalProfileAssistant
-import kotlin.math.max
 
 class DownloadWizardActivity : BaseEuiccAccessActivity() {
     data class DownloadWizardState(
@@ -98,21 +97,21 @@ class DownloadWizardActivity : BaseEuiccAccessActivity() {
         val origHeight = navigation.layoutParams.height
 
         ViewCompat.setOnApplyWindowInsetsListener(navigation) { v, insets ->
-            val bars = insets.getInsetsIgnoringVisibility(
+            val bars = insets.getInsets(
                 WindowInsetsCompat.Type.systemBars()
                     or WindowInsetsCompat.Type.displayCutout()
+                    or WindowInsetsCompat.Type.ime()
             )
-            val ime = insets.getInsets(WindowInsetsCompat.Type.ime())
-            v.updatePadding(bars.left, 0, bars.right, max(bars.bottom, ime.bottom))
+            v.updatePadding(bars.left, 0, bars.right, bars.bottom)
             val newParams = navigation.layoutParams
-            newParams.height = origHeight + max(bars.bottom, ime.bottom)
+            newParams.height = origHeight + bars.bottom
             navigation.layoutParams = newParams
             WindowInsetsCompat.CONSUMED
         }
 
         val fragmentRoot = requireViewById<View>(R.id.step_fragment_container)
         ViewCompat.setOnApplyWindowInsetsListener(fragmentRoot) { v, insets ->
-            val bars = insets.getInsetsIgnoringVisibility(
+            val bars = insets.getInsets(
                 WindowInsetsCompat.Type.systemBars()
                     or WindowInsetsCompat.Type.displayCutout()
             )

+ 9 - 1
app-common/src/main/java/im/angry/openeuicc/util/UiUtils.kt

@@ -34,10 +34,18 @@ fun DialogFragment.setWidthPercent(percentage: Int) {
     dialog?.window?.setLayout(percentWidth.toInt(), ViewGroup.LayoutParams.WRAP_CONTENT)
 }
 
+/**
+ * Call this method (in onActivityCreated or later)
+ * to make the dialog near-full screen.
+ */
+fun DialogFragment.setFullScreen() {
+    dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
+}
+
 fun AppCompatActivity.setupToolbarInsets() {
     val spacer = requireViewById<View>(R.id.toolbar_spacer)
     ViewCompat.setOnApplyWindowInsetsListener(requireViewById(R.id.toolbar)) { v, insets ->
-        val bars = insets.getInsetsIgnoringVisibility(
+        val bars = insets.getInsets(
             WindowInsetsCompat.Type.systemBars()
                 or WindowInsetsCompat.Type.displayCutout()
         )

+ 1 - 1
app/src/main/java/im/angry/openeuicc/ui/LuiActivity.kt

@@ -17,7 +17,7 @@ class LuiActivity : AppCompatActivity() {
         setContentView(R.layout.activity_lui)
 
         ViewCompat.setOnApplyWindowInsetsListener(requireViewById(R.id.lui_container)) { v, insets ->
-            val bars = insets.getInsetsIgnoringVisibility(
+            val bars = insets.getInsets(
                 WindowInsetsCompat.Type.systemBars()
                     or WindowInsetsCompat.Type.displayCutout()
             )