Enabled EdgeToEdge mode in project to support latest windowInset API.

This commit is contained in:
MohitMaliFtechiz 2024-12-26 16:16:31 +05:30 committed by Kelson
parent db41f1d876
commit ccfc896f02
23 changed files with 73 additions and 34 deletions

View File

@ -21,8 +21,7 @@
android:id="@+id/navigation_container" android:id="@+id/navigation_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/open_drawer" android:contentDescription="@string/open_drawer">
android:fitsSystemWindows="true">
<org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout <org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -53,7 +52,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_main" app:headerLayout="@layout/nav_main"
app:menu="@menu/menu_drawer_main" /> app:menu="@menu/menu_drawer_main" />
@ -62,7 +60,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="end" android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_right" /> app:headerLayout="@layout/drawer_right" />

View File

@ -1,24 +1,23 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"> android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/layout_standard_app_bar" /> <include layout="@layout/layout_standard_app_bar" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
tools:listitem="@layout/item_language"
android:id="@+id/language_recycler_view" android:id="@+id/language_recycler_view"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:contentDescription="@string/pref_language_title" android:contentDescription="@string/pref_language_title"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar" /> app:layout_constraintTop_toBottomOf="@id/app_bar"
tools:listitem="@layout/item_language" />
<androidx.core.widget.ContentLoadingProgressBar <androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/language_progressbar" android:id="@+id/language_progressbar"

View File

@ -22,7 +22,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.kiwix.kiwixmobile.webserver.ZimHostFragment"> tools:context="org.kiwix.kiwixmobile.webserver.ZimHostFragment">
<include layout="@layout/layout_toolbar" /> <include layout="@layout/layout_toolbar" />

View File

@ -21,8 +21,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout <org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -5,7 +5,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:fitsSystemWindows="true"
tools:context="org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferFragment"> tools:context="org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferFragment">

View File

@ -1,5 +1,3 @@
import io.opencensus.trace.Tracing
/** /**
* Generated by https://github.com/jmfayard/buildSrcVersions * Generated by https://github.com/jmfayard/buildSrcVersions
* *
@ -308,6 +306,8 @@ object Libs {
*/ */
const val core_ktx: String = "androidx.core:core-ktx:" + Versions.core_ktx const val core_ktx: String = "androidx.core:core-ktx:" + Versions.core_ktx
const val androidx_activity: String = "androidx.activity:activity:" + Versions.androidx_activity
/** /**
* https://github.com/kiwix/java-libkiwix * https://github.com/kiwix/java-libkiwix
*/ */

View File

@ -90,6 +90,8 @@ object Versions {
const val core_ktx: String = "1.15.0" const val core_ktx: String = "1.15.0"
const val androidx_activity: String = "1.9.3"
const val libkiwix: String = "2.2.3" const val libkiwix: String = "2.2.3"
const val material: String = "1.12.0" const val material: String = "1.12.0"

View File

@ -233,6 +233,7 @@ class AllProjectConfigurer {
kapt(Libs.roomCompiler) kapt(Libs.roomCompiler)
implementation(Libs.tracing) implementation(Libs.tracing)
implementation(Libs.fetchOkhttp) implementation(Libs.fetchOkhttp)
implementation(Libs.androidx_activity)
} }
} }
} }

View File

@ -17,8 +17,13 @@
*/ */
package org.kiwix.kiwixmobile.core.base package org.kiwix.kiwixmobile.core.base
import android.graphics.Color
import android.os.Build
import android.os.Bundle import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.changeStatusBarAndNavigationBarColorInAndroid15AndAbove
import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import javax.inject.Inject import javax.inject.Inject
@ -29,7 +34,14 @@ open class BaseActivity : AppCompatActivity() {
lateinit var sharedPreferenceUtil: SharedPreferenceUtil lateinit var sharedPreferenceUtil: SharedPreferenceUtil
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(Color.BLACK),
navigationBarStyle = SystemBarStyle.dark(Color.BLACK)
)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
changeStatusBarAndNavigationBarColorInAndroid15AndAbove()
}
LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil) LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil)
} }
} }

View File

@ -21,10 +21,14 @@ package org.kiwix.kiwixmobile.core.base
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.enableEdgeToEdgeMode
import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon
import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription
@ -46,7 +50,17 @@ abstract class BaseFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
enableEdgeToEdgeMode()
setupToolbar() setupToolbar()
this.view?.let {
ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val layoutParams = view.layoutParams as? ViewGroup.MarginLayoutParams
layoutParams?.topMargin = insets.top
view.layoutParams = layoutParams
WindowInsetsCompat.CONSUMED
}
}
} }
// Setup toolbar to handle common back pressed event // Setup toolbar to handle common back pressed event

View File

@ -29,6 +29,8 @@ import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.WindowInsetsController
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
@ -199,4 +201,21 @@ object ActivityExtensions {
val isWideEnough = configuration.smallestScreenWidthDp >= 600 val isWideEnough = configuration.smallestScreenWidthDp >= 600
return isLargeOrXLarge && isWideEnough return isLargeOrXLarge && isWideEnough
} }
/**
* This method is for setting the statusBar color for Android 15 and above.
* Since in Android 15 the setStatusBarColor method is deprecated and not works anymore.
*/
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
fun Activity.changeStatusBarAndNavigationBarColorInAndroid15AndAbove() {
window?.apply {
// Set the white color to icon since the statusBar color is black.
decorView.windowInsetsController?.setSystemBarsAppearance(
0,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
insetsController?.hide(android.view.WindowInsets.Type.statusBars())
insetsController?.show(android.view.WindowInsets.Type.statusBars())
}
}
} }

View File

@ -19,10 +19,12 @@
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
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
@ -55,3 +57,12 @@ fun View.closeKeyboard() {
} }
val Fragment.coreMainActivity get() = activity as CoreMainActivity val Fragment.coreMainActivity get() = activity as CoreMainActivity
fun Fragment.enableEdgeToEdgeMode() {
activity?.window?.let {
WindowCompat.setDecorFitsSystemWindows(
it,
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
)
}
}

View File

@ -4,5 +4,4 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"
android:fitsSystemWindows="true"
android:focusable="true" /> android:focusable="true" />

View File

@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".help.HelpFragment"> tools:context=".help.HelpFragment">
<include layout="@layout/layout_standard_app_bar" /> <include layout="@layout/layout_standard_app_bar" />

View File

@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar" android:id="@+id/app_bar"

View File

@ -20,8 +20,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_fragment_main_drawer_layout" android:id="@+id/navigation_fragment_main_drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -4,7 +4,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout

View File

@ -24,7 +24,6 @@
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true"
tools:ignore="ContentDescription" tools:ignore="ContentDescription"
android:src="@drawable/ic_home_kiwix_banner" /> android:src="@drawable/ic_home_kiwix_banner" />
</LinearLayout> </LinearLayout>

View File

@ -26,8 +26,7 @@
<org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout <org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<FrameLayout <FrameLayout
android:id="@+id/activity_main_content_frame" android:id="@+id/activity_main_content_frame"

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -2,8 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/tab_switcher_recycler_view" android:id="@+id/tab_switcher_recycler_view"

View File

@ -82,7 +82,6 @@
</style> </style>
<style name="Base.MaterialThemeBuilder" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <style name="Base.MaterialThemeBuilder" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor" tools:ignore="NewApi">@color/black</item> <item name="android:statusBarColor" tools:ignore="NewApi">@color/black</item>
<item name="actionModeBackground">@color/cornflower_blue</item> <item name="actionModeBackground">@color/cornflower_blue</item>
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>

View File

@ -22,7 +22,6 @@
android:id="@+id/custom_drawer_container" android:id="@+id/custom_drawer_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:ignore="UnusedIds"> tools:ignore="UnusedIds">
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
@ -38,7 +37,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_main" app:headerLayout="@layout/nav_main"
app:menu="@menu/menu_drawer_main" /> app:menu="@menu/menu_drawer_main" />
@ -48,6 +46,5 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_right" /> app:headerLayout="@layout/drawer_right" />
</androidx.drawerlayout.widget.DrawerLayout> </androidx.drawerlayout.widget.DrawerLayout>