import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
*/
public class FileDisplayActivity extends HookActivity implements
-FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener {
-
+FileFragment.ContainerActivity, OnNavigationListener,
+OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
+
private ArrayAdapter<String> mDirectories;
private SyncBroadcastReceiver mSyncBroadcastReceiver;
onTransferStateChanged(file, false, false);
}
+ @Override
+ public void onRefresh() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ OCFile folder = listOfFiles.getCurrentFile();
+ if (folder != null) {
+ /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
+ listDirectory(mFile);*/
+ startSyncFolderOperation(folder);
+ }
+ }
+ }
+
}
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.fragment.MoveFileListFragment;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.Log_OC;
public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
- OnClickListener{
+ OnClickListener, SwipeRefreshLayout.OnRefreshListener {
private SyncBroadcastReceiver mSyncBroadcastReceiver;
}
if (!stateWasRecovered) {
- MoveFileListFragment listOfFolders = getListOfFilesFragment();
+ OCFileListFragment listOfFolders = getListOfFilesFragment();
listOfFolders.listDirectory(folder);
startSyncFolderOperation(folder);
}
private void createFragments() {
- MoveFileListFragment listOfFiles = new MoveFileListFragment();
+ OCFileListFragment listOfFiles = new OCFileListFragment();
+ Bundle args = new Bundle();
+ args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
+ args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
+ listOfFiles.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
transaction.commit();
* loading or folder is empty
*/
private void setBackgroundText() {
- MoveFileListFragment MoveFileListFragment = getListOfFilesFragment();
- if (MoveFileListFragment != null) {
+ OCFileListFragment listFragment = getListOfFilesFragment();
+ if (listFragment != null) {
int message = R.string.file_list_loading;
if (!mSyncInProgress) {
// In case folder list is empty
message = R.string.file_list_empty_moving;
}
- MoveFileListFragment.setMessageForEmptyList(getString(message));
+ listFragment.setMessageForEmptyList(getString(message));
} else {
- Log.e(TAG, "MoveFileListFragment is null");
+ Log.e(TAG, "OCFileListFragment is null");
}
}
- private MoveFileListFragment getListOfFilesFragment() {
+ private OCFileListFragment getListOfFilesFragment() {
Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(MoveActivity.TAG_LIST_OF_FOLDERS);
if (listOfFiles != null) {
- return (MoveFileListFragment)listOfFiles;
+ return (OCFileListFragment)listOfFiles;
}
Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
return null;
}
protected void refreshListOfFilesFragment() {
- MoveFileListFragment fileListFragment = getListOfFilesFragment();
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory();
}
}
public void browseToRoot() {
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
if (listOfFiles != null) { // should never be null, indeed
OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
listOfFiles.listDirectory(root);
@Override
public void onBackPressed() {
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
if (listOfFiles != null) { // should never be null, indeed
int levelsUp = listOfFiles.onBrowseUp();
if (levelsUp == 0) {
}
if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- MoveFileListFragment fileListFragment = getListOfFilesFragment();
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory(currentDir);
}
}
+ @Override
+ public void onRefresh() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ OCFile folder = listOfFiles.getCurrentFile();
+ if (folder != null) {
+ /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
+ listDirectory(mFile);*/
+ startSyncFolderOperation(folder);
+ }
+ }
+ }
+
}
private Context mContext;\r
private OCFile mFile = null;\r
private Vector<OCFile> mFiles = null;\r
+ private boolean mJustFolders;\r
\r
private FileDataStorageManager mStorageManager;
private Account mAccount;
private ComponentsGetter mTransferServiceGetter;\r
\r
- public FileListListAdapter(Context context, ComponentsGetter transferServiceGetter) {\r
+ public FileListListAdapter(\r
+ boolean justFolders, \r
+ Context context, \r
+ ComponentsGetter transferServiceGetter\r
+ ) {\r
+ mJustFolders = justFolders;\r
mContext = context;\r
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
mTransferServiceGetter = transferServiceGetter;\r
}\r
if (mStorageManager != null) {\r
mFiles = mStorageManager.getFolderContent(mFile);\r
+ if (mJustFolders) {\r
+ mFiles = getFolders(mFiles);\r
+ }\r
} else {\r
mFiles = null;\r
}\r
notifyDataSetChanged();\r
}\r
\r
+ \r
+ /**\r
+ * Filter for getting only the folders\r
+ * @param files\r
+ * @return Vector<OCFile>\r
+ */\r
+ public Vector<OCFile> getFolders(Vector<OCFile> files) {\r
+ Vector<OCFile> ret = new Vector<OCFile>(); \r
+ OCFile current = null; \r
+ for (int i=0; i<files.size(); i++) {\r
+ current = files.get(i);\r
+ if (current.isFolder()) {\r
+ ret.add(current);\r
+ }\r
+ }\r
+ return ret;\r
+ }\r
+ \r
+ \r
/**\r
* Check if parent folder does not include 'S' permission and if file/folder\r
* is shared with me\r
+++ /dev/null
-/* 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
- * 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.adapter;
-
-import java.util.Vector;
-
-import android.accounts.Account;
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.TextView;
-
-import com.owncloud.android.R;
-import com.owncloud.android.authentication.AccountUtils;
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.ui.activity.ComponentsGetter;
-import com.owncloud.android.utils.DisplayUtils;
-
-
-/**
- * This Adapter populates a ListView with all the folders in an ownCloud instance.
- */
-public class FolderListListAdapter extends BaseAdapter implements ListAdapter {
- private final static String PERMISSION_SHARED_WITH_ME = "S";
-
- private Context mContext;
- private OCFile mFile = null;
- private Vector<OCFile> mFolders = null;
-
- private FileDataStorageManager mStorageManager;
- private Account mAccount;
- private ComponentsGetter mTransferServiceGetter;
-
- public FolderListListAdapter(Context context, ComponentsGetter transferServiceGetter) {
- mContext = context;
- mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
- mTransferServiceGetter = transferServiceGetter;
- }
-
- @Override
- public boolean areAllItemsEnabled() {
- return true;
- }
-
- @Override
- public boolean isEnabled(int position) {
- return true;
- }
-
- @Override
- public int getCount() {
- return mFolders != null ? mFolders.size() : 0;
- }
-
- @Override
- public Object getItem(int position) {
- if (mFolders == null || mFolders.size() <= position)
- return null;
- return mFolders.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- if (mFolders == null || mFolders.size() <= position)
- return 0;
- return mFolders.get(position).getFileId();
- }
-
- @Override
- public int getItemViewType(int position) {
- return 0;
- }
-
- @SuppressLint("InflateParams")
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if (view == null) {
- LayoutInflater inflator = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflator.inflate(R.layout.list_item, null);
- }
-
- if (mFolders != null && mFolders.size() > position) {
- OCFile file = mFolders.get(position);
- TextView fileName = (TextView) view.findViewById(R.id.Filename);
- String name = file.getFileName();
-
- fileName.setText(name);
- ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
- ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
- ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
- sharedWithMeIconV.setVisibility(View.GONE);
-
- ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
- localStateView.bringToFront();
- FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
- FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
-
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
- localStateView.setImageResource(R.drawable.downloading_file_indicator);
- localStateView.setVisibility(View.VISIBLE);
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
- localStateView.setImageResource(R.drawable.uploading_file_indicator);
- localStateView.setVisibility(View.VISIBLE);
- } else if (file.isDown()) {
- localStateView.setImageResource(R.drawable.local_file_indicator);
- localStateView.setVisibility(View.VISIBLE);
- } else {
- localStateView.setVisibility(View.INVISIBLE);
- }
-
- TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
- TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
- ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
-
-
- fileSizeV.setVisibility(View.INVISIBLE);
- lastModV.setVisibility(View.VISIBLE);
- lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
- checkBoxV.setVisibility(View.GONE);
- view.findViewById(R.id.imageView3).setVisibility(View.GONE);
-
- if (checkIfFileIsSharedWithMe(file)) {
- fileIcon.setImageResource(R.drawable.shared_with_me_folder);
- sharedWithMeIconV.setVisibility(View.VISIBLE);
- } else {
- fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName()));
- }
-
- // If folder is sharedByLink, icon folder must be changed to
- // folder-public one
- if (file.isShareByLink()) {
- fileIcon.setImageResource(R.drawable.folder_public);
- }
-
- if (file.isShareByLink()) {
- sharedIconV.setVisibility(View.VISIBLE);
- } else {
- sharedIconV.setVisibility(View.GONE);
- }
- }
-
- return view;
- }
-
- @Override
- public int getViewTypeCount() {
- return 1;
- }
-
- @Override
- public boolean hasStableIds() {
- return true;
- }
-
- @Override
- public boolean isEmpty() {
- return (mFolders == null || mFolders.isEmpty());
- }
-
- /**
- * Change the adapted directory for a new one
- * @param directory New file to adapt. Can be NULL, meaning "no content to adapt".
- * @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
- */
- public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager) {
- mFile = directory;
- if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {
- mStorageManager = updatedStorageManager;
- mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
- }
- if (mStorageManager != null) {
- // Only take into account the folders for after being listed
- mFolders = getFolders(mStorageManager.getFolderContent(mFile));
- } else {
- mFolders = null;
- }
- notifyDataSetChanged();
- }
-
- /**
- * Filter for getting only the folders
- * @param files
- * @return Vector<OCFile>
- */
- public Vector<OCFile> getFolders(Vector<OCFile> files) {
- Vector<OCFile> ret = new Vector<OCFile>();
- OCFile current = null;
- for (int i=0; i<files.size(); i++) {
- current = files.get(i);
- if (current.isFolder()) {
- ret.add(current);
- }
- }
- return ret;
- }
-
- /**
- * Check if parent folder does not include 'S' permission and if file/folder
- * is shared with me
- *
- * @param file: OCFile
- * @return boolean: True if it is shared with me and false if it is not
- */
- private boolean checkIfFileIsSharedWithMe(OCFile file) {
- return (mFile.getPermissions() != null && !mFile.getPermissions().contains(PERMISSION_SHARED_WITH_ME)
- && file.getPermissions() != null && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME));
- }
-}
/**
* TODO extending SherlockListFragment instead of SherlockFragment
*/
-public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener{
+public class ExtendedListFragment extends SherlockFragment
+implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = ExtendedListFragment.class.getSimpleName();
private ArrayList<Integer> mFirstPositions;
private ArrayList<Integer> mTops;
private int mHeightCell = 0;
+
+ private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null;
public void setListAdapter(ListAdapter listAdapter) {
// to be @overriden
mRefreshLayout.setRefreshing(false);
mRefreshEmptyLayout.setRefreshing(false);
+
+ if (mOnRefreshListener != null) {
+ mOnRefreshListener.onRefresh();
+ }
}
+
+ public void setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener) {
+ mOnRefreshListener = listener;
+ }
+
/**
* Enables swipe gesture
+++ /dev/null
-/* 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.fragment;
-
-import java.io.File;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.AdapterView;
-
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.ui.activity.MoveActivity;
-import com.owncloud.android.ui.adapter.FolderListListAdapter;
-import com.owncloud.android.utils.Log_OC;
-
-/**
- * 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 EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
-
- private FileFragment.ContainerActivity mContainerActivity;
-
- private OCFile mFile = null;
- private FolderListListAdapter mAdapter;
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- Log_OC.e(TAG, "onAttach");
- try {
- mContainerActivity = (FileFragment.ContainerActivity) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString() + " must implement " +
- FileFragment.ContainerActivity.class.getSimpleName());
- }
- }
-
-
- @Override
- public void onDetach() {
- mContainerActivity = null;
- super.onDetach();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- Log_OC.e(TAG, "onActivityCreated() start");
-
- if (savedInstanceState != null) {
- mFile = savedInstanceState.getParcelable(EXTRA_FILE);
- }
-
- mAdapter = new FolderListListAdapter(getSherlockActivity(), mContainerActivity);
- setListAdapter(mAdapter);
-
- registerForContextMenu(getListView());
- getListView().setOnCreateContextMenuListener(this);
- }
-
-
- /**
- * Saves the current listed folder.
- */
- @Override
- public void onSaveInstanceState (Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putParcelable(EXTRA_FILE, mFile);
- }
-
- /**
- * 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.
- *
- * return Count of folder levels browsed up.
- */
- public int onBrowseUp() {
- OCFile parentDir = null;
- int moveCount = 0;
-
- if(mFile != null){
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
-
- 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;
- parentDir = storageManager.getFileByPath(parentPath);
- moveCount++;
- } else {
- 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;
- parentDir = storageManager.getFileByPath(parentPath);
- moveCount++;
- } // exit is granted because storageManager.getFileByPath("/") never returns null
- mFile = parentDir;
-
- listDirectory(mFile);
-
- ((MoveActivity)mContainerActivity).startSyncFolderOperation(mFile);
-
- // restore index and top position
- restoreIndexAndTopPosition();
-
- } // else - should never happen now
-
- return moveCount;
- }
-
- @Override
- public void onItemClick(AdapterView<?> l, View v, int position, long id) {
- OCFile file = (OCFile) mAdapter.getItem(position);
- if (file != null) {
- if (file.isFolder()) {
- // update state and view of this fragment
- listDirectory(file);
- // then, notify parent activity to let it update its state and view
- mContainerActivity.onBrowsedDownTo(file);
- // save index and top position
- saveIndexAndTopPosition(position);
-
- }
-
- } else {
- Log_OC.d(TAG, "Null object in ListAdapter!!");
- }
-
- }
-
- /**
- * Use this to query the {@link OCFile} that is currently
- * being displayed by this fragment
- * @return The currently viewed OCFile
- */
- public OCFile getCurrentFile(){
- return mFile;
- }
-
- /**
- * Calls {@link MoveFileListFragment#listDirectory(OCFile)} with a null parameter
- */
- public void listDirectory(){
- listDirectory(null);
- }
-
- /**
- * Lists the given directory on the view. When the input parameter is null,
- * it will either refresh the last known directory. list the root
- * if there never was a directory.
- *
- * @param directory File to be listed
- */
- public void listDirectory(OCFile directory) {
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
- if (storageManager != null) {
-
- // Check input parameters for null
- if(directory == null){
- if(mFile != null){
- directory = mFile;
- } else {
- directory = storageManager.getFileByPath("/");
- if (directory == null) return; // no files, wait for sync
- }
- }
-
-
- // If that's not a directory -> List its parent
- if(!directory.isFolder()){
- Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
- directory = storageManager.getFileById(directory.getParentId());
- }
-
- mAdapter.swapDirectory(directory, storageManager);
- if (mFile == null || !mFile.equals(directory)) {
- mList.setSelectionFromTop(0, 0);
- }
- mFile = directory;
- }
- }
-
-
- @Override
- public void onRefresh() {
- super.onRefresh();
-
- if (mFile != null) {
- // Refresh mFile
- mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
-
- listDirectory(mFile);
-
- ((MoveActivity)mContainerActivity).startSyncFolderOperation(mFile);
- }
- }
-}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
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";
+
+ public final static String ARG_JUST_FOLDERS = MY_PACKAGE + ".JUST_FOLDERS";
+ public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL";
+
+ private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE";
private FileFragment.ContainerActivity mContainerActivity;
private OCFile mTargetFile;
+
/**
* {@inheritDoc}
*/
Log_OC.e(TAG, "onAttach");
try {
mContainerActivity = (FileFragment.ContainerActivity) activity;
+
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement " +
FileFragment.ContainerActivity.class.getSimpleName());
}
+ try {
+ setOnRefreshListener((SwipeRefreshLayout.OnRefreshListener) activity);
+
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString() + " must implement " +
+ SwipeRefreshLayout.OnRefreshListener.class.getSimpleName());
+ }
}
@Override
public void onDetach() {
+ setOnRefreshListener(null);
mContainerActivity = null;
super.onDetach();
}
Log_OC.e(TAG, "onActivityCreated() start");
if (savedInstanceState != null) {
- mFile = savedInstanceState.getParcelable(EXTRA_FILE);
+ mFile = savedInstanceState.getParcelable(KEY_FILE);
}
- mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity);
+ Bundle args = getArguments();
+ boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false);
+ mAdapter = new FileListListAdapter(
+ justFolders,
+ getSherlockActivity(),
+ mContainerActivity
+ );
setListAdapter(mAdapter);
registerForContextMenu(getListView());
@Override
public void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable(EXTRA_FILE, mFile);
+ outState.putParcelable(KEY_FILE, mFile);
}
/**
listDirectory(mFile);
- ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
+ onRefresh();
// restore index and top position
restoreIndexAndTopPosition();
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);
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
- OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
-
- if (mContainerActivity.getStorageManager() != null) {
- FileMenuFilter mf = new FileMenuFilter(
- targetFile,
- mContainerActivity.getStorageManager().getAccount(),
- mContainerActivity,
- getSherlockActivity()
- );
- mf.filter(menu);
- }
-
- /// additional restrictions for this fragment
- // TODO allow in the future 'open with' for previewable files
- MenuItem item = menu.findItem(R.id.action_open_file_with);
- if (item != null) {
- item.setVisible(false);
- item.setEnabled(false);
- }
- /// TODO break this direct dependency on FileDisplayActivity... if possible
- FileFragment frag = ((FileDisplayActivity)getSherlockActivity()).getSecondFragment();
- if (frag != null && frag instanceof FileDetailFragment &&
- frag.getFile().getFileId() == targetFile.getFileId()) {
- item = menu.findItem(R.id.action_see_details);
+ Bundle args = getArguments();
+ boolean allowContextualActions =
+ (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
+ if (allowContextualActions) {
+ MenuInflater inflater = getSherlockActivity().getMenuInflater();
+ inflater.inflate(R.menu.file_actions_menu, menu);
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
+ OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
+
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ targetFile,
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getSherlockActivity()
+ );
+ mf.filter(menu);
+ }
+
+ /// additional restrictions for this fragment
+ // TODO allow in the future 'open with' for previewable files
+ MenuItem item = menu.findItem(R.id.action_open_file_with);
if (item != null) {
item.setVisible(false);
item.setEnabled(false);
}
+ /// TODO break this direct dependency on FileDisplayActivity... if possible
+ FileFragment frag = ((FileDisplayActivity)getSherlockActivity()).getSecondFragment();
+ if (frag != null && frag instanceof FileDetailFragment &&
+ frag.getFile().getFileId() == targetFile.getFileId()) {
+ item = menu.findItem(R.id.action_see_details);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
}
-
-
}
}
}
-
- @Override
- public void onRefresh() {
- super.onRefresh();
-
- if (mFile != null) {
- // Refresh mFile
- mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
-
- listDirectory(mFile);
-
- ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
- }
- }
-
-
-
}