mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Improved the edge to edge mode in landscape mode.
* It was showing the content behind the display cutout in landscape mode. * Removed the unnecessary code from BaseFragment. * Enhanced the applying edge to edge mode for lower devices(Before Android 10).
This commit is contained in:
parent
e555e628bd
commit
77f67d4c8f
@ -129,7 +129,6 @@ class KiwixMainActivity : CoreMainActivity() {
|
||||
closeNavigationDrawer()
|
||||
onNavigationItemSelected(item)
|
||||
}
|
||||
applyEdgeToEdgeInsets()
|
||||
}
|
||||
activityKiwixMainBinding.bottomNavView.setupWithNavController(navController)
|
||||
lifecycleScope.launch {
|
||||
@ -138,7 +137,7 @@ class KiwixMainActivity : CoreMainActivity() {
|
||||
handleZimFileIntent(intent)
|
||||
handleNotificationIntent(intent)
|
||||
handleGetContentIntent(intent)
|
||||
readerTableOfContentsDrawer.applyEdgeToEdgeInsets()
|
||||
activityKiwixMainBinding.root.applyEdgeToEdgeInsets()
|
||||
}
|
||||
|
||||
private suspend fun migrateInternalToPublicAppDirectory() {
|
||||
|
@ -26,12 +26,10 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.extensions.applyEdgeToEdgeInsets
|
||||
import org.kiwix.kiwixmobile.core.extensions.enableEdgeToEdgeMode
|
||||
import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon
|
||||
import org.kiwix.kiwixmobile.core.extensions.setFragmentBackgroundColorForAndroid15AndAbove
|
||||
import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription
|
||||
import org.kiwix.kiwixmobile.core.main.CoreReaderFragment
|
||||
|
||||
/**
|
||||
* All fragments should inherit from this fragment.
|
||||
@ -56,8 +54,6 @@ abstract class BaseFragment : Fragment() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
setFragmentBackgroundColorForAndroid15AndAbove()
|
||||
}
|
||||
// Ignore adding the bottom padding to coreReaderFragment.
|
||||
this.view.applyEdgeToEdgeInsets(this !is CoreReaderFragment)
|
||||
}
|
||||
|
||||
// Setup toolbar to handle common back pressed event
|
||||
|
@ -86,7 +86,7 @@ open class ErrorActivity : BaseActivity() {
|
||||
}
|
||||
setupReportButton()
|
||||
activityKiwixErrorBinding?.restartButton?.setOnClickListener { restartApp() }
|
||||
activityKiwixErrorBinding?.root.applyEdgeToEdgeInsets(true)
|
||||
activityKiwixErrorBinding?.root.applyEdgeToEdgeInsets()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -19,16 +19,18 @@
|
||||
package org.kiwix.kiwixmobile.core.extensions
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.widget.TooltipCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
@ -91,48 +93,58 @@ fun View.setToolTipWithContentDescription(description: String) {
|
||||
|
||||
fun View.showFullScreenMode(window: Window) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
WindowInsetsControllerCompat(window, window.decorView).apply {
|
||||
hide(WindowInsetsCompat.Type.systemBars())
|
||||
hide(WindowInsetsCompat.Type.displayCutout())
|
||||
systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
WindowInsetsControllerCompat(window, window.decorView).apply {
|
||||
hide(WindowInsetsCompat.Type.systemBars())
|
||||
hide(WindowInsetsCompat.Type.displayCutout())
|
||||
systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
}
|
||||
}
|
||||
@Suppress("Deprecation")
|
||||
window.apply {
|
||||
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
fun View.closeFullScreenMode(window: Window) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
WindowInsetsControllerCompat(window, window.decorView).apply {
|
||||
show(WindowInsetsCompat.Type.systemBars())
|
||||
show(WindowInsetsCompat.Type.displayCutout())
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
WindowInsetsControllerCompat(window, window.decorView).apply {
|
||||
show(WindowInsetsCompat.Type.systemBars())
|
||||
show(WindowInsetsCompat.Type.displayCutout())
|
||||
}
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
window.apply {
|
||||
addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the view's top margin and optionally its bottom padding to handle edge-to-edge insets
|
||||
* (e.g., system bars, display cutouts, and system gestures).
|
||||
* Applies edge-to-edge insets to the current view by adjusting its margins
|
||||
* to account for system bars and display cutouts (e.g., status bar, navigation bar, and notches).
|
||||
*
|
||||
* By default, this method adds bottom padding to avoid content being obscured by the system bar.
|
||||
* However, bottom padding can be skipped for specific cases like the reader fragment, where adding
|
||||
* it might cause the BottomAppBar to overlap the content.
|
||||
* This method ensures that the view avoids overlapping with system UI components by dynamically
|
||||
* setting margins based on the insets provided by the system.
|
||||
*
|
||||
* @param shouldAddBottomPadding Whether to add padding to the bottom of the view to handle system insets.
|
||||
* Defaults to `true`.
|
||||
* Usage: Call this method on any view to apply edge-to-edge handling.
|
||||
*/
|
||||
fun View?.applyEdgeToEdgeInsets(shouldAddBottomPadding: Boolean = true) {
|
||||
fun View?.applyEdgeToEdgeInsets() {
|
||||
this?.let {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets ->
|
||||
val insets = windowInsets.getInsets(
|
||||
WindowInsetsCompat.Type.systemBars()
|
||||
or WindowInsetsCompat.Type.displayCutout()
|
||||
)
|
||||
val layoutParams = view.layoutParams as? ViewGroup.MarginLayoutParams
|
||||
layoutParams?.topMargin = insets.top
|
||||
view.layoutParams = layoutParams
|
||||
// Optionally add padding to the bottom to prevent content from being obscured by system bars.
|
||||
if (shouldAddBottomPadding) {
|
||||
val systemBarsInsets =
|
||||
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view.updatePadding(bottom = systemBarsInsets.bottom)
|
||||
val systemBarsInsets =
|
||||
windowInsets.getInsets(
|
||||
WindowInsetsCompat.Type.displayCutout() or
|
||||
WindowInsetsCompat.Type.systemBars()
|
||||
)
|
||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = systemBarsInsets.top
|
||||
leftMargin = systemBarsInsets.left
|
||||
bottomMargin = systemBarsInsets.bottom
|
||||
rightMargin = systemBarsInsets.right
|
||||
}
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
|
@ -91,6 +91,8 @@
|
||||
<item name="colorAccent">?colorSecondary</item>
|
||||
<item name="android:navigationBarColor">@color/black</item>
|
||||
|
||||
<!-- To prevent showing content behind the cutouts -->
|
||||
<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">never</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -85,8 +85,7 @@ class CustomMainActivity : CoreMainActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
activityCustomMainBinding = ActivityCustomMainBinding.inflate(layoutInflater)
|
||||
setContentView(activityCustomMainBinding.root)
|
||||
drawerNavView.applyEdgeToEdgeInsets()
|
||||
readerTableOfContentsDrawer.applyEdgeToEdgeInsets()
|
||||
activityCustomMainBinding.root.applyEdgeToEdgeInsets()
|
||||
if (savedInstanceState != null) {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user