|
@@ -1,5 +1,4 @@
|
|
/* ownCloud Android client application
|
|
/* ownCloud Android client application
|
|
- * Copyright (C) 2011 Bartek Przybylski
|
|
|
|
* Copyright (C) 2012-2014 ownCloud Inc.
|
|
* Copyright (C) 2012-2014 ownCloud Inc.
|
|
*
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* This program is free software: you can redistribute it and/or modify
|
|
@@ -15,10 +14,10 @@
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
+
|
|
package com.owncloud.android.ui.fragment;
|
|
package com.owncloud.android.ui.fragment;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
@@ -32,35 +31,23 @@ import com.owncloud.android.ui.adapter.FolderListListAdapter;
|
|
import com.owncloud.android.utils.Log_OC;
|
|
import com.owncloud.android.utils.Log_OC;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * A Fragment that lists all folders in a given path.
|
|
|
|
|
|
+ * A Fragment that shows all the folders in a given path, and allows browsing through them.
|
|
*
|
|
*
|
|
* TODO refactorize to get rid of direct dependency on MoveActivity
|
|
* TODO refactorize to get rid of direct dependency on MoveActivity
|
|
- *
|
|
|
|
*/
|
|
*/
|
|
public class MoveFileListFragment extends ExtendedListFragment {
|
|
public class MoveFileListFragment extends ExtendedListFragment {
|
|
|
|
|
|
private static final String TAG = MoveFileListFragment.class.getSimpleName();
|
|
private static final String TAG = MoveFileListFragment.class.getSimpleName();
|
|
|
|
|
|
- private static final String MY_PACKAGE = MoveFileListFragment.class.getPackage() != null ? MoveFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
|
|
|
|
|
|
+ private static final String MY_PACKAGE = MoveFileListFragment.class.getPackage() != null ?
|
|
|
|
+ MoveFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
|
|
private static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
|
|
private static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
|
|
|
|
|
|
- private static final String KEY_INDEXES = "INDEXES";
|
|
|
|
- private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
|
|
|
|
- private static final String KEY_TOPS = "TOPS";
|
|
|
|
- private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
|
|
|
|
- private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
|
|
|
|
-
|
|
|
|
private FileFragment.ContainerActivity mContainerActivity;
|
|
private FileFragment.ContainerActivity mContainerActivity;
|
|
|
|
|
|
private OCFile mFile = null;
|
|
private OCFile mFile = null;
|
|
private FolderListListAdapter mAdapter;
|
|
private FolderListListAdapter mAdapter;
|
|
|
|
|
|
- // Save the state of the scroll in browsing
|
|
|
|
- private ArrayList<Integer> mIndexes;
|
|
|
|
- private ArrayList<Integer> mFirstPositions;
|
|
|
|
- private ArrayList<Integer> mTops;
|
|
|
|
-
|
|
|
|
- private int mHeightCell = 0;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
@@ -92,31 +79,17 @@ public class MoveFileListFragment extends ExtendedListFragment {
|
|
super.onActivityCreated(savedInstanceState);
|
|
super.onActivityCreated(savedInstanceState);
|
|
Log_OC.e(TAG, "onActivityCreated() start");
|
|
Log_OC.e(TAG, "onActivityCreated() start");
|
|
|
|
|
|
- mAdapter = new FolderListListAdapter(getSherlockActivity(), mContainerActivity);
|
|
|
|
-
|
|
|
|
if (savedInstanceState != null) {
|
|
if (savedInstanceState != null) {
|
|
mFile = savedInstanceState.getParcelable(EXTRA_FILE);
|
|
mFile = savedInstanceState.getParcelable(EXTRA_FILE);
|
|
- mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES);
|
|
|
|
- mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS);
|
|
|
|
- mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS);
|
|
|
|
- mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL);
|
|
|
|
- setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE));
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- mIndexes = new ArrayList<Integer>();
|
|
|
|
- mFirstPositions = new ArrayList<Integer>();
|
|
|
|
- mTops = new ArrayList<Integer>();
|
|
|
|
- mHeightCell = 0;
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
mAdapter = new FolderListListAdapter(getSherlockActivity(), mContainerActivity);
|
|
mAdapter = new FolderListListAdapter(getSherlockActivity(), mContainerActivity);
|
|
-
|
|
|
|
setListAdapter(mAdapter);
|
|
setListAdapter(mAdapter);
|
|
|
|
|
|
registerForContextMenu(getListView());
|
|
registerForContextMenu(getListView());
|
|
getListView().setOnCreateContextMenuListener(this);
|
|
getListView().setOnCreateContextMenuListener(this);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* Saves the current listed folder.
|
|
* Saves the current listed folder.
|
|
@@ -125,18 +98,13 @@ public class MoveFileListFragment extends ExtendedListFragment {
|
|
public void onSaveInstanceState (Bundle outState) {
|
|
public void onSaveInstanceState (Bundle outState) {
|
|
super.onSaveInstanceState(outState);
|
|
super.onSaveInstanceState(outState);
|
|
outState.putParcelable(EXTRA_FILE, mFile);
|
|
outState.putParcelable(EXTRA_FILE, mFile);
|
|
- outState.putIntegerArrayList(KEY_INDEXES, mIndexes);
|
|
|
|
- outState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions);
|
|
|
|
- outState.putIntegerArrayList(KEY_TOPS, mTops);
|
|
|
|
- outState.putInt(KEY_HEIGHT_CELL, mHeightCell);
|
|
|
|
- outState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Call this, when the user presses the up button.
|
|
* Call this, when the user presses the up button.
|
|
*
|
|
*
|
|
- * Tries to move up the current folder one level. If the parent folder was removed from the database,
|
|
|
|
- * it continues browsing up until finding an existing folders.
|
|
|
|
|
|
+ * Tries to move up the current folder one level. If the parent folder was removed from the
|
|
|
|
+ * database, it continues browsing up until finding an existing folders.
|
|
*
|
|
*
|
|
* return Count of folder levels browsed up.
|
|
* return Count of folder levels browsed up.
|
|
*/
|
|
*/
|
|
@@ -150,22 +118,22 @@ public class MoveFileListFragment extends ExtendedListFragment {
|
|
String parentPath = null;
|
|
String parentPath = null;
|
|
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
|
|
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
|
|
parentPath = new File(mFile.getRemotePath()).getParent();
|
|
parentPath = new File(mFile.getRemotePath()).getParent();
|
|
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
|
|
|
|
|
|
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
|
+ parentPath + OCFile.PATH_SEPARATOR;
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
moveCount++;
|
|
moveCount++;
|
|
} else {
|
|
} else {
|
|
- parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH); // never returns null; keep the path in root folder
|
|
|
|
|
|
+ parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);
|
|
}
|
|
}
|
|
while (parentDir == null) {
|
|
while (parentDir == null) {
|
|
parentPath = new File(parentPath).getParent();
|
|
parentPath = new File(parentPath).getParent();
|
|
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
|
|
|
|
|
|
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
|
+ parentPath + OCFile.PATH_SEPARATOR;
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
moveCount++;
|
|
moveCount++;
|
|
} // exit is granted because storageManager.getFileByPath("/") never returns null
|
|
} // exit is granted because storageManager.getFileByPath("/") never returns null
|
|
- mFile = parentDir;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (mFile != null) {
|
|
|
|
|
|
+ mFile = parentDir;
|
|
|
|
+
|
|
listDirectory(mFile);
|
|
listDirectory(mFile);
|
|
|
|
|
|
((MoveActivity)mContainerActivity).startSyncFolderOperation(mFile);
|
|
((MoveActivity)mContainerActivity).startSyncFolderOperation(mFile);
|
|
@@ -178,58 +146,6 @@ public class MoveFileListFragment extends ExtendedListFragment {
|
|
return moveCount;
|
|
return moveCount;
|
|
}
|
|
}
|
|
|
|
|
|
- /*
|
|
|
|
- * Restore index and position
|
|
|
|
- */
|
|
|
|
- private void restoreIndexAndTopPosition() {
|
|
|
|
- if (mIndexes.size() > 0) {
|
|
|
|
- // needs to be checked; not every browse-up had a browse-down before
|
|
|
|
-
|
|
|
|
- int index = mIndexes.remove(mIndexes.size() - 1);
|
|
|
|
-
|
|
|
|
- int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1);
|
|
|
|
-
|
|
|
|
- int top = mTops.remove(mTops.size() - 1);
|
|
|
|
-
|
|
|
|
- mList.setSelectionFromTop(firstPosition, top);
|
|
|
|
-
|
|
|
|
- // Move the scroll if the selection is not visible
|
|
|
|
- int indexPosition = mHeightCell*index;
|
|
|
|
- int height = mList.getHeight();
|
|
|
|
-
|
|
|
|
- if (indexPosition > height) {
|
|
|
|
- if (android.os.Build.VERSION.SDK_INT >= 11)
|
|
|
|
- {
|
|
|
|
- mList.smoothScrollToPosition(index);
|
|
|
|
- }
|
|
|
|
- else if (android.os.Build.VERSION.SDK_INT >= 8)
|
|
|
|
- {
|
|
|
|
- mList.setSelectionFromTop(index, 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Save index and top position
|
|
|
|
- */
|
|
|
|
- private void saveIndexAndTopPosition(int index) {
|
|
|
|
-
|
|
|
|
- mIndexes.add(index);
|
|
|
|
-
|
|
|
|
- int firstPosition = mList.getFirstVisiblePosition();
|
|
|
|
- mFirstPositions.add(firstPosition);
|
|
|
|
-
|
|
|
|
- View view = mList.getChildAt(0);
|
|
|
|
- int top = (view == null) ? 0 : view.getTop() ;
|
|
|
|
-
|
|
|
|
- mTops.add(top);
|
|
|
|
-
|
|
|
|
- // Save the height of a cell
|
|
|
|
- mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
OCFile file = (OCFile) mAdapter.getItem(position);
|
|
OCFile file = (OCFile) mAdapter.getItem(position);
|
|
@@ -237,7 +153,7 @@ public class MoveFileListFragment extends ExtendedListFragment {
|
|
if (file.isFolder()) {
|
|
if (file.isFolder()) {
|
|
// update state and view of this fragment
|
|
// update state and view of this fragment
|
|
listDirectory(file);
|
|
listDirectory(file);
|
|
- // then, notify parent activity to let it update its state and view, and other fragments
|
|
|
|
|
|
+ // then, notify parent activity to let it update its state and view
|
|
mContainerActivity.onBrowsedDownTo(file);
|
|
mContainerActivity.onBrowsedDownTo(file);
|
|
// save index and top position
|
|
// save index and top position
|
|
saveIndexAndTopPosition(position);
|
|
saveIndexAndTopPosition(position);
|