Skip to content
Draft
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 @@ -398,13 +398,27 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {

testFolder.richWorkspace = " "
activity.storageManager.saveFile(testFolder)
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "")
sut.adapter.swapDirectory(
user,
testFolder,
activity.storageManager,
false,
""
) {
}

Assert.assertFalse(sut.adapter.shouldShowHeader())

testFolder.richWorkspace = null
activity.storageManager.saveFile(testFolder)
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "")
sut.adapter.swapDirectory(
user,
testFolder,
activity.storageManager,
false,
""
) {
}
Assert.assertFalse(sut.adapter.shouldShowHeader())

EspressoIdlingResource.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,11 @@ class FileDisplayActivity :
return
}

ocFileListFragment.listDirectory(currentDir, MainApp.isOnlyOnDevice())
ocFileListFragment.listDirectory(currentDir, MainApp.isOnlyOnDevice()) {
if (ocFileListFragment.isBrowseUp) {
ocFileListFragment.restoreIndexAndTopPosition()
}
}
}

private fun handleScrollBehaviour(ocFileListFragment: OCFileListFragment?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ interface CommonOCFileListAdapterInterface {
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
onComplete: () -> Unit
)

fun setHighlightedItem(file: OCFile)
Expand Down
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,
onComplete: () -> Unit
) = Unit

override fun setHighlightedItem(file: OCFile) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import androidx.recyclerview.widget.RecyclerView;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import me.zhanghai.android.fastscroll.PopupTextProvider;

/**
Expand Down Expand Up @@ -832,7 +833,8 @@ public void swapDirectory(
@NonNull OCFile directory,
@NonNull FileDataStorageManager updatedStorageManager,
boolean onlyOnDevice,
@NonNull String limitToMimeType) {
@NonNull String limitToMimeType,
@NonNull Function0<Unit> onComplete) {

this.onlyOnDevice = onlyOnDevice;

Expand Down Expand Up @@ -861,6 +863,7 @@ public void swapDirectory(
(newList, fileSortOrder) ->
{
updateAdapter((List<OCFile>) newList, directory);
onComplete.invoke();
return Unit.INSTANCE;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,6 @@ open class ExtendedListFragment :
if (savedInstanceState.getBoolean(KEY_IS_GRID_VISIBLE, false) && recyclerView?.adapter != null) {
switchToGridView()
}

val referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION)
Log_OC.v(TAG, "Setting grid position $referencePosition")
scrollToPosition(referencePosition)
}

override fun onSaveInstanceState(savedInstanceState: Bundle) {
Expand All @@ -445,16 +441,12 @@ open class ExtendedListFragment :
return mScale.roundToInt()
}

/*
* Restore index and position
*/
protected fun restoreIndexAndTopPosition() {
fun restoreIndexAndTopPosition() {
if (mIndexes.isEmpty()) {
Log_OC.d(TAG, "Indexes is null or empty")
return
}

// needs to be checked; not every browse-up had a browse-down before
val index = mIndexes.removeAt(mIndexes.size - 1)
val firstPosition = mFirstPositions.removeAt(mFirstPositions.size - 1)
val top = mTops.removeAt(mTops.size - 1)
Expand All @@ -467,30 +459,41 @@ open class ExtendedListFragment :
)
)

firstPosition?.let { scrollToPosition(it) }
if (firstPosition != null && firstPosition >= 0) {
mainThread(delay = 0L) {
scrollToPosition(firstPosition, top ?: 0)
}
}
}

private fun scrollToPosition(position: Int) {
private fun scrollToPosition(position: Int, top: Int = 0) {
val layoutManager = mRecyclerView?.layoutManager

if (layoutManager is LinearLayoutManager) {
val visibleItemCount = layoutManager.findLastCompletelyVisibleItemPosition() -
layoutManager.findFirstCompletelyVisibleItemPosition()
layoutManager.scrollToPositionWithOffset(position, (visibleItemCount / 2) * mHeightCell)
if (position < 0) {
return
}

when (layoutManager) {
is GridLayoutManager -> {
layoutManager.scrollToPositionWithOffset(position, top)
}

is LinearLayoutManager -> {
val visibleItemCount = layoutManager.findLastCompletelyVisibleItemPosition() -
layoutManager.findFirstCompletelyVisibleItemPosition()
val offsetTop = if (top != 0) top else (visibleItemCount / 2) * mHeightCell
layoutManager.scrollToPositionWithOffset(position, offsetTop)
}
}
}

/*
* Save index and top position
*/
protected fun saveIndexAndTopPosition(index: Int) {
mIndexes.add(index)

val layoutManager = mRecyclerView?.layoutManager
val firstPosition: Int = if (layoutManager is GridLayoutManager) {
layoutManager.findFirstCompletelyVisibleItemPosition()
} else {
(layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
val firstPosition: Int = when (val layoutManager = mRecyclerView?.layoutManager) {
is GridLayoutManager -> layoutManager.findFirstCompletelyVisibleItemPosition()
is LinearLayoutManager -> layoutManager.findFirstCompletelyVisibleItemPosition()
else -> RecyclerView.NO_POSITION
}

mFirstPositions.add(firstPosition)
Expand All @@ -504,9 +507,7 @@ open class ExtendedListFragment :
mHeightCell = if (view == null || mHeightCell != 0) mHeightCell else view.height
}

override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
// to be @overridden
}
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = Unit

override fun onRefresh() {
if (searchView != null) {
Expand Down Expand Up @@ -803,8 +804,6 @@ open class ExtendedListFragment :
companion object {
protected val TAG: String = ExtendedListFragment::class.java.getSimpleName()

protected const val KEY_SAVED_LIST_POSITION: String = "SAVED_LIST_POSITION"

private const val KEY_INDEXES = "INDEXES"
private const val KEY_FIRST_POSITIONS = "FIRST_POSITIONS"
private const val KEY_TOPS = "TOPS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.status.E2EVersion;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.Type;
Expand Down Expand Up @@ -148,6 +147,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;

import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
import static com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG;
Expand Down Expand Up @@ -228,6 +228,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
protected String mLimitToMimeType;
private FloatingActionButton mFabMain;
public static boolean isMultipleFileSelectedForCopyOrMove = false;
private static boolean isBrowseUp = false;

private static final Intent scanIntentExternalApp = new Intent("org.fairscan.app.action.SCAN_TO_PDF");

Expand All @@ -246,6 +247,10 @@ protected enum MenuItemAddRemove {

private static OCFileDepth fileDepth = OCFileDepth.Root;

public boolean isBrowseUp() {
return isBrowseUp;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -1042,6 +1047,7 @@ public int onBrowseUp() {
searchFragment = true;
}

isBrowseUp = true;
updateFileList();
return result.first;
}
Expand Down Expand Up @@ -1088,9 +1094,11 @@ private String ensureTrailingSeparator(String path) {
}

private void updateFileList() {
listDirectory(mFile, MainApp.isOnlyOnDevice());
onRefresh(false);
restoreIndexAndTopPosition();
listDirectory(mFile, MainApp.isOnlyOnDevice(), () -> {
Log_OC.d(TAG, "list directory completed");
onRefresh(false);
return Unit.INSTANCE;
});
}

/**
Expand Down Expand Up @@ -1306,6 +1314,9 @@ private void browseToFolder(OCFile file, int position) {
listDirectory(file, MainApp.isOnlyOnDevice());
// then, notify parent activity to let it update its state and view
mContainerActivity.onBrowsedDownTo(file);

isBrowseUp = false;

// save index and top position
saveIndexAndTopPosition(position);
}
Expand Down Expand Up @@ -1551,7 +1562,15 @@ public void refreshDirectory() {
}

public void listDirectory(@Nullable OCFile directory, boolean onlyOnDevice) {
listDirectory(directory, null, onlyOnDevice);
listDirectory(directory, null, onlyOnDevice, () -> Unit.INSTANCE);
}

public void listDirectory(@Nullable OCFile directory, OCFile file, boolean onlyOnDevice) {
listDirectory(directory, file, onlyOnDevice, () -> Unit.INSTANCE);
}

public void listDirectory(@Nullable OCFile directory, boolean onlyOnDevice, @NonNull Function0<Unit> onComplete) {
listDirectory(directory, null, onlyOnDevice, onComplete);
}

private OCFile getDirectoryForListDirectory(@Nullable OCFile directory, FileDataStorageManager storageManager) {
Expand All @@ -1578,7 +1597,10 @@ private OCFile getDirectoryForListDirectory(@Nullable OCFile directory, FileData
*
* @param directory File to be listed
*/
public void listDirectory(@Nullable OCFile directory, OCFile file, boolean onlyOnDevice) {
public void listDirectory(@Nullable OCFile directory,
OCFile file,
boolean onlyOnDevice,
@NonNull Function0<Unit> onComplete) {
if (!searchFragment) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager == null) {
Expand Down Expand Up @@ -1607,7 +1629,8 @@ public void listDirectory(@Nullable OCFile directory, OCFile file, boolean onlyO
directory,
storageManager,
onlyOnDevice,
mLimitToMimeType);
mLimitToMimeType,
onComplete);

OCFile previousDirectory = mFile;
mFile = directory;
Expand Down
Loading