From 03cd871d02e9486121a3ae31b6572a36cad9481a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 21 Feb 2023 11:28:37 +0100 Subject: [PATCH] Fix that kavin.rocks is not shown as selected by default --- .../github/libretube/constants/Constants.kt | 4 ++-- .../ui/preferences/InstanceSettings.kt | 17 ++++++++++++---- app/src/main/res/values/array.xml | 20 +++++++++---------- app/src/main/res/xml/instance_settings.xml | 4 ++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/github/libretube/constants/Constants.kt b/app/src/main/java/com/github/libretube/constants/Constants.kt index 1b3d36c96..9846851c7 100644 --- a/app/src/main/java/com/github/libretube/constants/Constants.kt +++ b/app/src/main/java/com/github/libretube/constants/Constants.kt @@ -33,8 +33,8 @@ const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" /** * Retrofit Instance */ -const val PIPED_API_URL = "https://pipedapi.kavin.rocks/" -const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks/" +const val PIPED_API_URL = "https://pipedapi.kavin.rocks" +const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks" const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz" /** 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 e7e0043c6..f4de53566 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 @@ -122,6 +122,19 @@ class InstanceSettings : BasePreferenceFragment() { private fun initInstancesPref(instancePrefs: List) { val appContext = requireContext().applicationContext + + instancePrefs.forEach { instancePref -> + if (instancePref.entry.isNullOrBlank()) { + instancePref.value = context?.resources?.getStringArray(R.array.instancesValue)?.first().orEmpty() + } + + instancePref.summaryProvider = + Preference.SummaryProvider { preference -> + preference.entry.takeIf { !it.isNullOrBlank() } + ?: context?.resources?.getStringArray(R.array.instances)?.first().orEmpty() + } + } + lifecycleScope.launchWhenCreated { val customInstances = withContext(Dispatchers.IO) { Database.customInstanceDao().getAll() @@ -151,10 +164,6 @@ class InstanceSettings : BasePreferenceFragment() { // 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 - } } } } diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 125ff938b..b2e364c43 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -13,16 +13,16 @@ privacy.com.de - https://pipedapi.kavin.rocks/ - https://pipedapi.tokhmi.xyz/ - https://pipedapi.moomoo.me/ - https://pa.mint.lgbt/ - https://pa.il.ax/ - https://pipedapi.syncpundit.com/ - https://api-piped.mha.fi/ - https://api-piped.shimul.me/ - https://api.yt.jae.fi/ - https://piped-api.privacy.com.de/ + https://pipedapi.kavin.rocks + https://pipedapi.tokhmi.xyz + https://pipedapi.moomoo.me + https://pa.mint.lgbt + https://pa.il.ax + https://pipedapi.syncpundit.com + https://api-piped.mha.fi + https://api-piped.shimul.me + https://api.yt.jae.fi + https://piped-api.privacy.com.de diff --git a/app/src/main/res/xml/instance_settings.xml b/app/src/main/res/xml/instance_settings.xml index b22176484..89dbc5b63 100644 --- a/app/src/main/res/xml/instance_settings.xml +++ b/app/src/main/res/xml/instance_settings.xml @@ -6,7 +6,7 @@