Adds blacklisted words (ie: starting with %) -> TODO: make this special char configurable

This commit is contained in:
stom79 2017-10-31 11:43:49 +01:00
parent 939c10f30a
commit 1ced1f25d9
2 changed files with 22 additions and 0 deletions

View File

@ -128,6 +128,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private HashMap<String, String> urlConversion;
private HashMap<String, String> tagConversion;
private HashMap<String, String> mentionConversion;
private HashMap<String, String> blacklistConversion;
private final int DISPLAYED_STATUS = 1;
private List<Status> pins;
private int conversationPosition;
@ -934,6 +935,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
tagConversion = new HashMap<>();
mentionConversion = new HashMap<>();
urlConversion = new HashMap<>();
blacklistConversion = new HashMap<>();
Matcher matcher;
//Extracts urls
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
@ -982,6 +984,19 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
i++;
}
i = 0;
//Same for blacklisted words (ie: starting with %) with __b0__, __b1__, etc.
matcher = Helper.blacklistPattern.matcher(text);
while (matcher.find()){
String key = "__b" + String.valueOf(i) + "__";
String value = matcher.group(0);
blacklistConversion.put(key, value);
if( value != null) {
blacklistConversion.put(key, value);
text = text.replace(value, key);
}
i++;
}
if (translator == Helper.TRANS_YANDEX)
new YandexQuery(StatusListAdapter.this).getYandexTextview(status, text, currentLocale);
else if( translator == Helper.TRANS_GOOGLE) {
@ -1494,6 +1509,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
aJsonString = aJsonString.replace(pair.getKey().toString(), pair.getValue().toString());
itM.remove();
}
Iterator itB = blacklistConversion.entrySet().iterator();
while (itB.hasNext()) {
Map.Entry pair = (Map.Entry)itB.next();
aJsonString = aJsonString.replace(pair.getKey().toString(), pair.getValue().toString());
itB.remove();
}
status.setTranslated(true);
status.setTranslationShown(true);
status.setContent_translated(aJsonString);

View File

@ -279,6 +279,7 @@ public class Helper {
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_À-ú-]+)");
public static final Pattern mentionPattern = Pattern.compile("([\\w]*@[\\w]+)");
public static final Pattern blacklistPattern = Pattern.compile("(%[\\w_À-ú-]+)");
/**
* Converts emojis in input to unicode
* @param input String