<LinearLayout\r
android:layout_width="match_parent"\r
android:layout_height="wrap_content"\r
+ android:orientation="horizontal">\r
+\r
+ <ImageView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="1dp"\r
+ android:src="@drawable/uploader_list_separator"/>\r
+\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:orientation="horizontal"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingTop="8dp"\r
+ android:paddingLeft="16dp"\r
+ android:paddingRight="16dp">\r
+\r
+ <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:id="@+id/drawer_radio_group"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ android:gravity="center"\r
+ android:orientation="horizontal">\r
+\r
+ <RadioButton\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="@string/upload_copy_files"\r
+ android:id="@+id/upload_radio_copy"\r
+ android:paddingRight="8dp"\r
+ android:checked="false" />\r
+\r
+ <RadioButton\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="@string/upload_move_files"\r
+ android:id="@+id/upload_radio_move"\r
+ android:paddingRight="8dp"\r
+ android:checked="false" />\r
+ </RadioGroup>\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
android:gravity="center"\r
- android:orientation="horizontal" >\r
+ android:orientation="horizontal"\r
+ android:paddingLeft="16dp"\r
+ android:paddingRight="16dp"\r
+ android:paddingBottom="16dp">\r
\r
<android.support.v7.widget.AppCompatButton\r
android:id="@+id/upload_files_btn_cancel"\r
</declare-styleable>
+ <string-array name="pref_behaviour_entries">
+ <item>@string/pref_behaviour_entries_do_nothing</item>
+ <item>@string/pref_behaviour_entries_copy</item>
+ <item>@string/pref_behaviour_entries_move</item>
+ <item>@string/pref_behaviour_entries_delete</item>
+ </string-array>
+
+ <string-array name="pref_behaviour_entryValues">
+ <item>NOTHING</item>
+ <item>COPY</item>
+ <item>MOVE</item>
+ <item>DELETE</item>
+ </string-array>
</resources>
\ No newline at end of file
<string name="file_list__footer__files">%1$d files</string>
<string name="file_list__footer__files_and_folder">%1$d files, 1 folder</string>
<string name="file_list__footer__files_and_folders">%1$d files, %2$d folders</string>
+ <string name="prefs_instant_behaviour_dialogTitle">Upload file to server and ...</string>
+ <string name="prefs_instant_behaviour_title">Behaviour</string>
+ <string name="upload_copy_files">Copy file</string>
+ <string name="upload_move_files">Move file</string>
+
+ <string name="pref_behaviour_entries_do_nothing">do nothing</string>
+ <string name="pref_behaviour_entries_copy">copy file to OC folder</string>
+ <string name="pref_behaviour_entries_move">move file to OC folder</string>
+ <string name="pref_behaviour_entries_delete">delete origin file</string>
<string name="share_dialog_title">Sharing</string>
<string name="share_with_user_section_title">Share with Users and Groups</string>
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_category_instant_uploading" android:key="instant_uploading_category">
- <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
+ <com.owncloud.android.ui.dialog.OwnCloudListPreference android:key="prefs_instant_behaviour"
+ android:dialogTitle="@string/prefs_instant_behaviour_dialogTitle"
+ android:title="@string/prefs_instant_behaviour_title"
+ android:entries="@array/pref_behaviour_entries"
+ android:entryValues="@array/pref_behaviour_entryValues"
+ android:defaultValue="NOTHING"
+ android:summary="%s"
+ />
+
+ <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
android:title="@string/prefs_instant_upload"
android:summary="@string/prefs_instant_upload_summary"/>
<com.owncloud.android.ui.PreferenceWithLongSummary
return shares;
}
- public void triggerMediaScan(String path) {
+ public static void triggerMediaScan(String path) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
MainApp.getAppContext().sendBroadcast(intent);
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type);
i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
+
+ // instant upload behaviour
+ SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String behaviour = appPreferences.getString("prefs_instant_behaviour", "NOTHING");
+
+ if (behaviour.equalsIgnoreCase("NOTHING")) {
+ Log_OC.d(TAG, "upload file and do nothing");
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET);
+ } else if (behaviour.equalsIgnoreCase("COPY")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_COPY);
+ Log_OC.d(TAG, "upload file and copy file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("MOVE")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
+ Log_OC.d(TAG, "upload file and move file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("DELETE")){
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_REMOVE);
+ Log_OC.d(TAG, "upload file and delete file in original place");
+ }
+
context.startService(i);
}
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type);
i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
+
+ // instant upload behaviour
+ SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String behaviour = appPreferences.getString("prefs_instant_behaviour", "NOTHING");
+
+ if (behaviour.equalsIgnoreCase("NOTHING")) {
+ Log_OC.d(TAG, "upload file and do nothing");
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET);
+ } else if (behaviour.equalsIgnoreCase("COPY")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_COPY);
+ Log_OC.d(TAG, "upload file and copy file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("MOVE")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
+ Log_OC.d(TAG, "upload file and move file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("DELETE")){
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_REMOVE);
+ Log_OC.d(TAG, "upload file and delete file in original place");
+ }
+
context.startService(i);
}
i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, f.getName()));
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
+
+ // instant upload behaviour
+ SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String behaviour = appPreferences.getString("prefs_instant_behaviour", "NOTHING");
+
+ if (behaviour.equalsIgnoreCase("NOTHING")) {
+ Log_OC.d(TAG, "upload file and do nothing");
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET);
+ } else if (behaviour.equalsIgnoreCase("COPY")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_COPY);
+ Log_OC.d(TAG, "upload file and copy file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("MOVE")) {
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
+ Log_OC.d(TAG, "upload file and move file to oc folder");
+ } else if (behaviour.equalsIgnoreCase("DELETE")){
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_REMOVE);
+ Log_OC.d(TAG, "upload file and delete file in original place");
+ }
+
context.startService(i);
} else {
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_REMOVE = 3;
public static final int UPLOAD_SINGLE_FILE = 0;
public static final int UPLOAD_MULTIPLE_FILES = 1;
import android.net.Uri;
import com.owncloud.android.MainApp;
+import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.OwnCloudClient;
throw new OperationCancelledException();
}
- result = mUploadOperation.execute(client);
-
/// move local temporal file or original file to its corresponding
// location in the ownCloud local folder
if (result.isSuccess()) {
if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) {
mFile.setStoragePath(null);
-
+ } else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_REMOVE){
+ mFile.setStoragePath(null);
+ originalFile.delete();
} else {
mFile.setStoragePath(expectedPath);
File fileToMove = null;
}
}
}
-
+ FileDataStorageManager.triggerMediaScan(originalFile.getAbsolutePath());
+ FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
} else if (result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED ) {
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
}
import android.accounts.Account;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
+import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
+import android.widget.RadioButton;
import android.widget.TextView;
import com.owncloud.android.R;
+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;
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) {
Log_OC.d(TAG, "onCreate() start");
mCancelBtn.setOnClickListener(this);
mUploadBtn = (Button) findViewById(R.id.upload_files_btn_upload);
mUploadBtn.setOnClickListener(this);
+
+ SharedPreferences appPreferences = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext());
+
+ Integer localBehaviour = appPreferences.getInt("prefs_uploader_behaviour", FileUploader.LOCAL_BEHAVIOUR_COPY);
+
+ 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);
+ }
// Action bar setup
// return the list of selected files (success)
Intent data = new Intent();
data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
- setResult(RESULT_OK, data);
+
+ SharedPreferences.Editor appPreferencesEditor = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
+
+
+ if (mRadioBtnMoveFiles.isChecked()){
+ setResult(RESULT_OK_AND_MOVE, data);
+ appPreferencesEditor.putInt("prefs_uploader_behaviour",
+ FileUploader.LOCAL_BEHAVIOUR_MOVE);
+ } else {
+ setResult(RESULT_OK, data);
+ appPreferencesEditor.putInt("prefs_uploader_behaviour",
+ FileUploader.LOCAL_BEHAVIOUR_COPY);
+ }
+ appPreferencesEditor.apply();
finish();
-
} else {
// show a dialog to query the user if wants to move the selected files
// to the ownCloud folder instead of copying
--- /dev/null
+package com.owncloud.android.ui.dialog;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.PreferenceManager;
+import android.support.v7.app.AppCompatDialog;
+import android.util.AttributeSet;
+
+import com.owncloud.android.R;
+import com.owncloud.android.lib.common.utils.Log_OC;
+
+import java.lang.reflect.Method;
+
+public class OwnCloudListPreference extends ListPreference {
+ private static final String TAG = OwnCloudListPreference.class.getSimpleName();
+
+ private Context mContext;
+ private AppCompatDialog mDialog;
+
+ public OwnCloudListPreference(Context context) {
+ super(context);
+ this.mContext = context;
+ }
+
+ public OwnCloudListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ this.mContext = context;
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public OwnCloudListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public OwnCloudListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @Override
+ protected void showDialog(Bundle state) {
+ if (getEntries() == null || getEntryValues() == null) {
+ throw new IllegalStateException(
+ "ListPreference requires an entries array and an entryValues array.");
+ }
+
+ int preselect = findIndexOfValue(getValue());
+ // TODO for some reason value change is persisted but not directly shown in Android-15 emulator
+ // same thing happens for the Standard ListPreference though
+ android.support.v7.app.AlertDialog.Builder builder =
+ new android.support.v7.app.AlertDialog.Builder(mContext, R.style.ownCloud_AlertDialog)
+ .setTitle(getDialogTitle())
+ .setIcon(getDialogIcon())
+ .setSingleChoiceItems(getEntries(), preselect, this);
+
+ PreferenceManager pm = getPreferenceManager();
+ try {
+ Method method = pm.getClass().getDeclaredMethod(
+ "registerOnActivityDestroyListener",
+ PreferenceManager.OnActivityDestroyListener.class);
+ method.setAccessible(true);
+ method.invoke(pm, this);
+ } catch (Exception e) {
+ // no way to handle this but logging it
+ Log_OC.e(TAG, "error invoking registerOnActivityDestroyListener", e);
+ }
+
+ mDialog = builder.create();
+ if (state != null) {
+ mDialog.onRestoreInstanceState(state);
+ }
+ mDialog.show();
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which >= 0 && getEntryValues() != null) {
+ String value = getEntryValues()[which].toString();
+ if (callChangeListener(value)) {
+ setValue(value);
+ }
+ dialog.dismiss();
+ }
+ }
+
+ @Override
+ public AppCompatDialog getDialog() {
+ return mDialog;
+ }
+
+ @Override
+ public void onActivityDestroy() {
+ super.onActivityDestroy();
+ if (mDialog != null && mDialog.isShowing()) {
+ mDialog.dismiss();
+ }
+ }
+}