Merge pull request #664 from Bnyro/master

fix repeating items in recyclerviews
This commit is contained in:
Bnyro 2022-07-02 17:10:52 +02:00 committed by GitHub
commit 8d70d505ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 89 additions and 146 deletions

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.os.Bundle
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
@ -21,7 +20,6 @@ class ChannelAdapter(
private val childFragmentManager: FragmentManager
) :
RecyclerView.Adapter<ChannelViewHolder>() {
private lateinit var binding: VideoChannelRowBinding
override fun getItemCount(): Int {
return videoFeed.size
@ -34,13 +32,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 +51,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 +61,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 +69,4 @@ class ChannelAdapter(
}
}
class ChannelViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class ChannelViewHolder(val binding: VideoChannelRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,7 +1,6 @@
package com.github.libretube.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChapterColumnBinding
@ -14,17 +13,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 +38,4 @@ class ChaptersAdapter(
}
}
class ChaptersViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class ChaptersViewHolder(val binding: ChapterColumnBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -28,7 +28,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 +41,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 +66,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 +80,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 +89,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 +122,4 @@ class CommentsAdapter(
}
}
class CommentsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class CommentsViewHolder(val binding: CommentsRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -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)

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.app.Activity
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
@ -26,7 +25,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 +37,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 +52,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 +65,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 +102,4 @@ class PlaylistsAdapter(
}
}
class PlaylistsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class PlaylistsViewHolder(val binding: PlaylistsRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -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)

View File

@ -2,7 +2,6 @@ package com.github.libretube.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import androidx.recyclerview.widget.RecyclerView
@ -18,21 +17,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 +46,4 @@ class SearchHistoryAdapter(
}
}
class SearchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class SearchHistoryViewHolder(val binding: SearchhistoryRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,7 +1,6 @@
package com.github.libretube.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import androidx.recyclerview.widget.RecyclerView
@ -16,7 +15,6 @@ class SearchSuggestionsAdapter(
RecyclerView.Adapter<SearchSuggestionsViewHolder>() {
private val TAG = "SearchSuggestionsAdapter"
private lateinit var binding: SearchsuggestionRowBinding
override fun getItemCount(): Int {
return suggestionsList.size
@ -24,13 +22,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 +38,4 @@ class SearchSuggestionsAdapter(
}
}
class SearchSuggestionsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class SearchSuggestionsViewHolder(val binding: SearchsuggestionRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.os.Bundle
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.motion.widget.MotionLayout
@ -24,7 +23,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 +39,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 +54,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 +79,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 +89,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 +97,4 @@ class SubscriptionAdapter(
}
}
class SubscriptionViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class SubscriptionViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -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)

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.os.Bundle
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.motion.widget.MotionLayout
@ -24,7 +23,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 +30,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 +45,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 +75,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 +85,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 +93,4 @@ class TrendingAdapter(
}
}
class TrendingViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class TrendingViewHolder(val binding: TrendingRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -3,7 +3,6 @@ package com.github.libretube.adapters
import android.os.Bundle
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.motion.widget.MotionLayout
@ -24,7 +23,6 @@ class WatchHistoryAdapter(
) :
RecyclerView.Adapter<WatchHistoryViewHolder>() {
private val TAG = "WatchHistoryAdapter"
private lateinit var binding: WatchHistoryRowBinding
fun clear() {
val size = watchHistory.size
@ -34,13 +32,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 +47,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 +67,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 +76,7 @@ class WatchHistoryAdapter(
.commitNow()
}
root.setOnLongClickListener {
VideoOptionsDialog(video.videoId!!, holder.v.context)
VideoOptionsDialog(video.videoId!!, root.context)
.show(childFragmentManager, VideoOptionsDialog.TAG)
true
}
@ -90,7 +88,4 @@ class WatchHistoryAdapter(
}
}
class WatchHistoryViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}
class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -5,12 +5,10 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.databinding.FragmentHomeBinding
@ -46,15 +44,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 +70,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)
}
}
}

View File

@ -74,7 +74,6 @@
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
@ -34,4 +38,6 @@
android:layout_margin="8dp"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</LinearLayout>
</ScrollView>