mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
VideoViews global
This commit is contained in:
parent
bed29896d7
commit
f5aebe4b13
@ -64,7 +64,7 @@ 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!! != ""){
|
||||||
GlobalScope.launch {
|
lifecycleScope.launchWhenCreated {
|
||||||
fetchSuggestions(s.toString(), autoTextView)
|
fetchSuggestions(s.toString(), autoTextView)
|
||||||
delay(2000)
|
delay(2000)
|
||||||
fetchSearch(s.toString())
|
fetchSearch(s.toString())
|
||||||
@ -111,7 +111,9 @@ class SearchFragment : Fragment() {
|
|||||||
Log.e(TAG, "HttpException, unexpected response")
|
Log.e(TAG, "HttpException, unexpected response")
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
print(response!!.items!![0])
|
if(response.items!!.isNotEmpty()){
|
||||||
|
print(response!!.items!![0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package xyz.btcland.libretube
|
package xyz.btcland.libretube
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -11,8 +10,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import xyz.btcland.libretube.obj.StreamItem
|
import xyz.btcland.libretube.obj.StreamItem
|
||||||
import java.math.BigDecimal
|
|
||||||
import java.math.RoundingMode
|
|
||||||
|
|
||||||
class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Adapter<CustomViewHolder>() {
|
class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Adapter<CustomViewHolder>() {
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
@ -28,7 +25,7 @@ class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Ada
|
|||||||
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
|
||||||
val trending = videoFeed[position]
|
val trending = videoFeed[position]
|
||||||
holder.v.findViewById<TextView>(R.id.textView_title).text = trending.title
|
holder.v.findViewById<TextView>(R.id.textView_title).text = trending.title
|
||||||
holder.v.findViewById<TextView>(R.id.textView_channel).text = trending.uploaderName +" • "+ videoViews(trending.views)+" • "+trending.uploadedDate
|
holder.v.findViewById<TextView>(R.id.textView_channel).text = trending.uploaderName +" • "+ trending.views.videoViews()+" • "+trending.uploadedDate
|
||||||
val thumbnailImage = holder.v.findViewById<ImageView>(R.id.thumbnail)
|
val thumbnailImage = holder.v.findViewById<ImageView>(R.id.thumbnail)
|
||||||
val channelImage = holder.v.findViewById<ImageView>(R.id.channel_image)
|
val channelImage = holder.v.findViewById<ImageView>(R.id.channel_image)
|
||||||
channelImage.setOnClickListener{
|
channelImage.setOnClickListener{
|
||||||
@ -57,23 +54,4 @@ class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Ada
|
|||||||
class CustomViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
class CustomViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||||
init {
|
init {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun videoViews(views: Long?): String{
|
|
||||||
when {
|
|
||||||
views!!<1000 -> {
|
|
||||||
return views.toString()
|
|
||||||
}
|
|
||||||
views in 1000..999999 -> {
|
|
||||||
val decimal = BigDecimal(views/1000).setScale(0, RoundingMode.HALF_EVEN)
|
|
||||||
return decimal.toString()+"K"
|
|
||||||
}
|
|
||||||
views in 1000000..10000000 -> {
|
|
||||||
val decimal = BigDecimal(views/1000000).setScale(0, RoundingMode.HALF_EVEN)
|
|
||||||
return decimal.toString()+"M"
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
val decimal = BigDecimal(views/1000000).setScale(0, RoundingMode.HALF_EVEN)
|
|
||||||
return decimal.toString()+"M"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
22
app/src/main/java/xyz/btcland/libretube/VideoViews.kt
Normal file
22
app/src/main/java/xyz/btcland/libretube/VideoViews.kt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.btcland.libretube
|
||||||
|
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.math.RoundingMode
|
||||||
|
|
||||||
|
fun Long?.videoViews(): String = when {
|
||||||
|
this!!<1000 -> {
|
||||||
|
this.toString()
|
||||||
|
}
|
||||||
|
this in 1000..999999 -> {
|
||||||
|
val decimal = BigDecimal(this/1000).setScale(0, RoundingMode.HALF_EVEN)
|
||||||
|
decimal.toString()+"K"
|
||||||
|
}
|
||||||
|
this in 1000000..10000000 -> {
|
||||||
|
val decimal = BigDecimal(this/1000000).setScale(0, RoundingMode.HALF_EVEN)
|
||||||
|
decimal.toString()+"M"
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val decimal = BigDecimal(this/1000000).setScale(0, RoundingMode.HALF_EVEN)
|
||||||
|
decimal.toString()+"M"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user