mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
remove on long click, add context menu instead
This commit is contained in:
parent
397dd7b5b2
commit
cf63d7ce0e
5 changed files with 93 additions and 55 deletions
8
res/menu/upload_actions_menu.xml
Executable file
8
res/menu/upload_actions_menu.xml
Executable file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:id="@+id/action_open_file_with" android:title="@string/actionbar_open_with" android:icon="@android:drawable/ic_menu_set_as" android:orderInCategory="1" />
|
||||
<item android:id="@+id/action_cancel_upload" android:title="@string/common_cancel_upload" android:icon="@android:drawable/ic_menu_close_clear_cancel" android:orderInCategory="1" />
|
||||
<item android:id="@+id/action_see_details" android:title="@string/actionbar_see_details" android:icon="@android:drawable/ic_menu_info_details" android:orderInCategory="1" />
|
||||
|
||||
</menu>
|
|
@ -251,19 +251,28 @@ public class FileOperationsHelper {
|
|||
public void cancelTransference(OCFile file) {
|
||||
Account account = mFileActivity.getAccount();
|
||||
FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
|
||||
FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
|
||||
if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
|
||||
// Remove etag for parent, if file is a keep_in_sync
|
||||
if (file.keepInSync()) {
|
||||
OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
|
||||
parent.setEtag("");
|
||||
mFileActivity.getStorageManager().saveFile(parent);
|
||||
FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
|
||||
if (downloaderBinder != null) {
|
||||
if (downloaderBinder.isDownloading(account, file)) {
|
||||
// Remove etag for parent, if file is a keep_in_sync
|
||||
if (file.keepInSync()) {
|
||||
OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
|
||||
parent.setEtag("");
|
||||
mFileActivity.getStorageManager().saveFile(parent);
|
||||
}
|
||||
|
||||
downloaderBinder.cancel(account, file);
|
||||
} else {
|
||||
Log_OC.w(TAG, "Download for " + file + " not in progress. Cannot cancel.");
|
||||
}
|
||||
|
||||
downloaderBinder.cancel(account, file);
|
||||
|
||||
} else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
|
||||
uploaderBinder.cancel(account, file);
|
||||
} else if (uploaderBinder != null) {
|
||||
if (uploaderBinder.isUploading(account, file)) {
|
||||
uploaderBinder.cancel(account, file);
|
||||
} else {
|
||||
Log_OC.w(TAG, "Upload for " + file + " not in progress. Cannot cancel.");
|
||||
}
|
||||
} else {
|
||||
Log_OC.w(TAG, "Neither downloaderBinder nor uploaderBinder set. Cannot cancel.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,5 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUploadItemLongClick(UploadDbObject file) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||
/**
|
||||
* Extending ExtendedListFragment. This allows dividing list in groups.
|
||||
*/
|
||||
public class ExpandableListFragment extends ExtendedListFragment implements OnChildClickListener, OnItemLongClickListener
|
||||
public class ExpandableListFragment extends ExtendedListFragment implements OnChildClickListener
|
||||
{
|
||||
protected static final String TAG = ExpandableListFragment.class.getSimpleName();
|
||||
|
||||
|
@ -60,7 +60,6 @@ public class ExpandableListFragment extends ExtendedListFragment implements OnCh
|
|||
mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
|
||||
mList = (ExpandableListView)(v.findViewById(R.id.list_root));
|
||||
mList.setOnChildClickListener(this);
|
||||
mList.setOnItemLongClickListener(this);
|
||||
|
||||
mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
mList.setDividerHeight(1);
|
||||
|
@ -89,11 +88,4 @@ public class ExpandableListFragment extends ExtendedListFragment implements OnCh
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
// to be @overriden
|
||||
Log_OC.e(TAG, "onItemLongClick(). This method should be overriden!");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,19 +18,37 @@
|
|||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
|
||||
import android.widget.ListView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.db.UploadDbHandler.UploadStatus;
|
||||
import com.owncloud.android.db.UploadDbObject;
|
||||
import com.owncloud.android.files.FileMenuFilter;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.activity.MoveActivity;
|
||||
import com.owncloud.android.ui.adapter.ExpandableUploadListAdapter;
|
||||
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
|
||||
|
||||
/**
|
||||
* A Fragment that lists all files and folders in a given LOCAL path.
|
||||
|
@ -75,6 +93,9 @@ public class UploadListFragment extends ExpandableListFragment {
|
|||
super.onActivityCreated(savedInstanceState);
|
||||
mAdapter = new ExpandableUploadListAdapter(getActivity());
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
getListView().setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,26 +112,50 @@ public class UploadListFragment extends ExpandableListFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log_OC.d(TAG, "onItemLongClick() position: " + position + " id: " + id);
|
||||
int itemType = ExpandableListView.getPackedPositionType(id);
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
MenuInflater inflater = getSherlockActivity().getMenuInflater();
|
||||
inflater.inflate(R.menu.upload_actions_menu, menu);
|
||||
|
||||
if (itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
|
||||
int childPosition = ExpandableListView.getPackedPositionChild(id);
|
||||
int groupPosition = ExpandableListView.getPackedPositionGroup(id);
|
||||
UploadDbObject uploadDbObject = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||
if (uploadDbObject != null) {
|
||||
return mContainerActivity.onUploadItemLongClick(uploadDbObject);
|
||||
} else {
|
||||
Log_OC.w(TAG, "Null object in ListAdapter!!");
|
||||
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
|
||||
int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
|
||||
int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
|
||||
UploadDbObject uploadFile = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||
if (uploadFile.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED
|
||||
|| uploadFile.getUploadStatus() == UploadStatus.UPLOAD_FAILED_GIVE_UP) {
|
||||
MenuItem item = menu.findItem(R.id.action_cancel_upload);
|
||||
if (item != null) {
|
||||
item.setVisible(false);
|
||||
item.setEnabled(false);
|
||||
}
|
||||
} else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
|
||||
// clicked on group header. ignore.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected (MenuItem item) {
|
||||
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
|
||||
int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
|
||||
int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
|
||||
UploadDbObject uploadFile = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_cancel_upload: {
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().cancelTransference(uploadFile.getOCFile());
|
||||
return true;
|
||||
}
|
||||
case R.id.action_see_details: {
|
||||
Intent showDetailsIntent = new Intent(getActivity(), FileDisplayActivity.class);
|
||||
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable) uploadFile.getOCFile());
|
||||
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, uploadFile.getAccount(getActivity()));
|
||||
startActivity(showDetailsIntent);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_open_file_with: {
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().openFile(uploadFile.getOCFile());
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,15 +175,6 @@ public class UploadListFragment extends ExpandableListFragment {
|
|||
*/
|
||||
public boolean onUploadItemClick(UploadDbObject file);
|
||||
|
||||
/**
|
||||
* Callback method invoked when an upload item is long clicked by the user on
|
||||
* the upload list
|
||||
*
|
||||
* @param file
|
||||
* @return return true if click was handled.
|
||||
*/
|
||||
public boolean onUploadItemLongClick(UploadDbObject file);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue