mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
fetch servers from github
This commit is contained in:
parent
dfab644ae2
commit
641dd5f290
@ -54,4 +54,5 @@ dependencies {
|
|||||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||||
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'
|
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.1'
|
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.1'
|
||||||
|
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
|
||||||
}
|
}
|
@ -52,5 +52,7 @@ interface PipedApi {
|
|||||||
@POST("unsubscribe")
|
@POST("unsubscribe")
|
||||||
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): String
|
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): String
|
||||||
|
|
||||||
|
@GET("Instances.md")
|
||||||
|
suspend fun getInstances(): String
|
||||||
|
|
||||||
}
|
}
|
@ -2,29 +2,91 @@ package com.github.libretube
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.PreferenceManager
|
||||||
import okhttp3.HttpUrl
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
|
import retrofit2.HttpException
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.jackson.JacksonConverterFactory
|
import retrofit2.converter.jackson.JacksonConverterFactory
|
||||||
|
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class Settings : PreferenceFragmentCompat() {
|
class Settings : PreferenceFragmentCompat() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.settings, rootKey)
|
setPreferencesFromResource(R.xml.settings, rootKey)
|
||||||
val instance = findPreference<ListPreference>("instance")
|
val instance = findPreference<ListPreference>("instance")
|
||||||
|
fetchInstance()
|
||||||
instance?.setOnPreferenceChangeListener { preference, newValue ->
|
instance?.setOnPreferenceChangeListener { preference, newValue ->
|
||||||
RetrofitInstance.url=newValue.toString()
|
RetrofitInstance.url = newValue.toString()
|
||||||
RetrofitInstance.lazyMgr.reset()
|
RetrofitInstance.lazyMgr.reset()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
val login = findPreference<Preference>("login_register")
|
val login = findPreference<Preference>("login_register")
|
||||||
login?.setOnPreferenceClickListener {
|
login?.setOnPreferenceClickListener {
|
||||||
val newFragment = LoginDialog()
|
val newFragment = LoginDialog()
|
||||||
newFragment.show(childFragmentManager,"fuck")
|
newFragment.show(childFragmentManager, "fuck")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
val response = try {
|
||||||
|
api.getInstances()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
println(e)
|
||||||
|
Log.e("settings", "IOException, you might not have internet connection")
|
||||||
|
return@launchWhenCreated
|
||||||
|
} catch (e: HttpException) {
|
||||||
|
Log.e("settings", "HttpException, unexpected response ${e.toString()}")
|
||||||
|
return@launchWhenCreated
|
||||||
|
} catch (e: Exception){
|
||||||
|
Log.e("settings",e.toString())
|
||||||
|
return@launchWhenCreated
|
||||||
|
}
|
||||||
|
//println("dafaq $response")
|
||||||
|
val listEntries: MutableList<String> = ArrayList()
|
||||||
|
val listEntryValues: MutableList<String> = ArrayList()
|
||||||
|
var skipped = 0
|
||||||
|
val lines = response.split("\n")
|
||||||
|
for(line in lines) {
|
||||||
|
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 entryValues = listEntryValues.toTypedArray<CharSequence>()
|
||||||
|
runOnUiThread {
|
||||||
|
val instance = findPreference<ListPreference>("instance")
|
||||||
|
instance?.entries = entries
|
||||||
|
instance?.entryValues = entryValues
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||||
|
this ?: return
|
||||||
|
if (!isAdded) return // Fragment not attached to an Activity
|
||||||
|
activity?.runOnUiThread(action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string-array name="instances">
|
<string-array name="instances">
|
||||||
<item>piped.tokhmi.xyz</item>
|
<item>kavin.rocks (Official)</item>
|
||||||
<item>piped.kavin.rocks</item>
|
<item>silkky.cloud</item>
|
||||||
|
<item>tokhmi.xyz</item>
|
||||||
|
<item>moomoo.me</item>
|
||||||
|
<item>mint.lgbt</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="instancesValue">
|
<string-array name="instancesValue">
|
||||||
<item>https://pipedapi.tokhmi.xyz/</item>
|
|
||||||
<item>https://pipedapi.kavin.rocks/</item>
|
<item>https://pipedapi.kavin.rocks/</item>
|
||||||
|
<item>https://api.piped.silkky.cloud</item>
|
||||||
|
<item>https://pipedapi.tokhmi.xyz/</item>
|
||||||
|
<item>https://pipedapi.moomoo.me</item>
|
||||||
|
<item>https://pa.mint.lgbt</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="regions">
|
<string-array name="regions">
|
||||||
<item>Afghanistan</item>
|
<item>Afghanistan</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user