From 06b5a495098a230f166a52b006bbccddeff59bb8 Mon Sep 17 00:00:00 2001 From: Levin Li Date: Sun, 18 Dec 2022 14:22:16 +0800 Subject: [PATCH] Fix browser fragment insets --- app/src/main/AndroidManifest.xml | 2 +- .../java/space/celestia/mobilecelestia/MainActivity.kt | 10 +--------- .../celestia/mobilecelestia/browser/BrowserFragment.kt | 9 ++++++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 54dc0f63..37291802 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt index 7e25ea1b..11107f26 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt @@ -22,27 +22,19 @@ import android.os.Bundle import android.provider.DocumentsContract import android.util.LayoutDirection import android.util.Log -import android.view.Gravity -import android.view.MotionEvent import android.view.View import android.view.WindowManager import android.widget.FrameLayout import android.widget.Toast import androidx.activity.OnBackPressedCallback -import androidx.activity.addCallback import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity -import androidx.constraintlayout.widget.Guideline import androidx.core.animation.addListener import androidx.core.app.ShareCompat import androidx.core.content.FileProvider import androidx.core.graphics.Insets -import androidx.core.view.GravityCompat -import androidx.core.view.ViewCompat -import androidx.core.view.WindowCompat -import androidx.core.view.WindowInsetsCompat -import androidx.core.view.WindowInsetsControllerCompat +import androidx.core.view.* import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout.DrawerListener import androidx.fragment.app.Fragment diff --git a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserFragment.kt index 111db43a..1d7a205e 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserFragment.kt @@ -14,6 +14,7 @@ package space.celestia.mobilecelestia.browser import android.os.Bundle import android.view.* import android.widget.LinearLayout +import androidx.core.graphics.Insets import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment @@ -118,9 +119,11 @@ class BrowserFragment : Fragment(), Poppable, BrowserRootFragment, NavigationBar browserContainer = view.findViewById(R.id.browser_container) navigation = view.findViewById(R.id.navigation) - ViewCompat.setOnApplyWindowInsetsListener(browserContainer) { _, _ -> - // Consume insets because we have a bottom bar now - WindowInsetsCompat.CONSUMED + ViewCompat.setOnApplyWindowInsetsListener(view.findViewById(R.id.navigation_container)) { _, insets -> + // Consume bottom insets because we have a bottom bar now + // TODO: the suggested replacement for the deprecated methods does not work + val builder = WindowInsetsCompat.Builder(insets).setSystemWindowInsets(Insets.of(insets.systemWindowInsetLeft , insets.systemWindowInsetTop, insets.systemWindowInsetRight, 0)) + return@setOnApplyWindowInsetsListener builder.build() } return view