mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
channel fragment done
This commit is contained in:
parent
42760f76c2
commit
8782a4af38
@ -9,6 +9,9 @@ import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.adapters.ChannelAdapter
|
||||
import com.github.libretube.adapters.TrendingAdapter
|
||||
import com.squareup.picasso.Picasso
|
||||
import retrofit2.HttpException
|
||||
@ -26,6 +29,8 @@ class ChannelFragment : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var channel_id: String? = null
|
||||
private val TAG = "ChannelFragment"
|
||||
lateinit var recyclerView: RecyclerView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
@ -45,6 +50,8 @@ class ChannelFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
channel_id = channel_id!!.replace("/channel/","")
|
||||
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
||||
recyclerView = view.findViewById(R.id.channel_recView)
|
||||
recyclerView.layoutManager = GridLayoutManager(view.context, 1)
|
||||
fetchChannel(view)
|
||||
}
|
||||
|
||||
@ -69,6 +76,7 @@ class ChannelFragment : Fragment() {
|
||||
val channelImage = view.findViewById<ImageView>(R.id.channel_image)
|
||||
Picasso.get().load(response.bannerUrl).into(bannerImage)
|
||||
Picasso.get().load(response.avatarUrl).into(channelImage)
|
||||
recyclerView.adapter = ChannelAdapter(response.relatedStreams!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.MainActivity
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.github.libretube.PlayerFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.StreamItem
|
||||
import com.github.libretube.videoViews
|
||||
|
||||
class ChannelAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Adapter<ChannelViewHolder>() {
|
||||
override fun getItemCount(): Int {
|
||||
return videoFeed.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val cell = layoutInflater.inflate(R.layout.video_channel_row,parent,false)
|
||||
return ChannelViewHolder(cell)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
holder.v.findViewById<TextView>(R.id.channel_description).text = trending.title
|
||||
holder.v.findViewById<TextView>(R.id.channel_views).text = trending.views.videoViews()+" • "+trending.uploadedDate
|
||||
val thumbnailImage = holder.v.findViewById<ImageView>(R.id.channel_thumbnail)
|
||||
Picasso.get().load(trending.thumbnail).into(thumbnailImage)
|
||||
holder.v.setOnClickListener{
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId",trending.url!!.replace("/watch?v=",""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
class ChannelViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||
init {
|
||||
}
|
||||
}
|
@ -9,5 +9,5 @@ data class Channel(
|
||||
var nextpage: String? = null,
|
||||
var subscriberCount: Long = 0,
|
||||
var verified: Boolean = false,
|
||||
var relatedStreams: List<StreamItem?>? = null
|
||||
var relatedStreams: List<StreamItem>? = null
|
||||
)
|
||||
|
58
app/src/main/res/layout/video_channel_row.xml
Normal file
58
app/src/main/res/layout/video_channel_row.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:id="@+id/video_search"
|
||||
>
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent=".5"/>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/card_search_thumbnail"
|
||||
app:cardCornerRadius="8dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="16:9"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/channel_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:srcCompat="@tools:sample/backgrounds/scenic" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_views"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toBottomOf="@+id/channel_description" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user