From: tobiasKaminsky Date: Fri, 24 Oct 2014 16:18:06 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/develop' into fileCount X-Git-Tag: oc-android-1.7.0_signed~91^2~4 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/fbc3d970c565e16898eb019d7aef716521a40f10?ds=inline;hp=--cc Merge remote-tracking branch 'upstream/develop' into fileCount Conflicts: res/layout/list_fragment.xml res/values/strings.xml src/com/owncloud/android/ui/fragment/ExtendedListFragment.java src/com/owncloud/android/ui/fragment/OCFileListFragment.java --- fbc3d970c565e16898eb019d7aef716521a40f10 diff --cc res/layout/list_fragment.xml index 56e869cf,4236d070..160edc1d --- a/res/layout/list_fragment.xml +++ b/res/layout/list_fragment.xml @@@ -17,27 -17,42 +17,44 @@@ You should have received a copy of the GNU General Public License along with this program. If not, see . --> - + android:layout_weight="1" > - - ++ android:layout_height="match_parent" + android:layout_weight="1" - android:footerDividersEnabled="false" - /> - - ++ + - ++ + - - + android:visibility="gone" > - + + + + + + + diff --cc res/values/strings.xml index 30f6b4f5,af5a684d..dc7ec2a4 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -50,11 -60,9 +60,13 @@@ No content was received. Nothing to upload. %1$s is not allowed to access the shared content Uploading - There are no files in this folder.\nNew files can be added with the \"Upload\" menu option. + Nothing in here. Upload something! + Loading... + There are no files in this folder. + folder + folders + file + files Tap on a file to display additional information. Size: Type: diff --cc src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 2b9653e6,5d3f7ace..5c66bfe7 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@@ -18,7 -18,10 +18,8 @@@ package com.owncloud.android.ui.fragment; -import java.util.ArrayList; - import android.os.Bundle; + import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@@ -26,23 -29,44 +27,43 @@@ import android.widget.AdapterView import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; + import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; +import com.owncloud.android.Log_OC; import com.owncloud.android.R; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.ExtendedListView; -import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; /** - * TODO extending SherlockListFragment instead of SherlockFragment + * TODO extending SherlockListFragment instead of SherlockFragment */ - public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener { + public class ExtendedListFragment extends SherlockFragment + implements OnItemClickListener, OnEnforceableRefreshListener { - + private static final String TAG = ExtendedListFragment.class.getSimpleName(); - private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION"; + 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 mRefreshLayout; + private SwipeRefreshLayout mRefreshEmptyLayout; + private TextView mEmptyListMessage; + + // Save the state of the scroll in browsing + private ArrayList mIndexes; + private ArrayList mFirstPositions; + private ArrayList mTops; + private int mHeightCell = 0; + + private OnEnforceableRefreshListener mOnRefreshListener = null; + + public void setListAdapter(ListAdapter listAdapter) { mList.setAdapter(listAdapter); mList.invalidate(); @@@ -60,12 -80,12 +81,12 @@@ @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); - mList = (ExtendedListView)(v.findViewById(R.id.list_root)); + mList = (ExtendedListView) (v.findViewById(R.id.list_root)); mList.setOnItemClickListener(this); - // mList.setEmptyView(v.findViewById(R.id.empty_list_view)); // looks - // like it's not a cool idea + mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator)); mList.setDividerHeight(1); @@@ -73,27 -93,63 +94,64 @@@ int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION); setReferencePosition(referencePosition); } - + + // Pull down refresh + mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files); + mRefreshEmptyLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files_emptyView); + + onCreateSwipeToRefresh(mRefreshLayout); + onCreateSwipeToRefresh(mRefreshEmptyLayout); + + mList.setEmptyView(mRefreshEmptyLayout); + return v; } - + /** + * {@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(); + mFirstPositions = new ArrayList(); + mTops = new ArrayList(); + 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()); } - /** - * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when - * the device is turned to other position. + * Calculates the position of the item that will be used as a reference to + * reposition the visible items in the list when the device is turned to + * other position. * - * THe current policy is take as a reference the visible item in the center of the screen. + * THe current policy is take as a reference the visible item in the center + * of the screen. * - * @return The position in the list of the visible item in the center of the screen. + * @return The position in the list of the visible item in the center of the + * screen. */ protected int getReferencePosition() { if (mList != null) { @@@ -115,9 -171,143 +173,142 @@@ } } + + /* + * 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 arg0, View arg1, int arg2, long arg3) { + public void onItemClick (AdapterView parent, View view, int position, long id) { - // to be @overriden + // to be @overriden } + @Override + public void onRefresh() { + // to be @overriden + mRefreshLayout.setRefreshing(false); + mRefreshEmptyLayout.setRefreshing(false); + + if (mOnRefreshListener != null) { + mOnRefreshListener.onRefresh(); + } + } - + public void setOnRefreshListener(OnEnforceableRefreshListener listener) { + mOnRefreshListener = listener; + } + + + /** + * Enables swipe gesture + */ + public void enableSwipe() { + mRefreshLayout.setEnabled(true); + } + + /** + * Disables swipe gesture. It prevents manual gestures but keeps the option you show + * refreshing programmatically. + */ + public void disableSwipe() { + mRefreshLayout.setEnabled(false); + } + + /** + * It shows the SwipeRefreshLayout progress + */ + public void showSwipeProgress() { + mRefreshLayout.setRefreshing(true); + } + + /** + * It shows the SwipeRefreshLayout progress + */ + public void hideSwipeProgress() { + mRefreshLayout.setRefreshing(false); + } + + /** + * Set message for empty list view + */ + public void setMessageForEmptyList(String message) { + if (mEmptyListMessage != null) { + mEmptyListMessage.setText(message); + } + } + + /** + * Get the text of EmptyListMessage TextView + * + * @return String + */ + public String getEmptyViewText() { + return (mEmptyListMessage != null) ? mEmptyListMessage.getText().toString() : ""; + } + + private void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) { + // Colors in animations: background + refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, R.color.background_color, + R.color.background_color); + + refreshLayout.setOnRefreshListener(this); + } + + @Override + public void onRefresh(boolean ignoreETag) { + mRefreshLayout.setRefreshing(false); + mRefreshEmptyLayout.setRefreshing(false); + + if (mOnRefreshListener != null) { + mOnRefreshListener.onRefresh(ignoreETag); + } + } } diff --cc src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 5b9be478,0b1059fc..00000000 deleted file mode 100644,100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ /dev/null @@@ -1,568 -1,402 +1,0 @@@ --/* ownCloud Android client application -- * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. - * 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 . -- * -- */ --package com.owncloud.android.ui.fragment; -- --import java.io.File; - import java.util.ArrayList; - import java.util.List; - import java.util.Vector; -- - import android.accounts.Account; --import android.app.Activity; - import android.content.Context; -import android.content.Intent; --import android.os.Bundle; - import android.os.Handler; -import android.support.v4.widget.SwipeRefreshLayout; --import android.view.ContextMenu; - import android.view.LayoutInflater; --import android.view.MenuInflater; --import android.view.MenuItem; --import android.view.View; --import android.widget.AdapterView; --import android.widget.AdapterView.AdapterContextMenuInfo; - import android.widget.TextView; -- - import com.owncloud.android.Log_OC; --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.FileHandler; - import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; - import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; - import com.owncloud.android.operations.OnRemoteOperationListener; - import com.owncloud.android.operations.RemoteOperation; - import com.owncloud.android.operations.RemoveFileOperation; - import com.owncloud.android.operations.RenameFileOperation; - import com.owncloud.android.operations.SynchronizeFileOperation; -import com.owncloud.android.files.FileMenuFilter; -import com.owncloud.android.lib.common.utils.Log_OC; --import com.owncloud.android.ui.activity.FileDisplayActivity; - import com.owncloud.android.ui.activity.TransferServiceGetter; -import com.owncloud.android.ui.activity.MoveActivity; -import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; --import com.owncloud.android.ui.adapter.FileListListAdapter; - import com.owncloud.android.ui.dialog.EditNameDialog; - import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; - import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; -import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; -import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; -import com.owncloud.android.ui.dialog.RenameFileDialogFragment; --import com.owncloud.android.ui.preview.PreviewImageFragment; --import com.owncloud.android.ui.preview.PreviewMediaFragment; -- --/** -- * A Fragment that lists all files and folders in a given path. -- * - * @author Bartek Przybylski - * TODO refactorize to get rid of direct dependency on FileDisplayActivity -- * - * @author Bartek Przybylski - * @author masensio - * @author David A. Velasco -- */ - public class OCFileListFragment extends ExtendedListFragment implements EditNameDialogListener, - ConfirmationDialogFragmentListener { - -public class OCFileListFragment extends ExtendedListFragment { - -- 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 EXTRA_FILE = MY_PACKAGE + ".extra.FILE"; -- - private OCFileListFragment.ContainerActivity mContainerActivity; - private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? - OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment"; - - 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 mFile = null; -- private FileListListAdapter mAdapter; - private View mFooterView; - - private Handler mHandler; - -- private OCFile mTargetFile; -- - -- /** -- * {@inheritDoc} -- */ -- @Override -- public void onAttach(Activity activity) { -- super.onAttach(activity); -- Log_OC.e(TAG, "onAttach"); -- try { - mContainerActivity = (ContainerActivity) activity; - mContainerActivity = (FileFragment.ContainerActivity) activity; - -- } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement " - + OCFileListFragment.ContainerActivity.class.getSimpleName()); - throw new ClassCastException(activity.toString() + " must implement " + - FileFragment.ContainerActivity.class.getSimpleName()); - } - try { - setOnRefreshListener((OnEnforceableRefreshListener) 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(); -- } -- -- /** -- * {@inheritDoc} -- */ -- @Override -- public void onActivityCreated(Bundle savedInstanceState) { -- super.onActivityCreated(savedInstanceState); -- Log_OC.e(TAG, "onActivityCreated() start"); - - mFooterView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate( - R.layout.list_footer, null, false); - setFooterView(mFooterView); - - mAdapter = new FileListListAdapter(getActivity(), mContainerActivity); - -- if (savedInstanceState != null) { - mFile = savedInstanceState.getParcelable(EXTRA_FILE); - mFile = savedInstanceState.getParcelable(KEY_FILE); -- } - - Bundle args = getArguments(); - boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false); - mAdapter = new FileListListAdapter( - justFolders, - getSherlockActivity(), - mContainerActivity - ); -- setListAdapter(mAdapter); - - -- registerForContextMenu(getListView()); -- getListView().setOnCreateContextMenuListener(this); - - mHandler = new Handler(); - - } - - } - -- /** -- * Saves the current listed folder. -- */ -- @Override - public void onSaveInstanceState(Bundle outState) { - public void onSaveInstanceState (Bundle outState) { -- super.onSaveInstanceState(outState); - outState.putParcelable(EXTRA_FILE, mFile); - outState.putParcelable(KEY_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. - * 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. -- */ -- public int onBrowseUp() { -- OCFile parentDir = null; -- int moveCount = 0; - - if (mFile != null) { - - 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; - 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 - } // exit is granted because storageManager.getFileByPath("/") never returns null -- mFile = parentDir; - } - - if (mFile != null) { - -- listDirectory(mFile); - - mContainerActivity.startSyncFolderOperation(mFile); - } // else - should never happen now -- - onRefresh(false); - - // 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()) { - 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); - - } else { // / Click on a file - // save index and top position - saveIndexAndTopPosition(position); - - } else { /// Click on a file -- if (PreviewImageFragment.canBePreviewed(file)) { -- // preview image - it handles the download, if needed - mContainerActivity.startImagePreview(file); - - ((FileDisplayActivity)mContainerActivity).startImagePreview(file); - -- } else if (file.isDown()) { -- if (PreviewMediaFragment.canBePreviewed(file)) { -- // media preview - mContainerActivity.startMediaPreview(file, 0, true); - ((FileDisplayActivity)mContainerActivity).startMediaPreview(file, 0, true); -- } else { - // open with - mContainerActivity.openFile(file); - mContainerActivity.getFileOperationsHelper().openFile(file); -- } - - -- } else { -- // automatic download, preview on finish - mContainerActivity.startDownloadForPreview(file); - ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file); -- } - - -- } - - -- } else { -- Log_OC.d(TAG, "Null object in ListAdapter!!"); -- } - - -- } - - -- /** -- * {@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 = getActivity().getMenuInflater(); - inflater.inflate(R.menu.file_actions_menu, menu); - AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; - OCFile targetFile = (OCFile) mAdapter.getItem(info.position); - List toHide = new ArrayList(); - List toDisable = new ArrayList(); - - MenuItem item = null; - if (targetFile.isFolder()) { - // contextual menu for folders - toHide.add(R.id.action_open_file_with); - toHide.add(R.id.action_download_file); - toHide.add(R.id.action_cancel_download); - toHide.add(R.id.action_cancel_upload); - toHide.add(R.id.action_sync_file); - toHide.add(R.id.action_see_details); - if (mContainerActivity.getFileDownloaderBinder().isDownloading( - AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) - || mContainerActivity.getFileUploaderBinder().isUploading( - AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { - toDisable.add(R.id.action_rename_file); - toDisable.add(R.id.action_remove_file); - - } - - } else { - // contextual menu for regular files - - // new design: 'download' and 'open with' won't be available anymore - // in context menu - toHide.add(R.id.action_download_file); - toHide.add(R.id.action_open_file_with); - - if (targetFile.isDown()) { - toHide.add(R.id.action_cancel_download); - toHide.add(R.id.action_cancel_upload); - - } else { - toHide.add(R.id.action_sync_file); - } - if (mContainerActivity.getFileDownloaderBinder().isDownloading( - AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { - toHide.add(R.id.action_cancel_upload); - toDisable.add(R.id.action_rename_file); - toDisable.add(R.id.action_remove_file); - - } else if (mContainerActivity.getFileUploaderBinder().isUploading( - AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { - toHide.add(R.id.action_cancel_download); - toDisable.add(R.id.action_rename_file); - toDisable.add(R.id.action_remove_file); - - } else { - toHide.add(R.id.action_cancel_download); - toHide.add(R.id.action_cancel_upload); - 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); -- } - } - - for (int i : toHide) { - item = menu.findItem(i); - - /// 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); -- } - } - - for (int i : toDisable) { - item = menu.findItem(i); - if (item != null) { - 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); - } -- } -- } -- } - - - -- /** -- * {@inhericDoc} -- */ -- @Override - public boolean onContextItemSelected(MenuItem item) { - AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); - public boolean onContextItemSelected (MenuItem item) { - AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); -- mTargetFile = (OCFile) mAdapter.getItem(info.position); - switch (item.getItemId()) { - case R.id.action_rename_file: { - String fileName = mTargetFile.getFileName(); - int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf("."); - int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length(); - EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, - selectionEnd, this); - dialog.show(getFragmentManager(), EditNameDialog.TAG); - return true; - } - case R.id.action_remove_file: { - int messageStringId = R.string.confirmation_remove_alert; - int posBtnStringId = R.string.confirmation_remove_remote; - int neuBtnStringId = -1; - if (mTargetFile.isFolder()) { - messageStringId = R.string.confirmation_remove_folder_alert; - posBtnStringId = R.string.confirmation_remove_remote_and_local; - neuBtnStringId = R.string.confirmation_remove_folder_local; - } else if (mTargetFile.isDown()) { - posBtnStringId = R.string.confirmation_remove_remote_and_local; - neuBtnStringId = R.string.confirmation_remove_local; - switch (item.getItemId()) { - case R.id.action_share_file: { - mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile); - return true; -- } - ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(messageStringId, - new String[] { mTargetFile.getFileName() }, posBtnStringId, neuBtnStringId, R.string.common_cancel); - confDialog.setOnConfirmationListener(this); - confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION); - return true; - } - case R.id.action_sync_file: { - Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()); - RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, - mContainerActivity.getStorageManager(), account, true, getSherlockActivity()); - operation.execute(account, getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity()); - ((FileDisplayActivity) getSherlockActivity()).showLoadingDialog(); - return true; - } - case R.id.action_cancel_download: { - FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); - Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity()); - if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) { - downloaderBinder.cancel(account, mTargetFile); - listDirectory(); - mContainerActivity.onTransferStateChanged(mTargetFile, false, false); - case R.id.action_unshare_file: { - mContainerActivity.getFileOperationsHelper().unshareFileWithLink(mTargetFile); - return true; -- } - return true; - } - case R.id.action_cancel_upload: { - FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); - Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity()); - if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) { - uploaderBinder.cancel(account, mTargetFile); - listDirectory(); - mContainerActivity.onTransferStateChanged(mTargetFile, false, false); - case R.id.action_rename_file: { - RenameFileDialogFragment dialog = RenameFileDialogFragment.newInstance(mTargetFile); - dialog.show(getFragmentManager(), FileDetailFragment.FTAG_RENAME_FILE); - return true; -- } - return true; - } - case R.id.action_see_details: { - ((FileFragment.ContainerActivity) getActivity()).showDetails(mTargetFile); - return true; - } - default: - return super.onContextItemSelected(item); - case R.id.action_remove_file: { - RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(mTargetFile); - dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION); - return true; - } - case R.id.action_download_file: - case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile); - return true; - } - case R.id.action_cancel_download: - case R.id.action_cancel_upload: { - ((FileDisplayActivity)mContainerActivity).cancelTransference(mTargetFile); - return true; - } - case R.id.action_see_details: { - mContainerActivity.showDetails(mTargetFile); - return true; - } - case R.id.action_send_file: { - // Obtain the file - if (!mTargetFile.isDown()) { // Download the file - Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded"); - ((FileDisplayActivity)mContainerActivity).startDownloadForSending(mTargetFile); - - } else { - mContainerActivity.getFileOperationsHelper().sendDownloadedFile(mTargetFile); - } - return true; - } - case R.id.action_move: { - Intent action = new Intent(getActivity(), MoveActivity.class); - - // Pass mTargetFile that contains info of selected file/folder - action.putExtra(MoveActivity.EXTRA_TARGET_FILE, mTargetFile); - getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES); - return true; - } - default: - return super.onContextItemSelected(item); -- } -- } - -- -- /** - * Use this to query the {@link OCFile} that is currently being displayed by - * this fragment - * - * Use this to query the {@link OCFile} that is currently - * being displayed by this fragment -- * @return The currently viewed OCFile -- */ - public OCFile getCurrentFile() { - public OCFile getCurrentFile(){ -- return mFile; -- } - - -- /** - * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null - * parameter - * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter -- */ - public void listDirectory() { - 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. - * 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) { - if(directory == null){ - if(mFile != null){ -- directory = mFile; -- } else { -- directory = storageManager.getFileByPath("/"); - if (directory == null) - return; // no files, wait for sync - if (directory == null) return; // no files, wait for sync -- } -- } - - - -- // If that's not a directory -> List its parent - if (!directory.isFolder()) { - 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; - - // Update Footer - TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); - footerText.setText(generateFooterText(directory)); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); - } - } - - private String generateFooterText(OCFile directory) { - Integer files = 0; - Integer folders = 0; - - FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); - Vector mFiles = storageManager.getFolderContent(mFile); - - for (OCFile ocFile : mFiles) { - if (ocFile.isFolder()) { - folders++; - } else { - files++; - } - } - - String output = ""; - - if (folders == 1) { - output = folders.toString() + " " + getResources().getString(R.string.file_list_folder) + ", "; - } else if (folders > 1) { - output = folders.toString() + " " + getResources().getString(R.string.file_list_folders) + ", "; - } - if (files == 1) { - output = output + files.toString() + " " + getResources().getString(R.string.file_list_file); - } else { - output = output + files.toString() + " " + getResources().getString(R.string.file_list_files); - } - return output; - } - - /** - * Interface to implement by any Activity that includes some instance of - * FileListFragment - * - * @author David A. Velasco - */ - public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener, FileHandler { - - /** - * Callback method invoked when a the user browsed into a different - * folder through the list of files - * - * @param file - */ - public void onBrowsedDownTo(OCFile folder); - - public void startDownloadForPreview(OCFile file); - - public void startMediaPreview(OCFile file, int i, boolean b); - - public void startImagePreview(OCFile file); - - public void startSyncFolderOperation(OCFile folder); - - /** - * Getter for the current DataStorageManager in the container activity - */ - public FileDataStorageManager getStorageManager(); - - /** - * Callback method invoked when a the 'transfer state' of a file - * changes. - * - * This happens when a download or upload is started or ended for a - * file. - * - * This method is necessary by now to update the user interface of the - * double-pane layout in tablets because methods - * {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and - * {@link FileUploaderBinder#isUploading(Account, OCFile)} won't provide - * the needed response before the method where this is called finishes. - * - * TODO Remove this when the transfer state of a file is kept in the - * database (other thing TODO) - * - * @param file OCFile which state changed. - * @param downloading Flag signaling if the file is now downloading. - * @param uploading Flag signaling if the file is now uploading. - */ - public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading); - - } - - @Override - public void onDismiss(EditNameDialog dialog) { - if (dialog.getResult()) { - String newFilename = dialog.getNewFilename(); - Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename); - RemoteOperation operation = new RenameFileOperation(mTargetFile, - AccountUtils.getCurrentOwnCloudAccount(getActivity()), newFilename, - mContainerActivity.getStorageManager()); - operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), - mContainerActivity, mHandler, getSherlockActivity()); - ((FileDisplayActivity) getActivity()).showLoadingDialog(); -- } -- } - - @Override - public void onConfirmation(String callerTag) { - if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) { - if (mContainerActivity.getStorageManager().getFileById(mTargetFile.getFileId()) != null) { - RemoteOperation operation = new RemoveFileOperation(mTargetFile, true, - mContainerActivity.getStorageManager()); - operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), - mContainerActivity, mHandler, getSherlockActivity()); - - ((FileDisplayActivity) getActivity()).showLoadingDialog(); - } - } - - public void sortByName(boolean descending) { - mAdapter.setSortOrder(FileListListAdapter.SORT_NAME, descending); -- } -- - @Override - public void onNeutral(String callerTag) { - mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true); // TODO - // perform - // in - // background - // task - // / - // new - // thread - listDirectory(); - mContainerActivity.onTransferStateChanged(mTargetFile, false, false); - public void sortByDate(boolean descending) { - mAdapter.setSortOrder(FileListListAdapter.SORT_DATE, descending); -- } -- - @Override - public void onCancel(String callerTag) { - Log_OC.d(TAG, "REMOVAL CANCELED"); - } - public void sortBySize(boolean descending) { - mAdapter.setSortOrder(FileListListAdapter.SORT_SIZE, descending); - } -- --}