Browse Source

use StatusDrawable for conversationInfo and mention autocomplete

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 years ago
parent
commit
fc8462e0a5

+ 14 - 16
app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java

@@ -31,6 +31,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.json.mention.Mention;
 import com.nextcloud.talk.models.json.status.StatusType;
+import com.nextcloud.talk.ui.StatusDrawable;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 
@@ -38,7 +39,6 @@ import java.util.List;
 import java.util.Objects;
 import java.util.regex.Pattern;
 
-import androidx.core.content.ContextCompat;
 import androidx.core.content.res.ResourcesCompat;
 import eu.davidea.flexibleadapter.FlexibleAdapter;
 import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
@@ -49,8 +49,11 @@ import eu.davidea.flexibleadapter.utils.FlexibleUtils;
 public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
         implements IFilterable<String> {
 
+    private static final float STATUS_SIZE_IN_DP = 9f;
+    private static final String NO_ICON = "";
     public static final String SOURCE_CALLS = "calls";
     public static final String SOURCE_GUESTS = "guests";
+
     private String source;
     private final String objectId;
     private final String displayName;
@@ -171,7 +174,16 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
             holder.participantAvatar.setController(draweeController);
         }
 
-        if (holder.statusMessage != null && holder.participantEmoji != null && holder.participantOnlineStateImage != null) {
+
+        if (holder.statusMessage != null && holder.participantEmoji != null && holder.userStatusImage != null) {
+            float size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, context);
+            holder.userStatusImage.setImageDrawable(new StatusDrawable(
+                status,
+                NO_ICON,
+                size,
+                context.getResources().getColor(R.color.bg_default),
+                context));
+
             if (statusMessage != null) {
                 holder.statusMessage.setText(statusMessage);
             } else {
@@ -179,33 +191,19 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<UserItem.UserI
             }
 
             if (statusIcon != null && !statusIcon.isEmpty()) {
-                holder.participantEmoji.setVisibility(View.VISIBLE);
                 holder.participantEmoji.setText(statusIcon);
             } else {
                 holder.participantEmoji.setVisibility(View.GONE);
-                holder.participantEmoji.setText("");
             }
 
             if (status != null && status.equals(StatusType.DND.getString())) {
-                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
-                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_user_status_dnd_with_border));
-
                 if (statusMessage == null || statusMessage.isEmpty()) {
                     holder.statusMessage.setText(R.string.dnd);
                 }
             } else if (status != null && status.equals(StatusType.AWAY.getString())) {
-                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
-                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_user_status_away_with_border));
-
                 if (statusMessage == null || statusMessage.isEmpty()) {
                     holder.statusMessage.setText(R.string.away);
                 }
-            } else if (status != null && status.equals(StatusType.ONLINE.getString())) {
-                holder.participantOnlineStateImage.setVisibility(View.VISIBLE);
-                holder.participantOnlineStateImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.online_status_with_border));
-
-            } else {
-                holder.participantOnlineStateImage.setVisibility(View.GONE);
             }
         }
     }

+ 15 - 14
app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java

@@ -37,6 +37,7 @@ import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
 import com.nextcloud.talk.models.json.participants.Participant;
 import com.nextcloud.talk.models.json.participants.Participant.InCallFlags;
 import com.nextcloud.talk.models.json.status.StatusType;
+import com.nextcloud.talk.ui.StatusDrawable;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 
@@ -44,7 +45,6 @@ import java.util.List;
 import java.util.regex.Pattern;
 
 import androidx.annotation.Nullable;
-import androidx.core.content.ContextCompat;
 import androidx.core.content.res.ResourcesCompat;
 import androidx.emoji.widget.EmojiTextView;
 import butterknife.BindView;
@@ -59,6 +59,9 @@ import eu.davidea.viewholders.FlexibleViewHolder;
 public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder> implements
     ISectionable<UserItem.UserItemViewHolder, GenericTextHeaderItem>, IFilterable<String> {
 
+    private static final float STATUS_SIZE_IN_DP = 9f;
+    private static final String NO_ICON = "";
+
     private Context context;
     private Participant participant;
     private UserEntity userEntity;
@@ -131,7 +134,15 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
             }
         }
 
-        if (holder.statusMessage != null && holder.participantEmoji != null && holder.participantOnlineStateImage != null) {
+        if (holder.statusMessage != null && holder.participantEmoji != null && holder.userStatusImage != null) {
+            float size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, context);
+            holder.userStatusImage.setImageDrawable(new StatusDrawable(
+                participant.status,
+                NO_ICON,
+                size,
+                context.getResources().getColor(R.color.bg_default),
+                context));
+
             if (participant.statusMessage != null) {
                 holder.statusMessage.setText(participant.statusMessage);
             } else {
@@ -145,22 +156,13 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
             }
 
             if (participant.status != null && participant.status.equals(StatusType.DND.getString())) {
-                holder.participantOnlineStateImage.setImageDrawable(
-                    ContextCompat.getDrawable(context, R.drawable.ic_user_status_dnd_with_border));
                 if (participant.statusMessage == null || participant.statusMessage.isEmpty()) {
                     holder.statusMessage.setText(R.string.dnd);
                 }
             } else if (participant.status != null && participant.status.equals(StatusType.AWAY.getString())) {
-                holder.participantOnlineStateImage.setImageDrawable(
-                    ContextCompat.getDrawable(context, R.drawable.ic_user_status_away_with_border));
                 if (participant.statusMessage == null || participant.statusMessage.isEmpty()) {
                     holder.statusMessage.setText(R.string.away);
                 }
-            } else if (participant.status != null && participant.status.equals(StatusType.ONLINE.getString())) {
-                holder.participantOnlineStateImage.setImageDrawable(
-                    ContextCompat.getDrawable(context, R.drawable.online_status_with_border));
-            } else {
-                holder.participantOnlineStateImage.setVisibility(View.GONE);
             }
         }
 
@@ -328,9 +330,8 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
         @Nullable
         @BindView(R.id.participant_status_emoji)
         com.vanniktech.emoji.EmojiEditText participantEmoji;
-        @Nullable
-        @BindView(R.id.participant_online_state)
-        ImageView participantOnlineStateImage;
+        @BindView(R.id.user_status_image)
+        ImageView userStatusImage;
         @Nullable
         @BindView(R.id.conversation_info_status_message)
         EmojiTextView statusMessage;

+ 0 - 43
app/src/main/res/drawable/ic_user_status_away_with_border.xml

@@ -1,43 +0,0 @@
-<!--
-  Nextcloud Android client application
-
-  @author Tobias Kaminsky
-  Copyright (C) 2020 Tobias Kaminsky
-  Copyright (C) 2020 Nextcloud GmbH
-
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-  License as published by the Free Software Foundation; either
-  version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
-
-  You should have received a copy of the GNU Affero General Public
-  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<vector xmlns:tools="http://schemas.android.com/tools"
-    android:autoMirrored="true"
-    android:height="24dp"
-    android:viewportHeight="24"
-    android:viewportWidth="24"
-    android:width="24dp"
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    tools:ignore="VectorRaster">
-
-    <path
-        android:fillColor="@color/bg_default"
-        android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z"
-        android:strokeWidth="4"
-        android:strokeColor="@color/bg_default"/>
-
-    <path
-        android:fillColor="@color/bg_default"
-        android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z" />
-
-    <path
-        android:fillColor="#f4a331"
-        android:pathData="m10.615,2.1094c-4.8491,0.6811 -8.6152,4.8615 -8.6152,9.8906 0,5.5 4.5,10 10,10 5.0292,0 9.2096,-3.7661 9.8906,-8.6152 -1.4654,1.601 -3.5625,2.6152 -5.8906,2.6152 -4.4,0 -8,-3.6 -8,-8 0,-2.3281 1.0143,-4.4252 2.6152,-5.8906z" />
-</vector>

+ 0 - 41
app/src/main/res/drawable/ic_user_status_dnd_with_border.xml

@@ -1,41 +0,0 @@
-<!--
-  Nextcloud Android client application
-
-  @author Tobias Kaminsky
-  Copyright (C) 2020 Tobias Kaminsky
-  Copyright (C) 2020 Nextcloud GmbH
-
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-  License as published by the Free Software Foundation; either
-  version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
-
-  You should have received a copy of the GNU Affero General Public
-  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<vector xmlns:tools="http://schemas.android.com/tools"
-    android:autoMirrored="true"
-    android:height="24dp"
-    android:viewportHeight="24"
-    android:viewportWidth="24"
-    android:width="24dp"
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    tools:ignore="VectorRaster">
-    <path
-        android:fillColor="#ed484c"
-        android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z"
-        android:strokeWidth="2"
-        android:strokeColor="@color/bg_default"/>
-
-    <path
-        android:fillColor="#fdffff"
-        android:pathData="m8,10h8c1.108,0 2,0.892 2,2s-0.892,2 -2,2h-8c-1.108,0 -2,-0.892 -2,-2s0.892,-2 2,-2z"
-        android:strokeLineCap="round"
-        android:strokeLineJoin="round"
-        android:strokeWidth="2" />
-</vector>

+ 7 - 7
app/src/main/res/layout/rv_item_conversation_info_participant.xml

@@ -51,14 +51,14 @@
         app:layout_constraintTop_toBottomOf="@+id/name_text" />
 
     <ImageView
-        android:id="@+id/participant_online_state"
-        android:layout_width="16dp"
-        android:layout_height="16dp"
-        android:contentDescription="@null"
-        android:src="@drawable/online_status"
+        android:id="@+id/user_status_image"
+        android:layout_width="18dp"
+        android:layout_height="18dp"
+        android:layout_gravity="bottom|end"
+        android:contentDescription="@string/nc_account_chooser_active_user"
         app:layout_constraintBottom_toBottomOf="@+id/avatar_drawee_view"
-        app:layout_constraintEnd_toEndOf="@+id/avatar_drawee_view" />
-
+        app:layout_constraintEnd_toEndOf="@+id/avatar_drawee_view"
+        tools:src="@drawable/emoji_one_category_smileysandpeople"/>
 
     <androidx.emoji.widget.EmojiTextView
         android:id="@+id/name_text"

+ 2 - 1
app/src/main/res/layout/rv_item_conversation_with_last_message.xml

@@ -60,7 +60,8 @@
             android:layout_width="18dp"
             android:layout_height="18dp"
             android:layout_gravity="bottom|end"
-            android:contentDescription="@string/nc_account_chooser_active_user" />
+            android:contentDescription="@string/nc_account_chooser_active_user"
+            tools:src="@drawable/emoji_one_category_smileysandpeople"/>
     </FrameLayout>
 
     <RelativeLayout