|
@@ -8,16 +8,18 @@ import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
|
|
import eu.kanade.tachiyomi.data.track.TrackService
|
|
|
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.shikimori.ShikimoriApi
|
|
|
import eu.kanade.tachiyomi.util.getResourceColor
|
|
|
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
|
|
import eu.kanade.tachiyomi.widget.preference.TrackLoginDialog
|
|
|
+import eu.kanade.tachiyomi.widget.preference.TrackLogoutDialog
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
|
|
|
|
|
class SettingsTrackingController : SettingsController(),
|
|
|
- TrackLoginDialog.Listener {
|
|
|
+ TrackLoginDialog.Listener,
|
|
|
+ TrackLogoutDialog.Listener {
|
|
|
|
|
|
private val trackManager: TrackManager by injectLazy()
|
|
|
|
|
@@ -33,57 +35,57 @@ class SettingsTrackingController : SettingsController(),
|
|
|
titleRes = R.string.services
|
|
|
|
|
|
trackPreference(trackManager.myAnimeList) {
|
|
|
- onClick {
|
|
|
- val dialog = TrackLoginDialog(trackManager.myAnimeList)
|
|
|
- dialog.targetController = this@SettingsTrackingController
|
|
|
- dialog.showDialog(router)
|
|
|
- }
|
|
|
+ val dialog = TrackLoginDialog(trackManager.myAnimeList)
|
|
|
+ dialog.targetController = this@SettingsTrackingController
|
|
|
+ dialog.showDialog(router)
|
|
|
}
|
|
|
trackPreference(trackManager.aniList) {
|
|
|
- onClick {
|
|
|
- val tabsIntent = CustomTabsIntent.Builder()
|
|
|
- .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
- .build()
|
|
|
- tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
- tabsIntent.launchUrl(activity!!, AnilistApi.authUrl())
|
|
|
- }
|
|
|
+ val tabsIntent = CustomTabsIntent.Builder()
|
|
|
+ .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
+ .build()
|
|
|
+ tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
+ tabsIntent.launchUrl(activity!!, AnilistApi.authUrl())
|
|
|
}
|
|
|
trackPreference(trackManager.kitsu) {
|
|
|
- onClick {
|
|
|
- val dialog = TrackLoginDialog(trackManager.kitsu)
|
|
|
- dialog.targetController = this@SettingsTrackingController
|
|
|
- dialog.showDialog(router)
|
|
|
- }
|
|
|
+ val dialog = TrackLoginDialog(trackManager.kitsu)
|
|
|
+ dialog.targetController = this@SettingsTrackingController
|
|
|
+ dialog.showDialog(router)
|
|
|
}
|
|
|
trackPreference(trackManager.shikimori) {
|
|
|
- onClick {
|
|
|
- val tabsIntent = CustomTabsIntent.Builder()
|
|
|
- .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
- .build()
|
|
|
- tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
- tabsIntent.launchUrl(activity!!, ShikimoriApi.authUrl())
|
|
|
- }
|
|
|
+ val tabsIntent = CustomTabsIntent.Builder()
|
|
|
+ .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
+ .build()
|
|
|
+ tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
+ tabsIntent.launchUrl(activity!!, ShikimoriApi.authUrl())
|
|
|
}
|
|
|
trackPreference(trackManager.bangumi) {
|
|
|
- onClick {
|
|
|
- val tabsIntent = CustomTabsIntent.Builder()
|
|
|
- .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
- .build()
|
|
|
- tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
- tabsIntent.launchUrl(activity!!, BangumiApi.authUrl())
|
|
|
- }
|
|
|
+ val tabsIntent = CustomTabsIntent.Builder()
|
|
|
+ .setToolbarColor(context.getResourceColor(R.attr.colorPrimary))
|
|
|
+ .build()
|
|
|
+ tabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
+ tabsIntent.launchUrl(activity!!, BangumiApi.authUrl())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- inline fun PreferenceScreen.trackPreference(
|
|
|
+ private inline fun PreferenceScreen.trackPreference(
|
|
|
service: TrackService,
|
|
|
- block: (@DSL LoginPreference).() -> Unit
|
|
|
+ crossinline login: () -> Unit
|
|
|
): LoginPreference {
|
|
|
return initThenAdd(LoginPreference(context).apply {
|
|
|
key = Keys.trackUsername(service.id)
|
|
|
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) {
|
|
@@ -100,7 +102,11 @@ class SettingsTrackingController : SettingsController(),
|
|
|
pref?.notifyChanged()
|
|
|
}
|
|
|
|
|
|
- override fun trackDialogClosed(service: TrackService) {
|
|
|
+ override fun trackLoginDialogClosed(service: TrackService) {
|
|
|
+ updatePreference(service.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun trackLogoutDialogClosed(service: TrackService) {
|
|
|
updatePreference(service.id)
|
|
|
}
|
|
|
|