mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-05 11:46:48 -04:00
#2159 added navigation safeargs to allow for navigation to reader when selecting book from library
This commit is contained in:
parent
4af75bb276
commit
cb13f4440f
@ -3,6 +3,7 @@ import plugin.KiwixConfigurationPlugin
|
|||||||
plugins {
|
plugins {
|
||||||
android
|
android
|
||||||
id("com.github.triplet.play") version Versions.com_github_triplet_play_gradle_plugin
|
id("com.github.triplet.play") version Versions.com_github_triplet_play_gradle_plugin
|
||||||
|
id("androidx.navigation.safeargs")
|
||||||
}
|
}
|
||||||
plugins.apply(KiwixConfigurationPlugin::class)
|
plugins.apply(KiwixConfigurationPlugin::class)
|
||||||
|
|
||||||
@ -93,5 +94,4 @@ dependencies {
|
|||||||
implementation("androidx.navigation:navigation-ui-ktx:$navVersion")
|
implementation("androidx.navigation:navigation-ui-ktx:$navVersion")
|
||||||
// Testing Navigation
|
// Testing Navigation
|
||||||
androidTestImplementation("androidx.navigation:navigation-testing:$navVersion")
|
androidTestImplementation("androidx.navigation:navigation-testing:$navVersion")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ import org.kiwix.kiwixmobile.local_file_transfer.LocalFileTransferActivity
|
|||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainFragment
|
import org.kiwix.kiwixmobile.main.KiwixMainFragment
|
||||||
import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity
|
import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity
|
||||||
import org.kiwix.kiwixmobile.nav_destination_download.OnlineLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.nav_destination_library.LocalLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.nav_destination_reader.ReaderFragment
|
import org.kiwix.kiwixmobile.nav.destination.reader.ReaderFragment
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity
|
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity
|
||||||
import org.kiwix.kiwixmobile.splash.KiwixSplashActivity
|
import org.kiwix.kiwixmobile.splash.KiwixSplashActivity
|
||||||
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav_destination_library
|
package org.kiwix.kiwixmobile.nav.destination.library
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@ -75,7 +75,7 @@ class LocalLibraryFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
private val bookDelegate: BookOnDiskDelegate.BookDelegate by lazy {
|
private val bookDelegate: BookOnDiskDelegate.BookDelegate by lazy {
|
||||||
BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
||||||
{ offerAction(ZimManageViewModel.FileSelectActions.RequestOpen(it)) },
|
{ offerAction(ZimManageViewModel.FileSelectActions.RequestNavigateTo(it)) },
|
||||||
{ offerAction(ZimManageViewModel.FileSelectActions.RequestMultiSelection(it)) },
|
{ offerAction(ZimManageViewModel.FileSelectActions.RequestMultiSelection(it)) },
|
||||||
{ offerAction(ZimManageViewModel.FileSelectActions.RequestSelect(it)) })
|
{ offerAction(ZimManageViewModel.FileSelectActions.RequestSelect(it)) })
|
||||||
}
|
}
|
||||||
@ -135,7 +135,8 @@ class LocalLibraryFragment : BaseFragment() {
|
|||||||
zim_swiperefresh.isRefreshing = it!!
|
zim_swiperefresh.isRefreshing = it!!
|
||||||
})
|
})
|
||||||
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
|
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
|
||||||
zimManageViewModel.fileSelectActions.offer(ZimManageViewModel.FileSelectActions.RestartActionMode)
|
zimManageViewModel.fileSelectActions
|
||||||
|
.offer(ZimManageViewModel.FileSelectActions.RestartActionMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
disposable.add(zimManageViewModel.libraryTabIsVisible.subscribe { finishActionMode() })
|
disposable.add(zimManageViewModel.libraryTabIsVisible.subscribe { finishActionMode() })
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav_destination_download
|
package org.kiwix.kiwixmobile.nav.destination.library
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav_destination_reader
|
package org.kiwix.kiwixmobile.nav.destination.reader
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -28,6 +28,7 @@ import android.view.ViewGroup
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.navigation.fragment.navArgs
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||||
@ -39,7 +40,6 @@ import org.kiwix.kiwixmobile.core.main.CoreReaderFragment
|
|||||||
import org.kiwix.kiwixmobile.core.main.WebViewCallback
|
import org.kiwix.kiwixmobile.core.main.WebViewCallback
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||||
import org.kiwix.kiwixmobile.core.utils.EXTRA_ZIM_FILE
|
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES
|
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES
|
||||||
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE
|
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE
|
||||||
@ -48,6 +48,7 @@ import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_TAB
|
|||||||
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
||||||
import org.kiwix.kiwixmobile.core.utils.UpdateUtils
|
import org.kiwix.kiwixmobile.core.utils.UpdateUtils
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||||
|
import org.kiwix.kiwixmobile.destinationreader.ReaderFragmentArgs
|
||||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
||||||
import org.kiwix.kiwixmobile.main.KiwixWebViewClient
|
import org.kiwix.kiwixmobile.main.KiwixWebViewClient
|
||||||
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
||||||
@ -92,7 +93,7 @@ class ReaderFragment : CoreReaderFragment() {
|
|||||||
|
|
||||||
private fun manageExternalLaunchAndRestoringViewState() {
|
private fun manageExternalLaunchAndRestoringViewState() {
|
||||||
|
|
||||||
val data = uriFromIntent()
|
val data = uriFromNavigation()
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
val filePath = FileUtils.getLocalFilePathByUri(requireActivity().applicationContext, data)
|
val filePath = FileUtils.getLocalFilePathByUri(requireActivity().applicationContext, data)
|
||||||
|
|
||||||
@ -145,10 +146,10 @@ class ReaderFragment : CoreReaderFragment() {
|
|||||||
override fun isInvalidTitle(zimFileTitle: String?) =
|
override fun isInvalidTitle(zimFileTitle: String?) =
|
||||||
super.isInvalidTitle(zimFileTitle) || HOME_URL == getCurrentWebView().url
|
super.isInvalidTitle(zimFileTitle) || HOME_URL == getCurrentWebView().url
|
||||||
|
|
||||||
private fun uriFromIntent() =
|
private val args: ReaderFragmentArgs by navArgs()
|
||||||
activity?.intent?.data ?: activity?.intent?.getStringExtra(EXTRA_ZIM_FILE)?.let {
|
|
||||||
File(FileUtils.getFileName(it)).toUri()
|
private fun uriFromNavigation() =
|
||||||
}
|
args.zimFileUri.let { File(FileUtils.getFileName(it)).toUri() }
|
||||||
|
|
||||||
private fun restoreTabStates() {
|
private fun restoreTabStates() {
|
||||||
val settings = requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
|
val settings = requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
|
@ -54,6 +54,7 @@ import org.kiwix.kiwixmobile.zim_manager.NetworkState.CONNECTED
|
|||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.MultiModeFinished
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.MultiModeFinished
|
||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestDeleteMultiSelection
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestDeleteMultiSelection
|
||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestMultiSelection
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestMultiSelection
|
||||||
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestNavigateTo
|
||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestOpen
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestOpen
|
||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestSelect
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestSelect
|
||||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestShareMultiSelection
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestShareMultiSelection
|
||||||
@ -62,6 +63,7 @@ import org.kiwix.kiwixmobile.zim_manager.fileselect_view.FileSelectListState
|
|||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.None
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.None
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.OpenFile
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.OpenFile
|
||||||
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.OpenFileWithNavigation
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.ShareFiles
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.ShareFiles
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.StartMultiSelection
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.StartMultiSelection
|
||||||
import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem
|
import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem
|
||||||
@ -89,6 +91,7 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
sealed class FileSelectActions {
|
sealed class FileSelectActions {
|
||||||
data class RequestOpen(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
data class RequestOpen(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
||||||
|
data class RequestNavigateTo(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
||||||
data class RequestSelect(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
data class RequestSelect(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
||||||
data class RequestMultiSelection(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
data class RequestMultiSelection(val bookOnDisk: BookOnDisk) : FileSelectActions()
|
||||||
object RequestDeleteMultiSelection : FileSelectActions()
|
object RequestDeleteMultiSelection : FileSelectActions()
|
||||||
@ -149,6 +152,7 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
private fun fileSelectActions() = fileSelectActions.subscribe({
|
private fun fileSelectActions() = fileSelectActions.subscribe({
|
||||||
sideEffects.offer(
|
sideEffects.offer(
|
||||||
when (it) {
|
when (it) {
|
||||||
|
is RequestNavigateTo -> OpenFileWithNavigation(it.bookOnDisk)
|
||||||
is RequestOpen -> OpenFile(it.bookOnDisk)
|
is RequestOpen -> OpenFile(it.bookOnDisk)
|
||||||
is RequestMultiSelection -> startMultiSelectionAndSelectBook(it.bookOnDisk)
|
is RequestMultiSelection -> startMultiSelectionAndSelectBook(it.bookOnDisk)
|
||||||
RequestDeleteMultiSelection -> DeleteFiles(selectionsFromState())
|
RequestDeleteMultiSelection -> DeleteFiles(selectionsFromState())
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Kiwix Android
|
||||||
|
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import androidx.navigation.findNavController
|
||||||
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||||
|
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||||
|
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
|
||||||
|
import org.kiwix.kiwixmobile.destinationlibrary.LocalLibraryFragmentDirections
|
||||||
|
|
||||||
|
data class OpenFileWithNavigation(private val bookOnDisk: BooksOnDiskListItem.BookOnDisk) :
|
||||||
|
SideEffect<Unit> {
|
||||||
|
|
||||||
|
override fun invokeWith(activity: AppCompatActivity) {
|
||||||
|
val file = bookOnDisk.file
|
||||||
|
if (!file.canRead()) {
|
||||||
|
activity.toast(R.string.error_file_not_found)
|
||||||
|
} else {
|
||||||
|
val action = LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader(
|
||||||
|
file.toUri().toString()
|
||||||
|
)
|
||||||
|
activity.findNavController(org.kiwix.kiwixmobile.R.id.nav_host_fragment).navigate(action)
|
||||||
|
|
||||||
|
// activity.finish()
|
||||||
|
// activity.start<KiwixMainActivity> {
|
||||||
|
// data = file.toUri()
|
||||||
|
// flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,19 +23,27 @@
|
|||||||
app:startDestination="@id/navigation_library">
|
app:startDestination="@id/navigation_library">
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_reader"
|
android:id="@+id/navigation_reader"
|
||||||
android:name="org.kiwix.kiwixmobile.nav_destination_reader.ReaderFragment"
|
android:name="org.kiwix.kiwixmobile.nav.destination.reader.ReaderFragment"
|
||||||
android:label="Reader"
|
android:label="Reader"
|
||||||
tools:layout="@layout/fragment_destination_reader" />
|
tools:layout="@layout/fragment_destination_reader">
|
||||||
|
<argument
|
||||||
|
android:name="zimFileUri"
|
||||||
|
app:argType="string" />
|
||||||
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_library"
|
android:id="@+id/navigation_library"
|
||||||
android:name="org.kiwix.kiwixmobile.nav_destination_library.LocalLibraryFragment"
|
android:name="org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment"
|
||||||
android:label="Library"
|
android:label="Library"
|
||||||
tools:layout="@layout/fragment_destination_library" />
|
tools:layout="@layout/fragment_destination_library">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_navigation_library_to_navigation_reader"
|
||||||
|
app:destination="@id/navigation_reader" />
|
||||||
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_downloads"
|
android:id="@+id/navigation_downloads"
|
||||||
android:name="org.kiwix.kiwixmobile.nav_destination_download.OnlineLibraryFragment"
|
android:name="org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment"
|
||||||
android:label="Downloads"
|
android:label="Downloads"
|
||||||
tools:layout="@layout/fragment_destination_download" />
|
tools:layout="@layout/fragment_destination_download" />
|
||||||
</navigation>
|
</navigation>
|
||||||
|
@ -6,6 +6,10 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath(Libs.com_android_tools_build_gradle)
|
classpath(Libs.com_android_tools_build_gradle)
|
||||||
classpath(Libs.kotlin_gradle_plugin)
|
classpath(Libs.kotlin_gradle_plugin)
|
||||||
|
|
||||||
|
val navVersion = "2.3.0-rc01"
|
||||||
|
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$navVersion")
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user