From 9dc66c7c8d6280afecc01e64ca24a3899a36105e Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 4 Aug 2023 10:35:47 -0400 Subject: [PATCH] Combine tracking OAuth login activities --- app/src/main/AndroidManifest.xml | 59 +++------------- .../ui/setting/track/AnilistLoginActivity.kt | 22 ------ .../ui/setting/track/BangumiLoginActivity.kt | 21 ------ .../setting/track/MyAnimeListLoginActivity.kt | 21 ------ .../setting/track/ShikimoriLoginActivity.kt | 21 ------ .../ui/setting/track/TrackLoginActivity.kt | 70 +++++++++++++++++++ i18n/src/main/res/values/strings.xml | 1 + 7 files changed, 80 insertions(+), 135 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/AnilistLoginActivity.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/BangumiLoginActivity.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/MyAnimeListLoginActivity.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/ShikimoriLoginActivity.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5eefefd44..3e3eca0b8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -124,8 +124,8 @@ android:exported="false" /> @@ -133,54 +133,12 @@ - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + @@ -210,7 +168,8 @@ android:name=".data.updater.AppUpdateService" android:exported="false" /> - handleAnilist(data) + "bangumi-auth" -> handleBangumi(data) + "myanimelist-auth" -> handleMyAnimeList(data) + "shikimori-auth" -> handleShikimori(data) + } + } + + private fun handleAnilist(data: Uri) { + val regex = "(?:access_token=)(.*?)(?:&)".toRegex() + val matchResult = regex.find(data.fragment.toString()) + if (matchResult?.groups?.get(1) != null) { + lifecycleScope.launchIO { + trackManager.aniList.login(matchResult.groups[1]!!.value) + returnToSettings() + } + } else { + trackManager.aniList.logout() + returnToSettings() + } + } + + private fun handleBangumi(data: Uri) { + val code = data.getQueryParameter("code") + if (code != null) { + lifecycleScope.launchIO { + trackManager.bangumi.login(code) + returnToSettings() + } + } else { + trackManager.bangumi.logout() + returnToSettings() + } + } + + private fun handleMyAnimeList(data: Uri) { + val code = data.getQueryParameter("code") + if (code != null) { + lifecycleScope.launchIO { + trackManager.myAnimeList.login(code) + returnToSettings() + } + } else { + trackManager.myAnimeList.logout() + returnToSettings() + } + } + + private fun handleShikimori(data: Uri) { + val code = data.getQueryParameter("code") + if (code != null) { + lifecycleScope.launchIO { + trackManager.shikimori.login(code) + returnToSettings() + } + } else { + trackManager.shikimori.logout() + returnToSettings() + } + } +} diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 596de0f94..4ae199538 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -462,6 +462,7 @@ Available but source not installed: %s Services that provide enhanced features for specific sources. Entries are automatically tracked when added to your library. Track + Tracking login Hide entries already in library