Merge pull request #3145 from Bnyro/master

Fix that kavin.rocks is not shown as selected by default
This commit is contained in:
Bnyro 2023-02-21 11:29:17 +01:00 committed by GitHub
commit 23ba2f2503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 18 deletions

View File

@ -33,8 +33,8 @@ const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
/** /**
* Retrofit Instance * Retrofit Instance
*/ */
const val PIPED_API_URL = "https://pipedapi.kavin.rocks/" const val PIPED_API_URL = "https://pipedapi.kavin.rocks"
const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks/" const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks"
const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz" const val FALLBACK_INSTANCES_URL = "https://instances.tokhmi.xyz"
/** /**

View File

@ -122,6 +122,19 @@ class InstanceSettings : BasePreferenceFragment() {
private fun initInstancesPref(instancePrefs: List<ListPreference>) { private fun initInstancesPref(instancePrefs: List<ListPreference>) {
val appContext = requireContext().applicationContext 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<ListPreference> { preference ->
preference.entry.takeIf { !it.isNullOrBlank() }
?: context?.resources?.getStringArray(R.array.instances)?.first().orEmpty()
}
}
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val customInstances = withContext(Dispatchers.IO) { val customInstances = withContext(Dispatchers.IO) {
Database.customInstanceDao().getAll() Database.customInstanceDao().getAll()
@ -151,10 +164,6 @@ class InstanceSettings : BasePreferenceFragment() {
// add custom instances to the list preference // add custom instances to the list preference
instancePref.entries = instances.map { it.name }.toTypedArray() instancePref.entries = instances.map { it.name }.toTypedArray()
instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray() instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray()
instancePref.summaryProvider =
Preference.SummaryProvider<ListPreference> { preference ->
preference.entry
}
} }
} }
} }

View File

@ -13,16 +13,16 @@
<item>privacy.com.de</item> <item>privacy.com.de</item>
</string-array> </string-array>
<string-array name="instancesValue"> <string-array name="instancesValue">
<item>https://pipedapi.kavin.rocks/</item> <item>https://pipedapi.kavin.rocks</item>
<item>https://pipedapi.tokhmi.xyz/</item> <item>https://pipedapi.tokhmi.xyz</item>
<item>https://pipedapi.moomoo.me/</item> <item>https://pipedapi.moomoo.me</item>
<item>https://pa.mint.lgbt/</item> <item>https://pa.mint.lgbt</item>
<item>https://pa.il.ax/</item> <item>https://pa.il.ax</item>
<item>https://pipedapi.syncpundit.com/</item> <item>https://pipedapi.syncpundit.com</item>
<item>https://api-piped.mha.fi/</item> <item>https://api-piped.mha.fi</item>
<item>https://api-piped.shimul.me/</item> <item>https://api-piped.shimul.me</item>
<item>https://api.yt.jae.fi/</item> <item>https://api.yt.jae.fi</item>
<item>https://piped-api.privacy.com.de/</item> <item>https://piped-api.privacy.com.de</item>
</string-array> </string-array>
<string-array name="languages"> <string-array name="languages">

View File

@ -6,7 +6,7 @@
<ListPreference <ListPreference
android:icon="@drawable/ic_server" android:icon="@drawable/ic_server"
app:defaultValue="https://pipedapi.kavin.rocks/" app:defaultValue="https://pipedapi.kavin.rocks"
app:entries="@array/instances" app:entries="@array/instances"
app:entryValues="@array/instancesValue" app:entryValues="@array/instancesValue"
app:key="selectInstance" app:key="selectInstance"
@ -32,7 +32,7 @@
<ListPreference <ListPreference
android:icon="@drawable/ic_server" android:icon="@drawable/ic_server"
app:defaultValue="https://pipedapi.kavin.rocks/" app:defaultValue="https://pipedapi.kavin.rocks"
app:entries="@array/instances" app:entries="@array/instances"
app:entryValues="@array/instancesValue" app:entryValues="@array/instancesValue"
app:key="selectAuthInstance" app:key="selectAuthInstance"