Procházet zdrojové kódy

add showing icon on external folders

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky před 7 roky
rodič
revize
cbb9e0cbde

+ 5 - 0
drawable_resources/folder_external.svg

@@ -0,0 +1,5 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1">
+    <path
+        d="M1.46 2c-.25 0-.46.21-.46.46v11.08c0 .258.202.46.46.46h13.08c.258 0 .46-.202.46-.46V4.462c0-.25-.21-.463-.46-.463H8L6 2H1.46zm6.517 3.793h3.57v3.385L10.355 8.05 8.57 9.743l-1.19-1.13 1.786-1.69-1.19-1.13zm-2.38.564H7.38l.597.565h-2.38v4.514h4.758V9.178l.596.564v1.694c0 .312-.265.564-.595.564h-4.76c-.33 0-.595-.252-.595-.564V6.922c0-.313.266-.565.596-.565z"
+        fill-rule="evenodd" fill="#0082c9"/>
+</svg>

+ 4 - 0
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -37,6 +37,7 @@ import android.support.annotation.Nullable;
 
 import com.owncloud.android.MainApp;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
+import com.owncloud.android.lib.common.network.WebdavEntry;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
@@ -479,6 +480,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
         cv.put(ProviderTableMeta.FILE_FAVORITE, file.getIsFavorite());
         cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, file.isEncrypted());
+        cv.put(ProviderTableMeta.FILE_MOUNT_TYPE, file.getMountType().ordinal());
         return cv;
     }
 
@@ -971,6 +973,8 @@ public class FileDataStorageManager {
             if (file.isEncrypted()) {
                 file.setFileName(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME)));
             }
+            file.setMountType(WebdavEntry.MountType.values()[c.getInt(
+                    c.getColumnIndex(ProviderTableMeta.FILE_MOUNT_TYPE))]);
         }
         return file;
     }

+ 13 - 0
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -32,6 +32,7 @@ import android.support.annotation.NonNull;
 import android.support.v4.content.FileProvider;
 
 import com.owncloud.android.R;
+import com.owncloud.android.lib.common.network.WebdavEntry;
 import com.owncloud.android.lib.common.network.WebdavUtils;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.MimeType;
@@ -97,6 +98,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     private boolean mIsEncrypted;
 
+    private WebdavEntry.MountType mMountType;
+
     /**
      * URI to the local path of the file contents, if stored in the device; cached after first call
      * to {@link #getStorageUri()}
@@ -160,6 +163,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mIsFavorite = source.readInt() == 1;
         mIsEncrypted = source.readInt() == 1;
         mEncryptedFileName = source.readString();
+        mMountType = (WebdavEntry.MountType) source.readSerializable();
     }
 
     @Override
@@ -189,6 +193,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeInt(mIsFavorite ? 1 : 0);
         dest.writeInt(mIsEncrypted ? 1 : 0);
         dest.writeString(mEncryptedFileName);
+        dest.writeSerializable(mMountType);
     }
 
     public boolean getIsFavorite() {
@@ -517,6 +522,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mIsFavorite = false;
         mIsEncrypted = false;
         mEncryptedFileName = null;
+        mMountType = WebdavEntry.MountType.INTERNAL;
     }
 
     /**
@@ -780,4 +786,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return permissions != null && permissions.contains(PERMISSION_CAN_RESHARE);
     }
 
+    public WebdavEntry.MountType getMountType() {
+        return mMountType;
+    }
+
+    public void setMountType(WebdavEntry.MountType mountType) {
+        mMountType = mountType;
+    }
 }

+ 2 - 1
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 = 30;
+    public static final int DB_VERSION = 31;
 
     private ProviderMeta() {
     }
@@ -102,6 +102,7 @@ public class ProviderMeta {
         public static final String FILE_ETAG_IN_CONFLICT = "etag_in_conflict";
         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_ALL_COLUMNS = {_ID, FILE_PARENT, FILE_NAME
                , FILE_CREATION, FILE_MODIFIED,

+ 1 - 0
src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -432,6 +432,7 @@ public class RefreshFolderOperation extends RemoteOperation {
                 updatedFile.setEtag(localFile.getEtag());
                 if (updatedFile.isFolder()) {
                     updatedFile.setFileLength(remoteFile.getFileLength());
+                    updatedFile.setMountType(remoteFile.getMountType());
                 } else if (mRemoteFolderChanged && MimeTypeUtil.isImage(remoteFile) &&
                         remoteFile.getModificationTimestamp() !=
                                 localFile.getModificationTimestamp()) {

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

@@ -741,7 +741,8 @@ public class FileContentProvider extends ContentProvider {
                 + ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
                 + ProviderTableMeta.FILE_IS_ENCRYPTED + INTEGER // boolean
                 + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
-                + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);"
+                + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
+                + ProviderTableMeta.FILE_MOUNT_TYPE + "INTEGER);"
         );
     }
 
@@ -1666,6 +1667,24 @@ public class FileContentProvider extends ContentProvider {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
 
+            if (oldVersion < 31 && newVersion >= 31) {
+                Log_OC.i(SQL, "Entering in the #31 add mount type");
+                db.beginTransaction();
+                try {
+                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
+                            ADD_COLUMN + ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER ");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+
+            if (!upgraded) {
+                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+            }
+
         }
 
         @Override

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

@@ -260,7 +260,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
             // Folder
             fileIcon.setImageDrawable(
                     MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
-                            file.isSharedViaLink(), file.isEncrypted()));
+                            file.isSharedViaLink(), file.isEncrypted(), file.getMountType()));
         }
     }
 

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

@@ -416,7 +416,7 @@ public class FileListListAdapter extends BaseAdapter {
             } else {
                 // Folder
                 fileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() ||
-                        file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted()));
+                        file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType()));
             }
         }
         return view;

+ 8 - 7
src/main/java/com/owncloud/android/ui/adapter/UploaderAdapter.java

@@ -70,17 +70,17 @@ public class UploaderAdapter extends SimpleAdapter {
         HashMap<String, OCFile> data = (HashMap<String, OCFile>) getItem(position);
         OCFile file = data.get("dirname");
 
-        TextView filename = (TextView) vi.findViewById(R.id.filename);
+        TextView filename = vi.findViewById(R.id.filename);
         filename.setText(file.getFileName());
-        
-        ImageView fileIcon = (ImageView) vi.findViewById(R.id.thumbnail);
+
+        ImageView fileIcon = vi.findViewById(R.id.thumbnail);
         fileIcon.setTag(file.getFileId());
 
-        TextView lastModV = (TextView) vi.findViewById(R.id.last_mod);
+        TextView lastModV = vi.findViewById(R.id.last_mod);
         lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
 
-        TextView fileSizeV = (TextView) vi.findViewById(R.id.file_size);
-        TextView fileSizeSeparatorV = (TextView) vi.findViewById(R.id.file_separator);
+        TextView fileSizeV = vi.findViewById(R.id.file_size);
+        TextView fileSizeSeparatorV = vi.findViewById(R.id.file_separator);
 
         if(!file.isFolder()) {
             fileSizeV.setVisibility(View.VISIBLE);
@@ -93,7 +93,8 @@ public class UploaderAdapter extends SimpleAdapter {
 
         if (file.isFolder()) {
             fileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() ||
-                    file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), mAccount));
+                            file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), mAccount,
+                    file.getMountType()));
         } else {
             // get Thumbnail if file is image
             if (MimeTypeUtil.isImage(file) && file.getRemoteId() != null) {

+ 1 - 0
src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -174,6 +174,7 @@ public class FileStorageUtils {
         if (file.isFolder()) {
             file.setEncrypted(remote.getIsEncrypted());
         }
+        file.setMountType(remote.getMountType());
         return file;
     }
 

+ 8 - 4
src/main/java/com/owncloud/android/utils/MimeTypeUtil.java

@@ -26,6 +26,7 @@ import android.webkit.MimeTypeMap;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.network.WebdavEntry;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -128,8 +129,9 @@ public class MimeTypeUtil {
      * @param isSharedViaLink  flag if the folder is publicly shared via link
      * @return Identifier of an image resource.
      */
-    public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSharedViaLink, boolean isEncrypted) {
-        return getFolderTypeIcon(isSharedViaUsers, isSharedViaLink, isEncrypted, null);
+    public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSharedViaLink, boolean isEncrypted,
+                                             WebdavEntry.MountType mountType) {
+        return getFolderTypeIcon(isSharedViaUsers, isSharedViaLink, isEncrypted, null, mountType);
     }
 
     /**
@@ -142,7 +144,7 @@ public class MimeTypeUtil {
      * @return Identifier of an image resource.
      */
     public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSharedViaLink,
-                                             boolean isEncrypted, Account account) {
+                                             boolean isEncrypted, Account account, WebdavEntry.MountType mountType) {
         int drawableId;
 
         if (isSharedViaLink) {
@@ -151,6 +153,8 @@ public class MimeTypeUtil {
             drawableId = R.drawable.shared_with_me_folder;
         } else if (isEncrypted) {
             drawableId = R.drawable.ic_list_encrypted_folder;
+        } else if (WebdavEntry.MountType.EXTERNAL.equals(mountType)) {
+            drawableId = R.drawable.folder_external;
         } else {
             drawableId = R.drawable.folder;
         }
@@ -159,7 +163,7 @@ public class MimeTypeUtil {
     }
 
     public static Drawable getDefaultFolderIcon() {
-        return getFolderTypeIcon(false, false, false);
+        return getFolderTypeIcon(false, false, false, WebdavEntry.MountType.INTERNAL);
     }
 
 

+ 10 - 0
src/main/res/drawable/folder_external.xml

@@ -0,0 +1,10 @@
+<vector android:height="24dp"
+        android:viewportHeight="16.0"
+        android:viewportWidth="16.0"
+        android:width="24dp"
+        xmlns:android="http://schemas.android.com/apk/res/android">
+    <path
+        android:fillColor="#0082c9"
+        android:fillType="evenOdd"
+        android:pathData="M1.46,2c-0.25,0 -0.46,0.21 -0.46,0.46v11.08c0,0.258 0.202,0.46 0.46,0.46h13.08c0.258,0 0.46,-0.202 0.46,-0.46L15,4.462c0,-0.25 -0.21,-0.463 -0.46,-0.463L8,3.999L6,2L1.46,2zM7.977,5.793h3.57v3.385L10.355,8.05 8.57,9.743l-1.19,-1.13 1.786,-1.69 -1.19,-1.13zM5.597,6.357L7.38,6.357l0.597,0.565h-2.38v4.514h4.758L10.355,9.178l0.596,0.564v1.694c0,0.312 -0.265,0.564 -0.595,0.564h-4.76c-0.33,0 -0.595,-0.252 -0.595,-0.564L5.001,6.922c0,-0.313 0.266,-0.565 0.596,-0.565z"/>
+</vector>