Fix up whitespace tagging and tag detection prompt.
1) Fix up the whitespace tagging so that it's a little more strict. 2) Don't display whitespace tags that we add to our own messages. 3) Make the tag detection prompt a little more visually pleasing.pull/1/head
parent
4c3b7cbe08
commit
f39b8e5fc8
@ -0,0 +1,36 @@
|
|||||||
|
package org.thoughtcrime.securesms.protocol;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||||
|
|
||||||
|
public class Tag {
|
||||||
|
|
||||||
|
public static final String WHITESPACE_TAG = " ";
|
||||||
|
|
||||||
|
public static boolean isTaggable(Context context, String message) {
|
||||||
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
|
return sp.getBoolean(ApplicationPreferencesActivity.WHITESPACE_PREF, true) &&
|
||||||
|
message.matches(".*[^\\s].*") &&
|
||||||
|
message.replaceAll("\\s+$", "").length() + WHITESPACE_TAG.length() <= 158;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTagged(String message) {
|
||||||
|
return message.matches(".*[^\\s]" + WHITESPACE_TAG + "$");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTaggedMessage(String message) {
|
||||||
|
return message.replaceAll("\\s+$", "") + WHITESPACE_TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String stripTag(String message) {
|
||||||
|
if (isTagged(message))
|
||||||
|
return message.substring(0, message.length() - WHITESPACE_TAG.length());
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue