Browse Source

add folder type to persistent entity

AndyScherzinger 8 years ago
parent
commit
8e3edb5a19

+ 4 - 5
src/main/java/com/owncloud/android/datamodel/MediaFolder.java

@@ -27,11 +27,10 @@ import java.util.List;
  * Business object representing a media folder with all information that are gathered via media queries.
  * Business object representing a media folder with all information that are gathered via media queries.
  */
  */
 public class MediaFolder {
 public class MediaFolder {
-    public static final int AUDIO = 3;
-    public static final int VIDEO = 1;
-    public static final int IMAGE = 2;
-    public static final int IMAGE_VIDEO = 3;
-    public static final int CUSTOM = 4;
+    public static final Integer IMAGE = 0;
+    public static final Integer VIDEO = 1;
+    public static final Integer IMAGE_VIDEO = 2;
+    public static final Integer CUSTOM = 3;
 
 
     /** name of the folder. */
     /** name of the folder. */
     public String folderName;
     public String folderName;

+ 15 - 2
src/main/java/com/owncloud/android/datamodel/SyncedFolder.java

@@ -38,6 +38,7 @@ public class SyncedFolder implements Serializable {
     private String account;
     private String account;
     private Integer uploadAction;
     private Integer uploadAction;
     private boolean enabled;
     private boolean enabled;
+    private Integer type;
 
 
     /**
     /**
      * constructor for already persisted entity.
      * constructor for already persisted entity.
@@ -51,9 +52,10 @@ public class SyncedFolder implements Serializable {
      * @param account         the account owning the synced folder
      * @param account         the account owning the synced folder
      * @param uploadAction    the action to be done after the upload
      * @param uploadAction    the action to be done after the upload
      * @param enabled         flag if synced folder config is active
      * @param enabled         flag if synced folder config is active
+     * @param type            the type of the folder
      */
      */
     public SyncedFolder(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
     public SyncedFolder(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
-                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled) {
+                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled, Integer type) {
         this.id = id;
         this.id = id;
         this.localPath = localPath;
         this.localPath = localPath;
         this.remotePath = remotePath;
         this.remotePath = remotePath;
@@ -63,6 +65,7 @@ public class SyncedFolder implements Serializable {
         this.account = account;
         this.account = account;
         this.uploadAction = uploadAction;
         this.uploadAction = uploadAction;
         this.enabled = enabled;
         this.enabled = enabled;
+        this.type = type;
     }
     }
 
 
     /**
     /**
@@ -76,9 +79,10 @@ public class SyncedFolder implements Serializable {
      * @param account         the account owning the synced folder
      * @param account         the account owning the synced folder
      * @param uploadAction    the action to be done after the upload
      * @param uploadAction    the action to be done after the upload
      * @param enabled         flag if synced folder config is active
      * @param enabled         flag if synced folder config is active
+     * @param type            the type of the folder
      */
      */
     public SyncedFolder(String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
     public SyncedFolder(String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
-                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled) {
+                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled, Integer type) {
         this.localPath = localPath;
         this.localPath = localPath;
         this.remotePath = remotePath;
         this.remotePath = remotePath;
         this.wifiOnly = wifiOnly;
         this.wifiOnly = wifiOnly;
@@ -87,6 +91,7 @@ public class SyncedFolder implements Serializable {
         this.account = account;
         this.account = account;
         this.uploadAction = uploadAction;
         this.uploadAction = uploadAction;
         this.enabled = enabled;
         this.enabled = enabled;
+        this.type = type;
     }
     }
 
 
     public long getId() {
     public long getId() {
@@ -160,4 +165,12 @@ public class SyncedFolder implements Serializable {
     public void setEnabled(boolean enabled) {
     public void setEnabled(boolean enabled) {
         this.enabled = enabled;
         this.enabled = enabled;
     }
     }
+
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
 }
 }

+ 4 - 14
src/main/java/com/owncloud/android/datamodel/SyncedFolderDisplayItem.java

@@ -31,7 +31,6 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
     private List<String> filePaths;
     private List<String> filePaths;
     private String folderName;
     private String folderName;
     private long numberOfFiles;
     private long numberOfFiles;
-    private int type;
 
 
     /**
     /**
      * constructor for the display item specialization for a synced folder object.
      * constructor for the display item specialization for a synced folder object.
@@ -52,18 +51,17 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
      */
      */
     public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
     public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
                                    Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
                                    Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
-                                   List<String> filePaths, String folderName, long numberOfFiles, int type) {
-        super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled);
+                                   List<String> filePaths, String folderName, long numberOfFiles, Integer type) {
+        super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         this.filePaths = filePaths;
         this.filePaths = filePaths;
         this.folderName = folderName;
         this.folderName = folderName;
         this.numberOfFiles = numberOfFiles;
         this.numberOfFiles = numberOfFiles;
-        this.type = type;
     }
     }
 
 
     public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
     public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
                                    Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
                                    Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
-                                   String folderName) {
-        super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled);
+                                   String folderName, Integer type) {
+        super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         this.folderName = folderName;
         this.folderName = folderName;
     }
     }
 
 
@@ -90,12 +88,4 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
     public void setNumberOfFiles(long numberOfFiles) {
     public void setNumberOfFiles(long numberOfFiles) {
         this.numberOfFiles = numberOfFiles;
         this.numberOfFiles = numberOfFiles;
     }
     }
-
-    public int getType() {
-        return type;
-    }
-
-    public void setType(int type) {
-        this.type = type;
-    }
 }
 }

+ 6 - 6
src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

@@ -187,7 +187,6 @@ public class SyncedFolderProvider extends Observable {
         }
         }
 
 
         return result;
         return result;
-
     }
     }
 
 
     /**
     /**
@@ -211,15 +210,12 @@ public class SyncedFolderProvider extends Observable {
      *
      *
      * @param id for the synced folder.
      * @param id for the synced folder.
      */
      */
-
     private int deleteSyncFolderWithId(long id) {
     private int deleteSyncFolderWithId(long id) {
-        int result = mContentResolver.delete(
+        return mContentResolver.delete(
                 ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
                 ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
                 ProviderMeta.ProviderTableMeta._ID + " = ?",
                 ProviderMeta.ProviderTableMeta._ID + " = ?",
                 new String[]{String.valueOf(id)}
                 new String[]{String.valueOf(id)}
         );
         );
-
-        return result;
     }
     }
 
 
 
 
@@ -325,9 +321,11 @@ public class SyncedFolderProvider extends Observable {
                     ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
                     ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
             Boolean enabled = cursor.getInt(cursor.getColumnIndex(
             Boolean enabled = cursor.getInt(cursor.getColumnIndex(
                     ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
                     ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
+            Integer type = cursor.getInt(cursor.getColumnIndex(
+                    ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE));
 
 
             syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
             syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
-                    accountName, uploadAction, enabled);
+                    accountName, uploadAction, enabled, type);
         }
         }
         return syncedFolder;
         return syncedFolder;
     }
     }
@@ -349,6 +347,8 @@ public class SyncedFolderProvider extends Observable {
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.getSubfolderByDate());
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.getSubfolderByDate());
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
         cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
+        cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType());
+
         return cv;
         return cv;
     }
     }
 
 

+ 1 - 0
src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -176,6 +176,7 @@ public class ProviderMeta {
         public static final String SYNCED_FOLDER_WIFI_ONLY = "wifi_only";
         public static final String SYNCED_FOLDER_WIFI_ONLY = "wifi_only";
         public static final String SYNCED_FOLDER_CHARGING_ONLY = "charging_only";
         public static final String SYNCED_FOLDER_CHARGING_ONLY = "charging_only";
         public static final String SYNCED_FOLDER_ENABLED = "enabled";
         public static final String SYNCED_FOLDER_ENABLED = "enabled";
+        public static final String SYNCED_FOLDER_TYPE = "type";
         public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
         public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
         public static final String SYNCED_FOLDER_ACCOUNT = "account";
         public static final String SYNCED_FOLDER_ACCOUNT = "account";
         public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";
         public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";

+ 15 - 0
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -937,7 +937,22 @@ public class FileContentProvider extends ContentProvider {
                 } finally {
                 } finally {
                     db.endTransaction();
                     db.endTransaction();
                 }
                 }
+            }
+
+            if (oldVersion < 18 && newVersion >= 18) {
+                Log_OC.i(SQL, "Entering in the #18 ADD in onUpgrade");
+                db.beginTransaction();
+                try {
+                    // add type column default being IMAGE(0)
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                            ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
+                            " INTEGER " + " DEFAULT 0");
 
 
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
             }
             }
 
 
             if (!upgraded) {
             if (!upgraded) {

+ 2 - 1
src/main/java/com/owncloud/android/ui/activity/FolderSyncActivity.java

@@ -294,7 +294,8 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
                 syncedFolder.getAccount(),
                 syncedFolder.getAccount(),
                 syncedFolder.getUploadAction(),
                 syncedFolder.getUploadAction(),
                 syncedFolder.isEnabled(),
                 syncedFolder.isEnabled(),
-                new File(syncedFolder.getLocalPath()).getName());
+                new File(syncedFolder.getLocalPath()).getName(),
+                syncedFolder.getType());
     }
     }
 
 
     /**
     /**