mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
fix repeating videos
This commit is contained in:
parent
fdb9bf5dbe
commit
f6cd63b8c4
@ -21,7 +21,6 @@ class ChannelAdapter(
|
||||
private val childFragmentManager: FragmentManager
|
||||
) :
|
||||
RecyclerView.Adapter<ChannelViewHolder>() {
|
||||
private lateinit var binding: VideoChannelRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return videoFeed.size
|
||||
@ -34,13 +33,13 @@ class ChannelAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = VideoChannelRowBinding.inflate(layoutInflater, parent, false)
|
||||
return ChannelViewHolder(binding.root)
|
||||
val binding = VideoChannelRowBinding.inflate(layoutInflater, parent, false)
|
||||
return ChannelViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
channelDescription.text = trending.title
|
||||
channelViews.text =
|
||||
trending.views.formatShort() + " • " +
|
||||
@ -53,7 +52,7 @@ class ChannelAdapter(
|
||||
bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
val activity = root.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -63,7 +62,7 @@ class ChannelAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, holder.v.context)
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
true
|
||||
}
|
||||
@ -71,7 +70,4 @@ class ChannelAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class ChannelViewHolder(val binding: VideoChannelRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -5,6 +5,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.ChapterColumnBinding
|
||||
import com.github.libretube.databinding.VideoChannelRowBinding
|
||||
import com.github.libretube.obj.ChapterSegment
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.squareup.picasso.Picasso
|
||||
@ -14,17 +15,16 @@ class ChaptersAdapter(
|
||||
private val exoPlayer: ExoPlayer
|
||||
) : RecyclerView.Adapter<ChaptersViewHolder>() {
|
||||
val TAG = "ChaptersAdapter"
|
||||
private lateinit var binding: ChapterColumnBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChaptersViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = ChapterColumnBinding.inflate(layoutInflater, parent, false)
|
||||
return ChaptersViewHolder(binding.root)
|
||||
val binding = ChapterColumnBinding.inflate(layoutInflater, parent, false)
|
||||
return ChaptersViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ChaptersViewHolder, position: Int) {
|
||||
val chapter = chapters[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
Picasso.get().load(chapter.image).fit().centerCrop().into(chapterImage)
|
||||
chapterTitle.text = chapter.title
|
||||
|
||||
@ -40,7 +40,4 @@ class ChaptersAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class ChaptersViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class ChaptersViewHolder(val binding: ChapterColumnBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.MainActivity
|
||||
import com.github.libretube.databinding.ChapterColumnBinding
|
||||
import com.github.libretube.databinding.CommentsRowBinding
|
||||
import com.github.libretube.obj.Comment
|
||||
import com.github.libretube.obj.CommentsPage
|
||||
@ -28,7 +29,6 @@ class CommentsAdapter(
|
||||
private val comments: MutableList<Comment>
|
||||
) : RecyclerView.Adapter<CommentsViewHolder>() {
|
||||
private val TAG = "CommentsAdapter"
|
||||
private lateinit var binding: CommentsRowBinding
|
||||
|
||||
private var isLoading = false
|
||||
private var nextpage = ""
|
||||
@ -42,13 +42,13 @@ class CommentsAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentsViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = CommentsRowBinding.inflate(layoutInflater, parent, false)
|
||||
return CommentsViewHolder(binding.root)
|
||||
val binding = CommentsRowBinding.inflate(layoutInflater, parent, false)
|
||||
return CommentsViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) {
|
||||
val comment = comments[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
commentInfos.text =
|
||||
comment.author.toString() +
|
||||
" • " + comment.commentedTime.toString()
|
||||
@ -67,7 +67,7 @@ class CommentsAdapter(
|
||||
heartedImageView.visibility = View.VISIBLE
|
||||
}
|
||||
commentorImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to comment.commentorUrl)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
try {
|
||||
@ -81,7 +81,7 @@ class CommentsAdapter(
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
repliesRecView.layoutManager = LinearLayoutManager(holder.v.context)
|
||||
repliesRecView.layoutManager = LinearLayoutManager(root.context)
|
||||
val repliesAdapter = RepliesAdapter(CommentsPage().comments)
|
||||
repliesRecView.adapter = repliesAdapter
|
||||
root.setOnClickListener {
|
||||
@ -90,7 +90,7 @@ class CommentsAdapter(
|
||||
nextpage = comment.repliesPage
|
||||
fetchReplies(nextpage, repliesAdapter)
|
||||
} else {
|
||||
Toast.makeText(holder.v.context, R.string.no_replies, Toast.LENGTH_SHORT)
|
||||
Toast.makeText(root.context, R.string.no_replies, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
@ -123,7 +123,4 @@ class CommentsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class CommentsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class CommentsViewHolder(val binding: CommentsRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -33,7 +33,6 @@ class PlaylistAdapter(
|
||||
private val childFragmentManager: FragmentManager
|
||||
) : RecyclerView.Adapter<PlaylistViewHolder>() {
|
||||
private val TAG = "PlaylistAdapter"
|
||||
private lateinit var binding: PlaylistRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return videoFeed.size
|
||||
@ -46,13 +45,13 @@ class PlaylistAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = PlaylistRowBinding.inflate(layoutInflater, parent, false)
|
||||
return PlaylistViewHolder(binding.root)
|
||||
val binding = PlaylistRowBinding.inflate(layoutInflater, parent, false)
|
||||
return PlaylistViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PlaylistViewHolder, position: Int) {
|
||||
val streamItem = videoFeed[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
playlistTitle.text = streamItem.title
|
||||
playlistDescription.text = streamItem.uploaderName
|
||||
playlistDuration.text = DateUtils.formatElapsedTime(streamItem.duration!!)
|
||||
@ -63,7 +62,7 @@ class PlaylistAdapter(
|
||||
bundle.putString("playlistId", playlistId)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
val activity = root.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -73,7 +72,7 @@ class PlaylistAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
val videoId = streamItem.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, holder.v.context)
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
true
|
||||
}
|
||||
@ -81,7 +80,7 @@ class PlaylistAdapter(
|
||||
if (isOwner) {
|
||||
deletePlaylist.visibility = View.VISIBLE
|
||||
deletePlaylist.setOnClickListener {
|
||||
val token = PreferenceHelper.getToken(holder.v.context)
|
||||
val token = PreferenceHelper.getToken(root.context)
|
||||
removeFromPlaylist(token, position)
|
||||
}
|
||||
}
|
||||
@ -121,7 +120,4 @@ class PlaylistAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class PlaylistViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class PlaylistViewHolder(val binding: PlaylistRowBinding) : RecyclerView.ViewHolder(binding.root)
|
@ -9,6 +9,7 @@ import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.MainActivity
|
||||
import com.github.libretube.databinding.PlaylistRowBinding
|
||||
import com.github.libretube.databinding.PlaylistsRowBinding
|
||||
import com.github.libretube.obj.PlaylistId
|
||||
import com.github.libretube.obj.Playlists
|
||||
@ -26,7 +27,6 @@ class PlaylistsAdapter(
|
||||
private val activity: Activity
|
||||
) : RecyclerView.Adapter<PlaylistsViewHolder>() {
|
||||
val TAG = "PlaylistsAdapter"
|
||||
private lateinit var binding: PlaylistsRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return playlists.size
|
||||
@ -39,13 +39,13 @@ class PlaylistsAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistsViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = PlaylistsRowBinding.inflate(layoutInflater, parent, false)
|
||||
return PlaylistsViewHolder(binding.root)
|
||||
val binding = PlaylistsRowBinding.inflate(layoutInflater, parent, false)
|
||||
return PlaylistsViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
|
||||
val playlist = playlists[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
Picasso.get().load(playlist.thumbnail).into(playlistThumbnail)
|
||||
// set imageview drawable as empty playlist if imageview empty
|
||||
if (playlistThumbnail.drawable == null) {
|
||||
@ -54,11 +54,11 @@ class PlaylistsAdapter(
|
||||
}
|
||||
playlistTitle.text = playlist.name
|
||||
deletePlaylist.setOnClickListener {
|
||||
val builder = MaterialAlertDialogBuilder(holder.v.context)
|
||||
val builder = MaterialAlertDialogBuilder(root.context)
|
||||
builder.setTitle(R.string.deletePlaylist)
|
||||
builder.setMessage(R.string.areYouSure)
|
||||
builder.setPositiveButton(R.string.yes) { _, _ ->
|
||||
val token = PreferenceHelper.getToken(holder.v.context)
|
||||
val token = PreferenceHelper.getToken(root.context)
|
||||
deletePlaylist(playlist.id!!, token, position)
|
||||
}
|
||||
builder.setNegativeButton(R.string.cancel) { _, _ ->
|
||||
@ -67,7 +67,7 @@ class PlaylistsAdapter(
|
||||
}
|
||||
root.setOnClickListener {
|
||||
// playlists clicked
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("playlist_id" to playlist.id)
|
||||
activity.navController.navigate(R.id.playlistFragment, bundle)
|
||||
}
|
||||
@ -104,7 +104,4 @@ class PlaylistsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class PlaylistsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class PlaylistsViewHolder(val binding: PlaylistsRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -16,9 +16,7 @@ import com.squareup.picasso.Picasso
|
||||
class RepliesAdapter(
|
||||
private val replies: MutableList<Comment>
|
||||
) : RecyclerView.Adapter<RepliesViewHolder>() {
|
||||
|
||||
private val TAG = "RepliesAdapter"
|
||||
private lateinit var binding: RepliesRowBinding
|
||||
|
||||
fun clear() {
|
||||
val size: Int = replies.size
|
||||
@ -34,12 +32,12 @@ class RepliesAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepliesViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = RepliesRowBinding.inflate(layoutInflater, parent, false)
|
||||
return RepliesViewHolder(binding.root)
|
||||
val binding = RepliesRowBinding.inflate(layoutInflater, parent, false)
|
||||
return RepliesViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RepliesViewHolder, position: Int) {
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
val reply = replies[position]
|
||||
commentInfos.text =
|
||||
reply.author.toString() +
|
||||
@ -59,7 +57,7 @@ class RepliesAdapter(
|
||||
heartedImageView.visibility = View.VISIBLE
|
||||
}
|
||||
commentorImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to reply.commentorUrl)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
try {
|
||||
@ -81,7 +79,4 @@ class RepliesAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class RepliesViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class RepliesViewHolder(val binding: RepliesRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -18,21 +18,19 @@ class SearchHistoryAdapter(
|
||||
) :
|
||||
RecyclerView.Adapter<SearchHistoryViewHolder>() {
|
||||
|
||||
private lateinit var binding: SearchhistoryRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return historyList.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchHistoryViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = SearchhistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchHistoryViewHolder(binding.root)
|
||||
val binding = SearchhistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchHistoryViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) {
|
||||
val history = historyList[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
historyText.text = history
|
||||
|
||||
deleteHistory.setOnClickListener {
|
||||
@ -49,7 +47,4 @@ class SearchHistoryAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class SearchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class SearchHistoryViewHolder(val binding: SearchhistoryRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -16,7 +16,6 @@ class SearchSuggestionsAdapter(
|
||||
RecyclerView.Adapter<SearchSuggestionsViewHolder>() {
|
||||
|
||||
private val TAG = "SearchSuggestionsAdapter"
|
||||
private lateinit var binding: SearchsuggestionRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return suggestionsList.size
|
||||
@ -24,13 +23,13 @@ class SearchSuggestionsAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchSuggestionsViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchSuggestionsViewHolder(binding.root)
|
||||
val binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SearchSuggestionsViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SearchSuggestionsViewHolder, position: Int) {
|
||||
val suggestion = suggestionsList[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
suggestionText.text = suggestion
|
||||
root.setOnClickListener {
|
||||
editText.setText(suggestion)
|
||||
@ -40,7 +39,4 @@ class SearchSuggestionsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class SearchSuggestionsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class SearchSuggestionsViewHolder(val binding: SearchsuggestionRowBinding) : RecyclerView.ViewHolder(binding.root)
|
@ -24,7 +24,6 @@ class SubscriptionAdapter(
|
||||
private val childFragmentManager: FragmentManager
|
||||
) : RecyclerView.Adapter<SubscriptionViewHolder>() {
|
||||
private val TAG = "SubscriptionAdapter"
|
||||
private lateinit var binding: TrendingRowBinding
|
||||
|
||||
var i = 0
|
||||
override fun getItemCount(): Int {
|
||||
@ -41,13 +40,13 @@ class SubscriptionAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SubscriptionViewHolder(binding.root)
|
||||
val binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SubscriptionViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
textViewTitle.text = trending.title
|
||||
textViewChannel.text =
|
||||
trending.uploaderName + " • " +
|
||||
@ -56,11 +55,11 @@ class SubscriptionAdapter(
|
||||
if (trending.duration != -1L) {
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!)
|
||||
} else {
|
||||
thumbnailDuration.text = holder.v.context.getString(R.string.live)
|
||||
thumbnailDuration.text = root.context.getString(R.string.live)
|
||||
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
channelImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to trending.uploaderUrl)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
try {
|
||||
@ -81,7 +80,7 @@ class SubscriptionAdapter(
|
||||
bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
|
||||
val frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
val activity = root.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -91,7 +90,7 @@ class SubscriptionAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, holder.v.context)
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
true
|
||||
}
|
||||
@ -99,7 +98,4 @@ class SubscriptionAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class SubscriptionViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class SubscriptionViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -3,7 +3,6 @@ package com.github.libretube.adapters
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -24,7 +23,6 @@ import java.io.IOException
|
||||
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
|
||||
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
val TAG = "SubChannelAdapter"
|
||||
private lateinit var binding: ChannelSubscriptionRowBinding
|
||||
|
||||
private var subscribed = true
|
||||
private var isLoading = false
|
||||
@ -36,17 +34,17 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
|
||||
SubscriptionChannelViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = ChannelSubscriptionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SubscriptionChannelViewHolder(binding.root)
|
||||
val binding = ChannelSubscriptionRowBinding.inflate(layoutInflater, parent, false)
|
||||
return SubscriptionChannelViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
||||
val subscription = subscriptions[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
subscriptionChannelName.text = subscription.name
|
||||
Picasso.get().load(subscription.avatar).into(subscriptionChannelImage)
|
||||
root.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to subscription.url)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
}
|
||||
@ -56,11 +54,11 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
||||
val channelId = subscription.url?.replace("/channel/", "")!!
|
||||
if (subscribed) {
|
||||
unsubscribe(root.context, channelId)
|
||||
subscriptionSubscribe.text = holder.v.context.getString(R.string.subscribe)
|
||||
subscriptionSubscribe.text = root.context.getString(R.string.subscribe)
|
||||
} else {
|
||||
subscribe(root.context, channelId)
|
||||
subscriptionSubscribe.text =
|
||||
holder.v.context.getString(R.string.unsubscribe)
|
||||
root.context.getString(R.string.unsubscribe)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,7 +110,4 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
||||
}
|
||||
}
|
||||
|
||||
class SubscriptionChannelViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class SubscriptionChannelViewHolder(val binding: ChannelSubscriptionRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -24,7 +24,6 @@ class TrendingAdapter(
|
||||
private val childFragmentManager: FragmentManager
|
||||
) : RecyclerView.Adapter<TrendingViewHolder>() {
|
||||
private val TAG = "TrendingAdapter"
|
||||
private lateinit var binding: TrendingRowBinding
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return videoFeed.size
|
||||
@ -32,13 +31,13 @@ class TrendingAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrendingViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
|
||||
return TrendingViewHolder(binding.root)
|
||||
val binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
|
||||
return TrendingViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: TrendingViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
textViewTitle.text = trending.title
|
||||
textViewChannel.text =
|
||||
trending.uploaderName + " • " +
|
||||
@ -47,11 +46,11 @@ class TrendingAdapter(
|
||||
if (trending.duration != -1L) {
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!)
|
||||
} else {
|
||||
thumbnailDuration.text = holder.v.context.getString(R.string.live)
|
||||
thumbnailDuration.text = root.context.getString(R.string.live)
|
||||
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
channelImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to trending.uploaderUrl)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
try {
|
||||
@ -77,7 +76,7 @@ class TrendingAdapter(
|
||||
bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
val activity = root.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -87,7 +86,7 @@ class TrendingAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, holder.v.context)
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
true
|
||||
}
|
||||
@ -95,7 +94,4 @@ class TrendingAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class TrendingViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class TrendingViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -24,7 +24,6 @@ class WatchHistoryAdapter(
|
||||
) :
|
||||
RecyclerView.Adapter<WatchHistoryViewHolder>() {
|
||||
private val TAG = "WatchHistoryAdapter"
|
||||
private lateinit var binding: WatchHistoryRowBinding
|
||||
|
||||
fun clear() {
|
||||
val size = watchHistory.size
|
||||
@ -34,13 +33,13 @@ class WatchHistoryAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
return WatchHistoryViewHolder(binding.root)
|
||||
val binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
|
||||
return WatchHistoryViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: WatchHistoryViewHolder, position: Int) {
|
||||
val video = watchHistory[position]
|
||||
binding.apply {
|
||||
holder.binding.apply {
|
||||
videoTitle.text = video.title
|
||||
channelName.text = video.uploader
|
||||
uploadDate.text = video.uploadDate
|
||||
@ -49,7 +48,7 @@ class WatchHistoryAdapter(
|
||||
Picasso.get().load(video.uploaderAvatar).into(channelImage)
|
||||
|
||||
channelImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val activity = root.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to video.uploaderUrl)
|
||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||
try {
|
||||
@ -69,7 +68,7 @@ class WatchHistoryAdapter(
|
||||
bundle.putString("videoId", video.videoId)
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
val activity = root.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -78,7 +77,7 @@ class WatchHistoryAdapter(
|
||||
.commitNow()
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsDialog(video.videoId!!, holder.v.context)
|
||||
VideoOptionsDialog(video.videoId!!, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
true
|
||||
}
|
||||
@ -90,7 +89,4 @@ class WatchHistoryAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
class WatchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
||||
class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -46,15 +46,14 @@ class HomeFragment : Fragment() {
|
||||
resources.getInteger(R.integer.grid_items).toString()
|
||||
)!!
|
||||
binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt())
|
||||
fetchJson(binding.progressBar, binding.recview)
|
||||
fetchJson()
|
||||
binding.homeRefresh.isEnabled = true
|
||||
binding.homeRefresh.setOnRefreshListener {
|
||||
Log.d(TAG, "hmm")
|
||||
fetchJson(binding.progressBar, binding.recview)
|
||||
fetchJson()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchJson(progressBar: ProgressBar, recyclerView: RecyclerView) {
|
||||
private fun fetchJson() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
@ -73,8 +72,8 @@ class HomeFragment : Fragment() {
|
||||
binding.homeRefresh.isRefreshing = false
|
||||
}
|
||||
runOnUiThread {
|
||||
progressBar.visibility = View.GONE
|
||||
recyclerView.adapter = TrendingAdapter(response, childFragmentManager)
|
||||
binding.progressBar.visibility = View.GONE
|
||||
binding.recview.adapter = TrendingAdapter(response, childFragmentManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user