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)
1  2 
res/values/strings.xml
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/UploadFileOperation.java

      <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>
+     <string name="share_no_users">No data shared with users yet</string>
+     <string name="share_add_user_or_group">Add User or Group</string>
+     <string name="share_search">Search</string>
+     <string name="search_users_and_groups_hint">Search users and groups</string>
+     <string name="share_group_clarification">%1$s (group)</string>
+     <string name="share_sharee_unavailable">Sorry, your server version does not allow share with users within clients.
+         \nPlease contact your administrator</string>
  </resources>
@@@ -1490,47 -1497,67 +1497,67 @@@ public class FileDataStorageManager 
              }
          }
          return preparedOperations;
-         
-         /*
-         if (operations.size() > 0) {
-             try {
-                 if (getContentResolver() != null) {
-                     getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  
-                 } else {
-                     getContentProviderClient().applyBatch(operations);
-                 }
+     }
  
-             } catch (OperationApplicationException e) {
-                 Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
+     private ArrayList<ContentProviderOperation> prepareRemoveSharesInFile(
+             String filePath, ArrayList<ContentProviderOperation> preparedOperations) {
+         String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
+                 + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
+         String[] whereArgs = new String[]{filePath, mAccount.name};
+         preparedOperations.add(
+                 ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE).
+                         withSelection(where, whereArgs).
+                         build()
+         );
+         return preparedOperations;
+     }
+     public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName){
+         // Condition
+         String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
+                 + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"+ "AND"
+                 + " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
+                 + ProviderTableMeta.OCSHARES_SHARE_TYPE +  "=? ) ";
+         String [] whereArgs = new String[]{ filePath, accountName ,
+                 Integer.toString(ShareType.USER.getValue()),
+                 Integer.toString(ShareType.GROUP.getValue()) };
+         Cursor c = null;
+         if (getContentResolver() != null) {
+             c = getContentResolver().query(
+                     ProviderTableMeta.CONTENT_URI_SHARE,
+                     null, where, whereArgs, null);
+         } else {
+             try {
+                 c = getContentProviderClient().query(
+                         ProviderTableMeta.CONTENT_URI_SHARE,
+                         null, where, whereArgs, null);
  
              } catch (RemoteException e) {
-                 Log_OC.e(TAG, "Exception in batch of operations  " + e.getMessage());
+                 Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
+                 c = null;
              }
-         }            
-         */
-             
-             /*
-             if (getContentResolver() != null) {
-                 
-                 getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, 
-                                             where,
-                                             whereArgs);
-             } else {
-                 try {
-                     getContentProviderClient().delete(  ProviderTableMeta.CONTENT_URI_SHARE, 
-                                                         where,
-                                                         whereArgs);
+         }
+         ArrayList<OCShare> shares = new ArrayList<OCShare>();
+         OCShare share = null;
+         if (c.moveToFirst()) {
+             do {
+                 share = createShareInstance(c);
+                 shares.add(share);
+                 // }
+             } while (c.moveToNext());
+         }
+         c.close();
  
-                 } catch (RemoteException e) {
-                     Log_OC.e(TAG, "Exception deleting shares in a folder " + e.getMessage());
-                 }
-             }
-             */
-         //}
+         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);
@@@ -322,47 -320,48 +321,49 @@@ public class UploadFileOperation extend
              while (listener.hasNext()) {
                  mUploadOperation.addDatatransferProgressListener(listener.next());
              }
-             if (!mCancellationRequested.get()) {
-                 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;
-                         if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY
-                             // ; see where temporalFile was
-                             // set
-                             fileToMove = temporalFile;
-                         } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE
-                             fileToMove = originalFile;
-                         }
-                         if (!expectedFile.equals(fileToMove)) {
-                             File expectedFolder = expectedFile.getParentFile();
-                             expectedFolder.mkdirs();
-                             if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) {
-                                 mFile.setStoragePath(null); // forget the local file
-                                 // by now, treat this as a success; the file was
-                                 // uploaded; the user won't like that the local file
-                                 // is not linked, but this should be a very rare
-                                 // fail;
-                                 // the best option could be show a warning message
-                                 // (but not a fail)
-                                 // result = new
-                                 // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
-                                 // return result;
-                             }
+             if (mCancellationRequested.get()) {
+                 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;
+                     if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY
+                         // ; see where temporalFile was
+                         // set
+                         fileToMove = temporalFile;
+                     } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE
+                         fileToMove = originalFile;
+                     }
+                     if (!expectedFile.equals(fileToMove)) {
+                         File expectedFolder = expectedFile.getParentFile();
+                         expectedFolder.mkdirs();
+                         if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) {
+                             mFile.setStoragePath(null); // forget the local file
+                             // by now, treat this as a success; the file was
+                             // uploaded; the user won't like that the local file
+                             // is not linked, but this should be a very rare
+                             // fail;
+                             // the best option could be show a warning message
+                             // (but not a fail)
+                             // result = new
+                             // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
+                             // return result;
                          }
                      }
-                     FileDataStorageManager.triggerMediaScan(originalFile.getAbsolutePath());
-                     FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
                  }
 -
++                FileDataStorageManager.triggerMediaScan(originalFile.getAbsolutePath());
++                FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
+             } else if (result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED ) {
+                 result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
              }
  
          } catch (Exception e) {