Fix logout of mangadex
This commit is contained in:
parent
1480829dd1
commit
b769043f36
@ -45,6 +45,7 @@ import exh.md.utils.MdUtil
|
|||||||
import exh.metadata.metadata.MangaDexSearchMetadata
|
import exh.metadata.metadata.MangaDexSearchMetadata
|
||||||
import exh.source.DelegatedHttpSource
|
import exh.source.DelegatedHttpSource
|
||||||
import exh.ui.metadata.adapters.MangaDexDescriptionAdapter
|
import exh.ui.metadata.adapters.MangaDexDescriptionAdapter
|
||||||
|
import kotlinx.coroutines.CancellationException
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -209,19 +210,10 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun logout(): Boolean {
|
override suspend fun logout(): Boolean {
|
||||||
val result = try {
|
val e = runCatching { loginHelper.logout() }.exceptionOrNull()
|
||||||
loginHelper.logout()
|
if (e is CancellationException) throw e
|
||||||
true
|
|
||||||
} catch (e: NoSessionException) {
|
|
||||||
true
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.message?.equals("HTTP error 405") ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (result) {
|
|
||||||
mdList.logout()
|
mdList.logout()
|
||||||
true
|
return true
|
||||||
} else false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun fetchAllFollows(): List<Pair<SManga, MangaDexSearchMetadata>> {
|
override suspend fun fetchAllFollows(): List<Pair<SManga, MangaDexSearchMetadata>> {
|
||||||
|
@ -416,10 +416,6 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ClearDatabaseDialogController : DialogController() {
|
class ClearDatabaseDialogController : DialogController() {
|
||||||
// SY -->
|
|
||||||
var keepReadManga = false
|
|
||||||
// SY <--
|
|
||||||
|
|
||||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||||
val item = arrayOf(
|
val item = arrayOf(
|
||||||
activity!!.getString(R.string.clear_db_exclude_read)
|
activity!!.getString(R.string.clear_db_exclude_read)
|
||||||
@ -427,6 +423,7 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
val selected = booleanArrayOf(true)
|
val selected = booleanArrayOf(true)
|
||||||
return MaterialAlertDialogBuilder(activity!!)
|
return MaterialAlertDialogBuilder(activity!!)
|
||||||
.setMessage(R.string.clear_database_confirmation)
|
.setMessage(R.string.clear_database_confirmation)
|
||||||
|
// SY -->
|
||||||
.setMultiChoiceItems(item, selected) { _, _, isChecked ->
|
.setMultiChoiceItems(item, selected) { _, _, isChecked ->
|
||||||
selected[0] = isChecked
|
selected[0] = isChecked
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import exh.md.dto.LoginRequestDto
|
|||||||
import exh.md.dto.RefreshTokenDto
|
import exh.md.dto.RefreshTokenDto
|
||||||
import exh.md.service.MangaDexAuthService
|
import exh.md.service.MangaDexAuthService
|
||||||
import exh.md.utils.MdUtil
|
import exh.md.utils.MdUtil
|
||||||
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
|
|
||||||
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
||||||
@ -30,6 +31,10 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
|||||||
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
|
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
|
||||||
preferences.trackToken(mdList).set(MdUtil.jsonParser.encodeToString(jsonResponse.token))
|
preferences.trackToken(mdList).set(MdUtil.jsonParser.encodeToString(jsonResponse.token))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val e = refresh.exceptionOrNull()
|
||||||
|
if (e is CancellationException) throw e
|
||||||
|
|
||||||
return refresh.isSuccess
|
return refresh.isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +46,9 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
|||||||
val loginRequest = LoginRequestDto(username, password)
|
val loginRequest = LoginRequestDto(username, password)
|
||||||
val loginResult = runCatching { authService.login(loginRequest) }
|
val loginResult = runCatching { authService.login(loginRequest) }
|
||||||
|
|
||||||
|
val e = loginResult.exceptionOrNull()
|
||||||
|
if (e is CancellationException) throw e
|
||||||
|
|
||||||
val loginResponseDto = loginResult.getOrNull()
|
val loginResponseDto = loginResult.getOrNull()
|
||||||
MdUtil.updateLoginToken(
|
MdUtil.updateLoginToken(
|
||||||
loginResponseDto?.token,
|
loginResponseDto?.token,
|
||||||
|
@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.source.SourceManager
|
|||||||
import eu.kanade.tachiyomi.source.online.LoginSource
|
import eu.kanade.tachiyomi.source.online.LoginSource
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import exh.log.xLogW
|
import exh.log.xLogW
|
||||||
import exh.source.getMainSource
|
import exh.source.getMainSource
|
||||||
@ -107,7 +108,7 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
|||||||
)
|
)
|
||||||
if (result) {
|
if (result) {
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
launchUI {
|
withUIContext {
|
||||||
binding.root.context.toast(R.string.login_success)
|
binding.root.context.toast(R.string.login_success)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,11 +8,13 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.source.online.LoginSource
|
||||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchNow
|
import eu.kanade.tachiyomi.util.lang.launchNow
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import exh.source.getMainSource
|
import exh.source.getMainSource
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
@ -23,7 +25,7 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
|
|
||||||
class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
||||||
|
|
||||||
val source = Injekt.get<SourceManager>().get(args.getLong("key", 0))?.getMainSource() as? MangaDex
|
val source = Injekt.get<SourceManager>().get(args.getLong("key", 0))?.getMainSource() as? LoginSource
|
||||||
|
|
||||||
val trackManager: TrackManager by injectLazy()
|
val trackManager: TrackManager by injectLazy()
|
||||||
|
|
||||||
@ -40,29 +42,21 @@ class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
|||||||
launchNow {
|
launchNow {
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
var exception: Exception? = null
|
val loggedOut = withIOContext {
|
||||||
val loggedOut = try {
|
source.logout()
|
||||||
withIOContext { source.logout() }
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (e is CancellationException) throw e
|
|
||||||
exception = e
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loggedOut) {
|
if (loggedOut) {
|
||||||
trackManager.mdList.logout()
|
withUIContext {
|
||||||
activity?.toast(R.string.logout_success)
|
activity?.toast(R.string.logout_success)
|
||||||
|
}
|
||||||
(targetController as? Listener)?.siteLogoutDialogClosed(source)
|
(targetController as? Listener)?.siteLogoutDialogClosed(source)
|
||||||
} else {
|
} else {
|
||||||
launchUI {
|
withUIContext {
|
||||||
if (exception != null) {
|
|
||||||
activity?.toast(exception.message)
|
|
||||||
} else {
|
|
||||||
activity?.toast(R.string.unknown_error)
|
activity?.toast(R.string.unknown_error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else withUIContext { activity?.toast("Mangadex not enabled") }
|
||||||
} else launchUI { activity?.toast("Mangadex not enabled") }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user