Sharees will be in NC17 (#4284)

Sharees will be in NC17
This commit is contained in:
Tobias Kaminsky 2019-08-21 13:21:12 +02:00 committed by GitHub
commit 7a29f488e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 32 deletions

View file

@ -35,6 +35,8 @@ import android.os.RemoteException;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.network.WebdavEntry; 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.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType; 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.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.operations.RemoteOperationFailedException; 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_ID, file.getOwnerId());
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName());
cv.put(ProviderTableMeta.FILE_NOTE, file.getNote()); 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()); boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath || if (sameRemotePath ||
@ -454,7 +457,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_OWNER_ID, folder.getOwnerId()); cv.put(ProviderTableMeta.FILE_OWNER_ID, folder.getOwnerId());
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, folder.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, folder.getOwnerDisplayName());
cv.put(ProviderTableMeta.FILE_NOTE, folder.getNote()); 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; return cv;
} }
@ -494,7 +497,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId()); cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId());
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName()); cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName());
cv.put(ProviderTableMeta.FILE_NOTE, file.getNote()); 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; return cv;
} }
@ -996,10 +999,17 @@ public class FileDataStorageManager {
String sharees = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_SHAREES)); String sharees = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_SHAREES));
if (sharees == null || sharees.isEmpty()) { if ("null".equals(sharees) || sharees.isEmpty()) {
file.setSharees(new ArrayList<>()); file.setSharees(new ArrayList<>());
} else { } 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<>());
}
} }
} }

View file

@ -30,21 +30,22 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface; import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.lib.resources.shares.ShareeUser;
import com.owncloud.android.utils.MimeType; import com.owncloud.android.utils.MimeType;
import lombok.Getter;
import lombok.Setter;
import third_parties.daveKoeller.AlphanumComparator;
import java.io.File; import java.io.File;
import java.util.ArrayList; 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<OCFile>, ServerFileInterface { public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
private final static String PERMISSION_SHARED_WITH_ME = "S"; private final static String PERMISSION_SHARED_WITH_ME = "S";
@ -89,7 +90,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
@Getter @Setter private String ownerId; @Getter @Setter private String ownerId;
@Getter @Setter private String ownerDisplayName; @Getter @Setter private String ownerDisplayName;
@Getter @Setter String note; @Getter @Setter String note;
@Getter @Setter private List<String> sharees = new ArrayList<>(); @Getter @Setter private ArrayList<ShareeUser> sharees;
/** /**
* URI to the local path of the file contents, if stored in the device; cached after first call * URI to the local path of the file contents, if stored in the device; cached after first call

View file

@ -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.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType; 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.RefreshFolderOperation;
import com.owncloud.android.operations.RemoteOperationFailedException; import com.owncloud.android.operations.RemoteOperationFailedException;
import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService;
@ -130,7 +131,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks = new ArrayList<>(); private List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks = new ArrayList<>();
private boolean onlyOnDevice; private boolean onlyOnDevice;
private boolean showShareAvatar; private boolean showShareAvatar = false;
@Setter private OCFile highlightedItem; @Setter private OCFile highlightedItem;
public OCFileListAdapter( public OCFileListAdapter(
@ -143,7 +144,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
boolean argHideItemOptions, boolean argHideItemOptions,
boolean gridView boolean gridView
) { ) {
this.ocFileListFragmentInterface = ocFileListFragmentInterface; this.ocFileListFragmentInterface = ocFileListFragmentInterface;
mContext = context; mContext = context;
this.preferences = preferences; this.preferences = preferences;
@ -163,9 +163,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
userId = ""; userId = "";
} }
// TODO change when https://github.com/nextcloud/server/pull/14429 is merged
showShareAvatar = false;
// initialise thumbnails cache on background thread // initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute(); new ThumbnailsCacheManager.InitDiskCacheTask().execute();
} }
@ -366,11 +363,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
itemViewHolder.sharedAvatars.removeAllViews(); itemViewHolder.sharedAvatars.removeAllViews();
String fileOwner = file.getOwnerId(); String fileOwner = file.getOwnerId();
ArrayList<String> sharees = (ArrayList<String>) file.getSharees(); ArrayList<ShareeUser> sharees = file.getSharees();
// use fileOwner if not oneself, then add at first // use fileOwner if not oneself, then add at first
if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwner)) { ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
sharees.add(fileOwner); if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) {
sharees.add(fileOwnerSharee);
} }
Collections.reverse(sharees); Collections.reverse(sharees);
@ -383,20 +381,33 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
int size = 60 * (shareeSize - 1) + w; int size = 60 * (shareeSize - 1) + w;
for (int i = 0; i < shareeSize; i++) { for (int i = 0; i < shareeSize; i++) {
String sharee = file.getSharees().get(i); ShareeUser sharee = file.getSharees().get(i);
ImageView avatar = new ImageView(mContext); ImageView avatar = new ImageView(mContext);
if (i == 0 && sharees.size() > 3) { if (i == 0 && sharees.size() > 3) {
avatar.setImageResource(R.drawable.ic_people); avatar.setImageResource(R.drawable.ic_people);
} else { } else {
if (sharee.contains("@")) { if (sharee.getShareType().equals(ShareType.GROUP)) {
showFederatedShareAvatar(sharee, avatarRadius, resources, avatar); 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 { } else {
avatar.setTag(sharee); avatar.setTag(sharee);
DisplayUtils.setAvatar(account, sharee, this, avatarRadius, resources, DisplayUtils.setAvatar(account,
avatar, mContext); sharee.getUserId(),
Log_OC.d(TAG, "avatar: " + sharee); sharee.getDisplayName(),
this,
avatarRadius,
resources,
avatar,
mContext);
} }
} }
@ -701,6 +712,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) { if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) {
mStorageManager = updatedStorageManager; mStorageManager = updatedStorageManager;
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
this.account = account; this.account = account;
} }
if (mStorageManager != null) { if (mStorageManager != null) {
@ -732,6 +744,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
FileDataStorageManager storageManager, OCFile folder, boolean clear) { FileDataStorageManager storageManager, OCFile folder, boolean clear) {
if (storageManager != null && mStorageManager == null) { if (storageManager != null && mStorageManager == null) {
mStorageManager = storageManager; mStorageManager = storageManager;
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
} }
if (clear) { if (clear) {

View file

@ -456,6 +456,27 @@ public final class DisplayUtils {
*/ */
public static void setAvatar(@NonNull Account account, @NonNull String userId, AvatarGenerationListener listener, public static void setAvatar(@NonNull Account account, @NonNull String userId, AvatarGenerationListener listener,
float avatarRadius, Resources resources, Object callContext, Context context) { float avatarRadius, Resources resources, Object callContext, Context context) {
setAvatar(account, userId, userId, listener, avatarRadius, resources, callContext, context);
}
/**
* fetches and sets the avatar of the given account in the passed callContext
*
* @param account the account to be used to connect to server
* @param userId the userId which avatar should be set
* @param displayName displayName used to generate avatar with first char, only used as fallback
* @param avatarRadius the avatar radius
* @param resources reference for density information
* @param callContext which context is called to set the generated avatar
*/
public static void setAvatar(@NonNull Account account,
@NonNull String userId,
String displayName,
AvatarGenerationListener listener,
float avatarRadius,
Resources resources,
Object callContext,
Context context) {
if (callContext instanceof View) { if (callContext instanceof View) {
((View) callContext).setContentDescription(String.valueOf(account.hashCode())); ((View) callContext).setContentDescription(String.valueOf(account.hashCode()));
} }
@ -468,12 +489,12 @@ public final class DisplayUtils {
// first show old one // first show old one
Drawable avatar = BitmapUtils.bitmapToCircularBitmapDrawable(resources, Drawable avatar = BitmapUtils.bitmapToCircularBitmapDrawable(resources,
ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey)); ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey));
// if no one exists, show colored icon with initial char // if no one exists, show colored icon with initial char
if (avatar == null) { if (avatar == null) {
try { try {
avatar = TextDrawable.createAvatarByUserId(userId, avatarRadius); avatar = TextDrawable.createAvatarByUserId(displayName, avatarRadius);
} catch (Exception e) { } catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e); Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
avatar = resources.getDrawable(R.drawable.account_circle_white); avatar = resources.getDrawable(R.drawable.account_circle_white);
@ -483,11 +504,11 @@ public final class DisplayUtils {
// check for new avatar, eTag is compared, so only new one is downloaded // check for new avatar, eTag is compared, so only new one is downloaded
if (ThumbnailsCacheManager.cancelPotentialAvatarWork(userId, callContext)) { if (ThumbnailsCacheManager.cancelPotentialAvatarWork(userId, callContext)) {
final ThumbnailsCacheManager.AvatarGenerationTask task = final ThumbnailsCacheManager.AvatarGenerationTask task =
new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources, new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources,
avatarRadius, userId, serverName, context); avatarRadius, userId, serverName, context);
final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable = final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task); new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
listener.avatarGenerated(asyncDrawable, callContext); listener.avatarGenerated(asyncDrawable, callContext);
task.execute(userId); task.execute(userId);
} }

View file

@ -47,6 +47,7 @@ import java.io.OutputStream;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -210,7 +211,7 @@ public final class FileStorageUtils {
file.setOwnerId(remote.getOwnerId()); file.setOwnerId(remote.getOwnerId());
file.setOwnerDisplayName(remote.getOwnerDisplayName()); file.setOwnerDisplayName(remote.getOwnerDisplayName());
file.setNote(remote.getNote()); file.setNote(remote.getNote());
file.setSharees(remote.getSharees()); file.setSharees(new ArrayList<>(Arrays.asList(remote.getSharees())));
return file; return file;
} }