Skip to content

Commit

Permalink
Updated avatar handling
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky authored and AndyScherzinger committed Nov 17, 2020
1 parent f0b7eb4 commit 85551b5
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class FileDetailSharingFragmentIT : AbstractIT() {
@Test
@ScreenshotTest
@Suppress("MagicNumber")
/**
* Use same values as {@link OCFileListFragmentStaticServerIT showSharedFiles }
*/
fun listSharesFileAllShareTypes() {
OCShare(file.decryptedRemotePath).apply {
remoteId = 1
Expand Down Expand Up @@ -115,14 +118,14 @@ class FileDetailSharingFragmentIT : AbstractIT() {
OCShare(file.decryptedRemotePath).apply {
remoteId = 4
shareType = ShareType.PUBLIC_LINK
sharedWithDisplayName = "Customer"
label = "Customer"
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 5
shareType = ShareType.PUBLIC_LINK
sharedWithDisplayName = "Colleagues"
label = "Colleagues"
activity.storageManager.saveShare(this)
}

Expand All @@ -138,14 +141,50 @@ class FileDetailSharingFragmentIT : AbstractIT() {
OCShare(file.decryptedRemotePath).apply {
remoteId = 7
shareType = ShareType.CIRCLE
sharedWithDisplayName = "Private circle"
sharedWithDisplayName = "Personal circle"
permissions = SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 8
shareType = ShareType.CIRCLE
sharedWithDisplayName = "Public circle"
permissions = SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 9
shareType = ShareType.CIRCLE
sharedWithDisplayName = "Closed circle"
permissions = SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 10
shareType = ShareType.CIRCLE
sharedWithDisplayName = "Secret circle"
permissions = SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 11
shareType = ShareType.ROOM
sharedWithDisplayName = "Admin"
permissions = SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}

OCShare(file.decryptedRemotePath).apply {
remoteId = 12
shareType = ShareType.ROOM
sharedWithDisplayName = "Meeting"
permissions = SHARE_PERMISSION_FLAG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,39 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {

@Test
@ScreenshotTest
/**
* Use same values as {@link FileDetailSharingFragmentIT listSharesFileAllShareTypes }
*/
fun showSharedFiles() {
val sut = testActivityRule.launchActivity(null)
val fragment = OCFileListFragment()

val groupShare = OCFile("/sharedToGroup.jpg").apply {
val userShare = OCFile("/sharedToUser.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
}
sut.storageManager.saveFile(groupShare)
sut.storageManager.saveFile(userShare)

val roomShare = OCFile("/sharedToRoom.jpg").apply {
val groupShare = OCFile("/sharedToGroup.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
}
sut.storageManager.saveFile(roomShare)
sut.storageManager.saveFile(groupShare)

val circleShare = OCFile("/sharedToCircle.jpg").apply {
val emailShare = OCFile("/sharedToEmail.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
}
sut.storageManager.saveFile(circleShare)
sut.storageManager.saveFile(emailShare)

val userShare = OCFile("/sharedToUser.jpg").apply {
val publicLink = OCFile("/publicLink.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
isSharedViaLink = true
}
sut.storageManager.saveFile(userShare)
sut.storageManager.saveFile(publicLink)

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

val emailShare = OCFile("/sharedToEmail.jpg").apply {
val personalCircleShare = OCFile("/sharedToPersonalCircle.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
sharees = listOf(ShareeUser("circle", "Circle (Personal circle)", ShareType.CIRCLE))
}
sut.storageManager.saveFile(emailShare)

val publicLink = OCFile("/publicLink.jpg").apply {
sut.storageManager.saveFile(personalCircleShare)

// as we cannot distinguish circle types, we do not need them right now
// val publicCircleShare = OCFile("/sharedToPublicCircle.jpg").apply {
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
// isSharedWithSharee = true
// sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
// }
// sut.storageManager.saveFile(publicCircleShare)
//
// val closedCircleShare = OCFile("/sharedToClosedCircle.jpg").apply {
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
// isSharedWithSharee = true
// sharees = listOf(ShareeUser("circle", "Circle (Closed circle)", ShareType.CIRCLE))
// }
// sut.storageManager.saveFile(closedCircleShare)
//
// val secretCircleShare = OCFile("/sharedToSecretCircle.jpg").apply {
// parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
// isSharedWithSharee = true
// sharees = listOf(ShareeUser("circle", "Circle (Secret circle)", ShareType.CIRCLE))
// }
// sut.storageManager.saveFile(secretCircleShare)

val userRoomShare = OCFile("/sharedToUserRoom.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedViaLink = true
isSharedWithSharee = true
sharees = listOf(ShareeUser("Conversation", "Admin", ShareType.ROOM))
}
sut.storageManager.saveFile(publicLink)
sut.storageManager.saveFile(userRoomShare)

val noShare = OCFile("/notShared.jpg").apply {
val groupRoomShare = OCFile("/sharedToGroupRoom.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
}
sut.storageManager.saveFile(noShare)
sut.storageManager.saveFile(groupRoomShare)

val usersShare = OCFile("/sharedToUser.jpg").apply {
val usersShare = OCFile("/sharedToUsers.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
isSharedWithSharee = true
sharees = listOf(
Expand All @@ -150,6 +177,11 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
}
sut.storageManager.saveFile(usersShare)

val noShare = OCFile("/notShared.jpg").apply {
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
}
sut.storageManager.saveFile(noShare)

sut.addFragment(fragment)

shortSleep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
binding.copyInternalLinkIcon
.getBackground()
.setColorFilter(ResourcesCompat.getColor(context.getResources(),
R.color.grey_db,
R.color.nc_grey,
null),
PorterDuff.Mode.SRC_IN);
binding.copyInternalLinkIcon
.getDrawable()
.mutate()
.setColorFilter(ResourcesCompat.getColor(context.getResources(),
R.color.black,
R.color.icon_on_nc_grey,
null),
PorterDuff.Mode.SRC_IN);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.owncloud.android.ui.adapter;

import android.content.Context;
import android.graphics.PorterDuff;
import android.text.TextUtils;
import android.view.View;

Expand Down Expand Up @@ -57,16 +58,21 @@ public void bind(OCShare publicShare, ShareeListAdapterListener listener) {
R.drawable.ic_email,
null));
binding.copyLink.setVisibility(View.GONE);

binding.icon.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
PorterDuff.Mode.SRC_IN);
binding.icon.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
PorterDuff.Mode.SRC_IN);
} else {
if (!TextUtils.isEmpty(publicShare.getLabel())) {
String text = String.format(context.getString(R.string.share_link_with_label), publicShare.getLabel());
binding.name.setText(text);
} else {
binding.name.setText(R.string.share_link);
}
}

ThemeUtils.colorIconImageViewWithBackground(binding.icon, context);
ThemeUtils.colorIconImageViewWithBackground(binding.icon, context);
}

binding.copyLink.setOnClickListener(v -> listener.copyLink(publicShare));
binding.overflowMenu.setOnClickListener(v -> listener.showLinkOverflowMenu(publicShare, binding.overflowMenu));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,35 +436,10 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
} else {
switch (sharee.getShareType()) {
case 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);
ThemeUtils.setIconColor(avatar.getDrawable());
}
break;

case EMAIL:
case ROOM:
try {
if (!TextUtils.isEmpty(sharee.getDisplayName())) {
avatar.setImageDrawable(
TextDrawable.createNamedAvatar(sharee.getDisplayName(), avatarRadius));
} else {
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);
ThemeUtils.setIconColor(avatar.getDrawable());
}
break;

case CIRCLE:
avatar.setImageResource(R.drawable.ic_circles);
ThemeUtils.setIconColor(avatar.getDrawable());
ThemeUtils.createAvatar(sharee.getShareType(), avatar, activity);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ThemeUtils;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -66,14 +67,14 @@ public void bind(OCShare share,
switch (share.getShareType()) {
case GROUP:
name = context.getString(R.string.share_group_clarification, name);
setImage(binding.icon, share.getSharedWithDisplayName(), R.drawable.ic_group);
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
break;
case ROOM:
name = context.getString(R.string.share_room_clarification, name);
setImage(binding.icon, share.getSharedWithDisplayName(), R.drawable.ic_chat_bubble);
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
break;
case CIRCLE:
binding.icon.setImageResource(R.drawable.ic_circles);
ThemeUtils.createAvatar(share.getShareType(), binding.icon, context);
break;
case FEDERATED:
name = context.getString(R.string.share_remote_clarification, name);
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/com/owncloud/android/utils/ThemeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OCCapability;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -720,7 +721,7 @@ public static void colorIconImageViewWithBackground(ImageView imageView, Context
*
* @param primaryColor the primary color
*/
private static int getColorForPrimary(int primaryColor, Context context) {
public static int getColorForPrimary(int primaryColor, Context context) {
if (Color.BLACK == primaryColor) {
return Color.WHITE;
} else if (Color.WHITE == primaryColor) {
Expand Down Expand Up @@ -872,4 +873,54 @@ public static boolean isDarkModeActive(Context context) {

return Configuration.UI_MODE_NIGHT_YES == nightModeFlag;
}

public static void createAvatar(ShareType type, ImageView avatar, Context context) {
switch (type) {
case GROUP:
avatar.setImageResource(R.drawable.ic_group);
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.round_bgnd,
null));
avatar.setCropToPadding(true);
avatar.setPadding(4, 4, 4, 4);
ThemeUtils.colorIconImageViewWithBackground(avatar, context);
break;

case ROOM:
avatar.setImageResource(R.drawable.first_run_talk);
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.round_bgnd,
null));
avatar.setCropToPadding(true);
avatar.setPadding(8, 8, 8, 8);
ThemeUtils.colorIconImageViewWithBackground(avatar, context);
break;

case CIRCLE:
avatar.setImageResource(R.drawable.ic_circles);
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.round_bgnd,
null));
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
PorterDuff.Mode.SRC_IN);
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
PorterDuff.Mode.SRC_IN);
avatar.setCropToPadding(true);
avatar.setPadding(4, 4, 4, 4);
break;

case EMAIL:
avatar.setImageResource(R.drawable.ic_email);
avatar.setBackground(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.round_bgnd,
null));
avatar.setCropToPadding(true);
avatar.setPadding(8, 8, 8, 8);
avatar.getBackground().setColorFilter(context.getResources().getColor(R.color.nc_grey),
PorterDuff.Mode.SRC_IN);
avatar.getDrawable().mutate().setColorFilter(context.getResources().getColor(R.color.icon_on_nc_grey),
PorterDuff.Mode.SRC_IN);
break;
}
}
}
Loading

0 comments on commit 85551b5

Please sign in to comment.