Use typesafe request
This commit is contained in:
1 parent
06e9ff6fcf
commit
94a8b78d1a
3 files changed
+10
-17
No files matched your search
@@ -49,16 +49,14 @@ import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.client.EhClient.METHOD_GET_PROFILE
|
||||
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.LoginActivity.Companion.SELECT_SITE_ROUTE_NAME
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.Cookie
|
||||
@@ -105,7 +103,7 @@ fun CookieSignInScene(navController: NavController) {
|
||||
}
|
||||
|
||||
fun login() {
|
||||
signInJob?.cancel()
|
||||
if (signInJob?.isActive == true) return
|
||||
if (ipbMemberId.isBlank()) {
|
||||
ipbMemberIdErrorState = true
|
||||
return
|
||||
@@ -123,18 +121,16 @@ fun CookieSignInScene(navController: NavController) {
|
||||
isProgressIndicatorVisible = true
|
||||
signInJob = coroutineScope.launchIO {
|
||||
runCatching {
|
||||
EhClient.execute(METHOD_GET_PROFILE)
|
||||
EhEngine.getProfile()
|
||||
}.onSuccess {
|
||||
withUIContext {
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
}
|
||||
}.onFailure {
|
||||
EhApplication.ehCookieStore.signOut()
|
||||
if (it !is CancellationException) {
|
||||
loginErrorException = it
|
||||
showErrorDialog = true
|
||||
isProgressIndicatorVisible = false
|
||||
}
|
||||
loginErrorException = it
|
||||
showErrorDialog = true
|
||||
isProgressIndicatorVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,8 @@ import androidx.compose.ui.unit.dp
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.parser.ProfileParser
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
||||
@@ -135,7 +134,7 @@ fun SelectSiteScreen(finish: () -> Unit) {
|
||||
|
||||
suspend fun getProfile() {
|
||||
runCatching {
|
||||
(EhClient.execute(EhClient.METHOD_GET_PROFILE) as ProfileParser.Result).run {
|
||||
EhEngine.getProfile().run {
|
||||
Settings.putDisplayName(displayName)
|
||||
Settings.putAvatar(avatar)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ import androidx.navigation.NavController
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.UrlOpener
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.LoginActivity.Companion.COOKIE_SIGN_IN_ROUTE_NAME
|
||||
@@ -104,9 +104,7 @@ fun SignInScreen(navController: NavController) {
|
||||
EhUtils.signOut()
|
||||
signInJob = coroutineScope.launchIO {
|
||||
runCatching {
|
||||
(EhClient.execute(EhClient.METHOD_SIGN_IN, username, password) as String).let {
|
||||
Settings.putDisplayName(it)
|
||||
}
|
||||
EhEngine.signIn(username, password)
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
withUIContext {
|
||||
|
||||
Reference in new issue
Block a user