Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Launch certain views in single top mode
Browse files Browse the repository at this point in the history
To hopefully prevent crashes due to invalid navigation routes
  • Loading branch information
Doomsdayrs committed Jul 22, 2022
1 parent 6352c47 commit 05ec375
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import app.shosetsu.android.common.consts.*
import app.shosetsu.android.common.enums.TextAsset
Expand Down Expand Up @@ -96,14 +97,16 @@ class AboutController : ShosetsuController() {
private fun onClickLicense() {
findNavController().navigate(
R.id.action_aboutController_to_textAssetReader,
TextAsset.LICENSE.bundle
TextAsset.LICENSE.bundle,
navOptions = NavOptions.Builder().setLaunchSingleTop(true).build()
)
}

private fun onClickDisclaimer() {
findNavController().navigate(
R.id.action_aboutController_to_textAssetReader,
TextAsset.DISCLAIMER.bundle
TextAsset.DISCLAIMER.bundle,
navOptions = NavOptions.Builder().setLaunchSingleTop(true).build()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
import androidx.core.view.MenuProvider
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import app.shosetsu.android.activity.MainActivity
import app.shosetsu.android.common.consts.BundleKeys.BUNDLE_EXTENSION
Expand Down Expand Up @@ -155,7 +156,8 @@ class BrowseController : ShosetsuController(),
viewModel.resetSearch()
findNavController().navigate(
R.id.action_browseController_to_configureExtension,
(bundleOf(BUNDLE_EXTENSION to entity.id))
bundleOf(BUNDLE_EXTENSION to entity.id),
navOptions = NavOptions.Builder().setLaunchSingleTop(true).build()
)
}

Expand All @@ -167,11 +169,10 @@ class BrowseController : ShosetsuController(),
viewModel.resetSearch()
findNavController().navigate(
R.id.action_browseController_to_catalogController,
(
bundleOf(
BUNDLE_EXTENSION to entity.id
)
)
bundleOf(
BUNDLE_EXTENSION to entity.id
),
navOptions = NavOptions.Builder().setLaunchSingleTop(true).build()
)
} else makeSnackBar(R.string.controller_browse_snackbar_not_installed)?.setAction(
R.string.install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.os.bundleOf
import androidx.core.view.MenuProvider
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import app.shosetsu.android.activity.MainActivity
import app.shosetsu.android.common.SettingKey
Expand Down Expand Up @@ -119,7 +120,8 @@ class LibraryController
onOpen = { item ->
findNavController().navigate(
R.id.action_libraryController_to_novelController,
bundleOf(BundleKeys.BUNDLE_NOVEL_ID to item.id)
bundleOf(BundleKeys.BUNDLE_NOVEL_ID to item.id),
navOptions = NavOptions.Builder().setLaunchSingleTop(true).build()
)
},
toggleSelection = { item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import app.shosetsu.android.common.ext.makeSnackBar
import app.shosetsu.android.view.compose.ShosetsuCompose
Expand Down Expand Up @@ -71,8 +72,12 @@ class ComposeMoreController
{
makeSnackBar(R.string.style_wait)?.show()
}
) {
findNavController().navigate(it)
) { it, singleTop ->
findNavController().navigate(
it,
null,
navOptions = NavOptions.Builder().setLaunchSingleTop(singleTop).build()
)
}
}
}
Expand Down Expand Up @@ -112,13 +117,13 @@ fun MoreItemContent(
@Preview
@Composable
fun PreviewMoreContent() {
MoreContent({}) { }
MoreContent({}) { id, singleTop -> }
}

@Composable
fun MoreContent(
showStyleBar: () -> Unit,
pushController: (Int) -> Unit
pushController: (Int, singleTop: Boolean) -> Unit
) {
Column(
modifier = Modifier
Expand All @@ -144,19 +149,19 @@ fun MoreContent(
) {
item {
MoreItemContent(R.string.downloads, R.drawable.download) {
pushController(R.id.action_moreController_to_downloadsController)
pushController(R.id.action_moreController_to_downloadsController, true)
}
}

item {
MoreItemContent(R.string.backup, R.drawable.restore) {
pushController(R.id.action_moreController_to_backupSettings)
pushController(R.id.action_moreController_to_backupSettings, true)
}
}

item {
MoreItemContent(R.string.repositories, R.drawable.add_shopping_cart) {
pushController(R.id.action_moreController_to_repositoryController)
pushController(R.id.action_moreController_to_repositoryController, true)
}
}

Expand All @@ -168,19 +173,19 @@ fun MoreContent(

item {
MoreItemContent(R.string.qr_code_scan, R.drawable.ic_baseline_qr_code_scanner_24) {
pushController(R.id.action_moreController_to_addShareController)
pushController(R.id.action_moreController_to_addShareController, true)
}
}

item {
MoreItemContent(R.string.settings, R.drawable.settings) {
pushController(R.id.action_moreController_to_settingsController)
pushController(R.id.action_moreController_to_settingsController, false)
}
}

item {
MoreItemContent(R.string.about, R.drawable.info_outline) {
pushController(R.id.action_moreController_to_aboutController)
pushController(R.id.action_moreController_to_aboutController, false)
}
}

Expand Down

0 comments on commit 05ec375

Please sign in to comment.