Merge remote-tracking branch 'remotes/upstream/master' into avoidDuplicateFiles_Master
authortobiasKaminsky <tobias@kaminsky.me>
Sat, 21 Nov 2015 07:48:40 +0000 (08:48 +0100)
committertobiasKaminsky <tobias@kaminsky.me>
Sat, 21 Nov 2015 07:48:40 +0000 (08:48 +0100)
res/layout/upload_files_layout.xml
res/values/attrs.xml
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/UploadFileOperation.java
src/com/owncloud/android/ui/activity/UploadFilesActivity.java
src/com/owncloud/android/ui/dialog/OwnCloudListPreference.java [new file with mode: 0644]

index 95a3fb2..f7f802c 100644 (file)
     <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
index 800a4b6..7d80983 100644 (file)
 
        </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
index 320eea1..706baf0 100644 (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>
index 4823a83..161bb66 100644 (file)
        </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
index 237c846..5d49b2c 100644 (file)
@@ -1557,7 +1557,7 @@ public class FileDataStorageManager {
         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);
index 47f7127..f8254ff 100644 (file)
@@ -34,6 +34,7 @@ import android.accounts.Account;
 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;
@@ -122,6 +123,25 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         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);
     }
 
@@ -167,6 +187,25 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         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);
 
     }
@@ -207,6 +246,25 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
                         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 {
index 7c953b8..df4dccd 100644 (file)
@@ -101,6 +101,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_REMOVE = 3;
 
     public static final int UPLOAD_SINGLE_FILE = 0;
     public static final int UPLOAD_MULTIPLE_FILES = 1;
index ee9f7c8..ab74e79 100644 (file)
@@ -39,6 +39,7 @@ import android.content.Context;
 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;
@@ -324,14 +325,14 @@ public class UploadFileOperation extends RemoteOperation {
                 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;
@@ -359,7 +360,8 @@ public class UploadFileOperation extends RemoteOperation {
                         }
                     }
                 }
-
+                FileDataStorageManager.triggerMediaScan(originalFile.getAbsolutePath());
+                FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
             } else if (result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED ) {
                 result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
             }
index 9a3ce17..070d7b9 100644 (file)
@@ -22,9 +22,11 @@ package com.owncloud.android.ui.activity;
 
 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;
@@ -33,9 +35,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.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;
@@ -73,8 +77,10 @@ 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) {
         Log_OC.d(TAG, "onCreate() start");
@@ -112,6 +118,21 @@ public class UploadFilesActivity extends FileActivity implements
         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
@@ -342,9 +363,22 @@ public class UploadFilesActivity extends FileActivity implements
                 // 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
diff --git a/src/com/owncloud/android/ui/dialog/OwnCloudListPreference.java b/src/com/owncloud/android/ui/dialog/OwnCloudListPreference.java
new file mode 100644 (file)
index 0000000..67ccb3e
--- /dev/null
@@ -0,0 +1,102 @@
+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();
+        }
+    }
+}