From 1b0d10183f0739d03d520d34591e575f146c6712 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 23 Sep 2024 22:49:16 +0200 Subject: [PATCH] fixed bug in nextcloud auth --- .../podcini/net/sync/nextcloud/NextcloudLoginFlow.kt | 10 +++++++++- .../fragments/SynchronizationPreferencesFragment.kt | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/ac/mdiq/podcini/net/sync/nextcloud/NextcloudLoginFlow.kt b/app/src/main/kotlin/ac/mdiq/podcini/net/sync/nextcloud/NextcloudLoginFlow.kt index b054fa92..6d52c231 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/net/sync/nextcloud/NextcloudLoginFlow.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/net/sync/nextcloud/NextcloudLoginFlow.kt @@ -22,6 +22,7 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo private val hostname = HostnameParser(rawHostUrl) private var token: String? = null private var endpoint: String? = null + private var isWaitingForBrowser:Boolean = false fun saveInstanceState(): ArrayList { val state = ArrayList() @@ -51,7 +52,7 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo withContext(Dispatchers.Main) { val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(result)) context.startActivity(browserIntent) - poll() + isWaitingForBrowser = true } } catch (e: Throwable) { Log.e(TAG, Log.getStackTraceString(e)) @@ -79,6 +80,13 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo throw RuntimeException("Maximum retries exceeded") } + fun onResume(){ //trigger poll only when returning from the browser + if (token != null && isWaitingForBrowser){ + poll() + isWaitingForBrowser = false + } + } + private fun poll() { CoroutineScope(Dispatchers.IO).launch { try { diff --git a/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/SynchronizationPreferencesFragment.kt b/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/SynchronizationPreferencesFragment.kt index 3f56cf42..d936d6f4 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/SynchronizationPreferencesFragment.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/SynchronizationPreferencesFragment.kt @@ -285,6 +285,8 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() { } override fun onResume() { super.onResume() + nextcloudLoginFlow?.onResume() + if (shouldDismiss) dismiss() } override fun onNextcloudAuthenticated(server: String, username: String, password: String) {