+/* ownCloud Android client application
+ * Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
package com.owncloud.android.ui.activity;
import java.io.IOException;
package com.owncloud.android.ui.fragment;
+import java.util.ArrayList;
+
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
private static final String TAG = ExtendedListFragment.class.getSimpleName();
private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
+ 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";
protected ExtendedListView mList;
private SwipeRefreshLayout mRefreshEmptyLayout;
private TextView mEmptyListMessage;
+ // Save the state of the scroll in browsing
+ private ArrayList<Integer> mIndexes;
+ private ArrayList<Integer> mFirstPositions;
+ private ArrayList<Integer> mTops;
+ private int mHeightCell = 0;
+
+
public void setListAdapter(ListAdapter listAdapter) {
mList.setAdapter(listAdapter);
mList.invalidate();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.e(TAG, "onCreateView");
- //mList = new ExtendedListView(getActivity());
View v = inflater.inflate(R.layout.list_fragment, null);
mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ if (savedInstanceState != null) {
+ 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;
+ }
+ }
+
+
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Log_OC.e(TAG, "onSaveInstanceState()");
savedInstanceState.putInt(KEY_SAVED_LIST_POSITION, getReferencePosition());
+ savedInstanceState.putIntegerArrayList(KEY_INDEXES, mIndexes);
+ savedInstanceState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions);
+ savedInstanceState.putIntegerArrayList(KEY_TOPS, mTops);
+ savedInstanceState.putInt(KEY_HEIGHT_CELL, mHeightCell);
+ savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
}
}
}
+
+ /*
+ * Restore index and position
+ */
+ protected 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
+ */
+ protected 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
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
// to be @overriden
public void onActivityCreated(Bundle savedInstanceState) {
Log_OC.i(TAG, "onActivityCreated() start");
- super.onCreate(savedInstanceState);
+ super.onActivityCreated(savedInstanceState);
mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
setListAdapter(mAdapter);
listDirectory(file);
// notify the click to container Activity
mContainerActivity.onDirectoryClick(file);
+ // save index and top position
+ saveIndexAndTopPosition(position);
} else { /// Click on a file
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
parentDir = mDirectory.getParentFile(); // can be null
}
listDirectory(parentDir);
+
+ // restore index and top position
+ restoreIndexAndTopPosition();
}
/* ownCloud Android client application
- * Copyright (C) 2011 Bartek Przybylski
* Copyright (C) 2012-2014 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
package com.owncloud.android.ui.fragment;
import java.io.File;
-import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
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
- *
*/
public class MoveFileListFragment extends ExtendedListFragment {
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 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 OCFile mFile = null;
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}
super.onActivityCreated(savedInstanceState);
Log_OC.e(TAG, "onActivityCreated() start");
- mAdapter = new FolderListListAdapter(getSherlockActivity(), mContainerActivity);
-
if (savedInstanceState != null) {
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);
-
setListAdapter(mAdapter);
registerForContextMenu(getListView());
getListView().setOnCreateContextMenuListener(this);
- }
+ }
+
/**
* Saves the current listed folder.
public void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState(outState);
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.
*
- * 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.
*/
String parentPath = null;
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
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);
moveCount++;
} 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) {
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);
moveCount++;
} // exit is granted because storageManager.getFileByPath("/") never returns null
- mFile = parentDir;
- }
-
- if (mFile != null) {
+ mFile = parentDir;
+
listDirectory(mFile);
((MoveActivity)mContainerActivity).startSyncFolderOperation(mFile);
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
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
OCFile file = (OCFile) mAdapter.getItem(position);
if (file.isFolder()) {
// update state and view of this fragment
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);
// save index and top position
saveIndexAndTopPosition(position);
package com.owncloud.android.ui.fragment;
import java.io.File;
-import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
private static final String TAG = OCFileListFragment.class.getSimpleName();
- private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
+ private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ?
+ OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
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 OCFile mFile = null;
private OCFile mTargetFile;
- // 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}
*/
super.onActivityCreated(savedInstanceState);
Log_OC.e(TAG, "onActivityCreated() start");
- mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity);
-
if (savedInstanceState != null) {
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 FileListListAdapter(getSherlockActivity(), mContainerActivity);
-
setListAdapter(mAdapter);
registerForContextMenu(getListView());
public void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState(outState);
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.
*
- * 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.
*/
String parentPath = null;
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
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);
moveCount++;
} 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) {
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);
moveCount++;
} // exit is granted because storageManager.getFileByPath("/") never returns null
- mFile = parentDir;
- }
-
- if (mFile != null) {
+ mFile = parentDir;
+
listDirectory(mFile);
((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
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
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
OCFile file = (OCFile) mAdapter.getItem(position);
if (file.isFolder()) {
// update state and view of this fragment
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);
// save index and top position
saveIndexAndTopPosition(position);
* {@inheritDoc}
*/
@Override
- public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ public void onCreateContextMenu (
+ ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getSherlockActivity().getMenuInflater();
inflater.inflate(R.menu.file_actions_menu, menu);