handle emoji avatars

hide delete option from conversation info edit view if no custom avatar is set

remove themed avatars (This is the price of being able to have emoji avatars)

fix dark mode url

remove avatarVersion from url if it's null

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-05-02 18:44:03 +02:00
parent 21ba5d87f0
commit 579b3b5ab4
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
7 changed files with 38 additions and 71 deletions

View file

@ -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
}

View file

@ -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 -> {

View file

@ -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 -> {

View file

@ -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

View file

@ -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'

View file

@ -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) {

View file

@ -1,31 +0,0 @@
<!--
~ Nextcloud Talk application
~
~ @author Andy Scherzinger
~ Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:fillType="nonZero"
android:pathData="M13,5.921L9.818,9.105C9.111,9.812 8.781,10.723 8.83,11.562C8.88,12.401 9.263,13.146 9.818,13.701L11.23,12.285C10.663,11.717 10.686,11.065 11.232,10.519L14.414,7.337C14.939,6.812 15.664,6.814 16.186,7.335C16.668,7.891 16.713,8.574 16.182,9.105L15.362,9.925C15.917,10.71 16.007,11.291 15.955,12.16L17.596,10.519C18.833,9.282 18.833,7.154 17.596,5.917C16.36,4.681 14.254,4.706 13,5.921ZM13.707,9.806L12.293,11.224L12.297,11.224C12.847,11.774 12.804,12.482 12.293,12.994L9.111,16.175C8.415,16.767 7.813,16.646 7.342,16.175C6.715,15.549 6.842,14.907 7.342,14.407L8.192,13.56C7.636,12.777 7.543,12.195 7.594,11.328L5.928,12.994C4.689,14.233 4.692,16.354 5.928,17.589C7.163,18.825 9.29,18.825 10.526,17.589L13.707,14.407C14.416,13.699 14.747,12.789 14.698,11.949C14.65,11.109 14.266,10.362 13.709,9.808L13.707,9.806Z" />
</vector>