diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index f052e8c3e..4b85c045b 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -24,22 +24,19 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.MenuItem +import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode +import androidx.compose.runtime.mutableStateOf import androidx.core.content.pm.ShortcutInfoCompat import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.graphics.drawable.IconCompat import androidx.core.os.ConfigurationCompat import androidx.core.os.bundleOf -import androidx.core.view.isVisible -import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.NavDestination import androidx.navigation.fragment.NavHostFragment -import androidx.navigation.ui.NavigationUI -import androidx.navigation.ui.setupWithNavController -import com.google.android.material.navigation.NavigationView import eu.mhutti1.utils.storage.StorageDevice import eu.mhutti1.utils.storage.StorageDeviceUtils import kotlinx.coroutines.delay @@ -53,9 +50,6 @@ import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions import org.kiwix.kiwixmobile.core.dao.LibkiwixBookOnDisk import org.kiwix.kiwixmobile.core.downloader.downloadManager.DOWNLOAD_NOTIFICATION_TITLE -import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO -import org.kiwix.kiwixmobile.core.extensions.applyEdgeToEdgeInsets -import org.kiwix.kiwixmobile.core.extensions.getDialogHostComposeView import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB import org.kiwix.kiwixmobile.core.main.CoreMainActivity @@ -63,9 +57,7 @@ import org.kiwix.kiwixmobile.core.main.NEW_TAB_SHORTCUT_ID 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.dialog.AlertDialogShower -import org.kiwix.kiwixmobile.databinding.ActivityKiwixMainBinding import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragmentDirections import javax.inject.Inject const val ACTION_GET_CONTENT = "GET_CONTENT" @@ -77,27 +69,23 @@ class KiwixMainActivity : CoreMainActivity() { private var actionMode: ActionMode? = null override val cachedComponent by lazy { kiwixActivityComponent } override val searchFragmentResId: Int = R.id.searchFragment - override val navController by lazy { - ( - supportFragmentManager.findFragmentById(R.id.nav_host_fragment) - as NavHostFragment - ).navController - } - override val drawerContainerLayout: DrawerLayout by lazy { - activityKiwixMainBinding.navigationContainer - } + // override val drawerContainerLayout: DrawerLayout by lazy { + // // activityKiwixMainBinding.navigationContainer + // } - override val drawerNavView: NavigationView by lazy { - activityKiwixMainBinding.drawerNavView - } + // override val drawerNavView: NavigationView by lazy { + // activityKiwixMainBinding.drawerNavView + // } - override val readerTableOfContentsDrawer: NavigationView by lazy { - activityKiwixMainBinding.readerDrawerNavView - } + // override val readerTableOfContentsDrawer: NavigationView by lazy { + // activityKiwixMainBinding.readerDrawerNavView + // } - override val navHostContainer by lazy { - activityKiwixMainBinding.navHostFragment + override val navController: NavController by lazy { + val fragment = supportFragmentManager.findFragmentById(id.nav_host_fragment) + val navHostFragment = requireNotNull(fragment) as NavHostFragment + return@lazy navHostFragment.navController } @Inject lateinit var libkiwixBookOnDisk: LibkiwixBookOnDisk @@ -113,8 +101,9 @@ class KiwixMainActivity : CoreMainActivity() { override val helpFragmentResId: Int = R.id.helpFragment override val topLevelDestinations = setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment) + private val isBottomBarVisible = mutableStateOf(true) - private lateinit var activityKiwixMainBinding: ActivityKiwixMainBinding + // private lateinit var activityKiwixMainBinding: ActivityKiwixMainBinding private var isIntroScreenVisible: Boolean = false @@ -127,25 +116,31 @@ class KiwixMainActivity : CoreMainActivity() { override fun onCreate(savedInstanceState: Bundle?) { cachedComponent.inject(this) super.onCreate(savedInstanceState) - activityKiwixMainBinding = ActivityKiwixMainBinding.inflate(layoutInflater) - setContentView(activityKiwixMainBinding.root) - - navController.addOnDestinationChangedListener(finishActionModeOnDestinationChange) - activityKiwixMainBinding.drawerNavView.apply { - setupWithNavController(navController) - setNavigationItemSelectedListener { item -> - closeNavigationDrawer() - onNavigationItemSelected(item) - } + setContent { + KiwixMainActivityScreen( + navController = navController, + topLevelDestinations = topLevelDestinations.toList(), + isBottomBarVisible = isBottomBarVisible.value, + leftDrawerContent = { }, + rightDrawerContent = { } + ) } - activityKiwixMainBinding.bottomNavView.setupWithNavController(navController) + navController.addOnDestinationChangedListener(finishActionModeOnDestinationChange) + // activityKiwixMainBinding.drawerNavView.apply { + // setupWithNavController(navController) + // setNavigationItemSelectedListener { item -> + // closeNavigationDrawer() + // onNavigationItemSelected(item) + // } + // } + // activityKiwixMainBinding.bottomNavView.setupWithNavController(navController) lifecycleScope.launch { migrateInternalToPublicAppDirectory() } handleZimFileIntent(intent) handleNotificationIntent(intent) handleGetContentIntent(intent) - activityKiwixMainBinding.root.applyEdgeToEdgeInsets() + // activityKiwixMainBinding.root.applyEdgeToEdgeInsets() } private suspend fun migrateInternalToPublicAppDirectory() { @@ -180,46 +175,46 @@ class KiwixMainActivity : CoreMainActivity() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) - if (::activityKiwixMainBinding.isInitialized) { - activityKiwixMainBinding.bottomNavView.menu.apply { - findItem(R.id.readerFragment)?.title = resources.getString(string.reader) - findItem(R.id.libraryFragment)?.title = resources.getString(string.library) - findItem(R.id.downloadsFragment)?.title = resources.getString(string.download) - } - activityKiwixMainBinding.drawerNavView.menu.apply { - findItem(org.kiwix.kiwixmobile.core.R.id.menu_bookmarks_list)?.title = - resources.getString(string.bookmarks) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_history)?.title = - resources.getString(string.history) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_notes)?.title = - resources.getString(string.pref_notes) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_host_books)?.title = - resources.getString(string.menu_wifi_hotspot) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_settings)?.title = - resources.getString(string.menu_settings) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_help)?.title = - resources.getString(string.menu_help) - findItem(org.kiwix.kiwixmobile.core.R.id.menu_support_kiwix)?.title = - resources.getString(string.menu_support_kiwix) - } - } + // if (::activityKiwixMainBinding.isInitialized) { + // activityKiwixMainBinding.bottomNavView.menu.apply { + // findItem(R.id.readerFragment)?.title = resources.getString(string.reader) + // findItem(R.id.libraryFragment)?.title = resources.getString(string.library) + // findItem(R.id.downloadsFragment)?.title = resources.getString(string.download) + // } + // activityKiwixMainBinding.drawerNavView.menu.apply { + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_bookmarks_list)?.title = + // resources.getString(string.bookmarks) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_history)?.title = + // resources.getString(string.history) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_notes)?.title = + // resources.getString(string.pref_notes) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_host_books)?.title = + // resources.getString(string.menu_wifi_hotspot) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_settings)?.title = + // resources.getString(string.menu_settings) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_help)?.title = + // resources.getString(string.menu_help) + // findItem(org.kiwix.kiwixmobile.core.R.id.menu_support_kiwix)?.title = + // resources.getString(string.menu_support_kiwix) + // } + // } } override fun configureActivityBasedOn(destination: NavDestination) { super.configureActivityBasedOn(destination) - activityKiwixMainBinding.bottomNavView.isVisible = destination.id in topLevelDestinations + isBottomBarVisible.value = destination.id in topLevelDestinations } override fun onStart() { super.onStart() - navController.addOnDestinationChangedListener { _, destination, _ -> - activityKiwixMainBinding.bottomNavView.isVisible = destination.id in topLevelDestinations - if (destination.id !in topLevelDestinations) { - handleDrawerOnNavigation() - } - } + // navController.addOnDestinationChangedListener { _, destination, _ -> + // isBottomBarVisible.value = destination.id in topLevelDestinations + // if (destination.id !in topLevelDestinations) { + // handleDrawerOnNavigation() + // } + // } if (sharedPreferenceUtil.showIntro() && !isIntroScreenNotVisible()) { - navigate(KiwixReaderFragmentDirections.actionReaderFragmentToIntroFragment()) + // navigate(KiwixReaderFragmentDirections.actionReaderFragmentToIntroFragment()) } if (!sharedPreferenceUtil.prefIsTest) { sharedPreferenceUtil.setIsPlayStoreBuildType(BuildConfig.IS_PLAYSTORE) @@ -234,16 +229,16 @@ class KiwixMainActivity : CoreMainActivity() { * TODO Remove this once we migrate to compose. */ override fun toggleBottomNavigation(isVisible: Boolean) { - activityKiwixMainBinding.bottomNavView.animate() - ?.translationY( - if (isVisible) { - ZERO.toFloat() - } else { - activityKiwixMainBinding.bottomNavView.height.toFloat() - } - ) - ?.setDuration(KIWIX_BOTTOM_BAR_ANIMATION_DURATION) - ?.start() + // activityKiwixMainBinding.bottomNavView.animate() + // ?.translationY( + // if (isVisible) { + // ZERO.toFloat() + // } else { + // activityKiwixMainBinding.bottomNavView.height.toFloat() + // } + // ) + // ?.setDuration(KIWIX_BOTTOM_BAR_ANIMATION_DURATION) + // ?.start() } private fun setDefaultDeviceLanguage() { @@ -283,9 +278,9 @@ class KiwixMainActivity : CoreMainActivity() { private fun handleGetContentIntent(intent: Intent?) { if (intent?.action == ACTION_GET_CONTENT) { - activityKiwixMainBinding.bottomNavView.menu.findItem(R.id.downloadsFragment)?.let { - NavigationUI.onNavDestinationSelected(it, navController) - } + // activityKiwixMainBinding.bottomNavView.menu.findItem(R.id.downloadsFragment)?.let { + // NavigationUI.onNavDestinationSelected(it, navController) + // } } } @@ -356,7 +351,7 @@ class KiwixMainActivity : CoreMainActivity() { } override fun setDialogHostToActivity(alertDialogShower: AlertDialogShower) { - activityKiwixMainBinding.root.addView(getDialogHostComposeView(alertDialogShower), 0) + // activityKiwixMainBinding.root.addView(getDialogHostComposeView(alertDialogShower), 0) } // Outdated shortcut ids(new_tab, get_content) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt index 2b3dd8131..41728d8e3 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt @@ -18,34 +18,120 @@ package org.kiwix.kiwixmobile.main -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.slideInHorizontally -import androidx.compose.animation.slideOutHorizontally +import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.BottomAppBarDefaults import androidx.compose.material3.BottomAppBarScrollBehavior import androidx.compose.material3.DrawerValue import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon +import androidx.compose.material3.ModalDrawerSheet import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.rememberDrawerState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.fragment.app.FragmentManager +import androidx.compose.ui.viewinterop.AndroidView +import androidx.fragment.app.FragmentContainerView import androidx.navigation.NavController import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.fragment.NavHostFragment import org.kiwix.kiwixmobile.R.drawable import org.kiwix.kiwixmobile.R.id import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.R.navigation +import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.NAVIGATION_DRAWER_WIDTH + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun KiwixMainActivityScreen( + navController: NavController, + topLevelDestinations: List, + leftDrawerContent: @Composable ColumnScope.() -> Unit, + rightDrawerContent: @Composable ColumnScope.() -> Unit, + isBottomBarVisible: Boolean = true +) { + val rightDrawerState = rememberDrawerState(DrawerValue.Closed) + val coroutineScope = rememberCoroutineScope() + val scrollingBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior() + val context = LocalContext.current + val fragmentManager = (context as AppCompatActivity).supportFragmentManager + KiwixTheme { + ModalNavigationDrawer( + drawerContent = { + Column( + Modifier + .fillMaxHeight() + .width(NAVIGATION_DRAWER_WIDTH) + ) { + leftDrawerContent() + } + }, + gesturesEnabled = true + ) { + Box { + Scaffold( + bottomBar = { + if (isBottomBarVisible) { + BottomNavigationBar( + navController = navController, + scrollBehavior = scrollingBehavior, + topLevelDestinations = topLevelDestinations + ) + } + } + ) { paddingValues -> + Box(modifier = Modifier.padding(paddingValues)) { + // AndroidView to host your FragmentContainerView with nav graph + AndroidView( + modifier = Modifier.fillMaxSize(), + factory = { ctx -> + FragmentContainerView(ctx).apply { + id = R.id.nav_host_fragment + if (fragmentManager.findFragmentById(id) == null) { + val navHostFragment = NavHostFragment.create(navigation.kiwix_nav_graph) + fragmentManager.beginTransaction() + .replace(id, navHostFragment) + .setPrimaryNavigationFragment(navHostFragment) + .commitNow() + } + } + } + ) + } + } + + // Right drawer overlay + ModalDrawerSheet( + drawerState = rightDrawerState, + modifier = Modifier + .fillMaxHeight() + .align(Alignment.CenterEnd) + .width(NAVIGATION_DRAWER_WIDTH) + ) { + rightDrawerContent() + } + } + } + } +} @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -93,64 +179,3 @@ fun BottomNavigationBar( } } } - -@Composable -fun MainNavGraph( - fragmentManager: FragmentManager, - navGraphId: Int -) { - val navController = remember { - fragmentManager.findNavController(R.id.nav_host_fragment) - } - - // Drawer states - val leftDrawerState = rememberDrawerState(initialValue = DrawerValue.Closed) - val rightDrawerVisible = remember { mutableStateOf(false) } - - // Bottom nav destinations - val bottomNavDestinations = listOf( - id.readerFragment, - id.libraryFragment, - id.downloadsFragment - ) - - // Observe current destination - val navBackStackEntry by navController.currentBackStackEntryAsState() - val currentDestinationId = navBackStackEntry?.destination?.id - - // Coroutine scope for drawer - val scope = rememberCoroutineScope() - - ModalNavigationDrawer( - drawerState = leftDrawerState, - drawerContent = { DrawerContentLeft() } - ) { - Box(modifier = Modifier.fillMaxSize()) { - // Fragment content - FragmentContainer( - fragmentManager = fragmentManager, - containerId = R.id.nav_host_fragment, - navGraphId = navGraphId - ) - - // Right drawer (slide in) - AnimatedVisibility( - visible = rightDrawerVisible.value, - enter = slideInHorizontally(initialOffsetX = { it }), - exit = slideOutHorizontally(targetOffsetX = { it }), - modifier = Modifier.align(Alignment.CenterEnd) - ) { - DrawerContentRight( - onClose = { rightDrawerVisible.value = false } - ) - } - - // Bottom nav only on selected destinations - if (currentDestinationId in bottomNavDestinations) { - BottomNavigationBar( - navController = navController, - ) - } - } - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt index 846d5789e..be5b271bc 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt @@ -288,8 +288,8 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal zimManageViewModel.setAlertDialogShower(dialogShower as AlertDialogShower) zimManageViewModel.fileSelectListStates.observe(viewLifecycleOwner, Observer(::render)) .also { - coreMainActivity.navHostContainer - .setBottomMarginToFragmentContainerView(0) + // coreMainActivity.navHostContainer + // .setBottomMarginToFragmentContainerView(0) } coroutineJobs.apply { add(sideEffects()) @@ -363,10 +363,11 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal } } - private fun getBottomNavigationView() = - requireActivity().findViewById(R.id.bottom_nav_view) + // private fun getBottomNavigationView() = + // requireActivity().findViewById(R.id.bottom_nav_view) - private fun getBottomNavigationHeight() = getBottomNavigationView().measuredHeight + private fun getBottomNavigationHeight() = ZERO + // getBottomNavigationView().measuredHeight private fun filePickerButtonClick() { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { @@ -560,10 +561,10 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal } private fun animateBottomViewToOrigin() { - getBottomNavigationView().animate() - .translationY(0F) - .setDuration(MATERIAL_BOTTOM_VIEW_ENTER_ANIMATION_DURATION) - .start() + // getBottomNavigationView().animate() + // .translationY(0F) + // .setDuration(MATERIAL_BOTTOM_VIEW_ENTER_ANIMATION_DURATION) + // .start() } private fun render(state: FileSelectListState) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt index d159b74e1..04ee43084 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt @@ -44,7 +44,6 @@ import androidx.fragment.app.FragmentActivity import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope -import com.google.android.material.bottomnavigation.BottomNavigationView import com.tonyodev.fetch2.Status import eu.mhutti1.utils.storage.StorageDevice import kotlinx.coroutines.flow.launchIn @@ -212,10 +211,11 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { composeView = it } - private fun getBottomNavigationView() = - requireActivity().findViewById(org.kiwix.kiwixmobile.R.id.bottom_nav_view) + // private fun getBottomNavigationView() = + // requireActivity().findViewById(org.kiwix.kiwixmobile.R.id.bottom_nav_view) - private fun getBottomNavigationHeight() = getBottomNavigationView().measuredHeight + private fun getBottomNavigationHeight() = ZERO + // getBottomNavigationView().measuredHeight private fun onPauseResumeButtonClick(item: LibraryListItem.LibraryDownloadItem) { context?.let { context -> @@ -298,8 +298,8 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { .onEach { onLibraryItemsChange(it) } .launchIn(viewLifecycleOwner.lifecycleScope) .also { - coreMainActivity.navHostContainer - .setBottomMarginToFragmentContainerView(0) + // coreMainActivity.navHostContainer + // .setBottomMarginToFragmentContainerView(0) } // Observe when online library downloading. onlineLibraryDownloading diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt index abfe10b1b..c401f3823 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt @@ -151,8 +151,8 @@ class KiwixReaderFragment : CoreReaderFragment() { } override fun loadDrawerViews() { - drawerLayout = requireActivity().findViewById(R.id.navigation_container) - tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view) + // drawerLayout = requireActivity().findViewById(R.id.navigation_container) + // tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view) } override fun openHomeScreen() { @@ -199,13 +199,13 @@ class KiwixReaderFragment : CoreReaderFragment() { } private fun setFragmentContainerBottomMarginToSizeOfNavBar() { - val bottomNavigationView = - requireActivity().findViewById(R.id.bottom_nav_view) - bottomNavigationView?.let { - setBottomMarginToNavHostContainer( - bottomNavigationView.measuredHeight - ) - } + // val bottomNavigationView = + // requireActivity().findViewById(R.id.bottom_nav_view) + // bottomNavigationView?.let { + // setBottomMarginToNavHostContainer( + // bottomNavigationView.measuredHeight + // ) + // } } // override fun onPause() { @@ -240,8 +240,8 @@ class KiwixReaderFragment : CoreReaderFragment() { exitBook() } - override fun getBottomNavigationView(): BottomNavigationView? = - requireActivity().findViewById(R.id.bottom_nav_view) + override fun getBottomNavigationView(): BottomNavigationView? = null + // requireActivity().findViewById(R.id.bottom_nav_view) /** * Restores the view state based on the provided webViewHistoryItemList data and restore origin. @@ -299,11 +299,11 @@ class KiwixReaderFragment : CoreReaderFragment() { override fun updateNavigationBarHeight(toolbarOffset: Float) { // if no activity exist simply return. if (activity == null) return - activity?.findViewById(R.id.bottom_nav_view)?.let { view -> - val toolbarHeightPx = activity?.getToolbarHeight() ?: 0f - val offsetFactor = view.height / toolbarHeightPx.toFloat() - view.translationY = -1 * toolbarOffset * offsetFactor - } + // activity?.findViewById(R.id.bottom_nav_view)?.let { view -> + // val toolbarHeightPx = activity?.getToolbarHeight() ?: 0f + // val offsetFactor = view.height / toolbarHeightPx.toFloat() + // view.translationY = -1 * toolbarOffset * offsetFactor + // } } override fun onFullscreenVideoToggled(isFullScreen: Boolean) { @@ -328,15 +328,15 @@ class KiwixReaderFragment : CoreReaderFragment() { } private fun hideNavBar() { - requireActivity().findViewById(R.id.bottom_nav_view).visibility = GONE + // requireActivity().findViewById(R.id.bottom_nav_view).visibility = GONE setBottomMarginToNavHostContainer(0) } private fun showNavBar() { // show the navBar if fullScreenMode is not active. if (!isInFullScreenMode()) { - requireActivity().findViewById(R.id.bottom_nav_view).visibility = - VISIBLE + // requireActivity().findViewById(R.id.bottom_nav_view).visibility = + // VISIBLE } } @@ -345,7 +345,7 @@ class KiwixReaderFragment : CoreReaderFragment() { } private fun setBottomMarginToNavHostContainer(margin: Int) { - coreMainActivity.navHostContainer - .setBottomMarginToFragmentContainerView(margin) + // coreMainActivity.navHostContainer + // .setBottomMarginToFragmentContainerView(margin) } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt b/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt new file mode 100644 index 000000000..68c8933a7 --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt @@ -0,0 +1,170 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.ui + +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.viewinterop.AndroidView +import androidx.core.view.doOnAttach +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentContainerView +import androidx.fragment.app.commit +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment +import org.kiwix.kiwixmobile.core.page.history.HistoryFragment +import org.kiwix.kiwixmobile.core.page.notes.NotesFragment +import org.kiwix.kiwixmobile.core.search.SearchFragment +import org.kiwix.kiwixmobile.help.KiwixHelpFragment +import org.kiwix.kiwixmobile.intro.IntroFragment +import org.kiwix.kiwixmobile.language.LanguageFragment +import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferFragment +import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragment +import org.kiwix.kiwixmobile.nav.destination.library.online.OnlineLibraryFragment +import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment +import org.kiwix.kiwixmobile.settings.KiwixSettingsFragment +import org.kiwix.kiwixmobile.webserver.ZimHostFragment + +@Composable +fun KiwixNavGraph( + navController: NavHostController, + modifier: Modifier = Modifier +) { + NavHost( + navController = navController, + startDestination = "readerFragment", + modifier = modifier + ) { + composable("readerFragment") { + FragmentContainer { + KiwixReaderFragment().apply { + arguments = Bundle().apply { + putString("zimFileUri", "") + putString("findInPageSearchString", "") + putString("pageUrl", "") + putBoolean("shouldOpenInNewTab", false) + putString("searchItemTitle", "") + } + } + } + } + composable("libraryFragment") { + FragmentContainer { + LocalLibraryFragment().apply { + arguments = Bundle().apply { + putString("zimFileUri", "") + } + } + } + } + composable("downloadsFragment") { + FragmentContainer { + OnlineLibraryFragment() + } + } + composable("bookmarksFragment") { + FragmentContainer { + BookmarksFragment() + } + } + composable("notesFragment") { + FragmentContainer { + NotesFragment() + } + } + composable("introFragment") { + FragmentContainer { + IntroFragment() + } + } + composable("historyFragment") { + FragmentContainer { + HistoryFragment() + } + } + composable("languageFragment") { + FragmentContainer { + LanguageFragment() + } + } + composable("zimHostFragment") { + FragmentContainer { + ZimHostFragment() + } + } + composable("helpFragment") { + FragmentContainer { + KiwixHelpFragment() + } + } + composable("kiwixSettingsFragment") { + FragmentContainer { + KiwixSettingsFragment() + } + } + composable("searchFragment") { + FragmentContainer { + SearchFragment() + } + } + composable("localFileTransferFragment") { + FragmentContainer { + LocalFileTransferFragment().apply { + arguments = Bundle().apply { + putParcelableArray("uris", null) + } + } + } + } + } +} + +@Composable +fun FragmentContainer( + fragmentProvider: () -> Fragment +) { + val context = LocalContext.current + val fragmentManager = remember { + (context as AppCompatActivity).supportFragmentManager + } + val viewId = remember { View.generateViewId() } + + AndroidView( + modifier = Modifier.fillMaxSize(), + factory = { ctx -> + FragmentContainerView(ctx).apply { + id = viewId + doOnAttach { + fragmentManager.commit { + if (fragmentManager.findFragmentById(viewId) == null) { + add(viewId, fragmentProvider()) + } + } + } + } + } + ) +} diff --git a/app/src/main/res/layout/activity_kiwix_main.xml b/app/src/main/res/layout/activity_kiwix_main.xml deleted file mode 100644 index 111f83368..000000000 --- a/app/src/main/res/layout/activity_kiwix_main.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/attrs_page_indicator.xml b/app/src/main/res/values/attrs_page_indicator.xml deleted file mode 100644 index 3a9054a16..000000000 --- a/app/src/main/res/values/attrs_page_indicator.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt index 695b9feef..cf7cbeb2c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt @@ -91,9 +91,10 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { @Inject lateinit var zimReaderContainer: ZimReaderContainer abstract val navController: NavController - abstract val drawerContainerLayout: DrawerLayout - abstract val drawerNavView: NavigationView - abstract val readerTableOfContentsDrawer: NavigationView + + // abstract val drawerContainerLayout: DrawerLayout + // abstract val drawerNavView: NavigationView + // abstract val readerTableOfContentsDrawer: NavigationView abstract val bookmarksFragmentResId: Int abstract val settingsFragmentResId: Int abstract val historyFragmentResId: Int @@ -101,7 +102,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { abstract val helpFragmentResId: Int abstract val cachedComponent: CoreActivityComponent abstract val topLevelDestinations: Set - abstract val navHostContainer: FragmentContainerView + // abstract val navHostContainer: FragmentContainerView abstract val mainActivity: AppCompatActivity abstract val appName: String @@ -114,7 +115,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { @Suppress("InjectDispatcher") override fun onCreate(savedInstanceState: Bundle?) { - setTheme(R.style.KiwixTheme) + // setTheme(R.style.KiwixTheme) super.onCreate(savedInstanceState) if (!BuildConfig.DEBUG) { val appContext = applicationContext @@ -160,9 +161,9 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { downloadMonitor.startMonitoringDownload() stopDownloadServiceIfRunning() rateDialogHandler.checkForRateDialog(getIconResId()) - navController.addOnDestinationChangedListener { _, destination, _ -> - configureActivityBasedOn(destination) - } + // navController.addOnDestinationChangedListener { _, destination, _ -> + // configureActivityBasedOn(destination) + // } } /** @@ -206,17 +207,17 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { if (destination.id !in topLevelDestinations) { handleDrawerOnNavigation() } - readerTableOfContentsDrawer.setLockMode( - if (destination.id == readerFragmentResId) { - LOCK_MODE_UNLOCKED - } else { - LOCK_MODE_LOCKED_CLOSED - } - ) + // readerTableOfContentsDrawer.setLockMode( + // if (destination.id == readerFragmentResId) { + // LOCK_MODE_UNLOCKED + // } else { + // LOCK_MODE_LOCKED_CLOSED + // } + // ) } private fun NavigationView.setLockMode(lockMode: Int) { - drawerContainerLayout.setDrawerLockMode(lockMode, this) + // drawerContainerLayout.setDrawerLockMode(lockMode, this) } @Suppress("DEPRECATION") @@ -278,34 +279,34 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { // toolbar.getToolbarNavigationIcon()?.setToolTipWithContentDescription( // getString(R.string.open_drawer) // ) - drawerToggle = - ActionBarDrawerToggle( - this, - drawerContainerLayout, - R.string.open_drawer, - R.string.close_drawer - ) - drawerToggle?.let { - drawerContainerLayout.addDrawerListener(it) - it.syncState() - } - drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) - if (shouldEnableRightDrawer) { - // Enable the right drawer - drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END) - } + // drawerToggle = + // ActionBarDrawerToggle( + // this, + // drawerContainerLayout, + // R.string.open_drawer, + // R.string.close_drawer + // ) + // drawerToggle?.let { + // drawerContainerLayout.addDrawerListener(it) + // it.syncState() + // } + // drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) + // if (shouldEnableRightDrawer) { + // // Enable the right drawer + // drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END) + // } } open fun disableDrawer(disableRightDrawer: Boolean = true) { - drawerToggle?.isDrawerIndicatorEnabled = false - drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) - if (disableRightDrawer) { - // Disable the right drawer - drawerContainerLayout.setDrawerLockMode( - DrawerLayout.LOCK_MODE_LOCKED_CLOSED, - GravityCompat.END - ) - } + // drawerToggle?.isDrawerIndicatorEnabled = false + // drawerContainerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) + // if (disableRightDrawer) { + // // Disable the right drawer + // drawerContainerLayout.setDrawerLockMode( + // DrawerLayout.LOCK_MODE_LOCKED_CLOSED, + // GravityCompat.END + // ) + // } } open fun onNavigationItemSelected(item: MenuItem): Boolean { @@ -326,15 +327,15 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { handleDrawerOnNavigation() } - fun navigationDrawerIsOpen(): Boolean = - drawerContainerLayout.isDrawerOpen(drawerNavView) + fun navigationDrawerIsOpen(): Boolean = false + // drawerContainerLayout.isDrawerOpen(drawerNavView) fun closeNavigationDrawer() { - drawerContainerLayout.closeDrawer(drawerNavView) + // drawerContainerLayout.closeDrawer(drawerNavView) } fun openNavigationDrawer() { - drawerContainerLayout.openDrawer(drawerNavView) + // drawerContainerLayout.openDrawer(drawerNavView) } fun openSupportKiwixExternalLink() { diff --git a/core/src/main/res/values/ids.xml b/core/src/main/res/values/ids.xml index f3e24717c..7e2de03d3 100644 --- a/core/src/main/res/values/ids.xml +++ b/core/src/main/res/values/ids.xml @@ -4,4 +4,5 @@ +