paint single unicode hearts as red and slightly larger

This commit is contained in:
Daniel Gultsch 2015-05-10 03:12:44 +02:00
parent d9e5035c08
commit 4c486f5e58
3 changed files with 66 additions and 36 deletions

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -179,7 +180,7 @@ public class Message extends AbstractEntity {
values.put(TYPE, type); values.put(TYPE, type);
values.put(REMOTE_MSG_ID, remoteMsgId); values.put(REMOTE_MSG_ID, remoteMsgId);
values.put(RELATIVE_FILE_PATH, relativeFilePath); values.put(RELATIVE_FILE_PATH, relativeFilePath);
values.put(SERVER_MSG_ID,serverMsgId); values.put(SERVER_MSG_ID, serverMsgId);
return values; return values;
} }
@ -365,7 +366,7 @@ public class Message extends AbstractEntity {
message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_PGP &&
this.getType() == message.getType() && this.getType() == message.getType() &&
//this.getStatus() == message.getStatus() && //this.getStatus() == message.getStatus() &&
isStatusMergeable(this.getStatus(),message.getStatus()) && isStatusMergeable(this.getStatus(), message.getStatus()) &&
this.getEncryption() == message.getEncryption() && this.getEncryption() == message.getEncryption() &&
this.getCounterpart() != null && this.getCounterpart() != null &&
this.getCounterpart().equals(message.getCounterpart()) && this.getCounterpart().equals(message.getCounterpart()) &&
@ -375,13 +376,15 @@ public class Message extends AbstractEntity {
!message.bodyContainsDownloadable() && !message.bodyContainsDownloadable() &&
!this.bodyContainsDownloadable() && !this.bodyContainsDownloadable() &&
!message.getBody().startsWith(ME_COMMAND) && !message.getBody().startsWith(ME_COMMAND) &&
!this.getBody().startsWith(ME_COMMAND) !this.getBody().startsWith(ME_COMMAND) &&
!this.bodyIsHeart() &&
!message.bodyIsHeart()
); );
} }
private static boolean isStatusMergeable(int a, int b) { private static boolean isStatusMergeable(int a, int b) {
return a == b || ( return a == b || (
( a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_UNSEND) (a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_UNSEND)
|| (a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_SEND) || (a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_SEND)
|| (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND) || (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND)
|| (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND_RECEIVED) || (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND_RECEIVED)
@ -474,6 +477,11 @@ public class Message extends AbstractEntity {
} }
} }
public boolean bodyIsHeart() {
return body != null &&
(body.trim().equals(UIHelper.BLACK_HEART_SUIT) || body.trim().equals(UIHelper.HEAVY_BLACK_HEART_SUIT));
}
public ImageParams getImageParams() { public ImageParams getImageParams() {
ImageParams params = getLegacyImageParams(); ImageParams params = getLegacyImageParams();
if (params != null) { if (params != null) {

View File

@ -7,7 +7,9 @@ import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -213,6 +215,18 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setTextIsSelectable(false); viewHolder.messageBody.setTextIsSelectable(false);
} }
private void displayHeartMesage(final ViewHolder viewHolder, final String body) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
Spannable span = new SpannableString(body);
span.setSpan(new RelativeSizeSpan(4.0f),0,body.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(activity.getWarningTextColor()),0,body.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
viewHolder.messageBody.setText(span);
}
private void displayTextMessage(final ViewHolder viewHolder, final Message message) { private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
if (viewHolder.download_button != null) { if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.GONE);
@ -289,7 +303,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity,message))); viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)));
viewHolder.download_button.setOnClickListener(new OnClickListener() { viewHolder.download_button.setOnClickListener(new OnClickListener() {
@Override @Override
@ -527,10 +541,14 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else { } else {
if (GeoHelper.isGeoUri(message.getBody())) { if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder,message); displayLocationMessage(viewHolder,message);
} else {
if (message.bodyIsHeart()) {
displayHeartMesage(viewHolder," "+message.getBody().trim()+" ");
} else { } else {
displayTextMessage(viewHolder, message); displayTextMessage(viewHolder, message);
} }
} }
}
displayStatus(viewHolder, message); displayStatus(viewHolder, message);

View File

@ -17,6 +17,10 @@ import android.text.format.DateUtils;
import android.util.Pair; import android.util.Pair;
public class UIHelper { public class UIHelper {
public static String BLACK_HEART_SUIT = "\u2665";
public static String HEAVY_BLACK_HEART_SUIT = "\u2764";
private static final int SHORT_DATE_FLAGS = DateUtils.FORMAT_SHOW_DATE private static final int SHORT_DATE_FLAGS = DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL; | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL;
private static final int FULL_DATE_FLAGS = DateUtils.FORMAT_SHOW_TIME private static final int FULL_DATE_FLAGS = DateUtils.FORMAT_SHOW_TIME