From e241207c1cb89f5dfd7fb5a3fb91161ea4d45ebe Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 14 Apr 2023 10:57:59 +0200 Subject: [PATCH] Fix duplicating downloads --- .../libretube/ui/dialogs/DownloadDialog.kt | 2 +- .../ui/fragments/DownloadsFragment.kt | 5 ++-- .../ui/fragments/PlaylistFragment.kt | 26 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index d0a3ac816..f749b5f3c 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt index e84691cd6..db7fc7c9c 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 18f5306da..2f1cbd312 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -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) {