Browse Source

Merge pull request #3216 from nextcloud/hasPreviewProperty

Add has-preview property
Andy Scherzinger 6 years ago
parent
commit
4f1d4f4250

+ 2 - 10
src/gplay/java/com/owncloud/android/utils/PushUtils.java

@@ -395,19 +395,11 @@ public final class PushUtils {
                 PreferenceManager.setKeysMigration(context, true);
             } else {
                 if (oldPrivateKeyFile.exists()) {
-                    try {
-                        FileStorageUtils.moveFile(oldPrivateKeyFile, privateKeyFile);
-                    } catch (IOException e) {
-                        Log.e(TAG, "Failed to move old private key to new location");
-                    }
+                    FileStorageUtils.moveFile(oldPrivateKeyFile, privateKeyFile);
                 }
 
                 if (oldPublicKeyFile.exists()) {
-                    try {
-                        FileStorageUtils.moveFile(oldPublicKeyFile, publicKeyFile);
-                    } catch (IOException e) {
-                        Log.e(TAG, "Failed to move old public key to new location");
-                    }
+                    FileStorageUtils.moveFile(oldPublicKeyFile, publicKeyFile);
                 }
 
                 if (privateKeyFile.exists() && publicKeyFile.exists()) {

+ 11 - 9
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1,18 +1,18 @@
 /*
  * ownCloud Android client application
- * 
+ *
  * Copyright (C) 2012  Bartek Przybylski
  * Copyright (C) 2015 ownCloud Inc.
- * 
+ *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2,
  * as published by the Free Software Foundation.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -130,7 +130,7 @@ public class FileDataStorageManager {
         c.close();
         return file;
     }
-    
+
     public OCFile getFileByLocalPath(String path) {
         Cursor c = getFileCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
         OCFile file = null;
@@ -172,7 +172,7 @@ public class FileDataStorageManager {
 
     public List<OCFile> getFolderImages(OCFile folder, boolean onlyOnDevice) {
         List<OCFile> ret = new ArrayList<>();
-        
+
         if (folder != null) {
             // TODO better implementation, filtering in the access to database instead of here
             List<OCFile> tmp = getFolderContent(folder, onlyOnDevice);
@@ -490,6 +490,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_FAVORITE, file.isFavorite());
         cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, file.isEncrypted());
         cv.put(ProviderTableMeta.FILE_MOUNT_TYPE, file.getMountType().ordinal());
+        cv.put(ProviderTableMeta.FILE_HAS_PREVIEW, file.hasPreview() ? 1 : 0);
         return cv;
     }
 
@@ -600,7 +601,7 @@ public class FileDataStorageManager {
                 }
             }
 
-            // stage 2: remove the folder itself and any local file inside out of sync; 
+            // stage 2: remove the folder itself and any local file inside out of sync;
             //          for instance, after clearing the app cache or reinstalling
             success &= removeLocalFolder(localFolder);
         }
@@ -717,7 +718,7 @@ public class FileDataStorageManager {
                 Log_OC.e(TAG, "Fail to update " + file.getFileId() + " and descendants in database", e);
             }
 
-            /// 4. move in local file system 
+            /// 4. move in local file system
             String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
             String targetLocalPath = defaultSavePath + targetPath;
             File localFile = new File(originalLocalPath);
@@ -859,7 +860,7 @@ public class FileDataStorageManager {
                     }
                 } while (c.moveToNext());
             }
-            
+
             c.close();
         }
 
@@ -983,6 +984,7 @@ public class FileDataStorageManager {
             }
             file.setMountType(WebdavEntry.MountType.values()[c.getInt(
                     c.getColumnIndex(ProviderTableMeta.FILE_MOUNT_TYPE))]);
+            file.setHasPreview(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
         }
         return file;
     }

+ 25 - 17
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -43,23 +43,9 @@ import java.io.File;
 import third_parties.daveKoeller.AlphanumComparator;
 
 public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
-
-    public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
-
-        @Override
-        public OCFile createFromParcel(Parcel source) {
-            return new OCFile(source);
-        }
-
-        @Override
-        public OCFile[] newArray(int size) {
-            return new OCFile[size];
-        }
-    };
-
-    private final static String PERMISSION_SHARED_WITH_ME = "S";    // TODO move to better location
+    private final static String PERMISSION_SHARED_WITH_ME = "S";
     private final static String PERMISSION_CAN_RESHARE = "R";
-    private final static String PERMISSION_CAN_WRITE = "CK"; 
+    private final static String PERMISSION_CAN_WRITE = "CK";
 
     public static final String PATH_SEPARATOR = "/";
     public static final String ROOT_PATH = PATH_SEPARATOR;
@@ -79,6 +65,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
     private long mLastSyncDateForProperties;
     private long mLastSyncDateForData;
     private boolean mAvailableOffline;
+    private boolean mHasPreview;
 
     private String mEtag;
 
@@ -368,7 +355,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
                 getLegacyExposedFileUri(context);
             }
         }
-        
+
         return mExposedFileUri;
     }
 
@@ -797,4 +784,25 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
     public void setMountType(WebdavEntry.MountType mountType) {
         mMountType = mountType;
     }
+
+    public boolean hasPreview() {
+        return mHasPreview;
+    }
+
+    public void setHasPreview(boolean hasPreview) {
+        this.mHasPreview = hasPreview;
+    }
+
+    public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
+
+        @Override
+        public OCFile createFromParcel(Parcel source) {
+            return new OCFile(source);
+        }
+
+        @Override
+        public OCFile[] newArray(int size) {
+            return new OCFile[size];
+        }
+    };
 }

+ 5 - 3
src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -32,7 +32,7 @@ import com.owncloud.android.MainApp;
 public class ProviderMeta {
 
     public static final String DB_NAME = "filelist";
-    public static final int DB_VERSION = 35;
+    public static final int DB_VERSION = 36;
 
     private ProviderMeta() {
     }
@@ -103,13 +103,15 @@ public class ProviderMeta {
         public static final String FILE_FAVORITE = "favorite";
         public static final String FILE_IS_ENCRYPTED = "is_encrypted";
         public static final String FILE_MOUNT_TYPE = "mount_type";
+        public static final String FILE_HAS_PREVIEW = "has_preview";
 
         public static final String [] FILE_ALL_COLUMNS = {_ID, FILE_PARENT, FILE_NAME
                , FILE_CREATION, FILE_MODIFIED,
                 FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, FILE_CONTENT_LENGTH, FILE_CONTENT_TYPE, FILE_STORAGE_PATH,
                 FILE_PATH, FILE_ACCOUNT_OWNER, FILE_LAST_SYNC_DATE, FILE_LAST_SYNC_DATE_FOR_DATA, FILE_KEEP_IN_SYNC,
                 FILE_ETAG, FILE_SHARED_VIA_LINK, FILE_SHARED_WITH_SHAREE, FILE_PUBLIC_LINK, FILE_PERMISSIONS,
-                FILE_REMOTE_ID, FILE_UPDATE_THUMBNAIL, FILE_IS_DOWNLOADING, FILE_ETAG_IN_CONFLICT, FILE_FAVORITE};
+            FILE_REMOTE_ID, FILE_UPDATE_THUMBNAIL, FILE_IS_DOWNLOADING, FILE_ETAG_IN_CONFLICT, FILE_FAVORITE,
+            FILE_HAS_PREVIEW};
 
         public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME + " collate nocase asc";
 
@@ -170,7 +172,7 @@ public class ProviderMeta {
         public static final String CAPABILITIES_SERVER_SLOGAN = "server_slogan";
         public static final String CAPABILITIES_SERVER_BACKGROUND_DEFAULT = "background_default";
         public static final String CAPABILITIES_SERVER_BACKGROUND_PLAIN = "background_plain";
-        
+
         public static final String CAPABILITIES_END_TO_END_ENCRYPTION = "end_to_end_encryption";
         public static final String CAPABILITIES_ACTIVITY = "activity";
 

+ 20 - 1
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -748,7 +748,8 @@ public class FileContentProvider extends ContentProvider {
                 + ProviderTableMeta.FILE_IS_ENCRYPTED + INTEGER // boolean
                 + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
                 + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
-                + ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER);"
+            + ProviderTableMeta.FILE_MOUNT_TYPE + INTEGER
+            + ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER);"
         );
     }
 
@@ -1764,6 +1765,24 @@ public class FileContentProvider extends ContentProvider {
             if (!upgraded) {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
+
+            if (oldVersion < 36 && newVersion >= 36) {
+                Log_OC.i(SQL, "Entering in the #36 add has-preview to file table");
+                db.beginTransaction();
+                try {
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
+                        ADD_COLUMN + ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER ");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+
+            if (!upgraded) {
+                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+            }
         }
 
         @Override

+ 2 - 1
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -381,7 +381,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                             file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(),
                     mContext));
         } else {
-            if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) && file.getRemoteId() != null) {
+            if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) && file.getRemoteId() != null &&
+                file.hasPreview()) {
                 // Thumbnail in cache?
                 Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
                         ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId()

+ 5 - 3
src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -98,7 +98,7 @@ public final class FileStorageUtils {
 
     /**
      * Optimistic number of bytes available on sd-card. accountName is ignored.
-     * 
+     *
      * @return Optimistic number of available bytes (can be less)
      */
     public static long getUsableSpace() {
@@ -177,6 +177,8 @@ public final class FileStorageUtils {
             file.setEncrypted(remote.getIsEncrypted());
         }
         file.setMountType(remote.getMountType());
+        file.setHasPreview(remote.hasPreview());
+
         return file;
     }
 
@@ -318,7 +320,7 @@ public final class FileStorageUtils {
         return ret;
     }
 
-    public static boolean moveFile(File sourceFile, File targetFile) throws IOException {
+    public static boolean moveFile(File sourceFile, File targetFile) {
         if (copyFile(sourceFile, targetFile)) {
             return sourceFile.delete();
         } else {
@@ -366,7 +368,7 @@ public final class FileStorageUtils {
         if (file.isEncrypted()) {
             return true;
         }
-        
+
         while (!OCFile.ROOT_PATH.equals(file.getRemotePath())) {
             if (file.isEncrypted()) {
                 return true;