Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79796845 authored by Ivan's avatar Ivan
Browse files

Fix bug with empty avatars for contacts, whose names starts with "+"

There were problem, that if you have several contacts, whose names
starts with "+", their avatars not displayed in conversations list, or
displays as white circles.
Also minor tweak for "onDraw" function
parent 6d9532ad
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;

import com.moez.QKSMS.R;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.TypefaceManager;
@@ -53,6 +54,7 @@ public class AvatarView extends ImageView implements View.OnClickListener {
    private String mInitial = "#";
    private Paint mPaint;
    private Drawable mDefaultDrawable;
    private int mYOffset;

    /**
     * When setImageDrawable is called with a drawable, we circle crop to size of this view and use
@@ -89,6 +91,8 @@ public class AvatarView extends ImageView implements View.OnClickListener {
            }
            a.recycle();

            mYOffset = (int) ((mPaint.descent() + mPaint.ascent()) / 2);

            setOnClickListener(this);

            LiveViewManager.registerView(QKPreference.THEME, this, key -> {
@@ -175,7 +179,7 @@ public class AvatarView extends ImageView implements View.OnClickListener {
            if (mOriginalDrawable == null) super.setImageDrawable(null);
        } else if (isPhoneNumberFormat(name)) {
            mInitial = "";
            super.setImageDrawable(mDefaultDrawable);
            if (mOriginalDrawable == null) super.setImageDrawable(mDefaultDrawable);
        } else {
            mInitial = "" + name.toUpperCase().charAt(0);
            if (mOriginalDrawable == null) super.setImageDrawable(null);
@@ -185,9 +189,10 @@ public class AvatarView extends ImageView implements View.OnClickListener {
    }

    private boolean isPhoneNumberFormat(String name) {
        if (TextUtils.isEmpty(name)) {
            return false;
        }
//        We already checked it in first "if" condition in "setContactName"
//        if (TextUtils.isEmpty(name)) {
//            return false;
//        }

        char c = name.charAt(0);
        return !name.contains("@") && (c == '+' || c == '(' || Character.isDigit(c));
@@ -276,7 +281,7 @@ public class AvatarView extends ImageView implements View.OnClickListener {

        if (getDrawable() == null && !isInEditMode()) {
            int xPos = (getWidth() / 2);
            int yPos = (int) ((getHeight() / 2) - ((mPaint.descent() + mPaint.ascent()) / 2));
            int yPos = (getHeight() / 2) - mYOffset;
            canvas.drawText("" + mInitial, xPos, yPos, mPaint);
        }
    }