Skip to content

Commit

Permalink
Merge pull request #2206 from nextcloud/externalFolderIcon
Browse files Browse the repository at this point in the history
Add showing icon on external folders
  • Loading branch information
AndyScherzinger authored Mar 23, 2018
2 parents b66c597 + d26c57a commit 0d63edb
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pullapprove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ group_defaults:
ignored: true
approve_by_comment:
enabled: true
approve_regex: '^(Approved|:shipit:|:\+1:|LGTM)'
approve_regex: '^(Approved|:shipit:|:\+1:|LGTM|Merge)'
reject_regex: '^(Rejected|:-1:)'
reset_on_push:
enabled: false
Expand Down
5 changes: 5 additions & 0 deletions drawable_resources/folder_external.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

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;
Expand Down Expand Up @@ -479,6 +480,7 @@ private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
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;
}

Expand Down Expand Up @@ -971,6 +973,8 @@ private OCFile createFileInstance(Cursor c) {
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;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -97,6 +98,8 @@ public OCFile[] newArray(int size) {

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()}
Expand Down Expand Up @@ -160,6 +163,7 @@ private OCFile(Parcel source) {
mIsFavorite = source.readInt() == 1;
mIsEncrypted = source.readInt() == 1;
mEncryptedFileName = source.readString();
mMountType = (WebdavEntry.MountType) source.readSerializable();
}

@Override
Expand Down Expand Up @@ -189,6 +193,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mIsFavorite ? 1 : 0);
dest.writeInt(mIsEncrypted ? 1 : 0);
dest.writeString(mEncryptedFileName);
dest.writeSerializable(mMountType);
}

public boolean getIsFavorite() {
Expand Down Expand Up @@ -517,6 +522,7 @@ private void resetData() {
mIsFavorite = false;
mIsEncrypted = false;
mEncryptedFileName = null;
mMountType = WebdavEntry.MountType.INTERNAL;
}

/**
Expand Down Expand Up @@ -780,4 +786,11 @@ public boolean canReshare() {
return permissions != null && permissions.contains(PERMISSION_CAN_RESHARE);
}

public WebdavEntry.MountType getMountType() {
return mMountType;
}

public void setMountType(WebdavEntry.MountType mountType) {
mMountType = mountType;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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() {
}
Expand Down Expand Up @@ -102,6 +102,7 @@ static public class ProviderTableMeta implements BaseColumns {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ private void synchronizeData(ArrayList<Object> folderAndFiles) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ private void createFilesTable(SQLiteDatabase db) {
+ 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);"
);
}

Expand Down Expand Up @@ -1666,6 +1667,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void setBitmap(OCFile file, ImageView fileIcon) {
// Folder
fileIcon.setImageDrawable(
MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
file.isSharedViaLink(), file.isEncrypted()));
file.isSharedViaLink(), file.isEncrypted(), file.getMountType()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
} else {
// Folder
fileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() ||
file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted()));
file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType()));
}
}
return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public View getView(int position, View convertView, ViewGroup parent) {
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);
Expand All @@ -93,7 +93,8 @@ public View getView(int position, View convertView, ViewGroup parent) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public static OCFile fillOCFile(RemoteFile remote) {
if (file.isFolder()) {
file.setEncrypted(remote.getIsEncrypted());
}
file.setMountType(remote.getMountType());
return file;
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/owncloud/android/utils/MimeTypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -128,8 +129,9 @@ public static int getFileTypeIconId(String mimetype, String filename) {
* @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);
}

/**
Expand All @@ -142,7 +144,7 @@ public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSha
* @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) {
Expand All @@ -151,6 +153,8 @@ public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSha
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;
}
Expand All @@ -159,7 +163,7 @@ public static Drawable getFolderTypeIcon(boolean isSharedViaUsers, boolean isSha
}

public static Drawable getDefaultFolderIcon() {
return getFolderTypeIcon(false, false, false);
return getFolderTypeIcon(false, false, false, WebdavEntry.MountType.INTERNAL);
}


Expand Down
9 changes: 9 additions & 0 deletions src/main/res/drawable/folder_external.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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: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>

0 comments on commit 0d63edb

Please sign in to comment.