From cf6a0e2937c34629e8841876a30b7a1c0b86101d Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 3 Jul 2022 11:39:25 +0200 Subject: [PATCH] comments --- .../java/com/github/libretube/activities/MainActivity.kt | 1 + .../main/java/com/github/libretube/dialogs/LoginDialog.kt | 1 - .../com/github/libretube/preferences/InstanceSettings.kt | 7 ++++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 9072dbf3d..ccabdb1dc 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -61,6 +61,7 @@ class MainActivity : AppCompatActivity() { RetrofitInstance.url = PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!! + // set auth instance RetrofitInstance.authUrl = if (PreferenceHelper.getBoolean(this, "auth_instance_toggle", false)) { PreferenceHelper.getString( diff --git a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt index e689890f6..ed86ccef6 100644 --- a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt @@ -69,7 +69,6 @@ class LoginDialog : DialogFragment() { private fun login(login: Login) { fun run() { lifecycleScope.launchWhenCreated { - Log.e(TAG, RetrofitInstance.authUrl) val response = try { RetrofitInstance.authApi.login(login) } catch (e: IOException) { diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 5a7c8da70..bad5cad27 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -34,7 +34,6 @@ import java.io.IOException import java.io.InputStream import java.util.zip.ZipEntry import java.util.zip.ZipInputStream -import kotlin.math.log class InstanceSettings : PreferenceFragmentCompat() { val TAG = "InstanceSettings" @@ -62,8 +61,8 @@ class InstanceSettings : PreferenceFragmentCompat() { val jsonObject = JSONTokener(json).nextValue() as JSONObject Log.e(TAG, jsonObject.getJSONArray("subscriptions").toString()) for ( - i in 0 until jsonObject.getJSONArray("subscriptions") - .length() + i in 0 until jsonObject.getJSONArray("subscriptions") + .length() ) { var url = jsonObject.getJSONArray("subscriptions").getJSONObject(i) @@ -138,6 +137,7 @@ class InstanceSettings : PreferenceFragmentCompat() { } authInstance.setOnPreferenceChangeListener { _, newValue -> requireMainActivityRestart = true + // save new auth url RetrofitInstance.authUrl = newValue.toString() RetrofitInstance.lazyMgr.reset() logout() @@ -149,6 +149,7 @@ class InstanceSettings : PreferenceFragmentCompat() { requireMainActivityRestart = true authInstance.isVisible = newValue == true logout() + // either use new auth url or the normal api url if auth instance disabled RetrofitInstance.authUrl = if (newValue == false) RetrofitInstance.url else authInstance.value true