mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
feat: display currently selected instance as grayed out if not available
This commit is contained in:
parent
4180ddee61
commit
214aded22f
@ -9,8 +9,8 @@ import retrofit2.create
|
|||||||
|
|
||||||
object RetrofitInstance {
|
object RetrofitInstance {
|
||||||
private const val PIPED_API_URL = "https://pipedapi.kavin.rocks"
|
private const val PIPED_API_URL = "https://pipedapi.kavin.rocks"
|
||||||
private val url get() = PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, PIPED_API_URL)
|
val apiUrl get() = PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, PIPED_API_URL)
|
||||||
private val authUrl
|
val authUrl
|
||||||
get() = when (
|
get() = when (
|
||||||
PreferenceHelper.getBoolean(
|
PreferenceHelper.getBoolean(
|
||||||
PreferenceKeys.AUTH_INSTANCE_TOGGLE,
|
PreferenceKeys.AUTH_INSTANCE_TOGGLE,
|
||||||
@ -21,7 +21,7 @@ object RetrofitInstance {
|
|||||||
PreferenceKeys.AUTH_INSTANCE,
|
PreferenceKeys.AUTH_INSTANCE,
|
||||||
PIPED_API_URL
|
PIPED_API_URL
|
||||||
)
|
)
|
||||||
false -> url
|
false -> apiUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
val lazyMgr = resettableManager()
|
val lazyMgr = resettableManager()
|
||||||
@ -30,7 +30,7 @@ object RetrofitInstance {
|
|||||||
|
|
||||||
val api by resettableLazy(lazyMgr) {
|
val api by resettableLazy(lazyMgr) {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(url)
|
.baseUrl(apiUrl)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
.addConverterFactory(kotlinxConverterFactory)
|
.addConverterFactory(kotlinxConverterFactory)
|
||||||
.build()
|
.build()
|
||||||
@ -48,7 +48,7 @@ object RetrofitInstance {
|
|||||||
|
|
||||||
val externalApi by resettableLazy(lazyMgr) {
|
val externalApi by resettableLazy(lazyMgr) {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(url)
|
.baseUrl(apiUrl)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
.addConverterFactory(kotlinxConverterFactory)
|
.addConverterFactory(kotlinxConverterFactory)
|
||||||
.build()
|
.build()
|
||||||
|
@ -19,5 +19,6 @@ data class PipedInstance(
|
|||||||
@SerialName("registration_disabled") val registrationDisabled: Boolean = false,
|
@SerialName("registration_disabled") val registrationDisabled: Boolean = false,
|
||||||
@SerialName("uptime_24h") val uptimeToday: Float? = null,
|
@SerialName("uptime_24h") val uptimeToday: Float? = null,
|
||||||
@SerialName("uptime_7d") val uptimeWeek: Float? = null,
|
@SerialName("uptime_7d") val uptimeWeek: Float? = null,
|
||||||
@SerialName("uptime_30d") val uptimeMonth: Float? = null
|
@SerialName("uptime_30d") val uptimeMonth: Float? = null,
|
||||||
|
val isCurrentlyDown: Boolean = false,
|
||||||
)
|
)
|
||||||
|
@ -42,6 +42,8 @@ class InstancesAdapter(
|
|||||||
}
|
}
|
||||||
radioButton.text = instanceText
|
radioButton.text = instanceText
|
||||||
|
|
||||||
|
radioButton.alpha = if (instance.isCurrentlyDown) 0.5f else 1f
|
||||||
|
|
||||||
radioButton.setOnCheckedChangeListener(null)
|
radioButton.setOnCheckedChangeListener(null)
|
||||||
radioButton.isChecked = selectedInstanceIndex == position
|
radioButton.isChecked = selectedInstanceIndex == position
|
||||||
radioButton.setOnCheckedChangeListener { _, isChecked ->
|
radioButton.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
@ -29,11 +29,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
|
|
||||||
class InstanceSettings : BasePreferenceFragment() {
|
class InstanceSettings : BasePreferenceFragment() {
|
||||||
override val titleResourceId: Int = R.string.instance
|
override val titleResourceId: Int = R.string.instance
|
||||||
private val token get() = PreferenceHelper.getToken()
|
private val token get() = PreferenceHelper.getToken()
|
||||||
private var instances = listOf<PipedInstance>()
|
private var instances = mutableListOf<PipedInstance>()
|
||||||
private val authInstanceToggle get() = findPreference<SwitchPreferenceCompat>(PreferenceKeys.AUTH_INSTANCE_TOGGLE)!!
|
private val authInstanceToggle get() = findPreference<SwitchPreferenceCompat>(PreferenceKeys.AUTH_INSTANCE_TOGGLE)!!
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
@ -138,9 +140,18 @@ class InstanceSettings : BasePreferenceFragment() {
|
|||||||
Database.customInstanceDao().getAll()
|
Database.customInstanceDao().getAll()
|
||||||
}.map { PipedInstance(it.name, it.apiUrl) }
|
}.map { PipedInstance(it.name, it.apiUrl) }
|
||||||
|
|
||||||
instances = publicInstances
|
instances = publicInstances.plus(customInstances).toMutableList()
|
||||||
.plus(customInstances)
|
|
||||||
.sortedBy { it.name }
|
// add the currently used instances to the list if they're currently down / not part
|
||||||
|
// of the public instances list
|
||||||
|
for (apiUrl in listOf(RetrofitInstance.apiUrl, RetrofitInstance.authUrl)) {
|
||||||
|
if (instances.none { it.apiUrl == apiUrl }) {
|
||||||
|
val origin = apiUrl.toHttpUrl().host
|
||||||
|
instances.add(PipedInstance(origin, apiUrl, isCurrentlyDown = true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instances.sortBy { it.name }
|
||||||
|
|
||||||
// If any preference dialog is visible in this fragment, it's one of the instance selection
|
// If any preference dialog is visible in this fragment, it's one of the instance selection
|
||||||
// dialogs. In order to prevent UX issues, we don't update the instances list then.
|
// dialogs. In order to prevent UX issues, we don't update the instances list then.
|
||||||
|
Loading…
Reference in New Issue
Block a user