Fixed an issue with Google Translate not translating a particular toot, hopefully fixes other toots that were failing, though I've ony come across one, so far.

This commit is contained in:
PhotonQyv 2017-09-06 16:53:56 +01:00
parent d26ebec568
commit a73a1b53e0
4 changed files with 278 additions and 8 deletions

View File

@ -39,6 +39,7 @@ dependencies {
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.evernote:android-job:1.1.11'
compile 'com.github.chrisbanes:PhotoView:2.0.0'
compile 'com.vdurmont:emoji-java:3.3.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'org.jsoup:jsoup:1.10.3'
safetynetCompile 'com.google.android.gms:play-services-safetynet:11.0.4'

View File

@ -2424,4 +2424,261 @@ digit_one, 0x0031
digit_zero, 0x0030
family_man_woman_boy, 0x1f468,0x1f469,0x1f466
couple_with_heart_woman_man, 0x1f469,0x2764,0x1f468
kiss_woman_man, 0x1f469,0x2764,0x1f48b,0x1f468
kiss_woman_man, 0x1f469,0x2764,0x1f48b,0x1f468
ad, 0x1f1e6,0x1f1e9
ao, 0x1f1e6,0x1f1f4
af, 0x1f1e6,0x1f1eb
ai, 0x1f1e6,0x1f1ee
aq, 0x1f1e6,0x1f1f6
ag, 0x1f1e6,0x1f1ec
al, 0x1f1e6,0x1f1f1
ar, 0x1f1e6,0x1f1f7
as, 0x1f1e6,0x1f1f8
am, 0x1f1e6,0x1f1f2
aw, 0x1f1e6,0x1f1fc
au, 0x1f1e6,0x1f1fa
at, 0x1f1e6,0x1f1f9
ax, 0x1f1e6,0x1f1fd
az, 0x1f1e6,0x1f1ff
bs, 0x1f1e7,0x1f1f8
bh, 0x1f1e7,0x1f1ed
bd, 0x1f1e7,0x1f1e9
bb, 0x1f1e7,0x1f1e7
by, 0x1f1e7,0x1f1fe
be, 0x1f1e7,0x1f1ea
bz, 0x1f1e7,0x1f1ff
bj, 0x1f1e7,0x1f1ef
bm, 0x1f1e7,0x1f1f2
bt, 0x1f1e7,0x1f1f9
bo, 0x1f1e7,0x1f1f4
ba, 0x1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6
ae, 0x1f1e6,0x1f1ea
us, 0x1f1fa,0x1f1f8
uy, 0x1f1fa,0x1f1fe
uz, 0x1f1fa,0x1f1ff
vu, 0x1f1fb,0x1f1fa
va, 0x1f1fb,0x1f1e6
ve, 0x1f1fb,0x1f1ea
vn, 0x1f1fb,0x1f1f3
wf, 0x1f1fc,0x1f1eb
eh, 0x1f1ea,0x1f1ed
ye, 0x1f1fe,0x1f1ea
zm, 0x1f1ff,0x1f1f2
zw, 0x1f1ff,0x1f1fc
ac, 0x1f1e6,0x1f1e8
ta, 0x1f1f9,0x1f1e6
bv, 0x1f1e7,0x1f1fb
hm, 0x1f1ed,0x1f1f2
sj, 0x1f1f8,0x1f1ef
um, 0x1f1fa,0x1f1f2
ea, 0x1f1ea,0x1f1e6
cp, 0x1f1e8,0x1f1f5
dg, 0x1f1e9,0x1f1ec
dz, 0x1f1e9,0x1f1ff
mf, 0x1f1f2,0x1f1eb
Can't render this file because it has a wrong number of fields in line 168.

View File

@ -55,6 +55,8 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.vdurmont.emoji.EmojiManager;
import com.vdurmont.emoji.EmojiParser;
import org.json.JSONArray;
import org.json.JSONException;
@ -90,6 +92,7 @@ import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.shortnameToUnicode;
/**
@ -382,9 +385,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
}
if (translator == Helper.TRANS_YANDEX)
new YandexQuery(StatusListAdapter.this).getYandexTextview(position, text, currentLocale);
else if( translator == Helper.TRANS_GOOGLE)
else if( translator == Helper.TRANS_GOOGLE) {
text = EmojiParser.parseToAliases(text);
new GoogleTranslateQuery(StatusListAdapter.this).getGoogleTextview(position, text, currentLocale);
}
}else {
status.setTranslationShown(!status.isTranslationShown());
statusListAdapter.notifyDataSetChanged();
@ -970,7 +974,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
if (translator == Helper.TRANS_YANDEX)
aJsonString = yandexTranslateToText(translatedResult);
else if( translator == Helper.TRANS_GOOGLE)
aJsonString = googleTranslateToText(translatedResult);
aJsonString = shortnameToUnicode(googleTranslateToText(translatedResult), true);
if( aJsonString == null)
return;
Iterator itU = urlConversion.entrySet().iterator();

View File

@ -268,7 +268,7 @@ public class Helper {
private static boolean menuAccountsOpened = false;
private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):");
private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":( |)([-+\\w]+):");
public static final Pattern urlPattern = Pattern.compile(
"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",
@ -283,18 +283,26 @@ public class Helper {
*/
public static String shortnameToUnicode(String input, boolean removeIfUnsupported) {
Matcher matcher = SHORTNAME_PATTERN.matcher(input);
boolean supported = Build.VERSION.SDK_INT >= 16;
while (matcher.find()) {
String unicode = emoji.get(matcher.group(1));
String unicode = emoji.get(matcher.group(2));
if (unicode == null) {
continue;
}
if (supported) {
input = input.replace(":" + matcher.group(1) + ":", unicode);
if (matcher.group(1).equals(" "))
input = input.replace(": " + matcher.group(2) + ":", unicode);
else
input = input.replace(":" + matcher.group(2) + ":", unicode);
} else if (removeIfUnsupported) {
input = input.replace(":" + matcher.group(1) + ":", "");
if (matcher.group(1).equals(" "))
input = input.replace(": " + matcher.group(2) + ":", unicode);
else
input = input.replace(":" + matcher.group(2) + ":", "");
}
}
return input;
}
//Emoji manager