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