diff options
author | Marcel Hibbe <dev@mhibbe.de> | 2022-02-24 14:31:58 +0300 |
---|---|---|
committer | Marcel Hibbe <dev@mhibbe.de> | 2022-02-25 14:11:43 +0300 |
commit | 1da8c3b206be3e5cd1e3596c070fa672f869d1b1 (patch) | |
tree | 9054a4e4bbd82eadf51cc57df673ac88fb65abe7 /app/src | |
parent | 73ce2716de6ef18ecab65840c9a4b976ff49d624 (diff) |
modify StatusDrawable and use it for conversationList
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Diffstat (limited to 'app/src')
9 files changed, 55 insertions, 74 deletions
diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java index 1a9be11b0..0de0a2413 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java @@ -48,6 +48,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage; import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.models.json.status.Status; 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; @@ -70,6 +71,7 @@ import eu.davidea.viewholders.FlexibleViewHolder; public class ConversationItem extends AbstractFlexibleItem<ConversationItem.ConversationItemViewHolder> implements ISectionable<ConversationItem.ConversationItemViewHolder, GenericTextHeaderItem>, IFilterable<String> { + private static final float STATUS_SIZE_IN_DP = 9f; private Conversation conversation; private UserEntity userEntity; @@ -198,23 +200,13 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv } if (!Conversation.ConversationType.ROOM_SYSTEM.equals(conversation.getType())) { - if (status != null && status.getStatus().equals(StatusType.DND.getString())) { - setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border); - } else if (status != null && status.getIcon() != null && !status.getIcon().isEmpty()) { - holder.userStatusOnlineState.setVisibility(View.GONE); - holder.userStatusEmoji.setVisibility(View.VISIBLE); - holder.userStatusEmoji.setText(status.getIcon()); - } else if (status != null && status.getStatus().equals(StatusType.AWAY.getString())) { - setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border); - } else if (status != null && status.getStatus().equals(StatusType.ONLINE.getString())) { - setOnlineStateIcon(holder, R.drawable.online_status_with_border); - } else { - holder.userStatusEmoji.setVisibility(View.GONE); - holder.userStatusOnlineState.setVisibility(View.GONE); - } - } else { - holder.userStatusEmoji.setVisibility(View.GONE); - holder.userStatusOnlineState.setVisibility(View.GONE); + float size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, appContext); + holder.userStatusImage.setImageDrawable(new StatusDrawable( + status != null ? status.getStatus() : "", + status != null ? status.getIcon() : "", + size, + context.getResources().getColor(R.color.bg_default), + appContext)); } if (conversation.getLastMessage() != null) { @@ -314,12 +306,6 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv } } - private void setOnlineStateIcon(ConversationItemViewHolder holder, int icon) { - holder.userStatusEmoji.setVisibility(View.GONE); - holder.userStatusOnlineState.setVisibility(View.VISIBLE); - holder.userStatusOnlineState.setImageDrawable(ContextCompat.getDrawable(context, icon)); - } - @Override public boolean filter(String constraint) { return conversation.getDisplayName() != null && @@ -349,11 +335,8 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv Chip dialogUnreadBubble; @BindView(R.id.favoriteConversationImageView) ImageView pinnedConversationImageView; - @BindView(R.id.userStatusEmoji) - com.vanniktech.emoji.EmojiEditText userStatusEmoji; - @BindView(R.id.userStatusOnlineState) - ImageView userStatusOnlineState; - + @BindView(R.id.user_status_image) + ImageView userStatusImage; ConversationItemViewHolder(View view, FlexibleAdapter adapter) { super(view, adapter); diff --git a/app/src/main/java/com/nextcloud/talk/ui/StatusDrawable.java b/app/src/main/java/com/nextcloud/talk/ui/StatusDrawable.java index fc8e69ce3..fc2c77747 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/StatusDrawable.java +++ b/app/src/main/java/com/nextcloud/talk/ui/StatusDrawable.java @@ -43,49 +43,38 @@ public class StatusDrawable extends Drawable { private String text; private @DrawableRes int icon = -1; private Paint textPaint; - private Paint backgroundPaint; + private int backgroundColor; private final float radius; private Context context; - private final static int whiteBackground = Color.argb(200, 255, 255, 255); - private final static int onlineStatus = Color.argb(255, 73, 179, 130); - - public StatusDrawable(String status, String statusIcon, float statusSize, Context context) { - backgroundPaint = new Paint(); - backgroundPaint.setStyle(Paint.Style.FILL); - backgroundPaint.setAntiAlias(true); + public StatusDrawable(String status, String statusIcon, float statusSize, int backgroundColor, Context context) { radius = statusSize; + this.backgroundColor = backgroundColor; - if (TextUtils.isEmpty(statusIcon)) { - switch (status) { - case "dnd": - icon = R.drawable.ic_user_status_dnd; - backgroundPaint.setColor(whiteBackground); - this.context = context; - break; + if ("dnd".equals(status)) { + icon = R.drawable.ic_user_status_dnd; + this.context = context; + } else if (TextUtils.isEmpty(statusIcon)) { + switch (status) { case "online": - backgroundPaint.setColor(onlineStatus); + icon = R.drawable.online_status; + this.context = context; break; case "away": icon = R.drawable.ic_user_status_away; - backgroundPaint.setColor(whiteBackground); this.context = context; break; default: // do not show - backgroundPaint = null; break; } } else { text = statusIcon; - backgroundPaint.setColor(whiteBackground); - textPaint = new Paint(); - textPaint.setColor(Color.WHITE); textPaint.setTextSize(statusSize); textPaint.setAntiAlias(true); textPaint.setTextAlign(Paint.Align.CENTER); @@ -100,16 +89,20 @@ public class StatusDrawable extends Drawable { */ @Override public void draw(@NonNull Canvas canvas) { - if (backgroundPaint != null) { - canvas.drawCircle(radius, radius, radius, backgroundPaint); - } - if (text != null) { textPaint.setTextSize(1.6f * radius); canvas.drawText(text, radius, radius - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint); } if (icon != -1) { + + Paint backgroundPaint = new Paint(); + backgroundPaint.setStyle(Paint.Style.FILL); + backgroundPaint.setAntiAlias(true); + backgroundPaint.setColor(backgroundColor); + + canvas.drawCircle(radius, radius, radius, backgroundPaint); + Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), icon, null); if (drawable != null) { diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java index e40e55ee9..3a5138637 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java @@ -313,6 +313,7 @@ public class ChooseAccountDialogFragment extends DialogFragment { status.getStatus(), status.getIcon(), size, + getContext().getResources().getColor(R.color.dialog_background), getContext())); binding.currentAccount.ticker.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt index 837b2b993..9b07a7877 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt @@ -84,7 +84,7 @@ private const val LAST_SECOND_OF_MINUTE = 59 class SetStatusDialogFragment : DialogFragment(), PredefinedStatusClickListener { - private val logTag = ChooseAccountDialogFragment::class.java.simpleName + private val logTag = SetStatusDialogFragment::class.java.simpleName private lateinit var binding: DialogSetStatusBinding diff --git a/app/src/main/res/drawable/online_status.xml b/app/src/main/res/drawable/online_status.xml index fb042c2d3..694071933 100644 --- a/app/src/main/res/drawable/online_status.xml +++ b/app/src/main/res/drawable/online_status.xml @@ -17,7 +17,16 @@ 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/>. --> -<shape xmlns:android="http://schemas.android.com/apk/res/android" - android:shape="oval"> - <solid android:color="#00ff00" /> -</shape> +<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="#00ff00" + 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" /> +</vector> + diff --git a/app/src/main/res/layout/current_account_item.xml b/app/src/main/res/layout/current_account_item.xml index 5e6ab4d57..680fb3a36 100644 --- a/app/src/main/res/layout/current_account_item.xml +++ b/app/src/main/res/layout/current_account_item.xml @@ -107,6 +107,7 @@ android:maxLines="1" android:textColor="?android:attr/textColorSecondary" android:visibility="gone" + tools:visibility="visible" tools:text="☁️ My custom status" /> <TextView diff --git a/app/src/main/res/layout/rv_item_conversation_with_last_message.xml b/app/src/main/res/layout/rv_item_conversation_with_last_message.xml index 4f16aef4d..72da05b5d 100644 --- a/app/src/main/res/layout/rv_item_conversation_with_last_message.xml +++ b/app/src/main/res/layout/rv_item_conversation_with_last_message.xml @@ -55,24 +55,12 @@ app:tint="@color/favorite_icon_tint" app:tintMode="src_in" /> - <com.vanniktech.emoji.EmojiEditText - android:id="@+id/userStatusEmoji" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="bottom|end" - android:background="@color/transparent" - android:cursorVisible="false" - android:gravity="center" - android:text="@string/default_emoji" - android:textSize="16sp" /> - <ImageView - android:id="@+id/userStatusOnlineState" - android:layout_width="16dp" - android:layout_height="16dp" + android:id="@+id/user_status_image" + android:layout_width="18dp" + android:layout_height="18dp" android:layout_gravity="bottom|end" - android:contentDescription="@null" - android:src="@drawable/online_status"/> + android:contentDescription="@string/nc_account_chooser_active_user" /> </FrameLayout> <RelativeLayout diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 6d8a27370..2e630736f 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -68,4 +68,6 @@ <color name="list_divider_background">#222222</color> <color name="grey_200">#818181</color> + + <color name="dialog_background">#353535</color> </resources> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6e29db17a..0289c8679 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -100,4 +100,8 @@ <color name="list_divider_background">#eeeeee</color> <color name="grey_200">#EEEEEE</color> + <!-- this is just a helper for status icon background because getting the background color of a dialog is not + possible?! don't use this to set the background of dialogs --> + <color name="dialog_background">#FFFFFF</color> + </resources> |