mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 22:59:18 +01:00
Add tracker logout dialog (closes #2475)
This commit is contained in:
parent
1b3169e0d0
commit
98f86a44ef
@ -8,16 +8,18 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
import eu.kanade.tachiyomi.data.track.TrackService
|
import eu.kanade.tachiyomi.data.track.TrackService
|
||||||
import eu.kanade.tachiyomi.data.track.anilist.AnilistApi
|
import eu.kanade.tachiyomi.data.track.anilist.AnilistApi
|
||||||
import eu.kanade.tachiyomi.data.track.shikimori.ShikimoriApi
|
|
||||||
import eu.kanade.tachiyomi.data.track.bangumi.BangumiApi
|
import eu.kanade.tachiyomi.data.track.bangumi.BangumiApi
|
||||||
|
import eu.kanade.tachiyomi.data.track.shikimori.ShikimoriApi
|
||||||
import eu.kanade.tachiyomi.util.getResourceColor
|
import eu.kanade.tachiyomi.util.getResourceColor
|
||||||
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.TrackLoginDialog
|
import eu.kanade.tachiyomi.widget.preference.TrackLoginDialog
|
||||||
|
import eu.kanade.tachiyomi.widget.preference.TrackLogoutDialog
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||||
|
|
||||||
class SettingsTrackingController : SettingsController(),
|
class SettingsTrackingController : SettingsController(),
|
||||||
TrackLoginDialog.Listener {
|
TrackLoginDialog.Listener,
|
||||||
|
TrackLogoutDialog.Listener {
|
||||||
|
|
||||||
private val trackManager: TrackManager by injectLazy()
|
private val trackManager: TrackManager by injectLazy()
|
||||||
|
|
||||||
@ -33,57 +35,57 @@ class SettingsTrackingController : SettingsController(),
|
|||||||
titleRes = R.string.services
|
titleRes = R.string.services
|
||||||
|
|
||||||
trackPreference(trackManager.myAnimeList) {
|
trackPreference(trackManager.myAnimeList) {
|
||||||
onClick {
|
val dialog = TrackLoginDialog(trackManager.myAnimeList)
|
||||||
val dialog = TrackLoginDialog(trackManager.myAnimeList)
|
dialog.targetController = this@SettingsTrackingController
|
||||||
dialog.targetController = this@SettingsTrackingController
|
dialog.showDialog(router)
|
||||||
dialog.showDialog(router)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trackPreference(trackManager.aniList) {
|
trackPreference(trackManager.aniList) {
|
||||||
onClick {
|
val tabsIntent = CustomTabsIntent.Builder()
|
||||||
val tabsIntent = CustomTabsIntent.Builder()
|
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
||||||
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
.build()
|
||||||
.build()
|
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
||||||
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
tabsIntent.launchUrl(activity!!, AnilistApi.authUrl())
|
||||||
tabsIntent.launchUrl(activity!!, AnilistApi.authUrl())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trackPreference(trackManager.kitsu) {
|
trackPreference(trackManager.kitsu) {
|
||||||
onClick {
|
val dialog = TrackLoginDialog(trackManager.kitsu)
|
||||||
val dialog = TrackLoginDialog(trackManager.kitsu)
|
dialog.targetController = this@SettingsTrackingController
|
||||||
dialog.targetController = this@SettingsTrackingController
|
dialog.showDialog(router)
|
||||||
dialog.showDialog(router)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trackPreference(trackManager.shikimori) {
|
trackPreference(trackManager.shikimori) {
|
||||||
onClick {
|
val tabsIntent = CustomTabsIntent.Builder()
|
||||||
val tabsIntent = CustomTabsIntent.Builder()
|
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
||||||
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
.build()
|
||||||
.build()
|
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
||||||
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
tabsIntent.launchUrl(activity!!, ShikimoriApi.authUrl())
|
||||||
tabsIntent.launchUrl(activity!!, ShikimoriApi.authUrl())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trackPreference(trackManager.bangumi) {
|
trackPreference(trackManager.bangumi) {
|
||||||
onClick {
|
val tabsIntent = CustomTabsIntent.Builder()
|
||||||
val tabsIntent = CustomTabsIntent.Builder()
|
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
||||||
.setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
.build()
|
||||||
.build()
|
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
||||||
tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
tabsIntent.launchUrl(activity!!, BangumiApi.authUrl())
|
||||||
tabsIntent.launchUrl(activity!!, BangumiApi.authUrl())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun PreferenceScreen.trackPreference(
|
private inline fun PreferenceScreen.trackPreference(
|
||||||
service: TrackService,
|
service: TrackService,
|
||||||
block: (@DSL LoginPreference).() -> Unit
|
crossinline login: () -> Unit
|
||||||
): LoginPreference {
|
): LoginPreference {
|
||||||
return initThenAdd(LoginPreference(context).apply {
|
return initThenAdd(LoginPreference(context).apply {
|
||||||
key = Keys.trackUsername(service.id)
|
key = Keys.trackUsername(service.id)
|
||||||
title = service.name
|
title = service.name
|
||||||
}, block)
|
}, {
|
||||||
|
onClick {
|
||||||
|
if (service.isLogged) {
|
||||||
|
val dialog = TrackLogoutDialog(service)
|
||||||
|
dialog.targetController = this@SettingsTrackingController
|
||||||
|
dialog.showDialog(router)
|
||||||
|
} else {
|
||||||
|
login()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
override fun onActivityResumed(activity: Activity) {
|
||||||
@ -100,7 +102,11 @@ class SettingsTrackingController : SettingsController(),
|
|||||||
pref?.notifyChanged()
|
pref?.notifyChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun trackDialogClosed(service: TrackService) {
|
override fun trackLoginDialogClosed(service: TrackService) {
|
||||||
|
updatePreference(service.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun trackLogoutDialogClosed(service: TrackService) {
|
||||||
updatePreference(service.id)
|
updatePreference(service.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,11 +51,11 @@ class TrackLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
|
|||||||
|
|
||||||
override fun onDialogClosed() {
|
override fun onDialogClosed() {
|
||||||
super.onDialogClosed()
|
super.onDialogClosed()
|
||||||
(targetController as? Listener)?.trackDialogClosed(service)
|
(targetController as? Listener)?.trackLoginDialogClosed(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
fun trackDialogClosed(service: TrackService)
|
fun trackLoginDialogClosed(service: TrackService)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package eu.kanade.tachiyomi.widget.preference
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.os.Bundle
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
|
import eu.kanade.tachiyomi.data.track.TrackService
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
|
import eu.kanade.tachiyomi.util.toast
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
|
class TrackLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
||||||
|
|
||||||
|
private val service = Injekt.get<TrackManager>().getService(args.getInt("key"))!!
|
||||||
|
|
||||||
|
constructor(service: TrackService) : this(Bundle().apply { putInt("key", service.id) })
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||||
|
return MaterialDialog.Builder(activity!!)
|
||||||
|
.title(activity!!.getString(R.string.logout_title, service.name))
|
||||||
|
.positiveText(R.string.logout)
|
||||||
|
.onPositive { _, _ ->
|
||||||
|
service.logout()
|
||||||
|
(targetController as? Listener)?.trackLogoutDialogClosed(service)
|
||||||
|
activity?.toast(R.string.logout_success)
|
||||||
|
}
|
||||||
|
.negativeText(android.R.string.cancel)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Listener {
|
||||||
|
fun trackLogoutDialogClosed(service: TrackService)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -315,6 +315,9 @@
|
|||||||
<string name="show_password">Show password</string>
|
<string name="show_password">Show password</string>
|
||||||
<string name="login">Login</string>
|
<string name="login">Login</string>
|
||||||
<string name="login_success">Successfully logged in</string>
|
<string name="login_success">Successfully logged in</string>
|
||||||
|
<string name="logout_title">Logout from %1$s?</string>
|
||||||
|
<string name="logout">Logout</string>
|
||||||
|
<string name="logout_success">You are now logged out</string>
|
||||||
<string name="invalid_login">Could not log in</string>
|
<string name="invalid_login">Could not log in</string>
|
||||||
<string name="unknown_error">Unknown error</string>
|
<string name="unknown_error">Unknown error</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user