Added backward compatibility for edgeToEdge mode to support all android versions.

* Removed the deprecated `FLAG_FULLSCREEN` from our project.
This commit is contained in:
MohitMaliFtechiz 2024-12-27 14:49:46 +05:30 committed by Kelson
parent d94ca866df
commit e6bdc0af0e
2 changed files with 9 additions and 31 deletions

View File

@ -19,7 +19,6 @@
package org.kiwix.kiwixmobile.core.extensions package org.kiwix.kiwixmobile.core.extensions
import android.content.Context import android.content.Context
import android.os.Build
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
@ -60,9 +59,6 @@ val Fragment.coreMainActivity get() = activity as CoreMainActivity
fun Fragment.enableEdgeToEdgeMode() { fun Fragment.enableEdgeToEdgeMode() {
activity?.window?.let { activity?.window?.let {
WindowCompat.setDecorFitsSystemWindows( WindowCompat.setDecorFitsSystemWindows(it, false)
it,
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
)
} }
} }

View File

@ -19,15 +19,12 @@
package org.kiwix.kiwixmobile.core.extensions package org.kiwix.kiwixmobile.core.extensions
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Build
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window import android.view.Window
import android.view.WindowManager
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.widget.TooltipCompat import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.ViewGroupCompat
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
@ -94,33 +91,19 @@ fun View.setToolTipWithContentDescription(description: String) {
fun View.showFullScreenMode(window: Window) { fun View.showFullScreenMode(window: Window) {
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { WindowInsetsControllerCompat(window, window.decorView).apply {
WindowInsetsControllerCompat(window, window.decorView).apply { hide(WindowInsetsCompat.Type.systemBars())
hide(WindowInsetsCompat.Type.systemBars()) hide(WindowInsetsCompat.Type.displayCutout())
hide(WindowInsetsCompat.Type.displayCutout()) systemBarsBehavior =
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
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) { fun View.closeFullScreenMode(window: Window) {
WindowCompat.setDecorFitsSystemWindows(window, true) WindowCompat.setDecorFitsSystemWindows(window, true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { WindowInsetsControllerCompat(window, window.decorView).apply {
WindowInsetsControllerCompat(window, window.decorView).apply { show(WindowInsetsCompat.Type.systemBars())
show(WindowInsetsCompat.Type.systemBars()) show(WindowInsetsCompat.Type.displayCutout())
show(WindowInsetsCompat.Type.displayCutout())
}
}
@Suppress("DEPRECATION")
window.apply {
addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
} }
} }
@ -137,7 +120,6 @@ fun View.closeFullScreenMode(window: Window) {
*/ */
fun View?.applyEdgeToEdgeInsets(shouldAddBottomPadding: Boolean = true) { fun View?.applyEdgeToEdgeInsets(shouldAddBottomPadding: Boolean = true) {
this?.let { this?.let {
ViewGroupCompat.installCompatInsetsDispatch(this)
ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets -> ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets ->
val insets = windowInsets.getInsets( val insets = windowInsets.getInsets(
WindowInsetsCompat.Type.systemBars() WindowInsetsCompat.Type.systemBars()