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.helpers.PreferenceHelper
import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.IOException
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.IOException
import retrofit2.HttpException import retrofit2.HttpException
class DownloadDialog( class DownloadDialog(

View File

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

View File

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