mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
change fetch instances
This commit is contained in:
parent
ae713e3ef1
commit
bd77249443
@ -53,7 +53,7 @@ interface PipedApi {
|
|||||||
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): Message
|
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): Message
|
||||||
|
|
||||||
//only for fetching servers list
|
//only for fetching servers list
|
||||||
@GET("Instances.md")
|
@GET
|
||||||
suspend fun getInstances(): String
|
suspend fun getInstances(@Url url: String): List<Instances>
|
||||||
|
|
||||||
}
|
}
|
@ -48,16 +48,9 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchInstance() {
|
private fun fetchInstance() {
|
||||||
val api: PipedApi by lazy{
|
|
||||||
Retrofit.Builder()
|
|
||||||
.baseUrl("https://raw.githubusercontent.com/wiki/TeamPiped/Piped-Frontend/")
|
|
||||||
.addConverterFactory(ScalarsConverterFactory.create())
|
|
||||||
.build()
|
|
||||||
.create(PipedApi::class.java)
|
|
||||||
}
|
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
api.getInstances()
|
RetrofitInstance.api.getInstances("https://instances.tokhmi.xyz/")
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
Log.e("settings", "IOException, you might not have internet connection")
|
Log.e("settings", "IOException, you might not have internet connection")
|
||||||
@ -72,20 +65,9 @@ class Settings : PreferenceFragmentCompat() {
|
|||||||
//println("dafaq $response")
|
//println("dafaq $response")
|
||||||
val listEntries: MutableList<String> = ArrayList()
|
val listEntries: MutableList<String> = ArrayList()
|
||||||
val listEntryValues: MutableList<String> = ArrayList()
|
val listEntryValues: MutableList<String> = ArrayList()
|
||||||
var skipped = 0
|
for(item in response){
|
||||||
val lines = response.split("\n")
|
listEntries.add(item.name!!)
|
||||||
for(line in lines) {
|
listEntryValues.add(item.api_url!!)
|
||||||
val split = line.split("|")
|
|
||||||
if (split.size == 5) {
|
|
||||||
if (skipped < 2) {
|
|
||||||
skipped++
|
|
||||||
}else{
|
|
||||||
println("dafaq $line")
|
|
||||||
listEntries.add(split[0])
|
|
||||||
listEntryValues.add(split[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
val entries = listEntries.toTypedArray<CharSequence>()
|
val entries = listEntries.toTypedArray<CharSequence>()
|
||||||
val entryValues = listEntryValues.toTypedArray<CharSequence>()
|
val entryValues = listEntryValues.toTypedArray<CharSequence>()
|
||||||
|
12
app/src/main/java/com/github/libretube/obj/Instances.kt
Normal file
12
app/src/main/java/com/github/libretube/obj/Instances.kt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.github.libretube.obj
|
||||||
|
|
||||||
|
data class Instances(
|
||||||
|
var name: String? = null,
|
||||||
|
var api_url: String? = null,
|
||||||
|
var locations: String? = null,
|
||||||
|
var version: String? = null,
|
||||||
|
var up_to_date: Boolean? = null,
|
||||||
|
var cdn: Boolean? = null,
|
||||||
|
var registered: Long? = null,
|
||||||
|
var last_checked: Long? = null
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user