Skip to content

Commit ab4b829

Browse files
authored
Merge pull request #3968 from owncloud/spaces/available_offline
[SPACES] Available offline
2 parents c3ea57c + 25886de commit ab4b829

11 files changed

Lines changed: 122 additions & 77 deletions

File tree

owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ val viewModelModule = module {
106106
get(),
107107
get(),
108108
get(),
109+
get(),
109110
initialFolderToDisplay,
110111
fileListOption,
111112
)

owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/FileListAdapter.kt

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
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,
@@ -15,7 +17,6 @@
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

2122
package com.owncloud.android.presentation.files.filelist
@@ -41,6 +42,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager
4142
import com.owncloud.android.domain.files.model.FileListOption
4243
import com.owncloud.android.domain.files.model.OCFileWithSyncInfo
4344
import com.owncloud.android.domain.files.model.OCFooterFile
45+
import com.owncloud.android.domain.spaces.model.OCSpace
4446
import com.owncloud.android.presentation.authentication.AccountUtils
4547
import com.owncloud.android.utils.DisplayUtils
4648
import 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)

owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/FileListDiffCallback.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Fernando Sanz Velasco
55
* @author Juan Carlos Garrote Gascón
66
*
7-
* Copyright (C) 2022 ownCloud GmbH.
7+
* Copyright (C) 2023 ownCloud GmbH.
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU General Public License version 2,
@@ -17,14 +17,12 @@
1717
*
1818
* You should have received a copy of the GNU General Public License
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20-
*
2120
*/
2221

2322
package com.owncloud.android.presentation.files.filelist
2423

2524
import androidx.recyclerview.widget.DiffUtil
2625
import com.owncloud.android.domain.files.model.FileListOption
27-
import com.owncloud.android.domain.files.model.OCFileWithSyncInfo
2826
import com.owncloud.android.domain.files.model.OCFooterFile
2927

3028
class FileListDiffCallback(
@@ -50,8 +48,8 @@ class FileListDiffCallback(
5048
return true
5149
}
5250

53-
if (oldItem is OCFileWithSyncInfo && newItem is OCFileWithSyncInfo) {
54-
return oldItem.file.id == newItem.file.id
51+
if (oldItem is FileListAdapter.FileItem && newItem is FileListAdapter.FileItem) {
52+
return oldItem.fileWithSyncInfo.file.id == newItem.fileWithSyncInfo.file.id
5553
}
5654

5755
if (oldItem is OCFooterFile && newItem is OCFooterFile) {

owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21-
*
2221
*/
2322

2423
package com.owncloud.android.presentation.files.filelist
@@ -178,7 +177,7 @@ class MainFileListFragment : Fragment(),
178177
context = requireContext(),
179178
layoutManager = layoutManager,
180179
isPickerMode = isPickingAFolder(),
181-
listener = this@MainFileListFragment
180+
listener = this@MainFileListFragment,
182181
)
183182

184183
binding.recyclerViewMainFileList.adapter = fileListAdapter
@@ -238,7 +237,11 @@ class MainFileListFragment : Fragment(),
238237
collectLatestLifecycleFlow(mainFileListViewModel.fileListUiState) { fileListUiState ->
239238
if (fileListUiState !is MainFileListViewModel.FileListUiState.Success) return@collectLatestLifecycleFlow
240239

241-
fileListAdapter.updateFileList(filesToAdd = fileListUiState.folderContent, fileListOption = fileListUiState.fileListOption)
240+
fileListAdapter.updateFileList(
241+
filesToAdd = fileListUiState.folderContent,
242+
fileListOption = fileListUiState.fileListOption,
243+
spaces = mainFileListViewModel.spaces.value,
244+
)
242245
showOrHideEmptyView(fileListUiState)
243246

244247
fileListUiState.space?.let {

owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListViewModel.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21-
*
2221
*/
2322

2423
package com.owncloud.android.presentation.files.filelist
@@ -39,6 +38,7 @@ import com.owncloud.android.domain.files.usecases.GetSharedByLinkForAccountAsStr
3938
import com.owncloud.android.domain.files.usecases.SortFilesWithSyncInfoUseCase
4039
import com.owncloud.android.domain.spaces.model.OCSpace
4140
import com.owncloud.android.domain.spaces.usecases.GetSpaceWithSpecialsByIdForAccountUseCase
41+
import com.owncloud.android.domain.spaces.usecases.GetSpacesFromEveryAccountUseCase
4242
import com.owncloud.android.presentation.files.SortOrder
4343
import com.owncloud.android.presentation.files.SortOrder.Companion.PREF_FILE_LIST_SORT_ORDER
4444
import com.owncloud.android.presentation.files.SortType
@@ -67,9 +67,10 @@ class MainFileListViewModel(
6767
private val getFileByRemotePathUseCase: GetFileByRemotePathUseCase,
6868
private val getSpaceWithSpecialsByIdForAccountUseCase: GetSpaceWithSpecialsByIdForAccountUseCase,
6969
private val sortFilesWithSyncInfoUseCase: SortFilesWithSyncInfoUseCase,
70+
private val synchronizeFolderUseCase: SynchronizeFolderUseCase,
71+
private val getSpacesFromEveryAccountUseCase: GetSpacesFromEveryAccountUseCase, // TODO: To be deleted when adding the space to the file entity
7072
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
7173
private val sharedPreferencesProvider: SharedPreferencesProvider,
72-
private val synchronizeFolderUseCase: SynchronizeFolderUseCase,
7374
initialFolderToDisplay: OCFile,
7475
fileListOptionParam: FileListOption,
7576
) : ViewModel() {
@@ -82,6 +83,10 @@ class MainFileListViewModel(
8283
private val sortTypeAndOrder = MutableStateFlow(Pair(SortType.SORT_TYPE_BY_NAME, SortOrder.SORT_ORDER_ASCENDING))
8384
val space: MutableStateFlow<OCSpace?> = MutableStateFlow(null)
8485

86+
private val _spaces: MutableStateFlow<List<OCSpace>> = MutableStateFlow(emptyList())
87+
val spaces: StateFlow<List<OCSpace>>
88+
get() = _spaces
89+
8590
/** File list ui state combines the other fields and generate a new state whenever any of them changes */
8691
val fileListUiState: StateFlow<FileListUiState> =
8792
combine(
@@ -122,6 +127,10 @@ class MainFileListViewModel(
122127
)
123128
)
124129
}
130+
viewModelScope.launch(coroutinesDispatcherProvider.io) {
131+
val spacesList = getSpacesFromEveryAccountUseCase.execute(Unit)
132+
_spaces.update { spacesList }
133+
}
125134
}
126135

127136
fun navigateToFolderId(folderId: Long) {

owncloudApp/src/main/java/com/owncloud/android/presentation/transfers/TransferListFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class TransferListFragment : Fragment() {
9191
clearSuccessful = {
9292
transfersViewModel.clearSuccessfulTransfers()
9393
},
94-
personalName = getString(R.string.bottom_nav_personal),
9594
)
9695
binding.transfersRecyclerView.apply {
9796
layoutManager = LinearLayoutManager(context)

owncloudApp/src/main/java/com/owncloud/android/presentation/transfers/TransfersAdapter.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
3333
import com.owncloud.android.R
3434
import com.owncloud.android.databinding.UploadListGroupBinding
3535
import com.owncloud.android.databinding.UploadListItemBinding
36+
import com.owncloud.android.domain.files.model.OCFile
3637
import com.owncloud.android.domain.spaces.model.OCSpace
3738
import com.owncloud.android.domain.transfers.model.OCTransfer
3839
import com.owncloud.android.domain.transfers.model.TransferStatus
@@ -54,7 +55,6 @@ class TransfersAdapter(
5455
val clearFailed: () -> Unit,
5556
val retryFailed: () -> Unit,
5657
val clearSuccessful: () -> Unit,
57-
private val personalName: String,
5858
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
5959

6060
private val transferItemsList = mutableListOf<TransferRecyclerItem>()
@@ -87,17 +87,19 @@ class TransfersAdapter(
8787
uploadName.text = fileName
8888

8989
transferItem.space?.let {
90-
uploadSpaceName.isVisible = true
91-
spaceIcon.isVisible = true
90+
spacePathLine.spaceName.isVisible = true
91+
spacePathLine.spaceIcon.isVisible = true
9292
if (it.isPersonal) {
93-
spaceIcon.setImageResource(R.drawable.ic_folder)
94-
uploadSpaceName.text = personalName
93+
spacePathLine.spaceIcon.setImageResource(R.drawable.ic_folder)
94+
spacePathLine.spaceName.setText(R.string.bottom_nav_personal)
9595
} else {
96-
uploadSpaceName.text = it.name
96+
spacePathLine.spaceName.text = it.name
9797
}
9898
}
9999

100-
uploadRemotePath.text = remoteFile.parent
100+
remoteFile.parent?.let {
101+
spacePathLine.path.text = if (it.endsWith("${OCFile.PATH_SEPARATOR}")) it else "$it${OCFile.PATH_SEPARATOR}"
102+
}
101103

102104
uploadFileSize.text = DisplayUtils.bytesToHumanReadable(transferItem.transfer.fileSize, holder.itemView.context)
103105

owncloudApp/src/main/res/layout/item_file_list.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,14 @@
9595
app:layout_constraintTop_toBottomOf="@id/Filename"
9696
tools:text="Mod Date" />
9797

98-
<TextView
99-
android:id="@+id/file_list_path"
100-
android:layout_width="wrap_content"
98+
<include
99+
android:id="@+id/space_path_line"
100+
layout="@layout/space_path_line"
101+
android:layout_width="0dp"
101102
android:layout_height="wrap_content"
102-
android:ellipsize="middle"
103-
android:singleLine="true"
104-
android:textColor="@color/list_item_lastmod_and_filesize_text"
105-
android:textSize="@dimen/two_line_secondary_text_size"
106-
android:visibility="gone"
107103
app:layout_constraintStart_toStartOf="@+id/Filename"
108-
app:layout_constraintTop_toBottomOf="@+id/file_list_size"
109-
tools:text="/path/to/file"
110-
tools:visibility="visible"/>
104+
app:layout_constraintTop_toBottomOf="@+id/file_list_size" />
105+
111106
</androidx.constraintlayout.widget.ConstraintLayout>
112107

113108
<androidx.constraintlayout.widget.ConstraintLayout
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:gravity="center_vertical">
8+
9+
<ImageView
10+
android:id="@+id/space_icon"
11+
android:layout_width="15dp"
12+
android:layout_height="15dp"
13+
android:layout_marginEnd="2dp"
14+
android:src="@drawable/ic_spaces"
15+
android:visibility="gone"
16+
app:tint="@color/list_item_lastmod_and_filesize_text"
17+
tools:visibility="visible" />
18+
19+
<TextView
20+
android:id="@+id/space_name"
21+
android:layout_width="wrap_content"
22+
android:maxWidth="100dp"
23+
android:layout_height="wrap_content"
24+
android:layout_marginEnd="@dimen/standard_half_margin"
25+
android:textColor="@color/list_item_lastmod_and_filesize_text"
26+
android:textStyle="bold"
27+
android:ellipsize="middle"
28+
android:singleLine="true"
29+
android:textSize="12sp"
30+
android:visibility="gone"
31+
tools:text="Space name"
32+
tools:visibility="visible" />
33+
34+
<TextView
35+
android:id="@+id/path"
36+
android:layout_width="wrap_content"
37+
android:layout_height="wrap_content"
38+
android:textColor="@color/list_item_lastmod_and_filesize_text"
39+
android:ellipsize="middle"
40+
android:singleLine="true"
41+
android:textSize="12sp"
42+
tools:text="/path/to/file"
43+
tools:visibility="visible" />
44+
45+
</LinearLayout>

0 commit comments

Comments
 (0)