Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ class GalleryAdapter(
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
onSwapped: () -> Unit
) = Unit

override fun setHighlightedItem(file: OCFile) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface CommonOCFileListAdapterInterface {
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
onSwapped: () -> Unit = {}
)

fun setHighlightedItem(file: OCFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class OCFileListAdapter(
transferServiceGetter: ComponentsGetter,
ocFileListFragmentInterface: OCFileListFragmentInterface,
private val hideItemOptions: Boolean,
private var gridView: Boolean,
gridView: Boolean,
viewThemeUtils: ViewThemeUtils,
private val thumbnailGenerator: ThumbnailGenerator,
avatarGenerator: AvatarGenerator
Expand Down Expand Up @@ -208,7 +208,7 @@ class OCFileListAdapter(

OCFileListViewType.HEADER -> OCFileListHeaderViewHolder(ListHeaderBinding.inflate(inflater, parent, false))

OCFileListViewType.ITEM, OCFileListViewType.IMAGE -> if (gridView) {
OCFileListViewType.ITEM, OCFileListViewType.IMAGE -> if (ocFileListDelegate.gridView) {
OCFileListGridItemViewHolder(GridItemBinding.inflate(inflater, parent, false))
} else {
OCFileListItemViewHolder(ListItemBinding.inflate(inflater, parent, false))
Expand Down Expand Up @@ -279,7 +279,8 @@ class OCFileListAdapter(
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
onSwapped: () -> Unit
) {
this.onlyOnDevice = onlyOnDevice

Expand All @@ -300,7 +301,7 @@ class OCFileListAdapter(
preferences,
accountUserId
) { newList, _ ->
updateAdapter(newList, directory)
updateAdapter(newList, directory, onSwapped)
}
}

Expand Down Expand Up @@ -388,7 +389,7 @@ class OCFileListAdapter(
)
}

fun updateAdapter(newFiles: List<OCFile>, directory: OCFile?) {
fun updateAdapter(newFiles: List<OCFile>, directory: OCFile?, onUpdated: () -> Unit = {}) {
Log_OC.d(TAG, "updating the adapter")

allFiles.clear()
Expand All @@ -408,8 +409,10 @@ class OCFileListAdapter(
if (isSameDirectoryRefresh) {
differ.submitAndRebind(files)
} else {
differ.replace(files)
differ.replaceWithoutAnimation(files)
}

onUpdated()
}
}

Expand Down Expand Up @@ -570,7 +573,7 @@ class OCFileListAdapter(
}

fun setGridView(bool: Boolean) {
gridView = bool
ocFileListDelegate.gridView = bool
}

fun setShowMetadata(bool: Boolean) {
Expand Down Expand Up @@ -639,7 +642,7 @@ class OCFileListAdapter(
holder.fileFeaturesLayout?.setVisibleIf(holder.hasVisibleFeatureIndicators)
}

private fun shouldShowItemOptions(): Boolean = !(isMultiSelect() || gridView || hideItemOptions)
private fun shouldShowItemOptions(): Boolean = !(isMultiSelect() || ocFileListDelegate.gridView || hideItemOptions)

private fun bindMoreOptionsVisibility(holder: ListViewHolder) {
val showMoreOptions = !isMultiSelect() && !OCFileListFragment.isMultipleFileSelectedForCopyOrMove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.owncloud.android.ui.adapter.filelist.data

import android.annotation.SuppressLint
import androidx.core.view.doOnNextLayout
import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.ListUpdateCallback
Expand Down Expand Up @@ -94,6 +95,11 @@ class OCFileListDiffer(
adapter.notifyDataSetChanged()
}

fun replaceWithoutAnimation(newFiles: List<OCFile>) {
suppressItemAnimationsUntilNextLayout()
replace(newFiles)
}

fun sortForCurrentView(
files: MutableList<OCFile>,
searchType: SearchType?,
Expand Down Expand Up @@ -141,6 +147,13 @@ class OCFileListDiffer(
recyclerView = null
}

private fun suppressItemAnimationsUntilNextLayout() {
val recyclerView = recyclerView ?: return
val itemAnimator = recyclerView.itemAnimator ?: return
recyclerView.itemAnimator = null
recyclerView.doOnNextLayout { recyclerView.itemAnimator = itemAnimator }
}

private fun keepTopVisibleWhile(adapterPosition: Int, notify: () -> Unit) {
val wasAtTop = adapterPosition == 0 && recyclerView?.canScrollVertically(-1) == false
notify()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OCFileListDelegate(
private val user: User,
private val storageManager: FileDataStorageManager,
private val hideItemOptions: Boolean,
private val gridView: Boolean,
var gridView: Boolean,
private val transferServiceGetter: ComponentsGetter,
private val showMetadata: Boolean,
private var showShareAvatar: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,12 +1151,15 @@ open class OCFileListFragment :
}

Log_OC.i(TAG, "Listing directory ${directoryToList.decryptedRemotePath}, onlyOnDevice=$onlyOnDevice")
adapter.swapDirectory(accountManager.user, directoryToList, storageManager, onlyOnDevice, mimeType)

val previousDirectory = currentFile
adapter.swapDirectory(accountManager.user, directoryToList, storageManager, onlyOnDevice, mimeType) {
if (view == null) return@swapDirectory
fileListLayoutManager?.setLayoutViewMode()
scrollToHighlightedFileOrTop(adapter, highlightedFile, previousDirectory, directoryToList)
}

currentFile = directoryToList
updateUiForCurrentFolder()
scrollToHighlightedFileOrTop(adapter, highlightedFile, previousDirectory, directoryToList)
}

private fun scrollToHighlightedFileOrTop(
Expand Down Expand Up @@ -1207,7 +1210,6 @@ open class OCFileListFragment :
get() = adapter?.isEmpty ?: true

private fun updateUiForCurrentFolder() {
fileListLayoutManager?.setLayoutViewMode()
updateSortButtonLabel()
setLayoutSwitchButton()

Expand Down
Loading