22 * ownCloud Android client application
33 *
44 * @author Fernando Sanz Velasco
5- * Copyright (C) 2021 ownCloud GmbH.
5+ * @author Juan Carlos Garrote Gascón
6+ *
7+ * Copyright (C) 2023 ownCloud GmbH.
68 *
79 * This program is free software: you can redistribute it and/or modify
810 * it under the terms of the GNU General Public License version 2,
1517 *
1618 * You should have received a copy of the GNU General Public License
1719 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18- *
1920 */
2021
2122package com.owncloud.android.presentation.files.filelist
@@ -41,6 +42,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager
4142import com.owncloud.android.domain.files.model.FileListOption
4243import com.owncloud.android.domain.files.model.OCFileWithSyncInfo
4344import com.owncloud.android.domain.files.model.OCFooterFile
45+ import com.owncloud.android.domain.spaces.model.OCSpace
4446import com.owncloud.android.presentation.authentication.AccountUtils
4547import com.owncloud.android.utils.DisplayUtils
4648import com.owncloud.android.utils.MimetypeIconUtil
@@ -57,9 +59,14 @@ class FileListAdapter(
5759 private var account: Account ? = AccountUtils .getCurrentOwnCloudAccount(context)
5860 private var fileListOption: FileListOption = FileListOption .ALL_FILES
5961
60- fun updateFileList (filesToAdd : List <OCFileWithSyncInfo >, fileListOption : FileListOption ) {
62+ fun updateFileList (filesToAdd : List <OCFileWithSyncInfo >, fileListOption : FileListOption , spaces : List <OCSpace >) {
63+ val fileItems = filesToAdd.map { fileWithSyncInfo ->
64+ val space = spaces.firstOrNull { it.id == fileWithSyncInfo.file.spaceId && it.accountName == fileWithSyncInfo.file.owner }
65+ FileItem (fileWithSyncInfo, space)
66+ }
67+
6168 val listWithFooter = mutableListOf<Any >()
62- listWithFooter.addAll(filesToAdd )
69+ listWithFooter.addAll(fileItems )
6370
6471 if (listWithFooter.isNotEmpty()) {
6572 listWithFooter.add(OCFooterFile (manageListOfFilesAndGenerateText(filesToAdd)))
@@ -132,7 +139,7 @@ class FileListAdapter(
132139 layoutManager.spanCount == 1 -> {
133140 ViewType .LIST_ITEM .ordinal
134141 }
135- (files[position] as OCFileWithSyncInfo ) .file.isImage -> {
142+ (files[position] as FileItem ).fileWithSyncInfo .file.isImage -> {
136143 ViewType .GRID_IMAGE .ordinal
137144 }
138145 else -> {
@@ -172,7 +179,8 @@ class FileListAdapter(
172179
173180 if (viewType != ViewType .FOOTER .ordinal) { // Is Item
174181
175- val fileWithSyncInfo = files[position] as OCFileWithSyncInfo
182+ val fileItem = files[position] as FileItem
183+ val fileWithSyncInfo = fileItem.fileWithSyncInfo
176184 val file = fileWithSyncInfo.file
177185 val name = file.fileName
178186 val fileIcon = holder.itemView.findViewById<ImageView >(R .id.thumbnail).apply {
@@ -203,9 +211,25 @@ class FileListAdapter(
203211 it.Filename .text = file.fileName
204212 it.fileListSize.text = DisplayUtils .bytesToHumanReadable(file.length, context)
205213 it.fileListLastMod.text = DisplayUtils .getRelativeTimestamp(context, file.modificationTimestamp)
206- it.fileListPath.apply {
207- text = file.remotePath
208- isVisible = ! fileListOption.isAllFiles()
214+ if (fileListOption.isAvailableOffline() || (fileListOption.isSharedByLink() && fileItem.space == null )) {
215+ it.spacePathLine.path.apply {
216+ text = file.getParentRemotePath()
217+ isVisible = true
218+ }
219+ fileItem.space?.let { space ->
220+ it.spacePathLine.spaceIcon.isVisible = true
221+ it.spacePathLine.spaceName.isVisible = true
222+ if (space.isPersonal) {
223+ it.spacePathLine.spaceIcon.setImageResource(R .drawable.ic_folder)
224+ it.spacePathLine.spaceName.setText(R .string.bottom_nav_personal)
225+ } else {
226+ it.spacePathLine.spaceName.text = space.name
227+ }
228+ }
229+ } else {
230+ it.spacePathLine.path.isVisible = false
231+ it.spacePathLine.spaceIcon.isVisible = false
232+ it.spacePathLine.spaceName.isVisible = false
209233 }
210234 }
211235 }
@@ -382,6 +406,8 @@ class FileListAdapter(
382406 fun onLongItemClick (position : Int ): Boolean = true
383407 }
384408
409+ data class FileItem (val fileWithSyncInfo : OCFileWithSyncInfo , val space : OCSpace ? )
410+
385411 inner class GridViewHolder (val binding : GridItemBinding ) : RecyclerView.ViewHolder(binding.root)
386412 inner class GridImageViewHolder (val binding : GridItemBinding ) : RecyclerView.ViewHolder(binding.root)
387413 inner class ListViewHolder (val binding : ItemFileListBinding ) : RecyclerView.ViewHolder(binding.root)
0 commit comments