From 01dd416f5a33d0475ab07be8884360bf03b2c834 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 19 Oct 2023 18:30:13 +0200 Subject: [PATCH] feat: (ApiV3) - Update RecentChangesFragment with the apiV3 --- .../drive/ui/menu/RecentChangesFragment.kt | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/infomaniak/drive/ui/menu/RecentChangesFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/menu/RecentChangesFragment.kt index 68ab55023c..f9753c24d6 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/menu/RecentChangesFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/menu/RecentChangesFragment.kt @@ -26,7 +26,6 @@ import com.infomaniak.drive.R import com.infomaniak.drive.data.cache.FileController import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog import com.infomaniak.drive.ui.fileList.multiSelect.RecentChangesMultiSelectActionsBottomSheetDialog -import com.infomaniak.drive.utils.AccountUtils import com.infomaniak.drive.utils.Utils import com.infomaniak.lib.core.utils.setPagination import kotlinx.android.synthetic.main.fragment_file_list.fileRecyclerView @@ -53,14 +52,16 @@ class RecentChangesFragment : FileSubTypeListFragment() { fileRecyclerView.apply { setPagination({ if (!fileAdapter.isComplete && !isDownloadingChanges) { - recentChangesViewModel.currentPage++ - downloadFiles(false, false) + startLoading(isNewSort = false) + recentChangesViewModel.loadNextPage() } }) } sortButton.isGone = true setToolbarTitle(R.string.lastEditsTitle) + + observeRecentChanges() } private fun initParams() { @@ -78,6 +79,26 @@ class RecentChangesFragment : FileSubTypeListFragment() { ) } + private fun startLoading(isNewSort: Boolean) { + showLoadingTimer.start() + isDownloadingChanges = true + recentChangesViewModel.isNewSort = isNewSort + } + + private fun observeRecentChanges() { + recentChangesViewModel.recentChangesResults.observe(viewLifecycleOwner) { result -> + populateFileList( + files = result?.files ?: arrayListOf(), + folderId = FileController.RECENT_CHANGES_FILE_ID, + ignoreOffline = true, + isComplete = result?.isComplete ?: true, + realm = mainViewModel.realm, + isNewSort = recentChangesViewModel.isNewSort, + ) + isDownloadingChanges = false + } + } + companion object { const val MATOMO_CATEGORY = "recentChangesFileAction" } @@ -85,21 +106,10 @@ class RecentChangesFragment : FileSubTypeListFragment() { private inner class DownloadFiles : (Boolean, Boolean) -> Unit { override fun invoke(ignoreCache: Boolean, isNewSort: Boolean) { - showLoadingTimer.start() + startLoading(isNewSort) fileAdapter.isComplete = false - isDownloadingChanges = true - - recentChangesViewModel.getRecentChanges(AccountUtils.currentDriveId).observe(viewLifecycleOwner) { result -> - populateFileList( - files = result?.files ?: arrayListOf(), - folderId = FileController.RECENT_CHANGES_FILE_ID, - ignoreOffline = true, - isComplete = result?.isComplete ?: true, - realm = mainViewModel.realm, - isNewSort = isNewSort, - ) - isDownloadingChanges = false - } + + recentChangesViewModel.loadRecentChanges() } } }