Fix doubled videos in playlists on reload

This commit is contained in:
Bnyro 2023-01-08 17:23:27 +01:00
parent 1a9a12a1ae
commit b92bfa87ed
2 changed files with 29 additions and 35 deletions

View File

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

View File

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