diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt index 9e952d634..6d3d5cbcc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt @@ -184,7 +184,7 @@ class ConversationItem( ConversationType.ROOM_GROUP_CALL, ConversationType.FORMER_ONE_TO_ONE, ConversationType.ROOM_PUBLIC_CALL -> - holder.binding.dialogAvatar.loadConversationAvatar(user, model, false, viewThemeUtils) + holder.binding.dialogAvatar.loadConversationAvatar(user, model, false) else -> holder.binding.dialogAvatar.visibility = View.GONE } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index 4b5502ffc..bce388b02 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -807,7 +807,7 @@ class ConversationInfoActivity : } Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> { - binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils) + binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false) } Conversation.ConversationType.ROOM_SYSTEM -> { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 7a02bdead..38add4186 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -28,6 +28,7 @@ import android.text.TextUtils import android.util.Log import android.view.Menu import android.view.MenuItem +import android.view.View import android.widget.Toast import androidx.core.net.toFile import androidx.core.view.ViewCompat @@ -104,6 +105,8 @@ class ConversationInfoEditActivity : viewThemeUtils.material.colorTextInputLayout(binding.conversationDescriptionInputLayout) credentials = ApiUtils.getCredentials(conversationUser.username, conversationUser.token) + + pickImage = PickImage(this, conversationUser) } override fun onResume() { @@ -120,16 +123,19 @@ class ConversationInfoEditActivity : if (!CapabilitiesUtilNew.isConversationDescriptionEndpointAvailable(conversationUser)) { binding.conversationDescription.isEnabled = false } - - setupAvatarOptions() } private fun setupAvatarOptions() { - pickImage = PickImage(this, conversationUser) binding.avatarUpload.setOnClickListener { pickImage.selectLocal() } binding.avatarChoose.setOnClickListener { pickImage.selectRemote() } binding.avatarCamera.setOnClickListener { pickImage.takePicture() } - binding.avatarDelete.setOnClickListener { deleteAvatar() } + if (conversation?.hasCustomAvatar == true) { + binding.avatarDelete.visibility = View.VISIBLE + binding.avatarDelete.setOnClickListener { deleteAvatar() } + } else { + binding.avatarDelete.visibility = View.GONE + } + binding.avatarImage.let { ViewCompat.setTransitionName(it, "userAvatar.transitionTag") } binding.let { @@ -356,13 +362,15 @@ class ConversationInfoEditActivity : } private fun loadConversationAvatar() { + setupAvatarOptions() + when (conversation!!.type) { Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL -> if (!TextUtils.isEmpty(conversation!!.name)) { conversation!!.name?.let { binding.avatarImage.loadUserAvatar(conversationUser, it, true, false) } } Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> { - binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils) + binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false) } Conversation.ConversationType.ROOM_SYSTEM -> { diff --git a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt index ba550484c..65d46f5dd 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -55,29 +55,17 @@ private const val TAG = "ImageViewExtensions" fun ImageView.loadConversationAvatar( user: User, conversation: Conversation, - ignoreCache: Boolean, - viewThemeUtils: ViewThemeUtils? + ignoreCache: Boolean ): io.reactivex.disposables .Disposable { val imageRequestUri = ApiUtils.getUrlForConversationAvatarWithVersion( 1, user.baseUrl, conversation.token, + DisplayUtils.isDarkModeOn(this.context), conversation.avatarVersion ) - if (conversation.avatarVersion.isNullOrEmpty() && viewThemeUtils != null) { - when (conversation.type) { - Conversation.ConversationType.ROOM_GROUP_CALL -> - return loadDefaultGroupCallAvatar(viewThemeUtils) - - Conversation.ConversationType.ROOM_PUBLIC_CALL -> - return loadDefaultPublicCallAvatar(viewThemeUtils) - - else -> {} - } - } - // these placeholders are only used when the request fails completely. The server also return default avatars // when no own images are set. (although these default avatars can not be themed for the android app..) val errorPlaceholder = @@ -135,14 +123,8 @@ private fun ImageView.loadAvatarInternal( diskCacheKey?.let { diskCache?.remove(it) } } - val finalUrl = if (DisplayUtils.isDarkModeOn(this.context)) { - "$url/dark" - } else { - url - } - return DisposableWrapper( - load(finalUrl) { + load(url) { user?.let { addHeader( "Authorization", @@ -281,15 +263,6 @@ fun ImageView.loadDefaultGroupCallAvatar(viewThemeUtils: ViewThemeUtils): io.rea return loadUserAvatar(data) } -fun ImageView.loadDefaultPublicCallAvatar(viewThemeUtils: ViewThemeUtils): io.reactivex.disposables.Disposable { - val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - viewThemeUtils.talk.themePlaceholderAvatar(this, R.drawable.ic_avatar_link) as Any - } else { - R.drawable.ic_circular_link - } - return loadUserAvatar(data) -} - fun ImageView.loadMailAvatar(viewThemeUtils: ViewThemeUtils): io.reactivex.disposables.Disposable { val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { viewThemeUtils.talk.themePlaceholderAvatar(this, R.drawable.ic_avatar_mail) as Any diff --git a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt index b31eda0b7..f2051acc4 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt @@ -146,7 +146,13 @@ data class Conversation( var callRecording: Int = 0, @JsonField(name = ["avatarVersion"]) - var avatarVersion: String? = null + var avatarVersion: String? = null, + + // Be aware that variables with "is" at the beginning will lead to the error: + // "@JsonField annotation can only be used on private fields if both getter and setter are present." + // Instead, name it with "has" at the beginning: isCustomAvatar -> hasCustomAvatar + @JsonField(name = ["isCustomAvatar"]) + var hasCustomAvatar: Boolean? = null ) : Parcelable { // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index d2d1ab944..bc4b04027 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -380,8 +380,19 @@ public class ApiUtils { } public static String getUrlForConversationAvatarWithVersion(int version, String baseUrl, String token, - String avatarVersion) { - return getUrlForRoom(version, baseUrl, token) + "/avatar?avatarVersion=" + avatarVersion; + boolean isDark, + String avatarVersion) { + String isDarkString = ""; + if (isDark) { + isDarkString = "/dark"; + } + + String avatarVersionString = ""; + if (avatarVersion != null) { + avatarVersionString = "?avatarVersion=" + avatarVersion; + } + + return getUrlForRoom(version, baseUrl, token) + "/avatar" + isDarkString + avatarVersionString; } public static String getCredentials(String username, String token) { diff --git a/app/src/main/res/drawable/ic_avatar_link.xml b/app/src/main/res/drawable/ic_avatar_link.xml deleted file mode 100644 index 21e7d94dd..000000000 --- a/app/src/main/res/drawable/ic_avatar_link.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - \ No newline at end of file