Browse Source

CR: use enum instead of Integer

AndyScherzinger 7 years ago
parent
commit
aeda198d5b

+ 3 - 2
src/main/java/com/owncloud/android/MainApp.java

@@ -38,6 +38,7 @@ import android.support.v7.app.AlertDialog;
 import com.evernote.android.job.JobManager;
 import com.evernote.android.job.JobManager;
 import com.owncloud.android.authentication.PassCodeManager;
 import com.owncloud.android.authentication.PassCodeManager;
 import com.owncloud.android.datamodel.MediaFolder;
 import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.MediaProvider;
 import com.owncloud.android.datamodel.MediaProvider;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
@@ -356,7 +357,7 @@ public class MainApp extends MultiDexApplication {
                 for (int i = 0; i < imageMediaFolders.size(); i++) {
                 for (int i = 0; i < imageMediaFolders.size(); i++) {
                     if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {
                     if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
-                        newSyncedFolder.setType(MediaFolder.IMAGE);
+                        newSyncedFolder.setType(MediaFolderType.IMAGE);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                         Log_OC.i(TAG, "Migrated image synced_folders record: "
                         Log_OC.i(TAG, "Migrated image synced_folders record: "
                                 + primaryKey + " - " + newSyncedFolder.getLocalPath());
                                 + primaryKey + " - " + newSyncedFolder.getLocalPath());
@@ -367,7 +368,7 @@ public class MainApp extends MultiDexApplication {
                 for (int j = 0; j < videoMediaFolders.size(); j++) {
                 for (int j = 0; j < videoMediaFolders.size(); j++) {
                     if (videoMediaFolders.get(j).absolutePath.equals(syncedFolder.getLocalPath())) {
                     if (videoMediaFolders.get(j).absolutePath.equals(syncedFolder.getLocalPath())) {
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
                         newSyncedFolder = (SyncedFolder) syncedFolder.clone();
-                        newSyncedFolder.setType(MediaFolder.VIDEO);
+                        newSyncedFolder.setType(MediaFolderType.VIDEO);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                         primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
                         Log_OC.i(TAG, "Migrated video synced_folders record: "
                         Log_OC.i(TAG, "Migrated video synced_folders record: "
                                 + primaryKey + " - " + newSyncedFolder.getLocalPath());
                                 + primaryKey + " - " + newSyncedFolder.getLocalPath());

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

@@ -27,10 +27,6 @@ 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 Integer CUSTOM = 0;
-    public static final Integer IMAGE = 1;
-    public static final Integer VIDEO = 2;
-
     /** name of the folder. */
     /** name of the folder. */
     public String folderName;
     public String folderName;
 
 
@@ -43,5 +39,6 @@ public class MediaFolder {
     /** total number of files in the media folder. */
     /** total number of files in the media folder. */
     public long numberOfFiles;
     public long numberOfFiles;
 
 
-    public int type;
+    /** type of media folder. */
+    public MediaFolderType type;
 }
 }

+ 34 - 0
src/main/java/com/owncloud/android/datamodel/MediaFolderType.java

@@ -0,0 +1,34 @@
+package com.owncloud.android.datamodel;
+
+import android.util.SparseArray;
+
+/**
+ * Types of media folder.
+ */
+public enum MediaFolderType {
+    CUSTOM(0),
+    IMAGE(1),
+    VIDEO(2);
+
+    private Integer id;
+
+    private static SparseArray<MediaFolderType> reverseMap = new SparseArray<>(3);
+
+    static {
+        reverseMap.put(CUSTOM.getId(), CUSTOM);
+        reverseMap.put(IMAGE.getId(), IMAGE);
+        reverseMap.put(VIDEO.getId(), VIDEO);
+    }
+
+    MediaFolderType(Integer id) {
+        this.id = id;
+    }
+
+    public static MediaFolderType getById(Integer id) {
+        return reverseMap.get(id);
+    }
+
+    public Integer getId() {
+        return id;
+    }
+}

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

@@ -107,7 +107,7 @@ public class MediaProvider {
                 MediaFolder mediaFolder = new MediaFolder();
                 MediaFolder mediaFolder = new MediaFolder();
                 folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
                 folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
                         MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
                         MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
-                mediaFolder.type = MediaFolder.IMAGE;
+                mediaFolder.type = MediaFolderType.IMAGE;
                 mediaFolder.folderName = folderName;
                 mediaFolder.folderName = folderName;
                 mediaFolder.filePaths = new ArrayList<>();
                 mediaFolder.filePaths = new ArrayList<>();
 
 
@@ -206,7 +206,7 @@ public class MediaProvider {
                 MediaFolder mediaFolder = new MediaFolder();
                 MediaFolder mediaFolder = new MediaFolder();
                 folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
                 folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
                         MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
                         MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
-                mediaFolder.type = MediaFolder.VIDEO;
+                mediaFolder.type = MediaFolderType.VIDEO;
                 mediaFolder.folderName = folderName;
                 mediaFolder.folderName = folderName;
                 mediaFolder.filePaths = new ArrayList<>();
                 mediaFolder.filePaths = new ArrayList<>();
 
 

+ 7 - 5
src/main/java/com/owncloud/android/datamodel/SyncedFolder.java

@@ -38,7 +38,7 @@ public class SyncedFolder implements Serializable, Cloneable {
     private String account;
     private String account;
     private Integer uploadAction;
     private Integer uploadAction;
     private boolean enabled;
     private boolean enabled;
-    private Integer type;
+    private MediaFolderType type;
 
 
     /**
     /**
      * constructor for already persisted entity.
      * constructor for already persisted entity.
@@ -55,7 +55,8 @@ public class SyncedFolder implements Serializable, Cloneable {
      * @param type            the type of the folder
      * @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, Integer type) {
+                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
+                        MediaFolderType type) {
         this.id = id;
         this.id = id;
         this.localPath = localPath;
         this.localPath = localPath;
         this.remotePath = remotePath;
         this.remotePath = remotePath;
@@ -82,7 +83,8 @@ public class SyncedFolder implements Serializable, Cloneable {
      * @param type            the type of the folder
      * @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, Integer type) {
+                        Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
+                        MediaFolderType type) {
         this.localPath = localPath;
         this.localPath = localPath;
         this.remotePath = remotePath;
         this.remotePath = remotePath;
         this.wifiOnly = wifiOnly;
         this.wifiOnly = wifiOnly;
@@ -175,11 +177,11 @@ public class SyncedFolder implements Serializable, Cloneable {
         this.enabled = enabled;
         this.enabled = enabled;
     }
     }
 
 
-    public int getType() {
+    public MediaFolderType getType() {
         return type;
         return type;
     }
     }
 
 
-    public void setType(int type) {
+    public void setType(MediaFolderType type) {
         this.type = type;
         this.type = type;
     }
     }
 }
 }

+ 3 - 2
src/main/java/com/owncloud/android/datamodel/SyncedFolderDisplayItem.java

@@ -51,7 +51,8 @@ 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, Integer type) {
+                                   List<String> filePaths, String folderName, long numberOfFiles, MediaFolderType type)
+    {
         super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         this.filePaths = filePaths;
         this.filePaths = filePaths;
         this.folderName = folderName;
         this.folderName = folderName;
@@ -60,7 +61,7 @@ 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,
-                                   String folderName, Integer type) {
+                                   String folderName, MediaFolderType type) {
         super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
         this.folderName = folderName;
         this.folderName = folderName;
     }
     }

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

@@ -337,8 +337,8 @@ 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));
+            MediaFolderType type = MediaFolderType.getById(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, type);
                     accountName, uploadAction, enabled, type);
@@ -363,7 +363,7 @@ 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());
+        cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId());
 
 
         return cv;
         return cv;
     }
     }

+ 4 - 4
src/main/java/com/owncloud/android/jobs/FilesSyncJob.java

@@ -24,9 +24,9 @@ package com.owncloud.android.jobs;
 import android.accounts.Account;
 import android.accounts.Account;
 import android.content.ContentResolver;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Context;
-import android.support.media.ExifInterface;
 import android.os.PowerManager;
 import android.os.PowerManager;
 import android.support.annotation.NonNull;
 import android.support.annotation.NonNull;
+import android.support.media.ExifInterface;
 import android.text.TextUtils;
 import android.text.TextUtils;
 
 
 import com.evernote.android.job.Job;
 import com.evernote.android.job.Job;
@@ -34,7 +34,7 @@ import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
-import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader;
@@ -86,7 +86,7 @@ public class FilesSyncJob extends Job {
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
 
 
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
-            if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType())) {
+            if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.getType())) {
                 for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
                 for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
                         Long.toString(syncedFolder.getId()))) {
                         Long.toString(syncedFolder.getId()))) {
                     File file = new File(path);
                     File file = new File(path);
@@ -94,7 +94,7 @@ public class FilesSyncJob extends Job {
                     Long lastModificationTime = file.lastModified();
                     Long lastModificationTime = file.lastModified();
                     final Locale currentLocale = context.getResources().getConfiguration().locale;
                     final Locale currentLocale = context.getResources().getConfiguration().locale;
 
 
-                    if (MediaFolder.IMAGE == syncedFolder.getType()) {
+                    if (MediaFolderType.IMAGE == syncedFolder.getType()) {
                         String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
                         String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
                         if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
                         if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
                                 equalsIgnoreCase(mimetypeString)) {
                                 equalsIgnoreCase(mimetypeString)) {

+ 4 - 6
src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java

@@ -49,13 +49,13 @@ import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.MediaFolder;
 import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.MediaProvider;
 import com.owncloud.android.datamodel.MediaProvider;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.adapter.SyncedFolderAdapter;
 import com.owncloud.android.ui.adapter.SyncedFolderAdapter;
 import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
 import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
 import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment;
 import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment;
@@ -246,7 +246,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
                 SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath+"-"+mediaFolder.type);
                 SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath+"-"+mediaFolder.type);
                 syncedFoldersMap.remove(mediaFolder.absolutePath+"-"+mediaFolder.type);
                 syncedFoldersMap.remove(mediaFolder.absolutePath+"-"+mediaFolder.type);
 
 
-                if (MediaFolder.CUSTOM == syncedFolder.getType()) {
+                if (MediaFolderType.CUSTOM == syncedFolder.getType()) {
                     result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
                     result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
                 } else {
                 } else {
                     result.add(createSyncedFolder(syncedFolder, mediaFolder));
                     result.add(createSyncedFolder(syncedFolder, mediaFolder));
@@ -540,7 +540,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
 
 
         // custom folders newly created aren't in the list already,
         // custom folders newly created aren't in the list already,
         // so triggering a refresh
         // so triggering a refresh
-        if (MediaFolder.CUSTOM.equals(syncedFolder.getType()) && syncedFolder.getId() == UNPERSISTED_ID) {
+        if (MediaFolderType.CUSTOM.equals(syncedFolder.getType()) && syncedFolder.getId() == UNPERSISTED_ID) {
             SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(
             SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(
                     SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(),
                     SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(),
                     syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(),
                     syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(),
@@ -560,8 +560,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
             mAdapter.addSyncFolderItem(newCustomFolder);
             mAdapter.addSyncFolderItem(newCustomFolder);
         } else {
         } else {
             SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
             SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
-            Log_OC.e(TAG, "syncedFolder"+ syncedFolder.getLocalPath()+"-"+syncedFolder.getType());
-            Log_OC.e(TAG, "item"+ item.getLocalPath()+"-"+item.getType());
             item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder
             item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder
                     .getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder
                     .getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder
                     .getUploadAction(), syncedFolder.getEnabled());
                     .getUploadAction(), syncedFolder.getEnabled());
@@ -665,7 +663,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
         SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
                 SyncedFolder.UNPERSISTED_ID, null, null, true, false,
                 SyncedFolder.UNPERSISTED_ID, null, null, true, false,
                 false, AccountUtils.getCurrentOwnCloudAccount(this).name,
                 false, AccountUtils.getCurrentOwnCloudAccount(this).name,
-                FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolder.CUSTOM);
+                FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolderType.CUSTOM);
         onSyncFolderSettingsClick(0, emptyCustomFolder);
         onSyncFolderSettingsClick(0, emptyCustomFolder);
     }
     }
 }
 }

+ 3 - 3
src/main/java/com/owncloud/android/ui/adapter/SyncedFolderAdapter.java

@@ -34,7 +34,7 @@ import android.widget.TextView;
 
 
 import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter;
 import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.utils.ThemeUtils;
 import com.owncloud.android.utils.ThemeUtils;
@@ -110,9 +110,9 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SyncedFold
 
 
         holder.title.setText(mSyncFolderItems.get(section).getFolderName());
         holder.title.setText(mSyncFolderItems.get(section).getFolderName());
 
 
-        if (MediaFolder.VIDEO == mSyncFolderItems.get(section).getType()) {
+        if (MediaFolderType.VIDEO == mSyncFolderItems.get(section).getType()) {
             holder.type.setImageResource(R.drawable.ic_video_18dp);
             holder.type.setImageResource(R.drawable.ic_video_18dp);
-        } else if (MediaFolder.IMAGE == mSyncFolderItems.get(section).getType()) {
+        } else if (MediaFolderType.IMAGE == mSyncFolderItems.get(section).getType()) {
             holder.type.setImageResource(R.drawable.ic_image_18dp);
             holder.type.setImageResource(R.drawable.ic_image_18dp);
         } else {
         } else {
             holder.type.setImageResource(R.drawable.ic_folder_star_18dp);
             holder.type.setImageResource(R.drawable.ic_folder_star_18dp);

+ 2 - 2
src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java

@@ -42,7 +42,7 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.owncloud.android.R;
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.FolderPickerActivity;
 import com.owncloud.android.ui.activity.FolderPickerActivity;
@@ -141,7 +141,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
     private void setupDialogElements(View view) {
     private void setupDialogElements(View view) {
         int accentColor = ThemeUtils.primaryAccentColor();
         int accentColor = ThemeUtils.primaryAccentColor();
 
 
-        if (mSyncedFolder.getType() > MediaFolder.CUSTOM) {
+        if (mSyncedFolder.getType().getId() > MediaFolderType.CUSTOM.getId()) {
             // hide local folder chooser and delete for non-custom folders
             // hide local folder chooser and delete for non-custom folders
             view.findViewById(R.id.local_folder_container).setVisibility(View.GONE);
             view.findViewById(R.id.local_folder_container).setVisibility(View.GONE);
             view.findViewById(R.id.delete).setVisibility(View.GONE);
             view.findViewById(R.id.delete).setVisibility(View.GONE);

+ 6 - 5
src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java

@@ -23,6 +23,7 @@ package com.owncloud.android.ui.dialog.parcel;
 import android.os.Parcel;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.Parcelable;
 
 
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader;
 
 
@@ -38,7 +39,7 @@ public class SyncedFolderParcelable implements Parcelable {
     private Boolean mEnabled = false;
     private Boolean mEnabled = false;
     private Boolean mSubfolderByDate = false;
     private Boolean mSubfolderByDate = false;
     private Integer mUploadAction;
     private Integer mUploadAction;
-    private int mType;
+    private MediaFolderType mType;
     private long mId;
     private long mId;
     private String mAccount;
     private String mAccount;
     private int mSection;
     private int mSection;
@@ -70,7 +71,7 @@ public class SyncedFolderParcelable implements Parcelable {
         mChargingOnly = read.readInt() != 0;
         mChargingOnly = read.readInt() != 0;
         mEnabled = read.readInt() != 0;
         mEnabled = read.readInt() != 0;
         mSubfolderByDate = read.readInt() != 0;
         mSubfolderByDate = read.readInt() != 0;
-        mType = read.readInt();
+        mType = MediaFolderType.getById(read.readInt());
         mAccount = read.readString();
         mAccount = read.readString();
         mUploadAction = read.readInt();
         mUploadAction = read.readInt();
         mSection = read.readInt();
         mSection = read.readInt();
@@ -86,7 +87,7 @@ public class SyncedFolderParcelable implements Parcelable {
         dest.writeInt(mChargingOnly ? 1 : 0);
         dest.writeInt(mChargingOnly ? 1 : 0);
         dest.writeInt(mEnabled ? 1 : 0);
         dest.writeInt(mEnabled ? 1 : 0);
         dest.writeInt(mSubfolderByDate ? 1 : 0);
         dest.writeInt(mSubfolderByDate ? 1 : 0);
-        dest.writeInt(mType);
+        dest.writeInt(mType.getId());
         dest.writeString(mAccount);
         dest.writeString(mAccount);
         dest.writeInt(mUploadAction);
         dest.writeInt(mUploadAction);
         dest.writeInt(mSection);
         dest.writeInt(mSection);
@@ -167,11 +168,11 @@ public class SyncedFolderParcelable implements Parcelable {
         this.mSubfolderByDate = mSubfolderByDate;
         this.mSubfolderByDate = mSubfolderByDate;
     }
     }
 
 
-    public int getType() {
+    public MediaFolderType getType() {
         return mType;
         return mType;
     }
     }
 
 
-    public void setType(int mType) {
+    public void setType(MediaFolderType mType) {
         this.mType = mType;
         this.mType = mType;
     }
     }
 
 

+ 6 - 6
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -39,7 +39,7 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
-import com.owncloud.android.datamodel.MediaFolder;
+import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
@@ -83,7 +83,7 @@ public class FilesSyncHelper {
         boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
         boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
                 (GLOBAL, syncedFolderInitiatedKey));
                 (GLOBAL, syncedFolderInitiatedKey));
 
 
-        if (MediaFolder.IMAGE == syncedFolder.getType()) {
+        if (MediaFolderType.IMAGE == syncedFolder.getType()) {
             if (dryRun) {
             if (dryRun) {
                 arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
                 arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
                         currentTimeString);
                         currentTimeString);
@@ -94,7 +94,7 @@ public class FilesSyncHelper {
                         syncedFolder);
                         syncedFolder);
             }
             }
 
 
-        } else if (MediaFolder.VIDEO == syncedFolder.getType()) {
+        } else if (MediaFolderType.VIDEO == syncedFolder.getType()) {
 
 
             if (dryRun) {
             if (dryRun) {
                 arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
                 arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
@@ -152,7 +152,7 @@ public class FilesSyncHelper {
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
 
 
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
-            if ((syncedFolder.isEnabled()) && ((MediaFolder.CUSTOM != syncedFolder.getType()) || !skipCustom)) {
+            if ((syncedFolder.isEnabled()) && ((MediaFolderType.CUSTOM != syncedFolder.getType()) || !skipCustom)) {
                     insertAllDBEntriesForSyncedFolder(syncedFolder);
                     insertAllDBEntriesForSyncedFolder(syncedFolder);
             }
             }
         }
         }
@@ -263,9 +263,9 @@ public class FilesSyncHelper {
 
 
         if (syncedFolderProvider.getSyncedFolders() != null) {
         if (syncedFolderProvider.getSyncedFolders() != null) {
             for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
             for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
-                if (MediaFolder.VIDEO == syncedFolder.getType()) {
+                if (MediaFolderType.VIDEO == syncedFolder.getType()) {
                     hasVideoFolders = true;
                     hasVideoFolders = true;
-                } else if (MediaFolder.IMAGE == syncedFolder.getType()) {
+                } else if (MediaFolderType.IMAGE == syncedFolder.getType()) {
                     hasImageFolders = true;
                     hasImageFolders = true;
                 }
                 }
             }
             }