diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index d119f1860a..dd589b990f 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -20,7 +20,6 @@ import android.text.format.DateUtils import android.text.method.LinkMovementMethod import android.text.util.Linkify import android.util.Base64 -import android.util.Log import android.view.View import android.widget.TextView import android.widget.Toast @@ -49,7 +48,6 @@ import com.github.libretube.api.obj.PipedStream import com.github.libretube.api.obj.Segment import com.github.libretube.api.obj.StreamItem import com.github.libretube.api.obj.Streams -import com.github.libretube.api.obj.Token import com.github.libretube.constants.IntentData import com.github.libretube.constants.PreferenceKeys import com.github.libretube.databinding.FragmentPlayerBinding @@ -58,7 +56,6 @@ import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.db.obj.WatchPosition import com.github.libretube.enums.PlayerEvent import com.github.libretube.enums.ShareObjectType -import com.github.libretube.extensions.TAG import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.hideKeyboard diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 7df7983998..54a0398592 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -24,12 +24,12 @@ import com.github.libretube.extensions.TAG import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.dpToPx import com.github.libretube.extensions.query +import com.github.libretube.extensions.serializable import com.github.libretube.extensions.toID import com.github.libretube.helpers.ImageHelper import com.github.libretube.helpers.NavigationHelper import com.github.libretube.ui.adapters.PlaylistAdapter import com.github.libretube.ui.base.BaseFragment -import com.github.libretube.extensions.serializable import com.github.libretube.ui.models.PlayerViewModel import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet import com.github.libretube.util.PlayingQueue diff --git a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt index 7bcd0c6ba7..e7e0043c6d 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt @@ -33,10 +33,15 @@ class InstanceSettings : BasePreferenceFragment() { setPreferencesFromResource(R.xml.instance_settings, rootKey) val instancePref = findPreference(PreferenceKeys.FETCH_INSTANCE)!! - initCustomInstances(instancePref) + val authInstanceToggle = findPreference( + PreferenceKeys.AUTH_INSTANCE_TOGGLE + )!! + val authInstance = findPreference(PreferenceKeys.AUTH_INSTANCE)!! + initInstancesPref(listOf(instancePref, authInstance)) + instancePref.setOnPreferenceChangeListener { _, newValue -> RetrofitInstance.url = newValue.toString() - if (!PreferenceHelper.getBoolean(PreferenceKeys.AUTH_INSTANCE_TOGGLE, false)) { + if (!authInstanceToggle.isChecked) { RetrofitInstance.authUrl = newValue.toString() logoutAndUpdateUI() } @@ -45,12 +50,8 @@ class InstanceSettings : BasePreferenceFragment() { true } - val authInstance = findPreference(PreferenceKeys.AUTH_INSTANCE) - initCustomInstances(authInstance!!) // hide auth instance if option deselected - if (!PreferenceHelper.getBoolean(PreferenceKeys.AUTH_INSTANCE_TOGGLE, false)) { - authInstance.isVisible = false - } + authInstance.isVisible = authInstanceToggle.isChecked authInstance.setOnPreferenceChangeListener { _, newValue -> // save new auth url RetrofitInstance.authUrl = newValue.toString() @@ -59,9 +60,7 @@ class InstanceSettings : BasePreferenceFragment() { true } - val authInstanceToggle = - findPreference(PreferenceKeys.AUTH_INSTANCE_TOGGLE) - authInstanceToggle?.setOnPreferenceChangeListener { _, newValue -> + authInstanceToggle.setOnPreferenceChangeListener { _, newValue -> authInstance.isVisible = newValue == true // either use new auth url or the normal api url if auth instance disabled RetrofitInstance.authUrl = if (newValue == false) { @@ -121,7 +120,7 @@ class InstanceSettings : BasePreferenceFragment() { } } - private fun initCustomInstances(instancePref: ListPreference) { + private fun initInstancesPref(instancePrefs: List) { val appContext = requireContext().applicationContext lifecycleScope.launchWhenCreated { val customInstances = withContext(Dispatchers.IO) { @@ -148,13 +147,15 @@ class InstanceSettings : BasePreferenceFragment() { instances.addAll(customInstances.map { Instances(it.name, it.apiUrl) }) runOnUiThread { - // add custom instances to the list preference - instancePref.entries = instances.map { it.name }.toTypedArray() - instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray() - instancePref.summaryProvider = - Preference.SummaryProvider { preference -> - preference.entry - } + for (instancePref in instancePrefs) { + // add custom instances to the list preference + instancePref.entries = instances.map { it.name }.toTypedArray() + instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray() + instancePref.summaryProvider = + Preference.SummaryProvider { preference -> + preference.entry + } + } } } }