mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 23:07:26 -04:00
Changed navigation to a Compose-based architecture using named routes instead of fragment IDs, and refactored all related code for both Kiwix and custom apps.
This commit is contained in:
parent
86d9b1266f
commit
a3d6ea49f9
@ -18,10 +18,8 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.main
|
package org.kiwix.kiwixmobile.main
|
||||||
|
|
||||||
import androidx.annotation.IdRes
|
|
||||||
|
|
||||||
data class BottomNavItem(
|
data class BottomNavItem(
|
||||||
@IdRes val id: Int,
|
val route: String,
|
||||||
val title: String,
|
val title: String,
|
||||||
val iconRes: Int
|
val iconRes: Int
|
||||||
)
|
)
|
||||||
|
@ -61,6 +61,7 @@ import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
||||||
|
import org.kiwix.kiwixmobile.ui.KiwixDestination
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
const val ACTION_GET_CONTENT = "GET_CONTENT"
|
const val ACTION_GET_CONTENT = "GET_CONTENT"
|
||||||
@ -71,7 +72,7 @@ const val KIWIX_BOTTOM_BAR_ANIMATION_DURATION = 250L
|
|||||||
class KiwixMainActivity : CoreMainActivity() {
|
class KiwixMainActivity : CoreMainActivity() {
|
||||||
private var actionMode: ActionMode? = null
|
private var actionMode: ActionMode? = null
|
||||||
override val cachedComponent by lazy { kiwixActivityComponent }
|
override val cachedComponent by lazy { kiwixActivityComponent }
|
||||||
override val searchFragmentResId: Int = R.id.searchFragment
|
override val searchFragmentRoute: String = KiwixDestination.Search.route
|
||||||
|
|
||||||
// override val drawerContainerLayout: DrawerLayout by lazy {
|
// override val drawerContainerLayout: DrawerLayout by lazy {
|
||||||
// // activityKiwixMainBinding.navigationContainer
|
// // activityKiwixMainBinding.navigationContainer
|
||||||
@ -90,12 +91,12 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
override val mainActivity: AppCompatActivity by lazy { this }
|
override val mainActivity: AppCompatActivity by lazy { this }
|
||||||
override val appName: String by lazy { getString(R.string.app_name) }
|
override val appName: String by lazy { getString(R.string.app_name) }
|
||||||
|
|
||||||
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
|
override val bookmarksFragmentRoute: String = KiwixDestination.Bookmarks.route
|
||||||
override val settingsFragmentResId: Int = R.id.kiwixSettingsFragment
|
override val settingsFragmentRoute: String = KiwixDestination.Settings.route
|
||||||
override val historyFragmentResId: Int = R.id.historyFragment
|
override val historyFragmentRoute: String = KiwixDestination.History.route
|
||||||
override val notesFragmentResId: Int = R.id.notesFragment
|
override val notesFragmentRoute: String = KiwixDestination.Notes.route
|
||||||
override val readerFragmentResId: Int = R.id.readerFragment
|
override val readerFragmentRoute: String = KiwixDestination.Reader.route
|
||||||
override val helpFragmentResId: Int = R.id.helpFragment
|
override val helpFragmentRoute: String = KiwixDestination.Help.route
|
||||||
override val topLevelDestinations =
|
override val topLevelDestinations =
|
||||||
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)
|
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)
|
||||||
private val isBottomBarVisible = mutableStateOf(true)
|
private val isBottomBarVisible = mutableStateOf(true)
|
||||||
@ -117,9 +118,8 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
navController = rememberNavController()
|
navController = rememberNavController()
|
||||||
KiwixMainActivityScreen(
|
KiwixMainActivityScreen(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
topLevelDestinations = topLevelDestinations.toList(),
|
|
||||||
isBottomBarVisible = isBottomBarVisible.value,
|
isBottomBarVisible = isBottomBarVisible.value,
|
||||||
leftDrawerContent = rightNavigationDrawerMenuItems,
|
leftDrawerContent = leftNavigationDrawerMenuItems,
|
||||||
rightDrawerContent = { }
|
rightDrawerContent = { }
|
||||||
)
|
)
|
||||||
LaunchedEffect(navController) {
|
LaunchedEffect(navController) {
|
||||||
@ -365,7 +365,7 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
|
|
||||||
private fun openZimHostFragment() {
|
private fun openZimHostFragment() {
|
||||||
disableDrawer()
|
disableDrawer()
|
||||||
navigate(R.id.zimHostFragment)
|
navigate(KiwixDestination.ZimHost.route)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getIconResId() = mipmap.ic_launcher
|
override fun getIconResId() = mipmap.ic_launcher
|
||||||
|
@ -47,19 +47,20 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import org.kiwix.kiwixmobile.R.drawable
|
import org.kiwix.kiwixmobile.R.drawable
|
||||||
import org.kiwix.kiwixmobile.R.id
|
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
import org.kiwix.kiwixmobile.core.main.DrawerMenuGroup
|
import org.kiwix.kiwixmobile.core.main.DrawerMenuGroup
|
||||||
import org.kiwix.kiwixmobile.core.main.LeftDrawerMenu
|
import org.kiwix.kiwixmobile.core.main.LeftDrawerMenu
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.theme.Black
|
||||||
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
|
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.theme.White
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.NAVIGATION_DRAWER_WIDTH
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.NAVIGATION_DRAWER_WIDTH
|
||||||
|
import org.kiwix.kiwixmobile.ui.KiwixDestination
|
||||||
import org.kiwix.kiwixmobile.ui.KiwixNavGraph
|
import org.kiwix.kiwixmobile.ui.KiwixNavGraph
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun KiwixMainActivityScreen(
|
fun KiwixMainActivityScreen(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
topLevelDestinations: List<Int>,
|
|
||||||
leftDrawerContent: List<DrawerMenuGroup>,
|
leftDrawerContent: List<DrawerMenuGroup>,
|
||||||
rightDrawerContent: @Composable ColumnScope.() -> Unit,
|
rightDrawerContent: @Composable ColumnScope.() -> Unit,
|
||||||
isBottomBarVisible: Boolean = true
|
isBottomBarVisible: Boolean = true
|
||||||
@ -70,26 +71,20 @@ fun KiwixMainActivityScreen(
|
|||||||
KiwixTheme {
|
KiwixTheme {
|
||||||
ModalNavigationDrawer(
|
ModalNavigationDrawer(
|
||||||
drawerContent = {
|
drawerContent = {
|
||||||
Column(
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
Modifier
|
|
||||||
.fillMaxHeight()
|
|
||||||
.width(NAVIGATION_DRAWER_WIDTH)
|
|
||||||
) {
|
|
||||||
LeftDrawerMenu(leftDrawerContent)
|
LeftDrawerMenu(leftDrawerContent)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
gesturesEnabled = true
|
|
||||||
) {
|
) {
|
||||||
Box {
|
Box {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
if (isBottomBarVisible) {
|
// if (isBottomBarVisible) {
|
||||||
BottomNavigationBar(
|
BottomNavigationBar(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
scrollBehavior = scrollingBehavior,
|
scrollBehavior = scrollingBehavior
|
||||||
topLevelDestinations = topLevelDestinations
|
)
|
||||||
)
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Box(modifier = Modifier.padding(paddingValues)) {
|
Box(modifier = Modifier.padding(paddingValues)) {
|
||||||
@ -119,45 +114,45 @@ fun KiwixMainActivityScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
fun BottomNavigationBar(
|
fun BottomNavigationBar(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
scrollBehavior: BottomAppBarScrollBehavior,
|
scrollBehavior: BottomAppBarScrollBehavior
|
||||||
topLevelDestinations: List<Int>
|
|
||||||
) {
|
) {
|
||||||
val bottomNavItems = listOf(
|
val bottomNavItems = listOf(
|
||||||
BottomNavItem(
|
BottomNavItem(
|
||||||
id = id.readerFragment,
|
route = KiwixDestination.Reader.route,
|
||||||
title = stringResource(id = R.string.reader),
|
title = stringResource(id = R.string.reader),
|
||||||
iconRes = drawable.ic_reader_navigation_white_24px
|
iconRes = drawable.ic_reader_navigation_white_24px
|
||||||
),
|
),
|
||||||
BottomNavItem(
|
BottomNavItem(
|
||||||
id = id.libraryFragment,
|
route = KiwixDestination.Library.route,
|
||||||
title = stringResource(id = R.string.library),
|
title = stringResource(id = R.string.library),
|
||||||
iconRes = drawable.ic_library_navigation_white_24dp
|
iconRes = drawable.ic_library_navigation_white_24dp
|
||||||
),
|
),
|
||||||
BottomNavItem(
|
BottomNavItem(
|
||||||
id = id.downloadsFragment,
|
route = KiwixDestination.Downloads.route,
|
||||||
title = stringResource(id = R.string.download),
|
title = stringResource(id = R.string.download),
|
||||||
iconRes = drawable.ic_download_navigation_white_24dp
|
iconRes = drawable.ic_download_navigation_white_24dp
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
val currentDestinationId = navBackStackEntry?.destination?.id
|
val currentDestinationRoute = navBackStackEntry?.destination?.route
|
||||||
|
BottomAppBar(
|
||||||
if (currentDestinationId in topLevelDestinations) {
|
containerColor = Black,
|
||||||
BottomAppBar(scrollBehavior = scrollBehavior) {
|
contentColor = White,
|
||||||
bottomNavItems.forEach { item ->
|
scrollBehavior = scrollBehavior
|
||||||
NavigationBarItem(
|
) {
|
||||||
selected = currentDestinationId == item.id,
|
bottomNavItems.forEach { item ->
|
||||||
onClick = { navController.navigate(item.id) },
|
NavigationBarItem(
|
||||||
icon = {
|
selected = currentDestinationRoute == item.route,
|
||||||
Icon(
|
onClick = { navController.navigate(item.route) },
|
||||||
painter = painterResource(id = item.iconRes),
|
icon = {
|
||||||
contentDescription = item.title
|
Icon(
|
||||||
)
|
painter = painterResource(id = item.iconRes),
|
||||||
},
|
contentDescription = item.title
|
||||||
label = { Text(item.title) }
|
)
|
||||||
)
|
},
|
||||||
}
|
label = { Text(item.title) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,10 @@ fun KiwixNavGraph(
|
|||||||
) {
|
) {
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = "readerFragment",
|
startDestination = KiwixDestination.Reader.route,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
) {
|
) {
|
||||||
composable("readerFragment") {
|
composable(KiwixDestination.Reader.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
KiwixReaderFragment().apply {
|
KiwixReaderFragment().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
@ -71,7 +71,7 @@ fun KiwixNavGraph(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("libraryFragment") {
|
composable(KiwixDestination.Library.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
LocalLibraryFragment().apply {
|
LocalLibraryFragment().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
@ -80,57 +80,57 @@ fun KiwixNavGraph(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("downloadsFragment") {
|
composable(KiwixDestination.Downloads.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
OnlineLibraryFragment()
|
OnlineLibraryFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("bookmarksFragment") {
|
composable(KiwixDestination.Bookmarks.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
BookmarksFragment()
|
BookmarksFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("notesFragment") {
|
composable(KiwixDestination.Notes.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
NotesFragment()
|
NotesFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("introFragment") {
|
composable(KiwixDestination.Intro.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
IntroFragment()
|
IntroFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("historyFragment") {
|
composable(KiwixDestination.History.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
HistoryFragment()
|
HistoryFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("languageFragment") {
|
composable(KiwixDestination.Language.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
LanguageFragment()
|
LanguageFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("zimHostFragment") {
|
composable(KiwixDestination.ZimHost.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
ZimHostFragment()
|
ZimHostFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("helpFragment") {
|
composable(KiwixDestination.Help.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
KiwixHelpFragment()
|
KiwixHelpFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("kiwixSettingsFragment") {
|
composable(KiwixDestination.Settings.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
KiwixSettingsFragment()
|
KiwixSettingsFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("searchFragment") {
|
composable(KiwixDestination.Search.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
SearchFragment()
|
SearchFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable("localFileTransferFragment") {
|
composable(KiwixDestination.LocalFileTransfer.route) {
|
||||||
FragmentContainer {
|
FragmentContainer {
|
||||||
LocalFileTransferFragment().apply {
|
LocalFileTransferFragment().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
@ -168,3 +168,19 @@ fun FragmentContainer(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class KiwixDestination(val route: String) {
|
||||||
|
object Reader : KiwixDestination("readerFragment")
|
||||||
|
object Library : KiwixDestination("libraryFragment")
|
||||||
|
object Downloads : KiwixDestination("downloadsFragment")
|
||||||
|
object Bookmarks : KiwixDestination("bookmarksFragment")
|
||||||
|
object Notes : KiwixDestination("notesFragment")
|
||||||
|
object Intro : KiwixDestination("introFragment")
|
||||||
|
object History : KiwixDestination("historyFragment")
|
||||||
|
object Language : KiwixDestination("languageFragment")
|
||||||
|
object ZimHost : KiwixDestination("zimHostFragment")
|
||||||
|
object Help : KiwixDestination("helpFragment")
|
||||||
|
object Settings : KiwixDestination("kiwixSettingsFragment")
|
||||||
|
object Search : KiwixDestination("searchFragment")
|
||||||
|
object LocalFileTransfer : KiwixDestination("localFileTransferFragment")
|
||||||
|
}
|
||||||
|
@ -75,7 +75,7 @@ const val ACTION_NEW_TAB = "NEW_TAB"
|
|||||||
const val NEW_TAB_SHORTCUT_ID = "new_tab_shortcut"
|
const val NEW_TAB_SHORTCUT_ID = "new_tab_shortcut"
|
||||||
|
|
||||||
abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||||
abstract val searchFragmentResId: Int
|
abstract val searchFragmentRoute: String
|
||||||
|
|
||||||
@Inject lateinit var alertDialogShower: AlertDialogShower
|
@Inject lateinit var alertDialogShower: AlertDialogShower
|
||||||
|
|
||||||
@ -95,11 +95,11 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
// abstract val drawerContainerLayout: DrawerLayout
|
// abstract val drawerContainerLayout: DrawerLayout
|
||||||
// abstract val drawerNavView: NavigationView
|
// abstract val drawerNavView: NavigationView
|
||||||
// abstract val readerTableOfContentsDrawer: NavigationView
|
// abstract val readerTableOfContentsDrawer: NavigationView
|
||||||
abstract val bookmarksFragmentResId: Int
|
abstract val bookmarksFragmentRoute: String
|
||||||
abstract val settingsFragmentResId: Int
|
abstract val settingsFragmentRoute: String
|
||||||
abstract val historyFragmentResId: Int
|
abstract val historyFragmentRoute: String
|
||||||
abstract val notesFragmentResId: Int
|
abstract val notesFragmentRoute: String
|
||||||
abstract val helpFragmentResId: Int
|
abstract val helpFragmentRoute: String
|
||||||
abstract val cachedComponent: CoreActivityComponent
|
abstract val cachedComponent: CoreActivityComponent
|
||||||
abstract val topLevelDestinations: Set<Int>
|
abstract val topLevelDestinations: Set<Int>
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun openHelpFragment() {
|
protected fun openHelpFragment() {
|
||||||
navigate(helpFragmentResId)
|
navigate(helpFragmentRoute)
|
||||||
handleDrawerOnNavigation()
|
handleDrawerOnNavigation()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,9 +362,9 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
}
|
}
|
||||||
activeFragments().filterIsInstance<FragmentActivityExtensions>().forEach {
|
activeFragments().filterIsInstance<FragmentActivityExtensions>().forEach {
|
||||||
if (it.onBackPressed(this@CoreMainActivity) == ShouldCall) {
|
if (it.onBackPressed(this@CoreMainActivity) == ShouldCall) {
|
||||||
if (navController.currentDestination?.id?.equals(readerFragmentResId) == true &&
|
if (navController.currentDestination?.route?.equals(readerFragmentRoute) == true &&
|
||||||
navController.previousBackStackEntry?.destination
|
navController.previousBackStackEntry?.destination
|
||||||
?.id?.equals(searchFragmentResId) == false
|
?.route?.equals(searchFragmentRoute) == false
|
||||||
) {
|
) {
|
||||||
drawerToggle = null
|
drawerToggle = null
|
||||||
finish()
|
finish()
|
||||||
@ -400,8 +400,8 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun navigate(fragmentId: Int) {
|
fun navigate(route: String) {
|
||||||
navController.navigate(fragmentId)
|
navController.navigate(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun navigate(fragmentId: Int, bundle: Bundle) {
|
fun navigate(fragmentId: Int, bundle: Bundle) {
|
||||||
@ -414,11 +414,11 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
|
|
||||||
private fun openSettings() {
|
private fun openSettings() {
|
||||||
handleDrawerOnNavigation()
|
handleDrawerOnNavigation()
|
||||||
navigate(settingsFragmentResId)
|
navigate(settingsFragmentRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openHistory() {
|
private fun openHistory() {
|
||||||
navigate(historyFragmentResId)
|
navigate(historyFragmentRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openSearch(
|
fun openSearch(
|
||||||
@ -426,23 +426,23 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
isOpenedFromTabView: Boolean = false,
|
isOpenedFromTabView: Boolean = false,
|
||||||
isVoice: Boolean = false
|
isVoice: Boolean = false
|
||||||
) {
|
) {
|
||||||
navigate(
|
// navigate(
|
||||||
searchFragmentResId,
|
// searchFragmentRoute,
|
||||||
bundleOf(
|
// bundleOf(
|
||||||
NAV_ARG_SEARCH_STRING to searchString,
|
// NAV_ARG_SEARCH_STRING to searchString,
|
||||||
TAG_FROM_TAB_SWITCHER to isOpenedFromTabView,
|
// TAG_FROM_TAB_SWITCHER to isOpenedFromTabView,
|
||||||
EXTRA_IS_WIDGET_VOICE to isVoice
|
// EXTRA_IS_WIDGET_VOICE to isVoice
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openZimFromFilePath(path: String) {
|
fun openZimFromFilePath(path: String) {
|
||||||
navigate(
|
// navigate(
|
||||||
readerFragmentResId,
|
// readerFragmentRoute,
|
||||||
bundleOf(
|
// bundleOf(
|
||||||
ZIM_FILE_URI_KEY to path,
|
// ZIM_FILE_URI_KEY to path,
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openPage(
|
fun openPage(
|
||||||
@ -456,26 +456,26 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
}
|
}
|
||||||
val navOptions = NavOptions.Builder()
|
val navOptions = NavOptions.Builder()
|
||||||
.setLaunchSingleTop(true)
|
.setLaunchSingleTop(true)
|
||||||
.setPopUpTo(readerFragmentResId, inclusive = true)
|
.setPopUpTo(readerFragmentRoute, inclusive = true)
|
||||||
.build()
|
.build()
|
||||||
navigate(
|
// navigate(
|
||||||
readerFragmentResId,
|
// readerFragmentRoute,
|
||||||
bundleOf(
|
// bundleOf(
|
||||||
PAGE_URL_KEY to pageUrl,
|
// PAGE_URL_KEY to pageUrl,
|
||||||
ZIM_FILE_URI_KEY to zimFileUri,
|
// ZIM_FILE_URI_KEY to zimFileUri,
|
||||||
SHOULD_OPEN_IN_NEW_TAB to shouldOpenInNewTab
|
// SHOULD_OPEN_IN_NEW_TAB to shouldOpenInNewTab
|
||||||
),
|
// ),
|
||||||
navOptions
|
// navOptions
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openBookmarks() {
|
private fun openBookmarks() {
|
||||||
navigate(bookmarksFragmentResId)
|
navigate(bookmarksFragmentRoute)
|
||||||
handleDrawerOnNavigation()
|
handleDrawerOnNavigation()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openNotes() {
|
private fun openNotes() {
|
||||||
navigate(notesFragmentResId)
|
navigate(notesFragmentRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun handleDrawerOnNavigation() {
|
protected fun handleDrawerOnNavigation() {
|
||||||
@ -488,51 +488,57 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun findInPage(searchString: String) {
|
fun findInPage(searchString: String) {
|
||||||
navigate(readerFragmentResId, bundleOf(FIND_IN_PAGE_SEARCH_STRING to searchString))
|
// navigate(readerFragmentRoute, bundleOf(FIND_IN_PAGE_SEARCH_STRING to searchString))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val bookRelatedDrawerGroup = DrawerMenuGroup(
|
private val bookRelatedDrawerGroup by lazy {
|
||||||
listOfNotNull(
|
DrawerMenuGroup(
|
||||||
DrawerMenuItem(
|
listOfNotNull(
|
||||||
title = CoreApp.instance.getString(R.string.bookmarks),
|
DrawerMenuItem(
|
||||||
iconRes = R.drawable.ic_bookmark_black_24dp,
|
title = CoreApp.instance.getString(R.string.bookmarks),
|
||||||
true,
|
iconRes = R.drawable.ic_bookmark_black_24dp,
|
||||||
onClick = { openBookmarks() }
|
true,
|
||||||
),
|
onClick = { openBookmarks() }
|
||||||
DrawerMenuItem(
|
),
|
||||||
title = CoreApp.instance.getString(R.string.history),
|
DrawerMenuItem(
|
||||||
iconRes = R.drawable.ic_history_24px,
|
title = CoreApp.instance.getString(R.string.history),
|
||||||
true,
|
iconRes = R.drawable.ic_history_24px,
|
||||||
onClick = { openHistory() }
|
true,
|
||||||
),
|
onClick = { openHistory() }
|
||||||
DrawerMenuItem(
|
),
|
||||||
title = CoreApp.instance.getString(R.string.pref_notes),
|
DrawerMenuItem(
|
||||||
iconRes = R.drawable.ic_add_note,
|
title = CoreApp.instance.getString(R.string.pref_notes),
|
||||||
true,
|
iconRes = R.drawable.ic_add_note,
|
||||||
onClick = { openNotes() }
|
true,
|
||||||
),
|
onClick = { openNotes() }
|
||||||
zimHostDrawerMenuItem
|
),
|
||||||
)
|
zimHostDrawerMenuItem
|
||||||
)
|
|
||||||
|
|
||||||
private val settingDrawerGroup = DrawerMenuGroup(
|
|
||||||
listOf(
|
|
||||||
DrawerMenuItem(
|
|
||||||
title = CoreApp.instance.getString(R.string.menu_settings),
|
|
||||||
iconRes = R.drawable.ic_settings_24px,
|
|
||||||
true,
|
|
||||||
onClick = { openSettings() }
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
|
||||||
open val helpAndSupportDrawerGroup = DrawerMenuGroup(
|
private val settingDrawerGroup by lazy {
|
||||||
listOfNotNull(
|
DrawerMenuGroup(
|
||||||
helpDrawerMenuItem,
|
listOf(
|
||||||
supportDrawerMenuItem,
|
DrawerMenuItem(
|
||||||
aboutAppDrawerMenuItem
|
title = CoreApp.instance.getString(R.string.menu_settings),
|
||||||
|
iconRes = R.drawable.ic_settings_24px,
|
||||||
|
true,
|
||||||
|
onClick = { openSettings() }
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
|
||||||
|
private val helpAndSupportDrawerGroup by lazy {
|
||||||
|
DrawerMenuGroup(
|
||||||
|
listOfNotNull(
|
||||||
|
helpDrawerMenuItem,
|
||||||
|
supportDrawerMenuItem,
|
||||||
|
aboutAppDrawerMenuItem
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "Wi-Fi Hotspot" menu item in the left drawer.
|
* Returns the "Wi-Fi Hotspot" menu item in the left drawer.
|
||||||
@ -563,14 +569,16 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
*/
|
*/
|
||||||
abstract val aboutAppDrawerMenuItem: DrawerMenuItem?
|
abstract val aboutAppDrawerMenuItem: DrawerMenuItem?
|
||||||
|
|
||||||
val rightNavigationDrawerMenuItems = listOf<DrawerMenuGroup>(
|
val leftNavigationDrawerMenuItems by lazy {
|
||||||
bookRelatedDrawerGroup,
|
listOf<DrawerMenuGroup>(
|
||||||
settingDrawerGroup,
|
bookRelatedDrawerGroup,
|
||||||
helpAndSupportDrawerGroup
|
settingDrawerGroup,
|
||||||
)
|
helpAndSupportDrawerGroup
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun getIconResId(): Int
|
protected abstract fun getIconResId(): Int
|
||||||
abstract val readerFragmentResId: Int
|
abstract val readerFragmentRoute: String
|
||||||
abstract fun createApplicationShortcuts()
|
abstract fun createApplicationShortcuts()
|
||||||
abstract fun setDialogHostToActivity(alertDialogShower: AlertDialogShower)
|
abstract fun setDialogHostToActivity(alertDialogShower: AlertDialogShower)
|
||||||
|
|
||||||
|
@ -20,10 +20,13 @@ package org.kiwix.kiwixmobile.core.main
|
|||||||
|
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.statusBarsPadding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.material3.ListItem
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
@ -33,8 +36,11 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.components.ONE
|
||||||
import org.kiwix.kiwixmobile.core.ui.models.IconItem
|
import org.kiwix.kiwixmobile.core.ui.models.IconItem
|
||||||
import org.kiwix.kiwixmobile.core.ui.models.toPainter
|
import org.kiwix.kiwixmobile.core.ui.models.toPainter
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray350
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray600
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.NAVIGATION_DRAWER_WIDTH
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.NAVIGATION_DRAWER_WIDTH
|
||||||
|
|
||||||
@ -43,7 +49,8 @@ fun LeftDrawerMenu(drawerMenuGroupList: List<DrawerMenuGroup>) {
|
|||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(NAVIGATION_DRAWER_WIDTH)
|
.width(NAVIGATION_DRAWER_WIDTH)
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight()
|
||||||
|
.statusBarsPadding(),
|
||||||
shadowElevation = EIGHT_DP
|
shadowElevation = EIGHT_DP
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
@ -64,9 +71,22 @@ fun LeftDrawerMenu(drawerMenuGroupList: List<DrawerMenuGroup>) {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun DrawerGroup(items: List<DrawerMenuItem>) {
|
private fun DrawerGroup(items: List<DrawerMenuItem>) {
|
||||||
Column {
|
Column {
|
||||||
items.filter { it.visible }.forEach { item ->
|
// Add a horizontal divider at end if there are items in a group.
|
||||||
|
val dividerColor = if (isSystemInDarkTheme()) {
|
||||||
|
MineShaftGray600
|
||||||
|
} else {
|
||||||
|
MineShaftGray350
|
||||||
|
}
|
||||||
|
val visibleMenuItems = items.filter { it.visible }
|
||||||
|
if (visibleMenuItems.size == ONE) {
|
||||||
|
HorizontalDivider(color = dividerColor)
|
||||||
|
}
|
||||||
|
visibleMenuItems.forEach { item ->
|
||||||
DrawerMenuItemView(item)
|
DrawerMenuItemView(item)
|
||||||
}
|
}
|
||||||
|
if (visibleMenuItems.size == ONE) {
|
||||||
|
HorizontalDivider(color = dividerColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +104,6 @@ private fun DrawerMenuItemView(item: DrawerMenuItem) {
|
|||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { item.onClick }
|
.clickable { item.onClick.invoke() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1535,7 +1535,7 @@ abstract class CoreReaderFragment :
|
|||||||
|
|
||||||
private fun goToBookmarks(): Boolean {
|
private fun goToBookmarks(): Boolean {
|
||||||
val parentActivity = requireActivity() as CoreMainActivity
|
val parentActivity = requireActivity() as CoreMainActivity
|
||||||
parentActivity.navigate(parentActivity.bookmarksFragmentResId)
|
parentActivity.navigate(parentActivity.bookmarksFragmentRoute)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,8 +225,8 @@ class SearchFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun goBack() {
|
private fun goBack() {
|
||||||
val readerFragmentResId = (activity as CoreMainActivity).readerFragmentResId
|
val readerFragmentRoute = (activity as CoreMainActivity).readerFragmentRoute
|
||||||
findNavController().popBackStack(readerFragmentResId, false)
|
findNavController().popBackStack(readerFragmentRoute, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSearchListItemForQuery(query: String): SearchListItem? =
|
private fun getSearchListItemForQuery(query: String): SearchListItem? =
|
||||||
|
@ -35,11 +35,12 @@ data class OpenSearchItem(
|
|||||||
private val openInNewTab: Boolean = false
|
private val openInNewTab: Boolean = false
|
||||||
) : SideEffect<Unit> {
|
) : SideEffect<Unit> {
|
||||||
override fun invokeWith(activity: AppCompatActivity) {
|
override fun invokeWith(activity: AppCompatActivity) {
|
||||||
val readerFragmentResId = (activity as CoreMainActivity).readerFragmentResId
|
val readerFragmentRoute = (activity as CoreMainActivity).readerFragmentRoute
|
||||||
activity.navigate(
|
// TODO fix this when properly migrated to compose navigation.
|
||||||
readerFragmentResId,
|
// activity.navigate(
|
||||||
bundleOf(SEARCH_ITEM_TITLE_KEY to SEARCH_ITEM_TITLE_KEY)
|
// readerFragmentRoute,
|
||||||
)
|
// bundleOf(SEARCH_ITEM_TITLE_KEY to SEARCH_ITEM_TITLE_KEY)
|
||||||
|
// )
|
||||||
activity.setNavigationResultOnCurrent(
|
activity.setNavigationResultOnCurrent(
|
||||||
SearchItemToOpen(
|
SearchItemToOpen(
|
||||||
searchListItem.value,
|
searchListItem.value,
|
||||||
|
@ -187,7 +187,7 @@ abstract class CoreSettingsFragment : SettingsContract.View, BaseFragment() {
|
|||||||
(activity as CoreMainActivity?)?.let {
|
(activity as CoreMainActivity?)?.let {
|
||||||
it.navController.apply {
|
it.navController.apply {
|
||||||
popBackStack()
|
popBackStack()
|
||||||
navigate(it.settingsFragmentResId)
|
navigate(it.settingsFragmentRoute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user