Skip to content

Commit

Permalink
feat: (ApiV3) - Update RecentChangesFragment with the apiV3
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Oct 24, 2023
1 parent 9bb4a99 commit 5738cf7
Showing 1 changed file with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -50,14 +49,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() {
Expand All @@ -75,28 +76,37 @@ 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"
}

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

0 comments on commit 5738cf7

Please sign in to comment.