mirror of
https://github.com/nextcloud/android.git
synced 2024-11-29 10:49:04 +03:00
added right button for items in upload list (for cancel, retry, and remove)
This commit is contained in:
parent
61de793925
commit
3fdb78d0c9
6 changed files with 174 additions and 33 deletions
46
res/drawable/btn_small_round.xml
Executable file
46
res/drawable/btn_small_round.xml
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- pressed state of button, only change: color of actual button -->
|
||||||
|
<item android:state_pressed="true" >
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<!-- shadow, a little down and a little to the right -->
|
||||||
|
<item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#99000000" android:startColor="#99000000" />
|
||||||
|
</shape></item>
|
||||||
|
<!-- this is the actual button -->
|
||||||
|
<item android:bottom="1px" android:right="1px"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#47ffffff" android:startColor="#97ffffff" />
|
||||||
|
</shape></item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<!-- focused state of button, only change: color of actual button -->
|
||||||
|
<item android:state_focused="true" >
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<!-- shadow, a little down and a little to the right -->
|
||||||
|
<item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#22000000" android:startColor="#22000000" />
|
||||||
|
</shape></item>
|
||||||
|
<!-- this is the actual button -->
|
||||||
|
<item android:bottom="1px" android:right="1px"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#47ffffff" android:startColor="#97ffffff" />
|
||||||
|
</shape></item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
<!-- normal state of button. Template for other states. -->
|
||||||
|
<item>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<!-- shadow, a little down and a little to the right -->
|
||||||
|
<item>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#55000000" android:startColor="#55000000" />
|
||||||
|
</shape></item>
|
||||||
|
<!-- this is the actual button -->
|
||||||
|
<item android:bottom="1px" android:right="1px">
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient android:angle="270" android:endColor="#47ffffff" android:startColor="#97ffffff" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
</selector>
|
|
@ -88,4 +88,26 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/upload_right_button"
|
||||||
|
android:background ="@drawable/btn_small_round"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package com.owncloud.android.ui.activity;
|
package com.owncloud.android.ui.activity;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
|
@ -19,6 +22,8 @@ import com.owncloud.android.files.services.FileUploadService.FileUploaderBinder;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.ui.errorhandling.ExceptionHandler;
|
import com.owncloud.android.ui.errorhandling.ExceptionHandler;
|
||||||
import com.owncloud.android.ui.fragment.UploadListFragment;
|
import com.owncloud.android.ui.fragment.UploadListFragment;
|
||||||
|
import com.owncloud.android.ui.preview.PreviewImageActivity;
|
||||||
|
import com.owncloud.android.ui.preview.PreviewImageFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity listing pending, active, and completed uploads. User can delete
|
* Activity listing pending, active, and completed uploads. User can delete
|
||||||
|
@ -44,12 +49,32 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
||||||
// ////////////////////////////////////////
|
// ////////////////////////////////////////
|
||||||
@Override
|
@Override
|
||||||
public boolean onUploadItemClick(UploadDbObject file) {
|
public boolean onUploadItemClick(UploadDbObject file) {
|
||||||
|
File f = new File(file.getLocalPath());
|
||||||
|
if(!f.exists()) {
|
||||||
|
Toast.makeText(this, "Cannot open. Local file does not exist.", Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PreviewImageFragment.canBePreviewed(file.getOCFile())) {
|
||||||
|
// preview image
|
||||||
|
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
|
||||||
|
showDetailsIntent.putExtra(EXTRA_FILE, (Parcelable)file.getOCFile());
|
||||||
|
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
|
||||||
|
startActivity(showDetailsIntent);
|
||||||
|
} else {
|
||||||
|
//open file
|
||||||
|
getFileOperationsHelper().openFile(file.getOCFile());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private void openDetails(UploadDbObject file) {
|
||||||
OCFile ocFile = file.getOCFile();
|
OCFile ocFile = file.getOCFile();
|
||||||
Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
|
Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
|
||||||
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable) ocFile);
|
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable) ocFile);
|
||||||
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, file.getAccount(this));
|
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, file.getAccount(this));
|
||||||
startActivity(showDetailsIntent);
|
startActivity(showDetailsIntent);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,8 +12,10 @@ import android.graphics.Bitmap;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseExpandableListAdapter;
|
import android.widget.BaseExpandableListAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ExpandableListView;
|
import android.widget.ExpandableListView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -25,7 +27,9 @@ import com.owncloud.android.db.UploadDbObject;
|
||||||
import com.owncloud.android.files.services.FileUploadService;
|
import com.owncloud.android.files.services.FileUploadService;
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
import com.owncloud.android.ui.activity.FileActivity;
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
|
import com.owncloud.android.utils.UploadUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Adapter populates a ListView with following types of uploads: pending,
|
* This Adapter populates a ListView with following types of uploads: pending,
|
||||||
|
@ -64,6 +68,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
||||||
private UploadGroup[] mUploadGroups = null;
|
private UploadGroup[] mUploadGroups = null;
|
||||||
UploadDbHandler mDb;
|
UploadDbHandler mDb;
|
||||||
|
|
||||||
|
FileActivity parentFileActivity;
|
||||||
|
public void setFileActivity(FileActivity parentFileActivity) {
|
||||||
|
this.parentFileActivity = parentFileActivity;
|
||||||
|
}
|
||||||
|
|
||||||
public ExpandableUploadListAdapter(Activity context) {
|
public ExpandableUploadListAdapter(Activity context) {
|
||||||
Log_OC.d(TAG, "UploadListAdapter");
|
Log_OC.d(TAG, "UploadListAdapter");
|
||||||
mActivity = context;
|
mActivity = context;
|
||||||
|
@ -133,7 +142,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
||||||
view = inflator.inflate(R.layout.upload_list_item, null);
|
view = inflator.inflate(R.layout.upload_list_item, null);
|
||||||
}
|
}
|
||||||
if (uploadsItems != null && uploadsItems.length > position) {
|
if (uploadsItems != null && uploadsItems.length > position) {
|
||||||
UploadDbObject uploadObject = uploadsItems[position];
|
final UploadDbObject uploadObject = uploadsItems[position];
|
||||||
|
|
||||||
TextView fileName = (TextView) view.findViewById(R.id.upload_name);
|
TextView fileName = (TextView) view.findViewById(R.id.upload_name);
|
||||||
String file = uploadObject.getOCFile().getFileName();
|
String file = uploadObject.getOCFile().getFileName();
|
||||||
|
@ -189,6 +198,34 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
||||||
}
|
}
|
||||||
statusView.setText(status);
|
statusView.setText(status);
|
||||||
|
|
||||||
|
Button rightButton = (Button) view.findViewById(R.id.upload_right_button);
|
||||||
|
if (UploadUtils.userCanRetryUpload(uploadObject)) {
|
||||||
|
rightButton.setText("\u21BA"); //Anticlockwise Open Circle Arrow U+21BA
|
||||||
|
rightButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
parentFileActivity.getFileOperationsHelper().retryUpload(uploadObject.getOCFile());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (UploadUtils.userCanCancelUpload(uploadObject)) {
|
||||||
|
rightButton.setText("\u274C"); //Cross Mark U+274C
|
||||||
|
rightButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
parentFileActivity.getFileOperationsHelper().cancelTransference(uploadObject.getOCFile());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
rightButton.setText("\u267B"); //Black Universal Recycling Symbol U+267B
|
||||||
|
rightButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
parentFileActivity.getFileOperationsHelper().removeUploadFromList(uploadObject.getOCFile());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
|
ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
|
||||||
fileIcon.setImageResource(R.drawable.file);
|
fileIcon.setImageResource(R.drawable.file);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -40,6 +40,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.ui.activity.FileActivity;
|
import com.owncloud.android.ui.activity.FileActivity;
|
||||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||||
import com.owncloud.android.ui.adapter.ExpandableUploadListAdapter;
|
import com.owncloud.android.ui.adapter.ExpandableUploadListAdapter;
|
||||||
|
import com.owncloud.android.utils.UploadUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Fragment that lists all files and folders in a given LOCAL path.
|
* A Fragment that lists all files and folders in a given LOCAL path.
|
||||||
|
@ -56,7 +57,7 @@ public class UploadListFragment extends ExpandableListFragment {
|
||||||
*/
|
*/
|
||||||
private UploadListFragment.ContainerActivity mContainerActivity;
|
private UploadListFragment.ContainerActivity mContainerActivity;
|
||||||
|
|
||||||
BaseExpandableListAdapter mAdapter;
|
ExpandableUploadListAdapter mAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -84,6 +85,7 @@ public class UploadListFragment extends ExpandableListFragment {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mAdapter = new ExpandableUploadListAdapter(getActivity());
|
mAdapter = new ExpandableUploadListAdapter(getActivity());
|
||||||
setListAdapter(mAdapter);
|
setListAdapter(mAdapter);
|
||||||
|
mAdapter.setFileActivity(((FileActivity) getActivity()));
|
||||||
|
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
getListView().setOnCreateContextMenuListener(this);
|
getListView().setOnCreateContextMenuListener(this);
|
||||||
|
@ -112,7 +114,7 @@ public class UploadListFragment extends ExpandableListFragment {
|
||||||
int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
|
int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
|
||||||
int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
|
int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
|
||||||
UploadDbObject uploadFile = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
UploadDbObject uploadFile = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||||
if (userCanCancelUpload(uploadFile)) {
|
if (UploadUtils.userCanCancelUpload(uploadFile)) {
|
||||||
MenuItem item = menu.findItem(R.id.action_remove_upload);
|
MenuItem item = menu.findItem(R.id.action_remove_upload);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.setVisible(false);
|
item.setVisible(false);
|
||||||
|
@ -125,7 +127,7 @@ public class UploadListFragment extends ExpandableListFragment {
|
||||||
item.setEnabled(false);
|
item.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!userCanRetryUpload(uploadFile)) {
|
if (!UploadUtils.userCanRetryUpload(uploadFile)) {
|
||||||
MenuItem item = menu.findItem(R.id.action_retry_upload);
|
MenuItem item = menu.findItem(R.id.action_retry_upload);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.setVisible(false);
|
item.setVisible(false);
|
||||||
|
@ -134,34 +136,6 @@ public class UploadListFragment extends ExpandableListFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean userCanCancelUpload(UploadDbObject uploadFile) {
|
|
||||||
switch (uploadFile.getUploadStatus()) {
|
|
||||||
case UPLOAD_IN_PROGRESS:
|
|
||||||
case UPLOAD_LATER:
|
|
||||||
case UPLOAD_FAILED_RETRY:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true when user can choose to retry this upload.
|
|
||||||
*
|
|
||||||
* @param uploadFile
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean userCanRetryUpload(UploadDbObject uploadFile) {
|
|
||||||
switch (uploadFile.getUploadStatus()) {
|
|
||||||
case UPLOAD_CANCELLED:
|
|
||||||
//case UPLOAD_FAILED_RETRY://automatically retried. no need for user option.
|
|
||||||
case UPLOAD_FAILED_GIVE_UP:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected (MenuItem item) {
|
public boolean onContextItemSelected (MenuItem item) {
|
||||||
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
|
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.owncloud.android.utils;
|
package com.owncloud.android.utils;
|
||||||
|
|
||||||
|
import com.owncloud.android.db.UploadDbObject;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
@ -29,4 +31,39 @@ public class UploadUtils {
|
||||||
&& cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
|
&& cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
|
||||||
&& cm.getActiveNetworkInfo().getState() == State.CONNECTED;
|
&& cm.getActiveNetworkInfo().getState() == State.CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when user is able to cancel this upload. That is, when
|
||||||
|
* upload is currently in progress or scheduled for upload.
|
||||||
|
*/
|
||||||
|
static public boolean userCanCancelUpload(UploadDbObject uploadFile) {
|
||||||
|
switch (uploadFile.getUploadStatus()) {
|
||||||
|
case UPLOAD_IN_PROGRESS:
|
||||||
|
case UPLOAD_LATER:
|
||||||
|
case UPLOAD_FAILED_RETRY:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when user can choose to retry this upload. That is, when
|
||||||
|
* user cancelled upload before or when upload has failed.
|
||||||
|
*
|
||||||
|
* TODO Add other cases as described by
|
||||||
|
* https://github.com/owncloud/android/issues/765#issuecomment-66490312
|
||||||
|
* (certificate failure, wrong credentials, remote folder gone, ...) This
|
||||||
|
* needs special handling though!
|
||||||
|
*/
|
||||||
|
static public boolean userCanRetryUpload(UploadDbObject uploadFile) {
|
||||||
|
switch (uploadFile.getUploadStatus()) {
|
||||||
|
case UPLOAD_CANCELLED:
|
||||||
|
case UPLOAD_FAILED_RETRY://automatically retried. no need for user option.
|
||||||
|
case UPLOAD_FAILED_GIVE_UP:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue