Skip to content

Commit 7a29f48

Browse files
Sharees will be in NC17 (#4284)
Sharees will be in NC17
2 parents 66a8898 + 39cb5d9 commit 7a29f48

File tree

5 files changed

+78
-32
lines changed

5 files changed

+78
-32
lines changed

src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import android.provider.MediaStore;
3636
import android.text.TextUtils;
3737

38+
import com.google.gson.Gson;
39+
import com.google.gson.JsonSyntaxException;
3840
import com.owncloud.android.MainApp;
3941
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
4042
import com.owncloud.android.lib.common.network.WebdavEntry;
@@ -44,6 +46,7 @@
4446
import com.owncloud.android.lib.resources.files.model.RemoteFile;
4547
import com.owncloud.android.lib.resources.shares.OCShare;
4648
import com.owncloud.android.lib.resources.shares.ShareType;
49+
import com.owncloud.android.lib.resources.shares.ShareeUser;
4750
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
4851
import com.owncloud.android.lib.resources.status.OCCapability;
4952
import com.owncloud.android.operations.RemoteOperationFailedException;
@@ -210,7 +213,7 @@ public boolean saveFile(OCFile file) {
210213
cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId());
211214
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName());
212215
cv.put(ProviderTableMeta.FILE_NOTE, file.getNote());
213-
cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", file.getSharees()));
216+
cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(file.getSharees()));
214217

215218
boolean sameRemotePath = fileExists(file.getRemotePath());
216219
if (sameRemotePath ||
@@ -454,7 +457,7 @@ private ContentValues createContentValueForFile(OCFile folder) {
454457
cv.put(ProviderTableMeta.FILE_OWNER_ID, folder.getOwnerId());
455458
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, folder.getOwnerDisplayName());
456459
cv.put(ProviderTableMeta.FILE_NOTE, folder.getNote());
457-
cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", folder.getSharees()));
460+
cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(folder.getSharees()));
458461

459462
return cv;
460463
}
@@ -494,7 +497,7 @@ private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
494497
cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId());
495498
cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName());
496499
cv.put(ProviderTableMeta.FILE_NOTE, file.getNote());
497-
cv.put(ProviderTableMeta.FILE_SHAREES, TextUtils.join(",", file.getSharees()));
500+
cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(file.getSharees()));
498501

499502
return cv;
500503
}
@@ -996,10 +999,17 @@ private OCFile createFileInstance(Cursor c) {
996999

9971000
String sharees = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_SHAREES));
9981001

999-
if (sharees == null || sharees.isEmpty()) {
1002+
if ("null".equals(sharees) || sharees.isEmpty()) {
10001003
file.setSharees(new ArrayList<>());
10011004
} else {
1002-
file.setSharees(new ArrayList<>(Arrays.asList(sharees.split(","))));
1005+
try {
1006+
ShareeUser[] shareesArray = new Gson().fromJson(sharees, ShareeUser[].class);
1007+
1008+
file.setSharees(new ArrayList<>(Arrays.asList(shareesArray)));
1009+
} catch (JsonSyntaxException e) {
1010+
// ignore saved value due to api change
1011+
file.setSharees(new ArrayList<>());
1012+
}
10031013
}
10041014
}
10051015

src/main/java/com/owncloud/android/datamodel/OCFile.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@
3030
import android.os.Parcelable;
3131
import android.text.TextUtils;
3232

33-
import androidx.annotation.NonNull;
34-
import androidx.core.content.FileProvider;
3533
import com.owncloud.android.R;
3634
import com.owncloud.android.lib.common.network.WebdavEntry;
3735
import com.owncloud.android.lib.common.network.WebdavUtils;
3836
import com.owncloud.android.lib.common.utils.Log_OC;
3937
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
38+
import com.owncloud.android.lib.resources.shares.ShareeUser;
4039
import com.owncloud.android.utils.MimeType;
41-
import lombok.Getter;
42-
import lombok.Setter;
43-
import third_parties.daveKoeller.AlphanumComparator;
4440

4541
import java.io.File;
4642
import java.util.ArrayList;
47-
import java.util.List;
43+
44+
import androidx.annotation.NonNull;
45+
import androidx.core.content.FileProvider;
46+
import lombok.Getter;
47+
import lombok.Setter;
48+
import third_parties.daveKoeller.AlphanumComparator;
4849

4950
public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
5051
private final static String PERMISSION_SHARED_WITH_ME = "S";
@@ -89,7 +90,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
8990
@Getter @Setter private String ownerId;
9091
@Getter @Setter private String ownerDisplayName;
9192
@Getter @Setter String note;
92-
@Getter @Setter private List<String> sharees = new ArrayList<>();
93+
@Getter @Setter private ArrayList<ShareeUser> sharees;
9394

9495
/**
9596
* URI to the local path of the file contents, if stored in the device; cached after first call

src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.owncloud.android.lib.resources.files.model.RemoteFile;
6666
import com.owncloud.android.lib.resources.shares.OCShare;
6767
import com.owncloud.android.lib.resources.shares.ShareType;
68+
import com.owncloud.android.lib.resources.shares.ShareeUser;
6869
import com.owncloud.android.operations.RefreshFolderOperation;
6970
import com.owncloud.android.operations.RemoteOperationFailedException;
7071
import com.owncloud.android.services.OperationsService;
@@ -130,7 +131,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
130131

131132
private List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks = new ArrayList<>();
132133
private boolean onlyOnDevice;
133-
private boolean showShareAvatar;
134+
private boolean showShareAvatar = false;
134135
@Setter private OCFile highlightedItem;
135136

136137
public OCFileListAdapter(
@@ -143,7 +144,6 @@ public OCFileListAdapter(
143144
boolean argHideItemOptions,
144145
boolean gridView
145146
) {
146-
147147
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
148148
mContext = context;
149149
this.preferences = preferences;
@@ -163,9 +163,6 @@ public OCFileListAdapter(
163163
userId = "";
164164
}
165165

166-
// TODO change when https://github.com/nextcloud/server/pull/14429 is merged
167-
showShareAvatar = false;
168-
169166
// initialise thumbnails cache on background thread
170167
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
171168
}
@@ -366,11 +363,12 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
366363
itemViewHolder.sharedAvatars.removeAllViews();
367364

368365
String fileOwner = file.getOwnerId();
369-
ArrayList<String> sharees = (ArrayList<String>) file.getSharees();
366+
ArrayList<ShareeUser> sharees = file.getSharees();
370367

371368
// use fileOwner if not oneself, then add at first
372-
if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwner)) {
373-
sharees.add(fileOwner);
369+
ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
370+
if (fileOwner != null && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) {
371+
sharees.add(fileOwnerSharee);
374372
}
375373

376374
Collections.reverse(sharees);
@@ -383,20 +381,33 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
383381
int size = 60 * (shareeSize - 1) + w;
384382

385383
for (int i = 0; i < shareeSize; i++) {
386-
String sharee = file.getSharees().get(i);
384+
ShareeUser sharee = file.getSharees().get(i);
387385

388386
ImageView avatar = new ImageView(mContext);
389387

390388
if (i == 0 && sharees.size() > 3) {
391389
avatar.setImageResource(R.drawable.ic_people);
392390
} else {
393-
if (sharee.contains("@")) {
394-
showFederatedShareAvatar(sharee, avatarRadius, resources, avatar);
391+
if (sharee.getShareType().equals(ShareType.GROUP)) {
392+
try {
393+
avatar.setImageDrawable(
394+
TextDrawable.createAvatarByUserId(sharee.getUserId(), avatarRadius));
395+
} catch (Exception e) {
396+
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
397+
avatar.setImageResource(R.drawable.ic_people);
398+
}
399+
} else if (sharee.getUserId().contains("@")) {
400+
showFederatedShareAvatar(sharee.getUserId(), avatarRadius, resources, avatar);
395401
} else {
396402
avatar.setTag(sharee);
397-
DisplayUtils.setAvatar(account, sharee, this, avatarRadius, resources,
398-
avatar, mContext);
399-
Log_OC.d(TAG, "avatar: " + sharee);
403+
DisplayUtils.setAvatar(account,
404+
sharee.getUserId(),
405+
sharee.getDisplayName(),
406+
this,
407+
avatarRadius,
408+
resources,
409+
avatar,
410+
mContext);
400411
}
401412
}
402413

@@ -701,6 +712,7 @@ public void swapDirectory(
701712

702713
if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) {
703714
mStorageManager = updatedStorageManager;
715+
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
704716
this.account = account;
705717
}
706718
if (mStorageManager != null) {
@@ -732,6 +744,7 @@ public void setData(List<Object> objects, ExtendedListFragment.SearchType search
732744
FileDataStorageManager storageManager, OCFile folder, boolean clear) {
733745
if (storageManager != null && mStorageManager == null) {
734746
mStorageManager = storageManager;
747+
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
735748
}
736749

737750
if (clear) {

src/main/java/com/owncloud/android/utils/DisplayUtils.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,27 @@ public static void setAvatar(@NonNull Account account, AvatarGenerationListener
456456
*/
457457
public static void setAvatar(@NonNull Account account, @NonNull String userId, AvatarGenerationListener listener,
458458
float avatarRadius, Resources resources, Object callContext, Context context) {
459+
setAvatar(account, userId, userId, listener, avatarRadius, resources, callContext, context);
460+
}
461+
462+
/**
463+
* fetches and sets the avatar of the given account in the passed callContext
464+
*
465+
* @param account the account to be used to connect to server
466+
* @param userId the userId which avatar should be set
467+
* @param displayName displayName used to generate avatar with first char, only used as fallback
468+
* @param avatarRadius the avatar radius
469+
* @param resources reference for density information
470+
* @param callContext which context is called to set the generated avatar
471+
*/
472+
public static void setAvatar(@NonNull Account account,
473+
@NonNull String userId,
474+
String displayName,
475+
AvatarGenerationListener listener,
476+
float avatarRadius,
477+
Resources resources,
478+
Object callContext,
479+
Context context) {
459480
if (callContext instanceof View) {
460481
((View) callContext).setContentDescription(String.valueOf(account.hashCode()));
461482
}
@@ -468,12 +489,12 @@ public static void setAvatar(@NonNull Account account, @NonNull String userId, A
468489

469490
// first show old one
470491
Drawable avatar = BitmapUtils.bitmapToCircularBitmapDrawable(resources,
471-
ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey));
492+
ThumbnailsCacheManager.getBitmapFromDiskCache(avatarKey));
472493

473494
// if no one exists, show colored icon with initial char
474495
if (avatar == null) {
475496
try {
476-
avatar = TextDrawable.createAvatarByUserId(userId, avatarRadius);
497+
avatar = TextDrawable.createAvatarByUserId(displayName, avatarRadius);
477498
} catch (Exception e) {
478499
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
479500
avatar = resources.getDrawable(R.drawable.account_circle_white);
@@ -483,11 +504,11 @@ public static void setAvatar(@NonNull Account account, @NonNull String userId, A
483504
// check for new avatar, eTag is compared, so only new one is downloaded
484505
if (ThumbnailsCacheManager.cancelPotentialAvatarWork(userId, callContext)) {
485506
final ThumbnailsCacheManager.AvatarGenerationTask task =
486-
new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources,
487-
avatarRadius, userId, serverName, context);
507+
new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, account, resources,
508+
avatarRadius, userId, serverName, context);
488509

489510
final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable =
490-
new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
511+
new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
491512
listener.avatarGenerated(asyncDrawable, callContext);
492513
task.execute(userId);
493514
}

src/main/java/com/owncloud/android/utils/FileStorageUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.text.DateFormat;
4848
import java.text.SimpleDateFormat;
4949
import java.util.ArrayList;
50+
import java.util.Arrays;
5051
import java.util.Collections;
5152
import java.util.Date;
5253
import java.util.List;
@@ -210,7 +211,7 @@ public static OCFile fillOCFile(RemoteFile remote) {
210211
file.setOwnerId(remote.getOwnerId());
211212
file.setOwnerDisplayName(remote.getOwnerDisplayName());
212213
file.setNote(remote.getNote());
213-
file.setSharees(remote.getSharees());
214+
file.setSharees(new ArrayList<>(Arrays.asList(remote.getSharees())));
214215

215216
return file;
216217
}

0 commit comments

Comments
 (0)