From 39cb5d9179f8257f0b82cdd3817856ab0ef6db64 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 31 Jul 2019 14:23:07 +0200 Subject: [PATCH] sharees will be in NC17 later initialization of storageManager add support for groups catch potential wrong saved sharee date Signed-off-by: tobiasKaminsky --- .../datamodel/FileDataStorageManager.java | 20 ++++++--- .../owncloud/android/datamodel/OCFile.java | 15 +++---- .../android/ui/adapter/OCFileListAdapter.java | 41 ++++++++++++------- .../owncloud/android/utils/DisplayUtils.java | 31 +++++++++++--- .../android/utils/FileStorageUtils.java | 3 +- 5 files changed, 78 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 74176b5339..88d0382c58 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -35,6 +35,8 @@ import android.os.RemoteException; import android.provider.MediaStore; import android.text.TextUtils; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import com.owncloud.android.MainApp; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.lib.common.network.WebdavEntry; @@ -44,6 +46,7 @@ import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; import com.owncloud.android.lib.resources.files.model.RemoteFile; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.ShareeUser; import com.owncloud.android.lib.resources.status.CapabilityBooleanType; import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.operations.RemoteOperationFailedException; @@ -210,7 +213,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_NOTE, file.getNote()); - cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", file.getSharees())); + cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(file.getSharees())); boolean sameRemotePath = fileExists(file.getRemotePath()); if (sameRemotePath || @@ -454,7 +457,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_OWNER_ID, folder.getOwnerId()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, folder.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_NOTE, folder.getNote()); - cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", folder.getSharees())); + cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(folder.getSharees())); return cv; } @@ -494,7 +497,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_NOTE, file.getNote()); - cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", file.getSharees())); + cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(file.getSharees())); return cv; } @@ -996,10 +999,17 @@ public class FileDataStorageManager { String sharees = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_SHAREES)); - if (sharees == null || sharees.isEmpty()) { + if ("null".equals(sharees) || sharees.isEmpty()) { file.setSharees(new ArrayList<>()); } else { - file.setSharees(new ArrayList<>(Arrays.asList(sharees.split(",")))); + try { + ShareeUser[] shareesArray = new Gson().fromJson(sharees, ShareeUser[].class); + + file.setSharees(new ArrayList<>(Arrays.asList(shareesArray))); + } catch (JsonSyntaxException e) { + // ignore saved value due to api change + file.setSharees(new ArrayList<>()); + } } } diff --git a/src/main/java/com/owncloud/android/datamodel/OCFile.java b/src/main/java/com/owncloud/android/datamodel/OCFile.java index afaf7334b6..1c104cc7c8 100644 --- a/src/main/java/com/owncloud/android/datamodel/OCFile.java +++ b/src/main/java/com/owncloud/android/datamodel/OCFile.java @@ -30,21 +30,22 @@ import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; -import androidx.annotation.NonNull; -import androidx.core.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.lib.resources.files.model.ServerFileInterface; +import com.owncloud.android.lib.resources.shares.ShareeUser; import com.owncloud.android.utils.MimeType; -import lombok.Getter; -import lombok.Setter; -import third_parties.daveKoeller.AlphanumComparator; import java.io.File; import java.util.ArrayList; -import java.util.List; + +import androidx.annotation.NonNull; +import androidx.core.content.FileProvider; +import lombok.Getter; +import lombok.Setter; +import third_parties.daveKoeller.AlphanumComparator; public class OCFile implements Parcelable, Comparable, ServerFileInterface { private final static String PERMISSION_SHARED_WITH_ME = "S"; @@ -89,7 +90,7 @@ public class OCFile implements Parcelable, Comparable, ServerFileInterfa @Getter @Setter private String ownerId; @Getter @Setter private String ownerDisplayName; @Getter @Setter String note; - @Getter @Setter private List sharees = new ArrayList<>(); + @Getter @Setter private ArrayList sharees; /** * URI to the local path of the file contents, if stored in the device; cached after first call diff --git a/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index d398deef90..e1d90621e8 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -65,6 +65,7 @@ import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; import com.owncloud.android.lib.resources.files.model.RemoteFile; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.ShareeUser; import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.RemoteOperationFailedException; import com.owncloud.android.services.OperationsService; @@ -130,7 +131,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter asyncTasks = new ArrayList<>(); private boolean onlyOnDevice; - private boolean showShareAvatar; + private boolean showShareAvatar = false; @Setter private OCFile highlightedItem; public OCFileListAdapter( @@ -143,7 +144,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter sharees = (ArrayList) file.getSharees(); + ArrayList sharees = file.getSharees(); // use fileOwner if not oneself, then add at first - if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwner)) { - sharees.add(fileOwner); + ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER); + if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) { + sharees.add(fileOwnerSharee); } Collections.reverse(sharees); @@ -383,20 +381,33 @@ public class OCFileListAdapter extends RecyclerView.Adapter 3) { avatar.setImageResource(R.drawable.ic_people); } else { - if (sharee.contains("@")) { - showFederatedShareAvatar(sharee, avatarRadius, resources, avatar); + if (sharee.getShareType().equals(ShareType.GROUP)) { + try { + avatar.setImageDrawable( + TextDrawable.createAvatarByUserId(sharee.getUserId(), avatarRadius)); + } catch (Exception e) { + Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e); + avatar.setImageResource(R.drawable.ic_people); + } + } else if (sharee.getUserId().contains("@")) { + showFederatedShareAvatar(sharee.getUserId(), avatarRadius, resources, avatar); } else { avatar.setTag(sharee); - DisplayUtils.setAvatar(account, sharee, this, avatarRadius, resources, - avatar, mContext); - Log_OC.d(TAG, "avatar: " + sharee); + DisplayUtils.setAvatar(account, + sharee.getUserId(), + sharee.getDisplayName(), + this, + avatarRadius, + resources, + avatar, + mContext); } } @@ -701,6 +712,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter(Arrays.asList(remote.getSharees()))); return file; }