@@ -254,11 +254,9 @@ class OCFileListDelegate(
254254 val isFolderPickerActivity = (context is FolderPickerActivity )
255255 gridViewHolder.checkbox.setVisibleIf(isMultiSelect && ! isFolderPickerActivity)
256256
257- // download state
258- gridViewHolder.localFileIndicator.visibility = View .GONE // default first
259-
260257 // metadata (downloaded, favorite)
261- bindGridMetadataViews(file, gridViewHolder)
258+ showLocalFileIndicator(file, gridViewHolder)
259+ gridViewHolder.favorite.setVisibleIf(file.isFavorite && showMetadata)
262260
263261 // shares
264262 val shouldHideShare = (
@@ -352,16 +350,6 @@ class OCFileListDelegate(
352350 }
353351 }
354352
355- private fun bindGridMetadataViews (file : OCFile , gridViewHolder : ListViewHolder ) {
356- if (showMetadata) {
357- showLocalFileIndicator(file, gridViewHolder)
358- gridViewHolder.favorite.visibility = if (file.isFavorite) View .VISIBLE else View .GONE
359- } else {
360- gridViewHolder.localFileIndicator.visibility = View .GONE
361- gridViewHolder.favorite.visibility = View .GONE
362- }
363- }
364-
365353 private suspend fun isFolderFullyDownloaded (file : OCFile ): Boolean = withContext(Dispatchers .IO ) {
366354 file.isFolder &&
367355 storageManager.getSubfiles(file.fileId, user.accountName)
@@ -379,38 +367,28 @@ class OCFileListDelegate(
379367 }
380368
381369 private fun showLocalFileIndicator (file : OCFile , holder : ListViewHolder ) {
382- val icon = when {
383- isSynchronizing(file) -> R .drawable.ic_synchronizing
384- file.etagInConflict != null -> R .drawable.ic_synchronizing_error
385- file.isDown -> R .drawable.ic_synced
386- else -> null
387- }
388-
389- holder.localFileIndicator.run {
390- if (icon != null ) {
391- setImageResource(icon)
392- visibility = View .VISIBLE
393- } else {
394- visibility = View .GONE
395- }
396- }
397-
398- checkLocalFolderIndicatorAsynchronously(file, holder)
399- }
400-
401- private fun checkLocalFolderIndicatorAsynchronously (file : OCFile , holder : ListViewHolder ) {
402- if (! file.isFolder) {
403- return
404- }
405-
406370 ioScope.launch {
407- if (! isFolderFullyDownloaded(file)) {
408- return @launch
371+ val isFullyDownloaded = isFolderFullyDownloaded(file)
372+ val isSyncing = isSynchronizing(file)
373+ val hasConflict = (file.etagInConflict != null )
374+ val isDown = file.isDown
375+
376+ val icon = when {
377+ isSyncing -> R .drawable.ic_synchronizing
378+ hasConflict -> R .drawable.ic_synchronizing_error
379+ isDown || isFullyDownloaded -> R .drawable.ic_synced
380+ else -> null
409381 }
410382
411383 withContext(Dispatchers .Main ) {
412- holder.localFileIndicator.setImageResource(R .drawable.ic_synced)
413- holder.localFileIndicator.visibility = View .VISIBLE
384+ holder.localFileIndicator.run {
385+ if (icon != null && showMetadata) {
386+ setImageResource(icon)
387+ visibility = View .VISIBLE
388+ } else {
389+ visibility = View .GONE
390+ }
391+ }
414392 }
415393 }
416394 }
0 commit comments