mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 08:18:25 +00:00
Improve generated contact photos with emoji names
Improve the logic for generating contact photos with contact names which start with emoji or non-language characters. This fixes the infamous "question-mark-in-a-box" character from appearing in the contact photo for contacts whose names begin with an emoji or a non-language symbol. Closes #3684
This commit is contained in:
parent
b4e28e219b
commit
67415a8dcb
@ -4,9 +4,9 @@ import android.content.Context;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
@ -33,11 +33,21 @@ public class GeneratedContactPhoto implements ContactPhoto {
|
|||||||
.height(targetSize)
|
.height(targetSize)
|
||||||
.textColor(inverted ? color : Color.WHITE)
|
.textColor(inverted ? color : Color.WHITE)
|
||||||
.endConfig()
|
.endConfig()
|
||||||
.buildRound(String.valueOf(name.charAt(0)), inverted ? Color.WHITE : color);
|
.buildRound(getCharacter(name), inverted ? Color.WHITE : color);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCharacter(String name) {
|
||||||
|
String cleanedName = name.replaceFirst("[^\\p{L}\\p{Nd}\\p{P}\\p{S}]+", "");
|
||||||
|
|
||||||
|
if (cleanedName.isEmpty()) {
|
||||||
|
return "#";
|
||||||
|
} else {
|
||||||
|
return String.valueOf(cleanedName.charAt(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asCallCard(Context context) {
|
public Drawable asCallCard(Context context) {
|
||||||
return context.getResources().getDrawable(R.drawable.ic_contact_picture);
|
return ContextCompat.getDrawable(context, R.drawable.ic_contact_picture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user