Skip to content

Commit e844abf

Browse files
Updated avatar handling
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent 8283b5a commit e844abf

File tree

10 files changed

+235
-62
lines changed

10 files changed

+235
-62
lines changed

src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailSharingFragmentIT.kt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class FileDetailSharingFragmentIT : AbstractIT() {
8585
@Test
8686
@ScreenshotTest
8787
@Suppress("MagicNumber")
88+
/**
89+
* Use same values as {@link OCFileListFragmentStaticServerIT showSharedFiles }
90+
*/
8891
fun listSharesFileAllShareTypes() {
8992
OCShare(file.decryptedRemotePath).apply {
9093
remoteId = 1
@@ -115,14 +118,14 @@ class FileDetailSharingFragmentIT : AbstractIT() {
115118
OCShare(file.decryptedRemotePath).apply {
116119
remoteId = 4
117120
shareType = ShareType.PUBLIC_LINK
118-
sharedWithDisplayName = "Customer"
121+
label = "Customer"
119122
activity.storageManager.saveShare(this)
120123
}
121124

122125
OCShare(file.decryptedRemotePath).apply {
123126
remoteId = 5
124127
shareType = ShareType.PUBLIC_LINK
125-
sharedWithDisplayName = "Colleagues"
128+
label = "Colleagues"
126129
activity.storageManager.saveShare(this)
127130
}
128131

@@ -138,14 +141,50 @@ class FileDetailSharingFragmentIT : AbstractIT() {
138141
OCShare(file.decryptedRemotePath).apply {
139142
remoteId = 7
140143
shareType = ShareType.CIRCLE
141-
sharedWithDisplayName = "Private circle"
144+
sharedWithDisplayName = "Personal circle"
142145
permissions = SHARE_PERMISSION_FLAG
143146
userId = getUserId(user)
144147
activity.storageManager.saveShare(this)
145148
}
146149

147150
OCShare(file.decryptedRemotePath).apply {
148151
remoteId = 8
152+
shareType = ShareType.CIRCLE
153+
sharedWithDisplayName = "Public circle"
154+
permissions = SHARE_PERMISSION_FLAG
155+
userId = getUserId(user)
156+
activity.storageManager.saveShare(this)
157+
}
158+
159+
OCShare(file.decryptedRemotePath).apply {
160+
remoteId = 9
161+
shareType = ShareType.CIRCLE
162+
sharedWithDisplayName = "Closed circle"
163+
permissions = SHARE_PERMISSION_FLAG
164+
userId = getUserId(user)
165+
activity.storageManager.saveShare(this)
166+
}
167+
168+
OCShare(file.decryptedRemotePath).apply {
169+
remoteId = 10
170+
shareType = ShareType.CIRCLE
171+
sharedWithDisplayName = "Secret circle"
172+
permissions = SHARE_PERMISSION_FLAG
173+
userId = getUserId(user)
174+
activity.storageManager.saveShare(this)
175+
}
176+
177+
OCShare(file.decryptedRemotePath).apply {
178+
remoteId = 11
179+
shareType = ShareType.ROOM
180+
sharedWithDisplayName = "Admin"
181+
permissions = SHARE_PERMISSION_FLAG
182+
userId = getUserId(user)
183+
activity.storageManager.saveShare(this)
184+
}
185+
186+
OCShare(file.decryptedRemotePath).apply {
187+
remoteId = 12
149188
shareType = ShareType.ROOM
150189
sharedWithDisplayName = "Meeting"
151190
permissions = SHARE_PERMISSION_FLAG

src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,39 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
8080

8181
@Test
8282
@ScreenshotTest
83+
/**
84+
* Use same values as {@link FileDetailSharingFragmentIT listSharesFileAllShareTypes }
85+
*/
8386
fun showSharedFiles() {
8487
val sut = testActivityRule.launchActivity(null)
8588
val fragment = OCFileListFragment()
8689

87-
val groupShare = OCFile("/sharedToGroup.jpg").apply {
90+
val userShare = OCFile("/sharedToUser.jpg").apply {
8891
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
8992
isSharedWithSharee = true
90-
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
93+
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
9194
}
92-
sut.storageManager.saveFile(groupShare)
95+
sut.storageManager.saveFile(userShare)
9396

94-
val roomShare = OCFile("/sharedToRoom.jpg").apply {
97+
val groupShare = OCFile("/sharedToGroup.jpg").apply {
9598
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
9699
isSharedWithSharee = true
97-
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
100+
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
98101
}
99-
sut.storageManager.saveFile(roomShare)
102+
sut.storageManager.saveFile(groupShare)
100103

101-
val circleShare = OCFile("/sharedToCircle.jpg").apply {
104+
val emailShare = OCFile("/sharedToEmail.jpg").apply {
102105
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
103106
isSharedWithSharee = true
104-
sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
107+
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
105108
}
106-
sut.storageManager.saveFile(circleShare)
109+
sut.storageManager.saveFile(emailShare)
107110

108-
val userShare = OCFile("/sharedToUser.jpg").apply {
111+
val publicLink = OCFile("/publicLink.jpg").apply {
109112
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
110-
isSharedWithSharee = true
111-
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
113+
isSharedViaLink = true
112114
}
113-
sut.storageManager.saveFile(userShare)
115+
sut.storageManager.saveFile(publicLink)
114116

115117
val federatedUserShare = OCFile("/sharedToFederatedUser.jpg").apply {
116118
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
@@ -121,25 +123,50 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
121123
}
122124
sut.storageManager.saveFile(federatedUserShare)
123125

124-
val emailShare = OCFile("/sharedToEmail.jpg").apply {
126+
val personalCircleShare = OCFile("/sharedToPersonalCircle.jpg").apply {
125127
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
126128
isSharedWithSharee = true
127-
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
129+
sharees = listOf(ShareeUser("circle", "Circle (Personal circle)", ShareType.CIRCLE))
128130
}
129-
sut.storageManager.saveFile(emailShare)
130-
131-
val publicLink = OCFile("/publicLink.jpg").apply {
131+
sut.storageManager.saveFile(personalCircleShare)
132+
133+
// as we cannot distinguish circle types, we do not need them right now
134+
// val publicCircleShare = OCFile("/sharedToPublicCircle.jpg").apply {
135+
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
136+
// isSharedWithSharee = true
137+
// sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
138+
// }
139+
// sut.storageManager.saveFile(publicCircleShare)
140+
//
141+
// val closedCircleShare = OCFile("/sharedToClosedCircle.jpg").apply {
142+
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
143+
// isSharedWithSharee = true
144+
// sharees = listOf(ShareeUser("circle", "Circle (Closed circle)", ShareType.CIRCLE))
145+
// }
146+
// sut.storageManager.saveFile(closedCircleShare)
147+
//
148+
// val secretCircleShare = OCFile("/sharedToSecretCircle.jpg").apply {
149+
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
150+
// isSharedWithSharee = true
151+
// sharees = listOf(ShareeUser("circle", "Circle (Secret circle)", ShareType.CIRCLE))
152+
// }
153+
// sut.storageManager.saveFile(secretCircleShare)
154+
155+
val userRoomShare = OCFile("/sharedToUserRoom.jpg").apply {
132156
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
133-
isSharedViaLink = true
157+
isSharedWithSharee = true
158+
sharees = listOf(ShareeUser("Conversation", "Admin", ShareType.ROOM))
134159
}
135-
sut.storageManager.saveFile(publicLink)
160+
sut.storageManager.saveFile(userRoomShare)
136161

137-
val noShare = OCFile("/notShared.jpg").apply {
162+
val groupRoomShare = OCFile("/sharedToGroupRoom.jpg").apply {
138163
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
164+
isSharedWithSharee = true
165+
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
139166
}
140-
sut.storageManager.saveFile(noShare)
167+
sut.storageManager.saveFile(groupRoomShare)
141168

142-
val usersShare = OCFile("/sharedToUser.jpg").apply {
169+
val usersShare = OCFile("/sharedToUsers.jpg").apply {
143170
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
144171
isSharedWithSharee = true
145172
sharees = listOf(
@@ -150,6 +177,11 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
150177
}
151178
sut.storageManager.saveFile(usersShare)
152179

180+
val noShare = OCFile("/notShared.jpg").apply {
181+
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
182+
}
183+
sut.storageManager.saveFile(noShare)
184+
153185
sut.addFragment(fragment)
154186

155187
shortSleep()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
5252
binding.copyInternalLinkIcon
5353
.getBackground()
5454
.setColorFilter(ResourcesCompat.getColor(context.getResources(),
55-
R.color.grey_db,
55+
R.color.nc_grey,
5656
null),
5757
PorterDuff.Mode.SRC_IN);
5858
binding.copyInternalLinkIcon
5959
.getDrawable()
6060
.mutate()
6161
.setColorFilter(ResourcesCompat.getColor(context.getResources(),
62-
R.color.black,
62+
R.color.icon_on_nc_grey,
6363
null),
6464
PorterDuff.Mode.SRC_IN);
6565

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.owncloud.android.ui.adapter;
2424

2525
import android.content.Context;
26+
import android.graphics.PorterDuff;
2627
import android.text.TextUtils;
2728
import android.view.View;
2829

@@ -57,16 +58,21 @@ public void bind(OCShare publicShare, ShareeListAdapterListener listener) {
5758
R.drawable.ic_email,
5859
null));
5960
binding.copyLink.setVisibility(View.GONE);
61+
62+
binding.icon.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
63+
PorterDuff.Mode.SRC_IN);
64+
binding.icon.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
65+
PorterDuff.Mode.SRC_IN);
6066
} else {
6167
if (!TextUtils.isEmpty(publicShare.getLabel())) {
6268
String text = String.format(context.getString(R.string.share_link_with_label), publicShare.getLabel());
6369
binding.name.setText(text);
6470
} else {
6571
binding.name.setText(R.string.share_link);
6672
}
67-
}
6873

69-
ThemeUtils.colorIconImageViewWithBackground(binding.icon, context);
74+
ThemeUtils.colorIconImageViewWithBackground(binding.icon, context);
75+
}
7076

7177
binding.copyLink.setOnClickListener(v -> listener.copyLink(publicShare));
7278
binding.overflowMenu.setOnClickListener(v -> listener.showLinkOverflowMenu(publicShare, binding.overflowMenu));

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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -436,35 +436,10 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
436436
} else {
437437
switch (sharee.getShareType()) {
438438
case GROUP:
439-
try {
440-
avatar.setImageDrawable(TextDrawable.createAvatarByUserId(sharee.getUserId(),
441-
avatarRadius));
442-
} catch (Exception e) {
443-
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
444-
avatar.setImageResource(R.drawable.ic_people);
445-
ThemeUtils.setIconColor(avatar.getDrawable());
446-
}
447-
break;
448-
439+
case EMAIL:
449440
case ROOM:
450-
try {
451-
if (!TextUtils.isEmpty(sharee.getDisplayName())) {
452-
avatar.setImageDrawable(
453-
TextDrawable.createNamedAvatar(sharee.getDisplayName(), avatarRadius));
454-
} else {
455-
avatar.setImageDrawable(
456-
TextDrawable.createAvatarByUserId(sharee.getUserId(), avatarRadius));
457-
}
458-
} catch (Exception e) {
459-
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
460-
avatar.setImageResource(R.drawable.ic_people);
461-
ThemeUtils.setIconColor(avatar.getDrawable());
462-
}
463-
break;
464-
465441
case CIRCLE:
466-
avatar.setImageResource(R.drawable.ic_circles);
467-
ThemeUtils.setIconColor(avatar.getDrawable());
442+
ThemeUtils.createAvatar(sharee.getShareType(), avatar, activity);
468443
break;
469444

470445
default:

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.owncloud.android.databinding.FileDetailsShareShareItemBinding;
3131
import com.owncloud.android.lib.resources.shares.OCShare;
3232
import com.owncloud.android.ui.TextDrawable;
33+
import com.owncloud.android.utils.ThemeUtils;
3334

3435
import androidx.annotation.DrawableRes;
3536
import androidx.annotation.NonNull;
@@ -60,14 +61,14 @@ public void bind(OCShare share,
6061
switch (share.getShareType()) {
6162
case GROUP:
6263
name = context.getString(R.string.share_group_clarification, name);
63-
setImage(binding.icon, share.getSharedWithDisplayName(), R.drawable.ic_group);
64+
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
6465
break;
6566
case ROOM:
6667
name = context.getString(R.string.share_room_clarification, name);
67-
setImage(binding.icon, share.getSharedWithDisplayName(), R.drawable.ic_chat_bubble);
68+
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
6869
break;
6970
case CIRCLE:
70-
binding.icon.setImageResource(R.drawable.ic_circles);
71+
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
7172
break;
7273
case FEDERATED:
7374
name = context.getString(R.string.share_remote_clarification, name);

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.owncloud.android.R;
5757
import com.owncloud.android.datamodel.FileDataStorageManager;
5858
import com.owncloud.android.lib.common.utils.Log_OC;
59+
import com.owncloud.android.lib.resources.shares.ShareType;
5960
import com.owncloud.android.lib.resources.status.OCCapability;
6061

6162
import java.lang.reflect.Field;
@@ -720,7 +721,7 @@ public static void colorIconImageViewWithBackground(ImageView imageView, Context
720721
*
721722
* @param primaryColor the primary color
722723
*/
723-
private static int getColorForPrimary(int primaryColor, Context context) {
724+
public static int getColorForPrimary(int primaryColor, Context context) {
724725
if (Color.BLACK == primaryColor) {
725726
return Color.WHITE;
726727
} else if (Color.WHITE == primaryColor) {
@@ -872,4 +873,54 @@ public static boolean isDarkModeActive(Context context) {
872873

873874
return Configuration.UI_MODE_NIGHT_YES == nightModeFlag;
874875
}
876+
877+
public static void createAvatar(ShareType type, ImageView avatar, Context context) {
878+
switch (type) {
879+
case GROUP:
880+
avatar.setImageResource(R.drawable.ic_group);
881+
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
882+
R.drawable.round_bgnd,
883+
null));
884+
avatar.setCropToPadding(true);
885+
avatar.setPadding(4, 4, 4, 4);
886+
ThemeUtils.colorIconImageViewWithBackground(avatar, context);
887+
break;
888+
889+
case ROOM:
890+
avatar.setImageResource(R.drawable.first_run_talk);
891+
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
892+
R.drawable.round_bgnd,
893+
null));
894+
avatar.setCropToPadding(true);
895+
avatar.setPadding(8, 8, 8, 8);
896+
ThemeUtils.colorIconImageViewWithBackground(avatar, context);
897+
break;
898+
899+
case CIRCLE:
900+
avatar.setImageResource(R.drawable.ic_circles);
901+
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
902+
R.drawable.round_bgnd,
903+
null));
904+
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
905+
PorterDuff.Mode.SRC_IN);
906+
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
907+
PorterDuff.Mode.SRC_IN);
908+
avatar.setCropToPadding(true);
909+
avatar.setPadding(4, 4, 4, 4);
910+
break;
911+
912+
case EMAIL:
913+
avatar.setImageResource(R.drawable.ic_email);
914+
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
915+
R.drawable.round_bgnd,
916+
null));
917+
avatar.setCropToPadding(true);
918+
avatar.setPadding(8, 8, 8, 8);
919+
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
920+
PorterDuff.Mode.SRC_IN);
921+
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
922+
PorterDuff.Mode.SRC_IN);
923+
break;
924+
}
925+
}
875926
}

0 commit comments

Comments
 (0)