Merge remote-tracking branch 'theirs/develop' into gradleWithInternalDependency
authorMMMarcy <steiner.marcello@gmail.com>
Fri, 17 Oct 2014 12:58:27 +0000 (14:58 +0200)
committerMMMarcy <steiner.marcello@gmail.com>
Fri, 17 Oct 2014 12:58:27 +0000 (14:58 +0200)
Conflicts:
owncloud-android-library
pom.xml

1  2 
owncloud-android-library
pom.xml
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/operations/CreateShareOperation.java
src/com/owncloud/android/operations/GetSharesForFileOperation.java

diff --combined owncloud-android-library
index 19d453d,c29631b..0000000
deleted file mode 160000,160000
+++ /dev/null
@@@ -1,1 -1,1 +1,0 @@@
- Subproject commit 19d453dd55233d689754335af641e77087a1c431
 -Subproject commit c29631b8bfea22e5f0b448aab8ffff959ae4de66
diff --combined pom.xml
+++ b/pom.xml
@@@ -1,7 -1,6 +1,7 @@@
  <?xml version="1.0" encoding="UTF-8"?>
 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 -         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +    xmlns="http://maven.apache.org/POM/4.0.0"
 +    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.owncloud.android</groupId>
@@@ -14,7 -13,7 +14,7 @@@
          <owncloud.version>1.5.1-SNAPSHOT</owncloud.version>
          <java-version>1.6</java-version>
          <!-- Given by maven-android-sdk-deployer -->
 -        <google.android-version>4.4.2_r3</google.android-version>
 +        <google.android-version>4.4.2_r4</google.android-version>
          <!-- Usually the latest Android API -->
          <google.android-api>19</google.android-api>
          <actionbarsherlock-version>4.2.0</actionbarsherlock-version>
          <developerConnection>scm:git:git@github.com:owncloud/android.git</developerConnection>
          <url>https://github.com/owncloud/android</url>
      </scm>
 -    
 +
 +
 +    <!--<repositories>-->
 +        <!--<repository>-->
 +            <!--<id>android-support</id>-->
 +            <!--<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>-->
 +        <!--</repository>-->
 +    <!--</repositories>-->
 +
      <dependencies>
-         <!--<dependency>-->
-             <!--<groupId>com.actionbarsherlock</groupId>-->
-             <!--<artifactId>library</artifactId>-->
-             <!--<version>4.1.0</version>-->
-         <!--</dependency>-->
 +
+         <!-- Dirty trick, but it works. TouchImageView library is not available as Maven project. -->
+         <dependency>
+             <groupId>touch-image-view.jar</groupId>
+             <artifactId>touch-image-view.jar</artifactId>
+             <version>1.0</version>
+             <scope>system</scope>
+             <systemPath>${basedir}/libs/touch-image-view.jar</systemPath>
+         </dependency>
+           
+         <!-- This causes a (version?) conflict during packaging since sherlockactionbar also includes compatibility-v4 -->
+         <!--<dependency>
+             <groupId>android.support</groupId>
+             <artifactId>compatibility-v4</artifactId>
+             <version>19.1.0</version>
+         </dependency>-->
+         <!-- Instead we need to include the exact same version -->
 +
 +        <dependency>
 +            <groupId>com.jakewharton</groupId>
 +            <artifactId>disklrucache</artifactId>
 +            <version>2.0.2</version>
 +        </dependency>
 +
          <dependency>
              <groupId>android-support-v4.jar</groupId>
              <artifactId>android-support-v4.jar</artifactId>
              <scope>system</scope>
              <systemPath>${basedir}/third_party/android-support-library/android-support-v4.jar</systemPath>
          </dependency>
 -        
 -        <dependency>
 -            <groupId>android</groupId>
 -            <artifactId>android</artifactId>
 -            <version>${google.android-version}</version>
 -            <scope>provided</scope>
 -        </dependency>
 +
  
          <dependency>
              <groupId>com.actionbarsherlock</groupId>
 -            <artifactId>actionbarsherlock</artifactId>
 +            <artifactId>library</artifactId>
              <version>${actionbarsherlock-version}</version>
 -            <scope>provided</scope>
 +            <type>apklib</type>
          </dependency>
  
          <dependency>
 -            <groupId>com.actionbarsherlock</groupId>
 -            <artifactId>actionbarsherlock</artifactId>
 -            <version>${actionbarsherlock-version}</version>
 -            <type>apklib</type>
 +            <groupId>android</groupId>
 +            <artifactId>android</artifactId>
 +            <version>${google.android-version}</version>
 +            <scope>provided</scope>
          </dependency>
  
 +        <!--<dependency>-->
 +            <!--<groupId>android.support</groupId>-->
 +            <!--<artifactId>compatibility-v4</artifactId>-->
 +            <!--<version>19.1.0</version>-->
 +        <!--</dependency>-->
 +
 +
          <!-- MUST BE INSTALLED FIRST: cd owncloud-android-library; mvn install -->
          <dependency>
 -         <groupId>com.owncloud.android</groupId>
 -         <artifactId>owncloud-android-library</artifactId>
 -         <version>${owncloud.version}</version>
 -      </dependency>
 +            <groupId>com.owncloud.android</groupId>
 +            <artifactId>owncloud-android-library</artifactId>
 +            <version>${owncloud.version}</version>
 +        </dependency>
  
      </dependencies>
  
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
 -                <version>3.0</version>
 +                <version>3.1</version>
                  <configuration>
                      <source>${java-version}</source>
                      <target>${java-version}</target>
              <plugin>
                  <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                  <artifactId>android-maven-plugin</artifactId>
 -                <version>3.8.0</version>
 +                <version>3.8.2</version>
                  <configuration>
                      <sdk>
                          <path>${env.ANDROID_HOME}</path>
@@@ -27,11 -27,11 +27,11 @@@ import java.util.Vector
  
  import com.owncloud.android.MainApp;
  import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
+ import com.owncloud.android.lib.common.utils.Log_OC;
  import com.owncloud.android.lib.resources.shares.OCShare;
  import com.owncloud.android.lib.resources.shares.ShareType;
  import com.owncloud.android.lib.resources.files.FileUtils;
  import com.owncloud.android.utils.FileStorageUtils;
- import com.owncloud.android.utils.Log_OC;
  
  
  import android.accounts.Account;
@@@ -188,6 -188,7 +188,7 @@@ public class FileDataStorageManager 
          cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
          cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
          cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
+         cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
          
          boolean sameRemotePath = fileExists(file.getRemotePath());
          if (sameRemotePath ||
      }
  
      
+     public void moveLocalFile(OCFile file, String targetPath, String targetParentPath) {
+         if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) {
+             
+             OCFile targetParent = getFileByPath(targetParentPath);
+             if (targetParent == null) {
+                 // TODO panic
+             }
+             
+             /// 1. get all the descendants of the moved element in a single QUERY
+             Cursor c = null;
+             if (getContentProviderClient() != null) {
+                 try {
+                     c = getContentProviderClient().query(
+                         ProviderTableMeta.CONTENT_URI, 
+                         null,
+                         ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + 
+                                 ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                         new String[] { 
+                                 mAccount.name, 
+                                 file.getRemotePath() + "%"  
+                         }, 
+                         ProviderTableMeta.FILE_PATH + " ASC "
+                     );
+                 } catch (RemoteException e) {
+                     Log_OC.e(TAG, e.getMessage());
+                 }
+                 
+             } else {
+                 c = getContentResolver().query(
+                     ProviderTableMeta.CONTENT_URI, 
+                     null,
+                     ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + 
+                             ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                     new String[] { 
+                             mAccount.name, 
+                             file.getRemotePath() + "%"  
+                     }, 
+                     ProviderTableMeta.FILE_PATH + " ASC "
+                 );
+             }
+             /// 2. prepare a batch of update operations to change all the descendants
+             ArrayList<ContentProviderOperation> operations = 
+                     new ArrayList<ContentProviderOperation>(c.getCount());
+             String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
+             if (c.moveToFirst()) {
+                 int lengthOfOldPath = file.getRemotePath().length();
+                 int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
+                 do {
+                     ContentValues cv = new ContentValues(); // keep construction in the loop
+                     OCFile child = createFileInstance(c);
+                     cv.put(
+                         ProviderTableMeta.FILE_PATH, 
+                         targetPath + child.getRemotePath().substring(lengthOfOldPath)
+                     );
+                     if (child.getStoragePath() != null && 
+                             child.getStoragePath().startsWith(defaultSavePath)) {
+                         // update link to downloaded content - but local move is not done here!
+                         cv.put(
+                             ProviderTableMeta.FILE_STORAGE_PATH, 
+                             defaultSavePath + targetPath + 
+                                 child.getStoragePath().substring(lengthOfOldStoragePath)
+                         );
+                     }
+                     if (child.getRemotePath().equals(file.getRemotePath())) {
+                         cv.put(
+                                 ProviderTableMeta.FILE_PARENT,
+                                 targetParent.getFileId()
+                             );
+                     }
+                     operations.add(
+                         ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
+                             withValues(cv).
+                             withSelection(  
+                                     ProviderTableMeta._ID + "=?", 
+                                     new String[] { String.valueOf(child.getFileId()) }
+                                     )
+                             .build());
+                     
+                 } while (c.moveToNext());
+             }
+             c.close();
+             /// 3. apply updates in batch
+             try {
+                 if (getContentResolver() != null) {
+                     getContentResolver().applyBatch(MainApp.getAuthority(), operations);
+                 } else {
+                     getContentProviderClient().applyBatch(operations);
+                 }
+             } catch (Exception e) {
+                 Log_OC.e(
+                     TAG, 
+                     "Fail to update " + file.getFileId() + " and descendants in database", 
+                     e
+                 );
+             }
+             /// 4. move in local file system 
+             String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
+             File localFile = new File(localPath);
+             boolean renamed = false;
+             if (localFile.exists()) {
+                 File targetFile = new File(defaultSavePath + targetPath);
+                 File targetFolder = targetFile.getParentFile();
+                 if (!targetFolder.exists()) {
+                     targetFolder.mkdirs();
+                 }
+                 renamed = localFile.renameTo(targetFile);
+             }
+             Log_OC.d(TAG, "Local file RENAMED : " + renamed);
+             
+         }
+         
+     }
+     
+     
      private Vector<OCFile> getFolderContent(long parentId) {
  
          Vector<OCFile> ret = new Vector<OCFile>();
              file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
              file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
              file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
+             file.setNeedsUpdateThumbnail(c.getInt(
+                     c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
                      
          }
          return file;
                  cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
                  cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
                  cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
+                 cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail() ? 1 : 0);
  
                  boolean existsByPath = fileExists(file.getRemotePath());
                  if (existsByPath || fileExists(file.getFileId())) {
                  path = path + FileUtils.PATH_SEPARATOR;
              }           
  
 -            // Update OCFile with data from share: ShareByLink  ¿and publicLink?
 +            // Update OCFile with data from share: ShareByLink  and publicLink
              OCFile file = getFileByPath(path);
              if (file != null) {
                  if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
              */
          //}
      }
  }
@@@ -32,12 -32,12 +32,12 @@@ import com.owncloud.android.lib.common.
  import com.owncloud.android.lib.resources.shares.OCShare;
  import com.owncloud.android.lib.common.operations.RemoteOperation;
  import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+ import com.owncloud.android.lib.common.utils.Log_OC;
  import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
  import com.owncloud.android.lib.resources.shares.ShareType;
  import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
  import com.owncloud.android.lib.resources.files.FileUtils;
  import com.owncloud.android.operations.common.SyncOperation;
- import com.owncloud.android.utils.Log_OC;
  
  public class CreateShareOperation extends SyncOperation {
  
      /**
       * Constructor
       * @param path          Full path of the file/folder being shared. Mandatory argument
 -     * @param shareType     \910\92 = user, \911\92 = group, \913\92 = Public link. Mandatory argument
 +     * @param shareType     0 = user, 1 = group, 3 = Public link. Mandatory argument
       * @param shareWith     User/group ID with who the file should be shared.  This is mandatory for shareType of 0 or 1
 -     * @param publicUpload  If \91false\92 (default) public cannot upload to a public shared folder. 
 -     *                      If \91true\92 public can upload to a shared folder. Only available for public link shares
 +     * @param publicUpload  If false (default) public cannot upload to a public shared folder. 
 +     *                      If true public can upload to a shared folder. Only available for public link shares
       * @param password      Password to protect a public link share. Only available for public link shares
 -     * @param permissions   1 - Read only \96 Default for \93public\94 shares
 +     * @param permissions   1 - Read only - Default for public shares
       *                      2 - Update
       *                      4 - Create
       *                      8 - Delete
       *                      16- Re-share
 -     *                      31- All above \96 Default for \93private\94 shares
 +     *                      31- All above - Default for private shares
       *                      For user or group shares.
       *                      To obtain combinations, add the desired values together.  
 -     *                      For instance, for \93Re-Share\94\93delete\94\93read\94\93update\94, add 16+8+2+1 = 27.
 +     *                      For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
       */
      public CreateShareOperation(String path, ShareType shareType, String shareWith, boolean publicUpload, 
              String password, int permissions, Intent sendIntent) {
@@@ -23,9 -23,9 +23,9 @@@ import java.util.ArrayList
  import com.owncloud.android.lib.common.OwnCloudClient;
  import com.owncloud.android.lib.resources.shares.OCShare;
  import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+ import com.owncloud.android.lib.common.utils.Log_OC;
  import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
  import com.owncloud.android.operations.common.SyncOperation;
- import com.owncloud.android.utils.Log_OC;
  
  /**
   * Provide a list shares for a specific file.  
@@@ -45,10 -45,10 +45,10 @@@ public class GetSharesForFileOperation 
       * Constructor
       * 
       * @param path      Path to file or folder
 -     * @param reshares  If set to \91false\92 (default), only shares from the current user are returned
 -     *                  If set to \91true\92, all shares from the given file are returned
 -     * @param subfiles  If set to \91false\92 (default), lists only the folder being shared
 -     *                  If set to \91true\92, all shared files within the folder are returned.
 +     * @param reshares  If set to false (default), only shares from the current user are returned
 +     *                  If set to true, all shares from the given file are returned
 +     * @param subfiles  If set to false (default), lists only the folder being shared
 +     *                  If set to true, all shared files within the folder are returned.
       */
      public GetSharesForFileOperation(String path, boolean reshares, boolean subfiles) {
          mPath = path;