diff options
Diffstat (limited to '')
5 files changed, 83 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java index 55dd6d65f..d61510611 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java @@ -32,6 +32,7 @@ import de.pixart.messenger.entities.Transferable; import de.pixart.messenger.ui.ConversationFragment; import de.pixart.messenger.ui.XmppActivity; import de.pixart.messenger.ui.util.StyledAttributes; +import de.pixart.messenger.ui.widget.FailedCountCustomView; import de.pixart.messenger.ui.widget.UnreadCountCustomView; import de.pixart.messenger.utils.EmojiWrapper; import de.pixart.messenger.utils.IrregularUnicodeDetector; @@ -125,7 +126,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte } if (failedCount > 0) { viewHolder.failedCount.setVisibility(View.VISIBLE); - viewHolder.failedCount.setUnreadCount(failedCount); + viewHolder.failedCount.setFailedCount(failedCount); } else { viewHolder.failedCount.setVisibility(View.GONE); } @@ -356,7 +357,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte private TextView sender; private ImageView notificationIcon; private UnreadCountCustomView unreadCount; - private UnreadCountCustomView failedCount; + private FailedCountCustomView failedCount; private ImageView receivedStatus; private ImageView readStatus; private ImageView avatar; diff --git a/src/main/java/de/pixart/messenger/ui/widget/FailedCountCustomView.java b/src/main/java/de/pixart/messenger/ui/widget/FailedCountCustomView.java new file mode 100644 index 000000000..261ace3a4 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/widget/FailedCountCustomView.java @@ -0,0 +1,76 @@ +package de.pixart.messenger.ui.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Typeface; +import android.support.v4.content.ContextCompat; +import android.util.AttributeSet; +import android.view.View; + +import de.pixart.messenger.R; + +public class FailedCountCustomView extends View { + + private int count; + private Paint paint, textPaint; + private int backgroundColor = 0xffd50000; + + public FailedCountCustomView(Context context) { + super(context); + init(); + } + + public FailedCountCustomView(Context context, AttributeSet attrs) { + super(context, attrs); + initXMLAttrs(context, attrs); + init(); + } + + public FailedCountCustomView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initXMLAttrs(context, attrs); + init(); + } + + private void initXMLAttrs(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnreadCountCustomView); + //setBackgroundColor(a.getColor(a.getIndex(0), ContextCompat.getColor(context, R.color.accent))); + setBackgroundColor(ContextCompat.getColor(context, R.color.red700)); + a.recycle(); + } + + void init() { + paint = new Paint(); + paint.setColor(backgroundColor); + paint.setAntiAlias(true); + textPaint = new Paint(); + textPaint.setColor(Color.WHITE); + textPaint.setTextAlign(Paint.Align.CENTER); + textPaint.setAntiAlias(true); + textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + float midx = canvas.getWidth() / 2.0f; + float midy = canvas.getHeight() / 2.0f; + float radius = Math.min(canvas.getWidth(), canvas.getHeight()) / 2.0f; + float textOffset = canvas.getWidth() / 6.0f; + textPaint.setTextSize(0.95f * radius); + canvas.drawCircle(midx, midy, radius * 0.94f, paint); + canvas.drawText(count > 999 ? "\u221E" : String.valueOf(count), midx, midy + textOffset, textPaint); + } + + public void setFailedCount(int count) { + this.count = count; + invalidate(); + } + + public void setBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + } +} diff --git a/src/main/res/layout/conversation_list_row.xml b/src/main/res/layout/conversation_list_row.xml index 3e3bef6c9..ed0e9e1cc 100644 --- a/src/main/res/layout/conversation_list_row.xml +++ b/src/main/res/layout/conversation_list_row.xml @@ -146,7 +146,7 @@ android:visibility="gone" app:backgroundColor="?attr/colorAccent" /> - <de.pixart.messenger.ui.widget.UnreadCountCustomView + <de.pixart.messenger.ui.widget.FailedCountCustomView android:id="@+id/conversation_failed" android:layout_width="?attr/IconSize" android:layout_height="?attr/IconSize" diff --git a/src/main/res/values/colors.xml b/src/main/res/values/colors.xml index 6ea10548f..8dfec1519 100644 --- a/src/main/res/values/colors.xml +++ b/src/main/res/values/colors.xml @@ -27,7 +27,7 @@ <color name="grey900">#ff282828</color> <color name="red800">#ffc62828</color> <color name="red500">#fff44336</color> - <color name="red_a700">#ffd50000</color> + <color name="red700">#ffd50000</color> <color name="orange500">#ffff9800</color> <color name="bubble">#ff2e4272</color> <color name="realwhite">#ffffffff</color> diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 96a179311..8abbbd1e9 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -13,7 +13,7 @@ <item name="color_background_primary">@color/grey50</item> <item name="color_background_secondary">@color/grey200</item> <item name="color_background_tertiary">@color/grey300</item> - <item name="color_warning">@color/red_a700</item> + <item name="color_warning">@color/red700</item> <item name="TextColorOnline">@color/green500</item> <item name="TextColorError">@color/red800</item> @@ -166,7 +166,7 @@ <item name="color_background_primary">@color/grey700</item> <item name="color_background_secondary">@color/grey800</item> <item name="color_background_tertiary">@color/grey900</item> - <item name="color_warning">@color/red_a700</item> + <item name="color_warning">@color/red700</item> <item name="TextColorOnline">@color/green500</item> <item name="TextColorError">@color/red500</item> |