Merge ConfigureActivity into MainActivity
This commit is contained in:
1 parent
549387ac91
commit
3ad6b9106b
10 files changed
+46
-108
No files matched your search
@@ -37,11 +37,6 @@
|
||||
tools:targetApi="tiramisu">
|
||||
<profileable android:shell="true" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.ConfigureActivity"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:banner="@mipmap/ic_leanback_banner"
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.hippo.ehviewer.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.ui.destinations.BaseScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SelectSiteScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SignInScreenDestination
|
||||
import com.hippo.ehviewer.ui.tools.LocalWindowSizeClass
|
||||
import com.hippo.ehviewer.util.findActivity
|
||||
import com.ramcosta.composedestinations.DestinationsNavHost
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.rememberNavHostEngine
|
||||
|
||||
class ConfigureActivity : EhActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setMD3Content {
|
||||
val windowSizeClass = calculateWindowSizeClass(this)
|
||||
CompositionLocalProvider(LocalWindowSizeClass provides windowSizeClass) {
|
||||
DestinationsNavHost(
|
||||
navGraph = NavGraphs.root,
|
||||
modifier = Modifier.imePadding(),
|
||||
startRoute = if (Settings.needSignIn) {
|
||||
if (EhCookieStore.hasSignedIn()) SelectSiteScreenDestination else SignInScreenDestination
|
||||
} else {
|
||||
BaseScreenDestination
|
||||
},
|
||||
engine = rememberNavHostEngine(rootDefaultAnimations = ehNavAnim),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Destination
|
||||
@Composable
|
||||
fun Finish() {
|
||||
val context = LocalContext.current
|
||||
SideEffect {
|
||||
context.findActivity<Activity>().finish()
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
@@ -89,6 +90,7 @@ import androidx.lifecycle.compose.LifecycleResumeEffect
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser
|
||||
@@ -105,6 +107,9 @@ import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.HistoryScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.HomePageScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.ProgressScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SelectSiteScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SettingsScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SignInScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SubscriptionScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.ToplistScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.WhatshotScreenDestination
|
||||
@@ -115,6 +120,7 @@ import com.hippo.ehviewer.ui.screen.navigate
|
||||
import com.hippo.ehviewer.ui.settings.showNewVersion
|
||||
import com.hippo.ehviewer.ui.tools.LocalDialogState
|
||||
import com.hippo.ehviewer.ui.tools.LocalTouchSlopProvider
|
||||
import com.hippo.ehviewer.ui.tools.LocalWindowSizeClass
|
||||
import com.hippo.ehviewer.updater.AppUpdater
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
@@ -147,8 +153,12 @@ private val navItems = arrayOf(
|
||||
Triple(FavouritesScreenDestination, R.string.favourite, Icons.Default.Favorite),
|
||||
Triple(HistoryScreenDestination, R.string.history, Icons.Default.History),
|
||||
Triple(DownloadsScreenDestination, R.string.downloads, Icons.Default.Download),
|
||||
Triple(SettingsScreenDestination, R.string.settings, Icons.Default.Settings),
|
||||
)
|
||||
|
||||
val StartDestination
|
||||
get() = navItems[Settings.launchPage].first
|
||||
|
||||
class MainActivity : EhActivity() {
|
||||
private val sideSheet = mutableStateListOf<@Composable ColumnScope.(DrawerState2) -> Unit>()
|
||||
|
||||
@@ -357,19 +367,6 @@ class MainActivity : EhActivity() {
|
||||
},
|
||||
)
|
||||
}
|
||||
NavigationDrawerItem(
|
||||
label = {
|
||||
Text(text = stringResource(id = R.string.settings))
|
||||
},
|
||||
selected = false,
|
||||
onClick = {
|
||||
closeDrawer { startActivity(Intent(applicationContext, ConfigureActivity::class.java)) }
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
icon = {
|
||||
Icon(imageVector = Icons.Default.Settings, contentDescription = null)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -394,10 +391,18 @@ class MainActivity : EhActivity() {
|
||||
drawerState = sideSheetState,
|
||||
gesturesEnabled = sheet != null && !drawerLocked,
|
||||
) {
|
||||
CompositionLocalProvider(LocalViewConfiguration provides viewConfiguration) {
|
||||
val windowSizeClass = calculateWindowSizeClass(this)
|
||||
CompositionLocalProvider(
|
||||
LocalViewConfiguration provides viewConfiguration,
|
||||
LocalWindowSizeClass provides windowSizeClass,
|
||||
) {
|
||||
DestinationsNavHost(
|
||||
navGraph = NavGraphs.root,
|
||||
startRoute = navItems[Settings.launchPage].first,
|
||||
startRoute = if (Settings.needSignIn) {
|
||||
if (EhCookieStore.hasSignedIn()) SelectSiteScreenDestination else SignInScreenDestination
|
||||
} else {
|
||||
StartDestination
|
||||
},
|
||||
engine = rememberNavHostEngine(rootDefaultAnimations = ehNavAnim),
|
||||
navController = navController,
|
||||
)
|
||||
@@ -470,13 +475,6 @@ class MainActivity : EhActivity() {
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
if (Settings.needSignIn) {
|
||||
startActivity(Intent(this, ConfigureActivity::class.java))
|
||||
}
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
fun showTip(@StringRes id: Int, useToast: Boolean = false) {
|
||||
showTip(getString(id), useToast)
|
||||
}
|
||||
|
||||
@@ -55,8 +55,9 @@ import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.destinations.FinishDestination
|
||||
import com.hippo.ehviewer.ui.StartDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SelectSiteScreenDestination
|
||||
import com.hippo.ehviewer.ui.screen.popNavigate
|
||||
import com.hippo.ehviewer.ui.tools.LocalDialogState
|
||||
import com.hippo.ehviewer.ui.tools.LocalWindowSizeClass
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
@@ -123,7 +124,7 @@ fun CookieSignInScene(navigator: DestinationsNavigator) {
|
||||
EhEngine.getProfile()
|
||||
}.onSuccess {
|
||||
val canEx = withNonCancellableContext { postLogin() }
|
||||
withUIContext { navigator.navigate(if (canEx) SelectSiteScreenDestination else FinishDestination) }
|
||||
withUIContext { navigator.popNavigate(if (canEx) SelectSiteScreenDestination else StartDestination) }
|
||||
}.onFailure {
|
||||
EhCookieStore.signOut()
|
||||
dialogState.awaitPermissionOrCancel(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.hippo.ehviewer.ui.login
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -22,14 +20,14 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.ui.destinations.FinishDestination
|
||||
import com.hippo.ehviewer.ui.StartDestination
|
||||
import com.hippo.ehviewer.ui.screen.popNavigate
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
|
||||
@@ -37,11 +35,6 @@ import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
@Composable
|
||||
fun SelectSiteScreen(navigator: DestinationsNavigator) {
|
||||
var siteEx by remember { mutableStateOf(true) }
|
||||
val context = LocalContext.current
|
||||
|
||||
BackHandler {
|
||||
(context as Activity).moveTaskToBack(true)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.systemBarsPadding().padding(horizontal = dimensionResource(R.dimen.keyline_margin)).padding(top = dimensionResource(R.dimen.keyline_margin)).fillMaxSize(),
|
||||
@@ -71,7 +64,7 @@ fun SelectSiteScreen(navigator: DestinationsNavigator) {
|
||||
// Gallery site was set to ex in sad panda check
|
||||
if (!siteEx) Settings.gallerySite = EhUrl.SITE_E
|
||||
Settings.needSignIn = false
|
||||
navigator.navigate(FinishDestination)
|
||||
navigator.popNavigate(StartDestination)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.hippo.ehviewer.ui.login
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -61,21 +59,24 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.StartDestination
|
||||
import com.hippo.ehviewer.ui.destinations.CookieSignInSceneDestination
|
||||
import com.hippo.ehviewer.ui.destinations.FinishDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SelectSiteScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.WebViewSignInScreenDestination
|
||||
import com.hippo.ehviewer.ui.openBrowser
|
||||
import com.hippo.ehviewer.ui.screen.popNavigate
|
||||
import com.hippo.ehviewer.ui.tools.LocalDialogState
|
||||
import com.hippo.ehviewer.ui.tools.LocalWindowSizeClass
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootNavGraph
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
@RootNavGraph(start = true)
|
||||
@Destination
|
||||
@Composable
|
||||
fun SignInScreen(navigator: DestinationsNavigator) {
|
||||
@@ -92,10 +93,6 @@ fun SignInScreen(navigator: DestinationsNavigator) {
|
||||
var signInJob by remember { mutableStateOf<Job?>(null) }
|
||||
val dialogState = LocalDialogState.current
|
||||
|
||||
BackHandler {
|
||||
(context as Activity).moveTaskToBack(true)
|
||||
}
|
||||
|
||||
fun signIn() {
|
||||
if (signInJob?.isActive == true) return
|
||||
if (username.isEmpty()) {
|
||||
@@ -137,7 +134,7 @@ fun SignInScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
}.onSuccess {
|
||||
val canEx = withNonCancellableContext { postLogin() }
|
||||
withUIContext { navigator.navigate(if (canEx) SelectSiteScreenDestination else FinishDestination) }
|
||||
withUIContext { navigator.popNavigate(if (canEx) SelectSiteScreenDestination else StartDestination) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,7 +248,7 @@ fun SignInScreen(navigator: DestinationsNavigator) {
|
||||
onClick = {
|
||||
Settings.needSignIn = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
navigator.navigate(FinishDestination)
|
||||
navigator.popNavigate(StartDestination)
|
||||
},
|
||||
) {
|
||||
Text(
|
||||
@@ -347,7 +344,7 @@ fun SignInScreen(navigator: DestinationsNavigator) {
|
||||
onClick = {
|
||||
Settings.needSignIn = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
navigator.navigate(FinishDestination)
|
||||
navigator.popNavigate(StartDestination)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 4.dp),
|
||||
) {
|
||||
|
||||
@@ -14,8 +14,9 @@ import com.google.accompanist.web.rememberWebViewState
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.destinations.FinishDestination
|
||||
import com.hippo.ehviewer.ui.StartDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SelectSiteScreenDestination
|
||||
import com.hippo.ehviewer.ui.screen.popNavigate
|
||||
import com.hippo.ehviewer.util.setDefaultSettings
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
@@ -50,7 +51,7 @@ fun WebViewSignInScreen(navigator: DestinationsNavigator) {
|
||||
present = true
|
||||
coroutineScope.launchIO {
|
||||
val canEx = withNonCancellableContext { postLogin() }
|
||||
withUIContext { navigator.navigate(if (canEx) SelectSiteScreenDestination else FinishDestination) }
|
||||
withUIContext { navigator.popNavigate(if (canEx) SelectSiteScreenDestination else StartDestination) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.navigation.NavController
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser
|
||||
import com.hippo.ehviewer.client.parser.GalleryListUrlParser
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser
|
||||
import com.hippo.ehviewer.ui.NavGraphs
|
||||
import com.hippo.ehviewer.ui.destinations.GalleryDetailScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.ProgressScreenDestination
|
||||
@@ -29,6 +30,11 @@ fun DestinationsNavigator.navWithUrl(url: String): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun DestinationsNavigator.popNavigate(direction: Direction) = navigate(direction) {
|
||||
popUpTo(NavGraphs.root.route)
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun NavController.navWithUrl(url: String): Boolean {
|
||||
val dest = urlToDestination(url) ?: return false
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.hippo.ehviewer.ui.destinations.MyTagsScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.SignInScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.UConfigScreenDestination
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
import com.hippo.ehviewer.ui.screen.popNavigate
|
||||
import com.hippo.ehviewer.ui.tools.LocalDialogState
|
||||
import com.hippo.ehviewer.ui.tools.observed
|
||||
import com.hippo.ehviewer.ui.tools.rememberedAccessor
|
||||
@@ -118,7 +119,7 @@ fun EhScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
setPositiveButton(R.string.settings_eh_sign_out) { _, _ ->
|
||||
EhUtils.signOut()
|
||||
navigator.navigate(SignInScreenDestination)
|
||||
navigator.popNavigate(SignInScreenDestination)
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
+2
-5
@@ -25,23 +25,20 @@ import com.hippo.ehviewer.ui.destinations.AboutScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.AdvancedScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.DownloadScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.EhScreenDestination
|
||||
import com.hippo.ehviewer.ui.destinations.FinishDestination
|
||||
import com.hippo.ehviewer.ui.destinations.PrivacyScreenDestination
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootNavGraph
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
|
||||
@RootNavGraph(start = true)
|
||||
@Destination
|
||||
@Composable
|
||||
fun BaseScreen(navigator: DestinationsNavigator) {
|
||||
fun SettingsScreen(navigator: DestinationsNavigator) {
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(text = stringResource(id = R.string.settings)) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { navigator.navigate(FinishDestination) }) {
|
||||
IconButton(onClick = { navigator.navigateUp() }) {
|
||||
Icon(imageVector = Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
|
||||
}
|
||||
},
|
||||
Reference in new issue
Block a user