aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/utils/UIHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/utils/UIHelper.java')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UIHelper.java59
1 files changed, 43 insertions, 16 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
index 6ca5370a..e3ee0027 100644
--- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
@@ -5,16 +5,18 @@ import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.util.Pair;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import de.thedevstack.conversationsplus.ConversationsPlusColors;
+
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
-import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.entities.Transferable;
@@ -22,12 +24,6 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class UIHelper {
- private static String BLACK_HEART_SUIT = "\u2665";
- private static String HEAVY_BLACK_HEART_SUIT = "\u2764";
- private static String WHITE_HEART_SUIT = "\u2661";
-
- public static final ArrayList<String> HEARTS = new ArrayList<>(Arrays.asList(BLACK_HEART_SUIT,HEAVY_BLACK_HEART_SUIT,WHITE_HEART_SUIT));
-
private static final ArrayList<String> LOCATION_QUESTIONS = new ArrayList<>(Arrays.asList(
"where are you", //en
"where are you now", //en
@@ -184,9 +180,8 @@ public class UIHelper {
return new Pair<>(getFileDescriptionString(context,message),true);
}
} else {
- if (message.getBody().startsWith(Message.ME_COMMAND)) {
- return new Pair<>(message.getBody().replaceAll("^" + Message.ME_COMMAND,
- UIHelper.getMessageDisplayName(message) + " "), false);
+ if (message.hasMeCommand()) {
+ return new Pair<>(message.getBodyReplacedMeCommand(UIHelper.getMessageDisplayName(message)), false);
} else if (GeoHelper.isGeoUri(message.getBody())) {
if (message.getStatus() == Message.STATUS_RECEIVED) {
return new Pair<>(context.getString(R.string.received_location), true);
@@ -197,7 +192,7 @@ public class UIHelper {
return new Pair<>(context.getString(R.string.x_file_offered_for_download,
getFileDescriptionString(context,message)),true);
} else{
- return new Pair<>(message.getBody().trim(), false);
+ return new Pair<>(message.getBody(), false);
}
}
}
@@ -222,7 +217,7 @@ public class UIHelper {
} else if (mime.contains("vcard")) {
return context.getString(R.string.vcard) ;
} else {
- return mime;
+ return message.getRelativeFilePath();
}
}
@@ -249,13 +244,29 @@ public class UIHelper {
}
}
- public static String getDisplayedMucCounterpart(final Jid counterpart) {
+ public static int getStatusColor(Presence.Status status) {
+ switch (status) {
+ case ONLINE:
+ return ConversationsPlusColors.online();
+ case CHAT:
+ return ConversationsPlusColors.chat();
+ case AWAY:
+ return ConversationsPlusColors.away();
+ case XA:
+ return ConversationsPlusColors.xa();
+ case DND:
+ return ConversationsPlusColors.dnd();
+ }
+ return ConversationsPlusColors.offline();
+ }
+
+ private static String getDisplayedMucCounterpart(final Jid counterpart) {
if (counterpart==null) {
return "";
} else if (!counterpart.isBareJid()) {
- return counterpart.getResourcepart().trim();
+ return counterpart.getResourcepart();
} else {
- return counterpart.toString().trim();
+ return counterpart.toString();
}
}
@@ -265,7 +276,7 @@ public class UIHelper {
|| message.getType() != Message.TYPE_TEXT) {
return false;
}
- String body = message.getBody() == null ? null : message.getBody().trim().toLowerCase(Locale.getDefault());
+ String body = message.getBody() == null ? null : message.getBody().toLowerCase(Locale.getDefault());
body = body.replace("?","").replace("¿","");
return LOCATION_QUESTIONS.contains(body);
}
@@ -284,4 +295,20 @@ public class UIHelper {
return new ListItem.Tag(context.getString(R.string.presence_online), 0xff259b24);
}
}
+
+ public static String getHumanReadableFileSize(long filesize) {
+ if (0 > filesize) {
+ return "?";
+ }
+ double size = Double.valueOf(filesize);
+ String[] sizes = {" bytes", " Kb", " Mb", " Gb", " Tb"};
+ int i = 0;
+ while (1023 < size) {
+ size /= 1024d;
+ ++i;
+ }
+ BigDecimal readableSize = new BigDecimal(size);
+ readableSize = readableSize.setScale(2, BigDecimal.ROUND_HALF_UP);
+ return readableSize.doubleValue() + sizes[i];
+ }
}