move / copy updated

This commit is contained in:
tobiasKaminsky 2016-07-31 12:14:33 +02:00 committed by Andy Scherzinger
parent 470d89fb20
commit 1ad97d9ff7
9 changed files with 77 additions and 52 deletions

View file

@ -53,29 +53,11 @@
android:paddingLeft="16dp"
android:paddingRight="16dp">
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_radio_group"
android:layout_width="fill_parent"
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upload_copy_files"
android:id="@+id/upload_radio_copy"
android:paddingRight="8dp"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upload_move_files"
android:id="@+id/upload_radio_move"
android:paddingRight="8dp"
android:checked="false" />
</RadioGroup>
android:id="@+id/upload_files_spinner_behaviour"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout

View file

@ -14,10 +14,18 @@
<string-array name="pref_behaviour_entries">
<item>@string/pref_behaviour_entries_keep_file</item>
<item>@string/pref_behaviour_entries_move</item>
<item>@string/pref_behaviour_entries_delete_file</item>
</string-array>
<string-array name="pref_behaviour_entryValues">
<item>NOTHING</item>
<item>MOVE</item>
<item>DELETE</item>
</string-array>
<string-array name="upload_files_behaviour">
<item>move to nextcloud folder</item>
<item>only upload</item>
<item>upload and delete from source</item>
</string-array>
</resources>

View file

@ -413,6 +413,7 @@
<string name="pref_behaviour_entries_keep_file">kept in original folder</string>
<string name="pref_behaviour_entries_move">moved to app folder</string>
<string name="pref_behaviour_entries_delete_file">deleted</string>
<string name="share_dialog_title">Sharing</string>
<string name="share_file">Share %1$s</string>

View file

@ -143,7 +143,7 @@ public abstract class PreferenceManager {
*/
public static int getUploaderBehaviour(Context context) {
return getDefaultSharedPreferences(context)
.getInt(AUTO_PREF__UPLOADER_BEHAVIOR, FileUploader.LOCAL_BEHAVIOUR_COPY);
.getInt(AUTO_PREF__UPLOADER_BEHAVIOR, 0);
}
/**

View file

@ -154,6 +154,9 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
} else if (behaviour.equalsIgnoreCase("MOVE")) {
Log_OC.d(TAG, "upload file and move file to oc folder");
return FileUploader.LOCAL_BEHAVIOUR_MOVE;
} else if (behaviour.equalsIgnoreCase("DELETE")) {
Log_OC.d(TAG, "upload file and delete original file");
return FileUploader.LOCAL_BEHAVIOUR_DELETE;
}
return null;
}

View file

@ -149,7 +149,7 @@ public class FileUploader extends Service
public static final int LOCAL_BEHAVIOUR_COPY = 0;
public static final int LOCAL_BEHAVIOUR_MOVE = 1;
public static final int LOCAL_BEHAVIOUR_FORGET = 2;
public static final int LOCAL_BEHAVIOUR_DELETE = 3;
private Looper mServiceLooper;
private ServiceHandler mServiceHandler;

View file

@ -397,6 +397,8 @@ public class UploadFileOperation extends SyncOperation {
}
mFile.setStoragePath("");
} else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_DELETE) {
originalFile.delete();
} else {
mFile.setStoragePath(expectedPath);

View file

@ -654,12 +654,16 @@ public class FileDisplayActivity extends HookActivity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS &&
(resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
(resultCode == RESULT_OK ||
resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
requestUploadOfContentFromApps(data, resultCode);
} else if (requestCode == REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM &&
(resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
(resultCode == RESULT_OK ||
resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE ||
resultCode == UploadFilesActivity.RESULT_OK_AND_DO_NOTHING ||
resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) {
requestUploadOfFilesFromFileSystem(data, resultCode);
@ -704,8 +708,23 @@ public class FileDisplayActivity extends HookActivity
remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
}
int behaviour = (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE) ? FileUploader
.LOCAL_BEHAVIOUR_MOVE : FileUploader.LOCAL_BEHAVIOUR_COPY;
// default, as fallback
int behaviour = FileUploader.LOCAL_BEHAVIOUR_FORGET;
switch (resultCode) {
case UploadFilesActivity.RESULT_OK_AND_MOVE:
behaviour = FileUploader.LOCAL_BEHAVIOUR_MOVE;
break;
case UploadFilesActivity.RESULT_OK_AND_DELETE:
behaviour = FileUploader.LOCAL_BEHAVIOUR_DELETE;
break;
case UploadFilesActivity.RESULT_OK_AND_DO_NOTHING:
behaviour = FileUploader.LOCAL_BEHAVIOUR_FORGET;
break;
}
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
requester.uploadNewFile(
this,

View file

@ -37,12 +37,11 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.db.PreferenceManager;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
@ -67,6 +66,7 @@ public class UploadFilesActivity extends FileActivity implements
private LocalFileListFragment mFileListFragment;
private Button mCancelBtn;
private Button mUploadBtn;
private Spinner mBehaviourSpinner;
private Account mAccountOnCreation;
private DialogFragment mCurrentDialog;
private Menu mOptionsMenu;
@ -74,8 +74,10 @@ public class UploadFilesActivity extends FileActivity implements
public static final String EXTRA_CHOSEN_FILES =
UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
public static final int RESULT_OK_AND_DO_NOTHING = 2;
public static final int RESULT_OK_AND_DELETE = 3;
private static final String KEY_DIRECTORY_PATH =
UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
private static final String KEY_ALL_SELECTED =
@ -84,9 +86,6 @@ public class UploadFilesActivity extends FileActivity implements
private static final String TAG = "UploadFilesActivity";
private static final String WAIT_DIALOG_TAG = "WAIT";
private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
private RadioButton mRadioBtnCopyFiles;
private RadioButton mRadioBtnMoveFiles;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -130,15 +129,13 @@ public class UploadFilesActivity extends FileActivity implements
int localBehaviour = PreferenceManager.getUploaderBehaviour(this);
mRadioBtnMoveFiles = (RadioButton) findViewById(R.id.upload_radio_move);
if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_MOVE){
mRadioBtnMoveFiles.setChecked(true);
}
mRadioBtnCopyFiles = (RadioButton) findViewById(R.id.upload_radio_copy);
if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY){
mRadioBtnCopyFiles.setChecked(true);
}
// file upload spinner
mBehaviourSpinner = (Spinner) findViewById(R.id.upload_files_spinner_behaviour);
ArrayAdapter<CharSequence> behaviourAdapter = ArrayAdapter.createFromResource(this,
R.array.upload_files_behaviour, android.R.layout.simple_spinner_item);
behaviourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mBehaviourSpinner.setAdapter(behaviourAdapter);
mBehaviourSpinner.setSelection(localBehaviour);
// setup the toolbar
setupToolbar();
@ -380,8 +377,9 @@ public class UploadFilesActivity extends FileActivity implements
if (v.getId() == R.id.upload_files_btn_cancel) {
setResult(RESULT_CANCELED);
finish();
} else if (v.getId() == R.id.upload_files_btn_upload) {
} else if (v.getId() == R.id.upload_files_btn_upload &&
mBehaviourSpinner.getSelectedItemPosition() == 0) {
new CheckAvailableSpaceTask().execute();
}
}
@ -441,13 +439,25 @@ public class UploadFilesActivity extends FileActivity implements
Intent data = new Intent();
data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
if (mRadioBtnMoveFiles.isChecked()){
setResult(RESULT_OK_AND_MOVE, data);
PreferenceManager.setUploaderBehaviour(getApplicationContext(), FileUploader.LOCAL_BEHAVIOUR_MOVE);
} else {
setResult(RESULT_OK, data);
PreferenceManager.setUploaderBehaviour(getApplicationContext(), FileUploader.LOCAL_BEHAVIOUR_COPY);
// set result code
switch (mBehaviourSpinner.getSelectedItemPosition()) {
case 0: // move to nextcloud folder
setResult(RESULT_OK_AND_MOVE, data);
break;
case 1: // only upload
setResult(RESULT_OK_AND_DO_NOTHING, data);
break;
case 2: // upload and delete from source
setResult(RESULT_OK_AND_DELETE, data);
break;
}
// store behaviour
PreferenceManager.setUploaderBehaviour(getApplicationContext(),
mBehaviourSpinner.getSelectedItemPosition());
finish();
} else {
// show a dialog to query the user if wants to move the selected files