浏览代码

WIP. add themed placeholders for conversationAvatars

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 1 年之前
父节点
当前提交
28046c2492

+ 1 - 1
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)
+                    holder.binding.dialogAvatar.loadConversationAvatar(user, model, false, viewThemeUtils)
 
                 else -> holder.binding.dialogAvatar.visibility = View.GONE
             }

+ 10 - 0
app/src/main/java/com/nextcloud/talk/api/NcApi.java

@@ -443,12 +443,22 @@ public interface NcApi {
     @DELETE
     Observable<GenericOverall> deleteAvatar(@Header("Authorization") String authorization, @Url String url);
 
+    @DELETE
+    Observable<RoomOverall> deleteConversationAvatar(@Header("Authorization") String authorization, @Url String url);
+
+
     @Multipart
     @POST
     Observable<GenericOverall> uploadAvatar(@Header("Authorization") String authorization,
                                             @Url String url,
                                             @Part MultipartBody.Part attachment);
 
+    @Multipart
+    @POST
+    Observable<RoomOverall> uploadConversationAvatar(@Header("Authorization") String authorization,
+                                            @Url String url,
+                                            @Part MultipartBody.Part attachment);
+
     @GET
     Observable<UserProfileFieldsOverall> getEditableUserProfileFields(@Header("Authorization") String authorization,
                                                                       @Url String url);

+ 1 - 1
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!!, true)
+                binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils)
             }
 
             Conversation.ConversationType.ROOM_SYSTEM -> {

+ 11 - 8
app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt

@@ -43,6 +43,7 @@ import com.nextcloud.talk.extensions.loadConversationAvatar
 import com.nextcloud.talk.extensions.loadSystemAvatar
 import com.nextcloud.talk.extensions.loadUserAvatar
 import com.nextcloud.talk.models.json.conversations.Conversation
+import com.nextcloud.talk.models.json.conversations.RoomOverall
 import com.nextcloud.talk.models.json.generic.GenericOverall
 import com.nextcloud.talk.repositories.conversations.ConversationsRepository
 import com.nextcloud.talk.utils.ApiUtils
@@ -95,7 +96,7 @@ class ConversationInfoEditActivity :
         conversationUser = extras?.getParcelable(BundleKeys.KEY_USER_ENTITY)!!
         conversationToken = extras.getString(BundleKeys.KEY_ROOM_TOKEN)!!
 
-        if (intent.hasExtra(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
+        if (conversation == null && intent.hasExtra(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
             conversation = Parcels.unwrap<Conversation>(extras.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION))
         }
 
@@ -290,19 +291,20 @@ class ConversationInfoEditActivity :
         )
 
         // upload file
-        ncApi.uploadAvatar(
+        ncApi.uploadConversationAvatar(
             credentials,
             ApiUtils.getUrlForConversationAvatar(1, conversationUser.baseUrl, conversation!!.token),
             filePart
         )
             .subscribeOn(Schedulers.io())
             .observeOn(AndroidSchedulers.mainThread())
-            .subscribe(object : Observer<GenericOverall> {
+            .subscribe(object : Observer<RoomOverall> {
                 override fun onSubscribe(d: Disposable) {
                     // unused atm
                 }
 
-                override fun onNext(genericOverall: GenericOverall) {
+                override fun onNext(roomOverall: RoomOverall) {
+                    conversation = roomOverall.ocs!!.data
                     loadConversationAvatar()
                 }
 
@@ -322,18 +324,19 @@ class ConversationInfoEditActivity :
     }
 
     private fun deleteAvatar() {
-        ncApi.deleteAvatar(
+        ncApi.deleteConversationAvatar(
             credentials,
             ApiUtils.getUrlForConversationAvatar(1, conversationUser.baseUrl, conversationToken)
         )
             .subscribeOn(Schedulers.io())
             .observeOn(AndroidSchedulers.mainThread())
-            .subscribe(object : Observer<GenericOverall> {
+            .subscribe(object : Observer<RoomOverall> {
                 override fun onSubscribe(d: Disposable) {
                     // unused atm
                 }
 
-                override fun onNext(genericOverall: GenericOverall) {
+                override fun onNext(roomOverall: RoomOverall) {
+                    conversation = roomOverall.ocs!!.data
                     loadConversationAvatar()
                 }
 
@@ -359,7 +362,7 @@ class ConversationInfoEditActivity :
             }
 
             Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> {
-                binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, true)
+                binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils)
             }
 
             Conversation.ConversationType.ROOM_SYSTEM -> {

+ 26 - 10
app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt

@@ -55,11 +55,10 @@ private const val TAG = "ImageViewExtensions"
 fun ImageView.loadConversationAvatar(
     user: User,
     conversation: Conversation,
-    ignoreCache: Boolean
+    ignoreCache: Boolean,
+    viewThemeUtils: ViewThemeUtils?
 ): io.reactivex.disposables
 .Disposable {
-    var finalIgnoreCache = ignoreCache
-
     val imageRequestUri = ApiUtils.getUrlForConversationAvatarWithVersion(
         1,
         user.baseUrl,
@@ -67,13 +66,21 @@ fun ImageView.loadConversationAvatar(
         conversation.avatarVersion
     )
 
-    if (conversation.avatarVersion.isNullOrEmpty()) {
-        finalIgnoreCache = true
+    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 placeholder =
+    val errorPlaceholder =
         when (conversation.type) {
             Conversation.ConversationType.ROOM_GROUP_CALL ->
                 ContextCompat.getDrawable(context, R.drawable.ic_circular_group)
@@ -84,7 +91,7 @@ fun ImageView.loadConversationAvatar(
             else -> ContextCompat.getDrawable(context, R.drawable.account_circle_96dp)
         }
 
-    return loadAvatarInternal(user, imageRequestUri, finalIgnoreCache, placeholder)
+    return loadAvatarInternal(user, imageRequestUri, ignoreCache, errorPlaceholder)
 }
 
 fun ImageView.loadUserAvatar(
@@ -108,7 +115,7 @@ private fun ImageView.loadAvatarInternal(
     user: User?,
     url: String,
     ignoreCache: Boolean,
-    placeholder: Drawable?
+    errorPlaceholder: Drawable?
 ): io.reactivex.disposables
 .Disposable {
     val cachePolicy = if (ignoreCache) {
@@ -143,8 +150,8 @@ private fun ImageView.loadAvatarInternal(
                 )
             }
             transformations(CircleCropTransformation())
-            error(placeholder ?: ContextCompat.getDrawable(context, R.drawable.account_circle_96dp))
-            fallback(placeholder ?: ContextCompat.getDrawable(context, R.drawable.account_circle_96dp))
+            error(errorPlaceholder ?: ContextCompat.getDrawable(context, R.drawable.account_circle_96dp))
+            fallback(errorPlaceholder ?: ContextCompat.getDrawable(context, R.drawable.account_circle_96dp))
             listener(onError = { _, result ->
                 Log.w(TAG, "Can't load avatar with URL: $url", result.throwable)
             })
@@ -274,6 +281,15 @@ 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

+ 31 - 0
app/src/main/res/drawable/ic_avatar_link.xml

@@ -0,0 +1,31 @@
+<!--
+  ~ 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>