Skip to content

Commit

Permalink
Merge pull request #17 from itszechs/revert-14-patch_shared_drive_pag…
Browse files Browse the repository at this point in the history
…ination

Revert "Fix: Pagination for Shared drives list"
  • Loading branch information
itszechs authored Jun 24, 2022
2 parents 7210081 + 56c446b commit 6976d38
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions app/src/main/java/zechs/drive/stream/ui/files/FilesViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,28 @@ class FilesViewModel @Inject constructor(
val filesDataModel = mutableListOf<FilesDataModel>()

try {
val filesList = files.files
.map {
FilesDataModel.File(
DriveFile(
id = it.id,
name = it.name,
size = it.getSize(),
mimeType = it.mimeType,
iconLink = it.iconLink
)
)
}.distinctBy { it.driveFile.id }
val filesList = files.files.map {
DriveFile(
id = it.id,
name = it.name,
size = it.getSize(),
mimeType = it.mimeType,
iconLink = it.iconLink
)
}.distinctBy { it.id }.toMutableList()

response = if (response == null) {
filesDataModel.addAll(filesList)
filesDataModel.addAll(
filesList.map {
FilesDataModel.File(it)
}
)
filesDataModel
} else {
// append new list of files
response!!.addAll(filesList)

response!!.addAll(
// append new list of files
filesList.map { FilesDataModel.File(it) }
)
// return new list and remove all Loading
response!!.filter {
it != FilesDataModel.Loading
Expand All @@ -151,13 +153,9 @@ class FilesViewModel @Inject constructor(
val teamDrives = drive
.teamdrives()
.list()
.setPageSize(pageSize)
.setPageToken(nextPageToken)
.execute()

Log.d(TAG, teamDrives.toString())
nextPageToken = teamDrives.nextPageToken
isLastPage = nextPageToken == null

val filesDataModel = mutableListOf<FilesDataModel>()
val sharedDrives = teamDrives.teamDrives
Expand All @@ -175,24 +173,7 @@ class FilesViewModel @Inject constructor(
.distinctBy { it.driveFile.id }
.sortedBy { it.driveFile.name }

response = if (response == null) {
filesDataModel.addAll(sharedDrives)
filesDataModel
} else {
// append new list of files
response!!.addAll(sharedDrives)

// return new list and remove all Loading
response!!.filter {
it != FilesDataModel.Loading
}.toMutableList()
}

// before submitting add Loading
// if list is not at last page
if (!isLastPage) {
response!!.add(FilesDataModel.Loading)
}
filesDataModel.addAll(sharedDrives)

_filesList.postValue(Resource.Success(filesDataModel.toList()))
}
Expand Down

0 comments on commit 6976d38

Please sign in to comment.