fix repeating videos

This commit is contained in:
Bnyro 2022-07-02 17:01:24 +02:00
parent fdb9bf5dbe
commit f6cd63b8c4
13 changed files with 82 additions and 131 deletions

View File

@ -21,7 +21,6 @@ class ChannelAdapter(
private val childFragmentManager: FragmentManager private val childFragmentManager: FragmentManager
) : ) :
RecyclerView.Adapter<ChannelViewHolder>() { RecyclerView.Adapter<ChannelViewHolder>() {
private lateinit var binding: VideoChannelRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return videoFeed.size return videoFeed.size
@ -34,13 +33,13 @@ class ChannelAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = VideoChannelRowBinding.inflate(layoutInflater, parent, false) val binding = VideoChannelRowBinding.inflate(layoutInflater, parent, false)
return ChannelViewHolder(binding.root) return ChannelViewHolder(binding)
} }
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) { override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
val trending = videoFeed[position] val trending = videoFeed[position]
binding.apply { holder.binding.apply {
channelDescription.text = trending.title channelDescription.text = trending.title
channelViews.text = channelViews.text =
trending.views.formatShort() + "" + trending.views.formatShort() + "" +
@ -53,7 +52,7 @@ class ChannelAdapter(
bundle.putString("videoId", trending.url!!.replace("/watch?v=", "")) bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
var frag = PlayerFragment() var frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = holder.v.context as AppCompatActivity val activity = root.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction() activity.supportFragmentManager.beginTransaction()
.remove(PlayerFragment()) .remove(PlayerFragment())
.commit() .commit()
@ -63,7 +62,7 @@ class ChannelAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
val videoId = trending.url!!.replace("/watch?v=", "") val videoId = trending.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, holder.v.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG) .show(childFragmentManager, VideoOptionsDialog.TAG)
true true
} }
@ -71,7 +70,4 @@ class ChannelAdapter(
} }
} }
class ChannelViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class ChannelViewHolder(val binding: VideoChannelRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -5,6 +5,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChapterColumnBinding import com.github.libretube.databinding.ChapterColumnBinding
import com.github.libretube.databinding.VideoChannelRowBinding
import com.github.libretube.obj.ChapterSegment import com.github.libretube.obj.ChapterSegment
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
@ -14,17 +15,16 @@ class ChaptersAdapter(
private val exoPlayer: ExoPlayer private val exoPlayer: ExoPlayer
) : RecyclerView.Adapter<ChaptersViewHolder>() { ) : RecyclerView.Adapter<ChaptersViewHolder>() {
val TAG = "ChaptersAdapter" val TAG = "ChaptersAdapter"
private lateinit var binding: ChapterColumnBinding
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChaptersViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChaptersViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = ChapterColumnBinding.inflate(layoutInflater, parent, false) val binding = ChapterColumnBinding.inflate(layoutInflater, parent, false)
return ChaptersViewHolder(binding.root) return ChaptersViewHolder(binding)
} }
override fun onBindViewHolder(holder: ChaptersViewHolder, position: Int) { override fun onBindViewHolder(holder: ChaptersViewHolder, position: Int) {
val chapter = chapters[position] val chapter = chapters[position]
binding.apply { holder.binding.apply {
Picasso.get().load(chapter.image).fit().centerCrop().into(chapterImage) Picasso.get().load(chapter.image).fit().centerCrop().into(chapterImage)
chapterTitle.text = chapter.title chapterTitle.text = chapter.title
@ -40,7 +40,4 @@ class ChaptersAdapter(
} }
} }
class ChaptersViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class ChaptersViewHolder(val binding: ChapterColumnBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.MainActivity import com.github.libretube.activities.MainActivity
import com.github.libretube.databinding.ChapterColumnBinding
import com.github.libretube.databinding.CommentsRowBinding import com.github.libretube.databinding.CommentsRowBinding
import com.github.libretube.obj.Comment import com.github.libretube.obj.Comment
import com.github.libretube.obj.CommentsPage import com.github.libretube.obj.CommentsPage
@ -28,7 +29,6 @@ class CommentsAdapter(
private val comments: MutableList<Comment> private val comments: MutableList<Comment>
) : RecyclerView.Adapter<CommentsViewHolder>() { ) : RecyclerView.Adapter<CommentsViewHolder>() {
private val TAG = "CommentsAdapter" private val TAG = "CommentsAdapter"
private lateinit var binding: CommentsRowBinding
private var isLoading = false private var isLoading = false
private var nextpage = "" private var nextpage = ""
@ -42,13 +42,13 @@ class CommentsAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentsViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = CommentsRowBinding.inflate(layoutInflater, parent, false) val binding = CommentsRowBinding.inflate(layoutInflater, parent, false)
return CommentsViewHolder(binding.root) return CommentsViewHolder(binding)
} }
override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) { override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) {
val comment = comments[position] val comment = comments[position]
binding.apply { holder.binding.apply {
commentInfos.text = commentInfos.text =
comment.author.toString() + comment.author.toString() +
"" + comment.commentedTime.toString() "" + comment.commentedTime.toString()
@ -67,7 +67,7 @@ class CommentsAdapter(
heartedImageView.visibility = View.VISIBLE heartedImageView.visibility = View.VISIBLE
} }
commentorImage.setOnClickListener { commentorImage.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to comment.commentorUrl) val bundle = bundleOf("channel_id" to comment.commentorUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
@ -81,7 +81,7 @@ class CommentsAdapter(
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
repliesRecView.layoutManager = LinearLayoutManager(holder.v.context) repliesRecView.layoutManager = LinearLayoutManager(root.context)
val repliesAdapter = RepliesAdapter(CommentsPage().comments) val repliesAdapter = RepliesAdapter(CommentsPage().comments)
repliesRecView.adapter = repliesAdapter repliesRecView.adapter = repliesAdapter
root.setOnClickListener { root.setOnClickListener {
@ -90,7 +90,7 @@ class CommentsAdapter(
nextpage = comment.repliesPage nextpage = comment.repliesPage
fetchReplies(nextpage, repliesAdapter) fetchReplies(nextpage, repliesAdapter)
} else { } 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() .show()
} }
} else { } else {
@ -123,7 +123,4 @@ class CommentsAdapter(
} }
} }
class CommentsViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class CommentsViewHolder(val binding: CommentsRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -33,7 +33,6 @@ class PlaylistAdapter(
private val childFragmentManager: FragmentManager private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<PlaylistViewHolder>() { ) : RecyclerView.Adapter<PlaylistViewHolder>() {
private val TAG = "PlaylistAdapter" private val TAG = "PlaylistAdapter"
private lateinit var binding: PlaylistRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return videoFeed.size return videoFeed.size
@ -46,13 +45,13 @@ class PlaylistAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = PlaylistRowBinding.inflate(layoutInflater, parent, false) val binding = PlaylistRowBinding.inflate(layoutInflater, parent, false)
return PlaylistViewHolder(binding.root) return PlaylistViewHolder(binding)
} }
override fun onBindViewHolder(holder: PlaylistViewHolder, position: Int) { override fun onBindViewHolder(holder: PlaylistViewHolder, position: Int) {
val streamItem = videoFeed[position] val streamItem = videoFeed[position]
binding.apply { holder.binding.apply {
playlistTitle.text = streamItem.title playlistTitle.text = streamItem.title
playlistDescription.text = streamItem.uploaderName playlistDescription.text = streamItem.uploaderName
playlistDuration.text = DateUtils.formatElapsedTime(streamItem.duration!!) playlistDuration.text = DateUtils.formatElapsedTime(streamItem.duration!!)
@ -63,7 +62,7 @@ class PlaylistAdapter(
bundle.putString("playlistId", playlistId) bundle.putString("playlistId", playlistId)
var frag = PlayerFragment() var frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = holder.v.context as AppCompatActivity val activity = root.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction() activity.supportFragmentManager.beginTransaction()
.remove(PlayerFragment()) .remove(PlayerFragment())
.commit() .commit()
@ -73,7 +72,7 @@ class PlaylistAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
val videoId = streamItem.url!!.replace("/watch?v=", "") val videoId = streamItem.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, holder.v.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG) .show(childFragmentManager, VideoOptionsDialog.TAG)
true true
} }
@ -81,7 +80,7 @@ class PlaylistAdapter(
if (isOwner) { if (isOwner) {
deletePlaylist.visibility = View.VISIBLE deletePlaylist.visibility = View.VISIBLE
deletePlaylist.setOnClickListener { deletePlaylist.setOnClickListener {
val token = PreferenceHelper.getToken(holder.v.context) val token = PreferenceHelper.getToken(root.context)
removeFromPlaylist(token, position) removeFromPlaylist(token, position)
} }
} }
@ -121,7 +120,4 @@ class PlaylistAdapter(
} }
} }
class PlaylistViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class PlaylistViewHolder(val binding: PlaylistRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -9,6 +9,7 @@ import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.MainActivity import com.github.libretube.activities.MainActivity
import com.github.libretube.databinding.PlaylistRowBinding
import com.github.libretube.databinding.PlaylistsRowBinding import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.obj.PlaylistId import com.github.libretube.obj.PlaylistId
import com.github.libretube.obj.Playlists import com.github.libretube.obj.Playlists
@ -26,7 +27,6 @@ class PlaylistsAdapter(
private val activity: Activity private val activity: Activity
) : RecyclerView.Adapter<PlaylistsViewHolder>() { ) : RecyclerView.Adapter<PlaylistsViewHolder>() {
val TAG = "PlaylistsAdapter" val TAG = "PlaylistsAdapter"
private lateinit var binding: PlaylistsRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return playlists.size return playlists.size
@ -39,13 +39,13 @@ class PlaylistsAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistsViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = PlaylistsRowBinding.inflate(layoutInflater, parent, false) val binding = PlaylistsRowBinding.inflate(layoutInflater, parent, false)
return PlaylistsViewHolder(binding.root) return PlaylistsViewHolder(binding)
} }
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) { override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
val playlist = playlists[position] val playlist = playlists[position]
binding.apply { holder.binding.apply {
Picasso.get().load(playlist.thumbnail).into(playlistThumbnail) Picasso.get().load(playlist.thumbnail).into(playlistThumbnail)
// set imageview drawable as empty playlist if imageview empty // set imageview drawable as empty playlist if imageview empty
if (playlistThumbnail.drawable == null) { if (playlistThumbnail.drawable == null) {
@ -54,11 +54,11 @@ class PlaylistsAdapter(
} }
playlistTitle.text = playlist.name playlistTitle.text = playlist.name
deletePlaylist.setOnClickListener { deletePlaylist.setOnClickListener {
val builder = MaterialAlertDialogBuilder(holder.v.context) val builder = MaterialAlertDialogBuilder(root.context)
builder.setTitle(R.string.deletePlaylist) builder.setTitle(R.string.deletePlaylist)
builder.setMessage(R.string.areYouSure) builder.setMessage(R.string.areYouSure)
builder.setPositiveButton(R.string.yes) { _, _ -> builder.setPositiveButton(R.string.yes) { _, _ ->
val token = PreferenceHelper.getToken(holder.v.context) val token = PreferenceHelper.getToken(root.context)
deletePlaylist(playlist.id!!, token, position) deletePlaylist(playlist.id!!, token, position)
} }
builder.setNegativeButton(R.string.cancel) { _, _ -> builder.setNegativeButton(R.string.cancel) { _, _ ->
@ -67,7 +67,7 @@ class PlaylistsAdapter(
} }
root.setOnClickListener { root.setOnClickListener {
// playlists clicked // playlists clicked
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("playlist_id" to playlist.id) val bundle = bundleOf("playlist_id" to playlist.id)
activity.navController.navigate(R.id.playlistFragment, bundle) activity.navController.navigate(R.id.playlistFragment, bundle)
} }
@ -104,7 +104,4 @@ class PlaylistsAdapter(
} }
} }
class PlaylistsViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class PlaylistsViewHolder(val binding: PlaylistsRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -16,9 +16,7 @@ import com.squareup.picasso.Picasso
class RepliesAdapter( class RepliesAdapter(
private val replies: MutableList<Comment> private val replies: MutableList<Comment>
) : RecyclerView.Adapter<RepliesViewHolder>() { ) : RecyclerView.Adapter<RepliesViewHolder>() {
private val TAG = "RepliesAdapter" private val TAG = "RepliesAdapter"
private lateinit var binding: RepliesRowBinding
fun clear() { fun clear() {
val size: Int = replies.size val size: Int = replies.size
@ -34,12 +32,12 @@ class RepliesAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepliesViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepliesViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = RepliesRowBinding.inflate(layoutInflater, parent, false) val binding = RepliesRowBinding.inflate(layoutInflater, parent, false)
return RepliesViewHolder(binding.root) return RepliesViewHolder(binding)
} }
override fun onBindViewHolder(holder: RepliesViewHolder, position: Int) { override fun onBindViewHolder(holder: RepliesViewHolder, position: Int) {
binding.apply { holder.binding.apply {
val reply = replies[position] val reply = replies[position]
commentInfos.text = commentInfos.text =
reply.author.toString() + reply.author.toString() +
@ -59,7 +57,7 @@ class RepliesAdapter(
heartedImageView.visibility = View.VISIBLE heartedImageView.visibility = View.VISIBLE
} }
commentorImage.setOnClickListener { commentorImage.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to reply.commentorUrl) val bundle = bundleOf("channel_id" to reply.commentorUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
@ -81,7 +79,4 @@ class RepliesAdapter(
} }
} }
class RepliesViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class RepliesViewHolder(val binding: RepliesRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -18,21 +18,19 @@ class SearchHistoryAdapter(
) : ) :
RecyclerView.Adapter<SearchHistoryViewHolder>() { RecyclerView.Adapter<SearchHistoryViewHolder>() {
private lateinit var binding: SearchhistoryRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return historyList.size return historyList.size
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchHistoryViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchHistoryViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = SearchhistoryRowBinding.inflate(layoutInflater, parent, false) val binding = SearchhistoryRowBinding.inflate(layoutInflater, parent, false)
return SearchHistoryViewHolder(binding.root) return SearchHistoryViewHolder(binding)
} }
override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) { override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) {
val history = historyList[position] val history = historyList[position]
binding.apply { holder.binding.apply {
historyText.text = history historyText.text = history
deleteHistory.setOnClickListener { deleteHistory.setOnClickListener {
@ -49,7 +47,4 @@ class SearchHistoryAdapter(
} }
} }
class SearchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class SearchHistoryViewHolder(val binding: SearchhistoryRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -16,7 +16,6 @@ class SearchSuggestionsAdapter(
RecyclerView.Adapter<SearchSuggestionsViewHolder>() { RecyclerView.Adapter<SearchSuggestionsViewHolder>() {
private val TAG = "SearchSuggestionsAdapter" private val TAG = "SearchSuggestionsAdapter"
private lateinit var binding: SearchsuggestionRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return suggestionsList.size return suggestionsList.size
@ -24,13 +23,13 @@ class SearchSuggestionsAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchSuggestionsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchSuggestionsViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false) val binding = SearchsuggestionRowBinding.inflate(layoutInflater, parent, false)
return SearchSuggestionsViewHolder(binding.root) return SearchSuggestionsViewHolder(binding)
} }
override fun onBindViewHolder(holder: SearchSuggestionsViewHolder, position: Int) { override fun onBindViewHolder(holder: SearchSuggestionsViewHolder, position: Int) {
val suggestion = suggestionsList[position] val suggestion = suggestionsList[position]
binding.apply { holder.binding.apply {
suggestionText.text = suggestion suggestionText.text = suggestion
root.setOnClickListener { root.setOnClickListener {
editText.setText(suggestion) editText.setText(suggestion)
@ -40,7 +39,4 @@ class SearchSuggestionsAdapter(
} }
} }
class SearchSuggestionsViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class SearchSuggestionsViewHolder(val binding: SearchsuggestionRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -24,7 +24,6 @@ class SubscriptionAdapter(
private val childFragmentManager: FragmentManager private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<SubscriptionViewHolder>() { ) : RecyclerView.Adapter<SubscriptionViewHolder>() {
private val TAG = "SubscriptionAdapter" private val TAG = "SubscriptionAdapter"
private lateinit var binding: TrendingRowBinding
var i = 0 var i = 0
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -41,13 +40,13 @@ class SubscriptionAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = TrendingRowBinding.inflate(layoutInflater, parent, false) val binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
return SubscriptionViewHolder(binding.root) return SubscriptionViewHolder(binding)
} }
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) { override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
val trending = videoFeed[position] val trending = videoFeed[position]
binding.apply { holder.binding.apply {
textViewTitle.text = trending.title textViewTitle.text = trending.title
textViewChannel.text = textViewChannel.text =
trending.uploaderName + "" + trending.uploaderName + "" +
@ -56,11 +55,11 @@ class SubscriptionAdapter(
if (trending.duration != -1L) { if (trending.duration != -1L) {
thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!) thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!)
} else { } else {
thumbnailDuration.text = holder.v.context.getString(R.string.live) thumbnailDuration.text = root.context.getString(R.string.live)
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark) thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
} }
channelImage.setOnClickListener { channelImage.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to trending.uploaderUrl) val bundle = bundleOf("channel_id" to trending.uploaderUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
@ -81,7 +80,7 @@ class SubscriptionAdapter(
bundle.putString("videoId", trending.url!!.replace("/watch?v=", "")) bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
val frag = PlayerFragment() val frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = holder.v.context as AppCompatActivity val activity = root.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction() activity.supportFragmentManager.beginTransaction()
.remove(PlayerFragment()) .remove(PlayerFragment())
.commit() .commit()
@ -91,7 +90,7 @@ class SubscriptionAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
val videoId = trending.url!!.replace("/watch?v=", "") val videoId = trending.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, holder.v.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG) .show(childFragmentManager, VideoOptionsDialog.TAG)
true true
} }
@ -99,7 +98,4 @@ class SubscriptionAdapter(
} }
} }
class SubscriptionViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class SubscriptionViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -24,7 +23,6 @@ import java.io.IOException
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) : class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
RecyclerView.Adapter<SubscriptionChannelViewHolder>() { RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
val TAG = "SubChannelAdapter" val TAG = "SubChannelAdapter"
private lateinit var binding: ChannelSubscriptionRowBinding
private var subscribed = true private var subscribed = true
private var isLoading = false private var isLoading = false
@ -36,17 +34,17 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
SubscriptionChannelViewHolder { SubscriptionChannelViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = ChannelSubscriptionRowBinding.inflate(layoutInflater, parent, false) val binding = ChannelSubscriptionRowBinding.inflate(layoutInflater, parent, false)
return SubscriptionChannelViewHolder(binding.root) return SubscriptionChannelViewHolder(binding)
} }
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) { override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
val subscription = subscriptions[position] val subscription = subscriptions[position]
binding.apply { holder.binding.apply {
subscriptionChannelName.text = subscription.name subscriptionChannelName.text = subscription.name
Picasso.get().load(subscription.avatar).into(subscriptionChannelImage) Picasso.get().load(subscription.avatar).into(subscriptionChannelImage)
root.setOnClickListener { root.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to subscription.url) val bundle = bundleOf("channel_id" to subscription.url)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
} }
@ -56,11 +54,11 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
val channelId = subscription.url?.replace("/channel/", "")!! val channelId = subscription.url?.replace("/channel/", "")!!
if (subscribed) { if (subscribed) {
unsubscribe(root.context, channelId) unsubscribe(root.context, channelId)
subscriptionSubscribe.text = holder.v.context.getString(R.string.subscribe) subscriptionSubscribe.text = root.context.getString(R.string.subscribe)
} else { } else {
subscribe(root.context, channelId) subscribe(root.context, channelId)
subscriptionSubscribe.text = 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) { class SubscriptionChannelViewHolder(val binding: ChannelSubscriptionRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -24,7 +24,6 @@ class TrendingAdapter(
private val childFragmentManager: FragmentManager private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<TrendingViewHolder>() { ) : RecyclerView.Adapter<TrendingViewHolder>() {
private val TAG = "TrendingAdapter" private val TAG = "TrendingAdapter"
private lateinit var binding: TrendingRowBinding
override fun getItemCount(): Int { override fun getItemCount(): Int {
return videoFeed.size return videoFeed.size
@ -32,13 +31,13 @@ class TrendingAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrendingViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrendingViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = TrendingRowBinding.inflate(layoutInflater, parent, false) val binding = TrendingRowBinding.inflate(layoutInflater, parent, false)
return TrendingViewHolder(binding.root) return TrendingViewHolder(binding)
} }
override fun onBindViewHolder(holder: TrendingViewHolder, position: Int) { override fun onBindViewHolder(holder: TrendingViewHolder, position: Int) {
val trending = videoFeed[position] val trending = videoFeed[position]
binding.apply { holder.binding.apply {
textViewTitle.text = trending.title textViewTitle.text = trending.title
textViewChannel.text = textViewChannel.text =
trending.uploaderName + "" + trending.uploaderName + "" +
@ -47,11 +46,11 @@ class TrendingAdapter(
if (trending.duration != -1L) { if (trending.duration != -1L) {
thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!) thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!)
} else { } else {
thumbnailDuration.text = holder.v.context.getString(R.string.live) thumbnailDuration.text = root.context.getString(R.string.live)
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark) thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
} }
channelImage.setOnClickListener { channelImage.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to trending.uploaderUrl) val bundle = bundleOf("channel_id" to trending.uploaderUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
@ -77,7 +76,7 @@ class TrendingAdapter(
bundle.putString("videoId", trending.url!!.replace("/watch?v=", "")) bundle.putString("videoId", trending.url!!.replace("/watch?v=", ""))
var frag = PlayerFragment() var frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = holder.v.context as AppCompatActivity val activity = root.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction() activity.supportFragmentManager.beginTransaction()
.remove(PlayerFragment()) .remove(PlayerFragment())
.commit() .commit()
@ -87,7 +86,7 @@ class TrendingAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
val videoId = trending.url!!.replace("/watch?v=", "") val videoId = trending.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, holder.v.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG) .show(childFragmentManager, VideoOptionsDialog.TAG)
true true
} }
@ -95,7 +94,4 @@ class TrendingAdapter(
} }
} }
class TrendingViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class TrendingViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -24,7 +24,6 @@ class WatchHistoryAdapter(
) : ) :
RecyclerView.Adapter<WatchHistoryViewHolder>() { RecyclerView.Adapter<WatchHistoryViewHolder>() {
private val TAG = "WatchHistoryAdapter" private val TAG = "WatchHistoryAdapter"
private lateinit var binding: WatchHistoryRowBinding
fun clear() { fun clear() {
val size = watchHistory.size val size = watchHistory.size
@ -34,13 +33,13 @@ class WatchHistoryAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)
binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false) val binding = WatchHistoryRowBinding.inflate(layoutInflater, parent, false)
return WatchHistoryViewHolder(binding.root) return WatchHistoryViewHolder(binding)
} }
override fun onBindViewHolder(holder: WatchHistoryViewHolder, position: Int) { override fun onBindViewHolder(holder: WatchHistoryViewHolder, position: Int) {
val video = watchHistory[position] val video = watchHistory[position]
binding.apply { holder.binding.apply {
videoTitle.text = video.title videoTitle.text = video.title
channelName.text = video.uploader channelName.text = video.uploader
uploadDate.text = video.uploadDate uploadDate.text = video.uploadDate
@ -49,7 +48,7 @@ class WatchHistoryAdapter(
Picasso.get().load(video.uploaderAvatar).into(channelImage) Picasso.get().load(video.uploaderAvatar).into(channelImage)
channelImage.setOnClickListener { channelImage.setOnClickListener {
val activity = holder.v.context as MainActivity val activity = root.context as MainActivity
val bundle = bundleOf("channel_id" to video.uploaderUrl) val bundle = bundleOf("channel_id" to video.uploaderUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
@ -69,7 +68,7 @@ class WatchHistoryAdapter(
bundle.putString("videoId", video.videoId) bundle.putString("videoId", video.videoId)
var frag = PlayerFragment() var frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = holder.v.context as AppCompatActivity val activity = root.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction() activity.supportFragmentManager.beginTransaction()
.remove(PlayerFragment()) .remove(PlayerFragment())
.commit() .commit()
@ -78,7 +77,7 @@ class WatchHistoryAdapter(
.commitNow() .commitNow()
} }
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsDialog(video.videoId!!, holder.v.context) VideoOptionsDialog(video.videoId!!, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG) .show(childFragmentManager, VideoOptionsDialog.TAG)
true true
} }
@ -90,7 +89,4 @@ class WatchHistoryAdapter(
} }
} }
class WatchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) { class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) : RecyclerView.ViewHolder(binding.root)
init {
}
}

View File

@ -46,15 +46,14 @@ class HomeFragment : Fragment() {
resources.getInteger(R.integer.grid_items).toString() resources.getInteger(R.integer.grid_items).toString()
)!! )!!
binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt()) binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt())
fetchJson(binding.progressBar, binding.recview) fetchJson()
binding.homeRefresh.isEnabled = true binding.homeRefresh.isEnabled = true
binding.homeRefresh.setOnRefreshListener { binding.homeRefresh.setOnRefreshListener {
Log.d(TAG, "hmm") fetchJson()
fetchJson(binding.progressBar, binding.recview)
} }
} }
private fun fetchJson(progressBar: ProgressBar, recyclerView: RecyclerView) { private fun fetchJson() {
fun run() { fun run() {
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val response = try { val response = try {
@ -73,8 +72,8 @@ class HomeFragment : Fragment() {
binding.homeRefresh.isRefreshing = false binding.homeRefresh.isRefreshing = false
} }
runOnUiThread { runOnUiThread {
progressBar.visibility = View.GONE binding.progressBar.visibility = View.GONE
recyclerView.adapter = TrendingAdapter(response, childFragmentManager) binding.recview.adapter = TrendingAdapter(response, childFragmentManager)
} }
} }
} }