Fix duplicating downloads

This commit is contained in:
Bnyro 2023-04-14 10:57:59 +02:00
parent 1710340bbf
commit e241207c1c
3 changed files with 17 additions and 16 deletions

View File

@ -23,10 +23,10 @@ import com.github.libretube.helpers.DownloadHelper
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.util.TextUtils
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.IOException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.IOException
import retrofit2.HttpException
class DownloadDialog(

View File

@ -74,9 +74,10 @@ class DownloadsFragment : Fragment() {
val dbDownloads = runBlocking(Dispatchers.IO) {
Database.downloadDao().getAll()
}
}.takeIf { it.isNotEmpty() } ?: return
downloads.clear()
downloads.addAll(dbDownloads)
if (downloads.isEmpty()) return
binding.downloadsEmpty.visibility = View.GONE
binding.downloads.visibility = View.VISIBLE

View File

@ -215,21 +215,21 @@ class PlaylistFragment : Fragment() {
}
})
binding.playlistRecView.adapter = playlistAdapter
binding.playlistScrollview.viewTreeObserver.addOnScrollChangedListener {
if (_binding?.playlistScrollview?.canScrollVertically(1) == false &&
!isLoading
) {
// append more playlists to the recycler view
if (playlistType != PlaylistType.PUBLIC) {
isLoading = true
playlistAdapter?.showMoreItems()
isLoading = false
} else {
fetchNextPage()
binding.playlistRecView.adapter = playlistAdapter
binding.playlistScrollview.viewTreeObserver.addOnScrollChangedListener {
if (_binding?.playlistScrollview?.canScrollVertically(1) == false &&
!isLoading
) {
// append more playlists to the recycler view
if (playlistType != PlaylistType.PUBLIC) {
isLoading = true
playlistAdapter?.showMoreItems()
isLoading = false
} else {
fetchNextPage()
}
}
}
}
// listener for swiping to the left or right
if (playlistType != PlaylistType.PUBLIC) {