sharees will be in NC17

later initialization of storageManager
add support for groups
catch potential wrong saved sharee date

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-07-31 14:23:07 +02:00
parent 259e106308
commit 39cb5d9179
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
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.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<>());
}
}
}

View file

@ -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<OCFile>, ServerFileInterface {
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 ownerDisplayName;
@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

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.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<RecyclerView.ViewHol
private List<ThumbnailsCacheManager.ThumbnailGenerationTask> 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<RecyclerView.ViewHol
boolean argHideItemOptions,
boolean gridView
) {
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
mContext = context;
this.preferences = preferences;
@ -163,9 +163,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
userId = "";
}
// TODO change when https://github.com/nextcloud/server/pull/14429 is merged
showShareAvatar = false;
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
}
@ -366,11 +363,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
itemViewHolder.sharedAvatars.removeAllViews();
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
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<RecyclerView.ViewHol
int size = 60 * (shareeSize - 1) + w;
for (int i = 0; i < shareeSize; i++) {
String sharee = file.getSharees().get(i);
ShareeUser sharee = file.getSharees().get(i);
ImageView avatar = new ImageView(mContext);
if (i == 0 && sharees.size() > 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<RecyclerView.ViewHol
if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) {
mStorageManager = updatedStorageManager;
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
this.account = account;
}
if (mStorageManager != null) {
@ -732,6 +744,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
FileDataStorageManager storageManager, OCFile folder, boolean clear) {
if (storageManager != null && mStorageManager == null) {
mStorageManager = storageManager;
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
}
if (clear) {

View file

@ -456,6 +456,27 @@ public final class DisplayUtils {
*/
public static void setAvatar(@NonNull Account account, @NonNull String userId, AvatarGenerationListener listener,
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) {
((View) callContext).setContentDescription(String.valueOf(account.hashCode()));
}
@ -468,12 +489,12 @@ public final class DisplayUtils {
// first show old one
Drawable avatar = BitmapUtils.bitmapToCircularBitmapDrawable(resources,
ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey));
ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey));
// if no one exists, show colored icon with initial char
if (avatar == null) {
try {
avatar = TextDrawable.createAvatarByUserId(userId, avatarRadius);
avatar = TextDrawable.createAvatarByUserId(displayName, avatarRadius);
} catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
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
if (ThumbnailsCacheManager.cancelPotentialAvatarWork(userId, callContext)) {
final ThumbnailsCacheManager.AvatarGenerationTask task =
new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources,
avatarRadius, userId, serverName, context);
new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources,
avatarRadius, userId, serverName, context);
final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
listener.avatarGenerated(asyncDrawable, callContext);
task.execute(userId);
}

View file

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