mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
commit
0fead06f01
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.adapters
|
package com.github.libretube.adapters
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
@ -6,5 +6,5 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
|||||||
data class ChapterSegment(
|
data class ChapterSegment(
|
||||||
var title: String? = null,
|
var title: String? = null,
|
||||||
var image: String? = null,
|
var image: String? = null,
|
||||||
var start: Long? = null
|
var start: Long? = null
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ data class SearchItem(
|
|||||||
var uploadedDate: String? = null,
|
var uploadedDate: String? = null,
|
||||||
var duration: Long? = null,
|
var duration: Long? = null,
|
||||||
var views: Long? = null,
|
var views: Long? = null,
|
||||||
var uploaderVerified: Boolean? = null,
|
var uploaderVerified: Boolean? = null,
|
||||||
// Channel and Playlist attributes
|
// Channel and Playlist attributes
|
||||||
var name: String? = null,
|
var name: String? = null,
|
||||||
var description: String? = null,
|
var description: String? = null,
|
||||||
|
@ -7,4 +7,4 @@ data class Segment(
|
|||||||
val actionType: String? = null,
|
val actionType: String? = null,
|
||||||
val category: String? = null,
|
val category: String? = null,
|
||||||
val segment: List<Float>? = arrayListOf()
|
val segment: List<Float>? = arrayListOf()
|
||||||
)
|
)
|
||||||
|
@ -16,4 +16,4 @@ data class StreamItem(
|
|||||||
var uploaderVerified: Boolean? = null,
|
var uploaderVerified: Boolean? = null,
|
||||||
var uploaded: Long? = null,
|
var uploaded: Long? = null,
|
||||||
var shortDescription: String? = null
|
var shortDescription: String? = null
|
||||||
)
|
)
|
||||||
|
@ -9,4 +9,4 @@ data class Subtitle(
|
|||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val code: String? = null,
|
val code: String? = null,
|
||||||
val autoGenerated: Boolean? = null
|
val autoGenerated: Boolean? = null
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,6 @@ import android.content.ContentResolver
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.TextUtils
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
@ -211,27 +210,43 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initCustomInstances(instancePref: ListPreference) {
|
private fun initCustomInstances(instancePref: ListPreference) {
|
||||||
val customInstances = PreferenceHelper.getCustomInstances()
|
lifecycleScope.launchWhenCreated {
|
||||||
|
val customInstances = PreferenceHelper.getCustomInstances()
|
||||||
|
|
||||||
var instanceNames = resources.getStringArray(R.array.instances)
|
var instanceNames = arrayListOf<String>()
|
||||||
var instanceValues = resources.getStringArray(R.array.instancesValue)
|
var instanceValues = arrayListOf<String>()
|
||||||
customInstances.forEach { instance ->
|
|
||||||
instanceNames += instance.name
|
|
||||||
instanceValues += instance.apiUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
// add custom instances to the list preference
|
// fetch official public instances
|
||||||
instancePref.entries = instanceNames
|
|
||||||
instancePref.entryValues = instanceValues
|
val response = try {
|
||||||
instancePref.summaryProvider =
|
RetrofitInstance.api.getInstances("https://instances.tokhmi.xyz/")
|
||||||
Preference.SummaryProvider<ListPreference> { preference ->
|
} catch (e: Exception) {
|
||||||
val text = preference.entry
|
e.printStackTrace()
|
||||||
if (TextUtils.isEmpty(text)) {
|
emptyList()
|
||||||
"kavin.rocks (Official)"
|
}
|
||||||
} else {
|
|
||||||
text
|
response.forEach {
|
||||||
|
if (it.name != null && it.api_url != null) {
|
||||||
|
instanceNames += it.name!!
|
||||||
|
instanceValues += it.api_url!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customInstances.forEach { instance ->
|
||||||
|
instanceNames += instance.name
|
||||||
|
instanceValues += instance.apiUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
|
// add custom instances to the list preference
|
||||||
|
instancePref.entries = instanceNames.toTypedArray()
|
||||||
|
instancePref.entryValues = instanceValues.toTypedArray()
|
||||||
|
instancePref.summaryProvider =
|
||||||
|
Preference.SummaryProvider<ListPreference> { preference ->
|
||||||
|
preference.entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logout() {
|
private fun logout() {
|
||||||
@ -239,49 +254,6 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
Toast.makeText(context, getString(R.string.loggedout), Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, getString(R.string.loggedout), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchInstance() {
|
|
||||||
lifecycleScope.launchWhenCreated {
|
|
||||||
val response = try {
|
|
||||||
RetrofitInstance.api.getInstances("https://instances.tokhmi.xyz/")
|
|
||||||
} 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")
|
|
||||||
return@launchWhenCreated
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("settings", e.toString())
|
|
||||||
return@launchWhenCreated
|
|
||||||
}
|
|
||||||
val listEntries: MutableList<String> = ArrayList()
|
|
||||||
val listEntryValues: MutableList<String> = ArrayList()
|
|
||||||
for (item in response) {
|
|
||||||
listEntries.add(item.name!!)
|
|
||||||
listEntryValues.add(item.api_url!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
// add custom instances to the list
|
|
||||||
|
|
||||||
val entries = listEntries.toTypedArray<CharSequence>()
|
|
||||||
val entryValues = listEntryValues.toTypedArray<CharSequence>()
|
|
||||||
runOnUiThread {
|
|
||||||
val instance = findPreference<ListPreference>("selectInstance")
|
|
||||||
instance?.entries = entries
|
|
||||||
instance?.entryValues = entryValues
|
|
||||||
instance?.summaryProvider =
|
|
||||||
Preference.SummaryProvider<ListPreference> { preference ->
|
|
||||||
val text = preference.entry
|
|
||||||
if (TextUtils.isEmpty(text)) {
|
|
||||||
"kavin.rocks (Official)"
|
|
||||||
} else {
|
|
||||||
text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||||
this ?: return
|
this ?: return
|
||||||
if (!isAdded) return // Fragment not attached to an Activity
|
if (!isAdded) return // Fragment not attached to an Activity
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.update
|
package com.github.libretube.update
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.github.libretube.GITHUB_API_URL
|
import com.github.libretube.GITHUB_API_URL
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
Loading…
Reference in New Issue
Block a user