mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Fix doubled videos in playlists on reload
This commit is contained in:
parent
1a9a12a1ae
commit
b92bfa87ed
@ -7,7 +7,6 @@ import com.google.android.material.button.MaterialButton
|
||||
|
||||
fun MaterialButton.setupNotificationBell(channelId: String) {
|
||||
var isIgnorable = PreferenceHelper.isChannelNotificationIgnorable(channelId)
|
||||
Log.e(channelId, isIgnorable.toString())
|
||||
setIconResource(if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification)
|
||||
|
||||
setOnClickListener {
|
||||
|
@ -35,8 +35,6 @@ import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.TextUtils
|
||||
import java.io.IOException
|
||||
import retrofit2.HttpException
|
||||
|
||||
class PlaylistFragment : BaseFragment() {
|
||||
private lateinit var binding: FragmentPlaylistBinding
|
||||
@ -47,7 +45,7 @@ class PlaylistFragment : BaseFragment() {
|
||||
private var playlistType: PlaylistType = PlaylistType.PUBLIC
|
||||
|
||||
// runtime variables
|
||||
private val playlistFeed = mutableListOf<StreamItem>()
|
||||
private var playlistFeed = mutableListOf<StreamItem>()
|
||||
private var playlistAdapter: PlaylistAdapter? = null
|
||||
private var nextPage: String? = null
|
||||
private var isLoading = true
|
||||
@ -107,14 +105,11 @@ class PlaylistFragment : BaseFragment() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
PlaylistsHelper.getPlaylist(playlistId!!)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG(), "HttpException, unexpected response")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG(), e.toString())
|
||||
return@launchWhenCreated
|
||||
}
|
||||
playlistFeed.addAll(response.relatedStreams.orEmpty())
|
||||
playlistFeed = response.relatedStreams.orEmpty().toMutableList()
|
||||
binding.playlistScrollview.visibility = View.VISIBLE
|
||||
nextPage = response.nextpage
|
||||
playlistName = response.name
|
||||
@ -190,29 +185,29 @@ class PlaylistFragment : BaseFragment() {
|
||||
|
||||
// listen for playlist items to become deleted
|
||||
playlistAdapter!!.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0) {
|
||||
ImageHelper.loadImage(
|
||||
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
||||
binding.thumbnail
|
||||
)
|
||||
}
|
||||
|
||||
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
|
||||
binding.playlistInfo.text = (
|
||||
if (info.size == 2) {
|
||||
info[0] + TextUtils.SEPARATOR
|
||||
} else {
|
||||
""
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0) {
|
||||
ImageHelper.loadImage(
|
||||
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
||||
binding.thumbnail
|
||||
)
|
||||
}
|
||||
) + getString(
|
||||
R.string.videoCount,
|
||||
playlistAdapter!!.itemCount.toString()
|
||||
)
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
|
||||
binding.playlistInfo.text = (
|
||||
if (info.size == 2) {
|
||||
info[0] + TextUtils.SEPARATOR
|
||||
} else {
|
||||
""
|
||||
}
|
||||
) + getString(
|
||||
R.string.videoCount,
|
||||
playlistAdapter!!.itemCount.toString()
|
||||
)
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
binding.playlistRecView.adapter = playlistAdapter
|
||||
binding.playlistScrollview.viewTreeObserver
|
||||
@ -265,10 +260,10 @@ class PlaylistFragment : BaseFragment() {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().getAll()
|
||||
}.firstOrNull { it.playlistId == playlistId }
|
||||
playlistBookmark?.let {
|
||||
if (playlistBookmark.thumbnailUrl != response.thumbnailUrl) {
|
||||
playlistBookmark.thumbnailUrl = response.thumbnailUrl
|
||||
if (it.thumbnailUrl != response.thumbnailUrl) {
|
||||
it.thumbnailUrl = response.thumbnailUrl
|
||||
query {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().update(playlistBookmark)
|
||||
DatabaseHolder.Database.playlistBookmarkDao().update(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user