mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
searchitem object
This commit is contained in:
parent
21d29ad4af
commit
30c4aa3794
@ -5,6 +5,7 @@ import retrofit2.http.Path
|
|||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
||||||
import xyz.btcland.libretube.obj.StreamItem
|
import xyz.btcland.libretube.obj.StreamItem
|
||||||
import xyz.btcland.libretube.obj.Streams
|
import xyz.btcland.libretube.obj.Streams
|
||||||
|
import xyz.btcland.libretube.obj.SearchResult
|
||||||
|
|
||||||
interface PipedApi {
|
interface PipedApi {
|
||||||
@GET("trending")
|
@GET("trending")
|
||||||
@ -16,8 +17,8 @@ interface PipedApi {
|
|||||||
@GET("search")
|
@GET("search")
|
||||||
suspend fun getSearchResults(
|
suspend fun getSearchResults(
|
||||||
@Query("q") searchQuery: String,
|
@Query("q") searchQuery: String,
|
||||||
@Query("filter") filer: String
|
@Query("filter") filter: String
|
||||||
): List<StreamItem>
|
): SearchResult
|
||||||
|
|
||||||
@GET("suggestions")
|
@GET("suggestions")
|
||||||
suspend fun getSuggestions(@Query("query") query: String): List<String>
|
suspend fun getSuggestions(@Query("query") query: String): List<String>
|
||||||
|
@ -6,7 +6,7 @@ import retrofit2.converter.jackson.JacksonConverterFactory
|
|||||||
object RetrofitInstance {
|
object RetrofitInstance {
|
||||||
val api: PipedApi by lazy {
|
val api: PipedApi by lazy {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl("https://piped-api.alefvanoon.xyz/")
|
.baseUrl("https://pipedapi.tokhmi.xyz/")
|
||||||
.addConverterFactory(JacksonConverterFactory.create())
|
.addConverterFactory(JacksonConverterFactory.create())
|
||||||
.build()
|
.build()
|
||||||
.create(PipedApi::class.java)
|
.create(PipedApi::class.java)
|
||||||
|
@ -11,6 +11,9 @@ import android.view.ViewGroup
|
|||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.AutoCompleteTextView
|
import android.widget.AutoCompleteTextView
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@ -61,11 +64,13 @@ class SearchFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
if(s!! != ""){
|
if(s!! != ""){
|
||||||
println(s.toString())
|
GlobalScope.launch {
|
||||||
fetchSuggestions(s.toString(), autoTextView)
|
fetchSuggestions(s.toString(), autoTextView)
|
||||||
}
|
delay(2000)
|
||||||
|
fetchSearch(s.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
|
||||||
@ -94,7 +99,21 @@ class SearchFragment : Fragment() {
|
|||||||
autoTextView.setAdapter(adapter)
|
autoTextView.setAdapter(adapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun fetchSearch(query: String){
|
||||||
|
lifecycleScope.launchWhenCreated {
|
||||||
|
val response = try {
|
||||||
|
RetrofitInstance.api.getSearchResults(query, "all")
|
||||||
|
} catch (e: IOException) {
|
||||||
|
println(e)
|
||||||
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
|
return@launchWhenCreated
|
||||||
|
} catch (e: HttpException) {
|
||||||
|
Log.e(TAG, "HttpException, unexpected response")
|
||||||
|
return@launchWhenCreated
|
||||||
|
}
|
||||||
|
print(response!!.items!![0])
|
||||||
|
}
|
||||||
|
}
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Use this factory method to create a new instance of
|
* Use this factory method to create a new instance of
|
||||||
|
22
app/src/main/java/xyz/btcland/libretube/obj/SearchItem.kt
Normal file
22
app/src/main/java/xyz/btcland/libretube/obj/SearchItem.kt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.btcland.libretube.obj
|
||||||
|
|
||||||
|
data class SearchItem(
|
||||||
|
var url: String?,
|
||||||
|
var title: String?,
|
||||||
|
var thumbnail: String?,
|
||||||
|
var uploaderName: String?,
|
||||||
|
var uploaderUrl: String?,
|
||||||
|
var uploaderAvatar: String?,
|
||||||
|
var uploadedDate: String?,
|
||||||
|
var duration: Long?,
|
||||||
|
var views: Long?,
|
||||||
|
var uploaderVerified: Boolean?,
|
||||||
|
//Channel and Playlist attributes
|
||||||
|
var name: String? = null,
|
||||||
|
var description: String? = null,
|
||||||
|
var subscribers: Long? = -1,
|
||||||
|
var videos: Long? = -1,
|
||||||
|
var verified: Boolean? = null
|
||||||
|
){
|
||||||
|
constructor() : this("","","","","","","",0,0,null)
|
||||||
|
}
|
10
app/src/main/java/xyz/btcland/libretube/obj/SearchResult.kt
Normal file
10
app/src/main/java/xyz/btcland/libretube/obj/SearchResult.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package xyz.btcland.libretube.obj
|
||||||
|
|
||||||
|
import xyz.btcland.libretube.obj.StreamItem
|
||||||
|
|
||||||
|
data class SearchResult(
|
||||||
|
val items: List<SearchItem>? = listOf(),
|
||||||
|
val nextpage: String? ="",
|
||||||
|
val suggestion: String?="",
|
||||||
|
val corrected: Boolean? = null
|
||||||
|
)
|
@ -1,15 +1,5 @@
|
|||||||
package xyz.btcland.libretube.obj
|
package xyz.btcland.libretube.obj
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo
|
|
||||||
import xyz.btcland.libretube.obj.search.SearchChannel
|
|
||||||
import xyz.btcland.libretube.obj.search.SearchPlaylist
|
|
||||||
|
|
||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
|
|
||||||
@JsonSubTypes(value =[
|
|
||||||
JsonSubTypes.Type(SearchChannel::class),
|
|
||||||
JsonSubTypes.Type(SearchPlaylist::class)
|
|
||||||
])
|
|
||||||
data class StreamItem(
|
data class StreamItem(
|
||||||
var url: String?,
|
var url: String?,
|
||||||
var title: String?,
|
var title: String?,
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package xyz.btcland.libretube.obj.search
|
|
||||||
|
|
||||||
data class SearchChannel(
|
|
||||||
var name: String? = null,
|
|
||||||
var thumbnail: String? = null,
|
|
||||||
var url: String? = null,
|
|
||||||
var description: String? = null,
|
|
||||||
var subscribers: Long? = -1,
|
|
||||||
var videos: Long? = -1,
|
|
||||||
var verified: Boolean? = null
|
|
||||||
)
|
|
@ -1,10 +0,0 @@
|
|||||||
package xyz.btcland.libretube.obj.search
|
|
||||||
|
|
||||||
data class SearchPlaylist(
|
|
||||||
var name: String? = null,
|
|
||||||
var thumbnail: String? = null,
|
|
||||||
var url: String? = null,
|
|
||||||
var uploaderName: String? =null,
|
|
||||||
var videos: Long = -1
|
|
||||||
|
|
||||||
)
|
|
Loading…
x
Reference in New Issue
Block a user