mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30: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 xyz.btcland.libretube.obj.StreamItem
|
||||
import xyz.btcland.libretube.obj.Streams
|
||||
import xyz.btcland.libretube.obj.SearchResult
|
||||
|
||||
interface PipedApi {
|
||||
@GET("trending")
|
||||
@ -16,8 +17,8 @@ interface PipedApi {
|
||||
@GET("search")
|
||||
suspend fun getSearchResults(
|
||||
@Query("q") searchQuery: String,
|
||||
@Query("filter") filer: String
|
||||
): List<StreamItem>
|
||||
@Query("filter") filter: String
|
||||
): SearchResult
|
||||
|
||||
@GET("suggestions")
|
||||
suspend fun getSuggestions(@Query("query") query: String): List<String>
|
||||
|
@ -6,7 +6,7 @@ import retrofit2.converter.jackson.JacksonConverterFactory
|
||||
object RetrofitInstance {
|
||||
val api: PipedApi by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl("https://piped-api.alefvanoon.xyz/")
|
||||
.baseUrl("https://pipedapi.tokhmi.xyz/")
|
||||
.addConverterFactory(JacksonConverterFactory.create())
|
||||
.build()
|
||||
.create(PipedApi::class.java)
|
||||
|
@ -11,6 +11,9 @@ import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.AutoCompleteTextView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
@ -61,11 +64,13 @@ class SearchFragment : Fragment() {
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
if(s!! != ""){
|
||||
println(s.toString())
|
||||
fetchSuggestions(s.toString(), autoTextView)
|
||||
}
|
||||
|
||||
GlobalScope.launch {
|
||||
fetchSuggestions(s.toString(), autoTextView)
|
||||
delay(2000)
|
||||
fetchSearch(s.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
||||
@ -94,7 +99,21 @@ class SearchFragment : Fragment() {
|
||||
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 {
|
||||
/**
|
||||
* 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
|
||||
|
||||
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(
|
||||
var url: 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