diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 247365c8..38181f46 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -57,6 +57,7 @@ import timber.log.Timber; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; +import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml; /** * Activity for user profile. When creating an Intent of this activity you need to bundle a String @@ -273,7 +274,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment { //Finds personal text Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); if (tmpEl != null) { - personalText = tmpEl.text().trim(); + personalText = emojiTagToHtml(tmpEl.text().trim()); } else { //Should never get here! //Something is wrong. diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 12e93a60..2d4ba9bf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -144,7 +144,7 @@ public class SummaryFragment extends Fragment { || summaryRow.text().contains("Κατάσταση")) continue; else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { //This needs special handling since it may have css - pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow); + pHtml = ParseHelpers.emojiTagToHtml(ParseHelpers.youtubeEmbeddedFix(summaryRow)); //Add stuff to make it work in WebView //style.css pHtml = ("\n" + diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 976ff387..df79d093 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -7,6 +7,7 @@ import org.jsoup.nodes.TextNode; import org.jsoup.select.Elements; import java.util.ArrayList; +import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -194,7 +195,7 @@ public class ParseHelpers { * @param html html to parse * @return a document with deobfuscated emails */ - public static Document parse(String html){ + public static Document parse(String html) { Document document = Jsoup.parse(html); deobfuscateElements(document.select("span.__cf_email__,a.__cf_email__"), true); return document; @@ -203,19 +204,18 @@ public class ParseHelpers { /** * Use this method instead of parse() if you are targeting specific elements */ - public static void deobfuscateElements(Elements elements, boolean found){ - if(!found) + public static void deobfuscateElements(Elements elements, boolean found) { + if (!found) elements = elements.select("span.__cf_email__,a.__cf_email__"); for (Element obfuscatedElement : elements) { String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); - if(obfuscatedElement.is("span")){ + if (obfuscatedElement.is("span")) { Element parent = obfuscatedElement.parent(); - if (parent.is("a")&&parent.attr("href").contains("email-protection")) - parent.attr("href", "mailto:"+deobfuscatedEmail); - } - else if (obfuscatedElement.attr("href").contains("email-protection")) - obfuscatedElement.attr("href", "mailto:"+deobfuscatedEmail); + if (parent.is("a") && parent.attr("href").contains("email-protection")) + parent.attr("href", "mailto:" + deobfuscatedEmail); + } else if (obfuscatedElement.attr("href").contains("email-protection")) + obfuscatedElement.attr("href", "mailto:" + deobfuscatedEmail); obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); } @@ -226,7 +226,7 @@ public class ParseHelpers { * @param obfuscatedEmail CloudFlare-obfuscated email * @return deobfuscated email */ - private static String deobfuscateEmail(String obfuscatedEmail){ + private static String deobfuscateEmail(String obfuscatedEmail) { //Deobfuscate final StringBuilder stringBuilder = new StringBuilder(); final int r = Integer.parseInt(obfuscatedEmail.substring(0, 2), 16); @@ -238,4 +238,137 @@ public class ParseHelpers { Timber.i("Email deobfuscated."); return stringBuilder.toString(); } + + public static String emojiTagToHtml(String emojiTagedString) { + HashMap tagToHtmlMap = new HashMap<>(); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":)"), Pattern.MULTILINE), "\"Smiley\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(";)"), Pattern.MULTILINE), "\"Wink\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":D"), Pattern.MULTILINE), "\"Cheesy\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(";D"), Pattern.MULTILINE), "\"Grin\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(">:("), Pattern.MULTILINE), "\"Angry\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":("), Pattern.MULTILINE), "\"Sad\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":o"), Pattern.MULTILINE), "\"Shocked\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("8))"), Pattern.MULTILINE), "\"Cool\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":???:"), Pattern.MULTILINE), "\"Huh\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":P"), Pattern.MULTILINE), "\"Tongue\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":-["), Pattern.MULTILINE), "\"Embarrassed\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":-X"), Pattern.MULTILINE), "\"Lips"); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":-\\"), Pattern.MULTILINE), "\"Undecided\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":-*"), Pattern.MULTILINE), "\"Kiss\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":'("), Pattern.MULTILINE), "\"Cry\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("<3"), Pattern.MULTILINE), "\"heart\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^locked^"), Pattern.MULTILINE), "\"kleidaria\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^rollover^"), Pattern.MULTILINE), "\"roll_over\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^redface^"), Pattern.MULTILINE), "\"redface\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^confused^"), Pattern.MULTILINE), "\"confused\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^innocent^"), Pattern.MULTILINE), "\"innocent\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^sleep^"), Pattern.MULTILINE), "\"sleep\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^sealed^"), Pattern.MULTILINE), "\"lips_sealed\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^cool^"), Pattern.MULTILINE), "\"cool\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^crazy^"), Pattern.MULTILINE), "\"crazy\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^mad^"), Pattern.MULTILINE), "\"mad\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^wav^"), Pattern.MULTILINE), "\"wav\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^binkybaby^"), Pattern.MULTILINE), "\"BinkyBaby\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^Police^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^dontknow^"), Pattern.MULTILINE), "\"DontKnow\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote(":angry4:"), Pattern.MULTILINE), "\"angry4\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^angryhot^"), Pattern.MULTILINE), "\"angryAndHot\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^angry^"), Pattern.MULTILINE), "\"angry\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^fouska^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^nysta^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^sfinaki^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^banghead^"), Pattern.MULTILINE), "\"bang_head\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^crybaby^"), Pattern.MULTILINE), "\"CryBaby\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^hello^"), Pattern.MULTILINE), "\"Hello\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^jerk^"), Pattern.MULTILINE), "\"jerk\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^nono^"), Pattern.MULTILINE), "\"NoNo\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^notworthy^"), Pattern.MULTILINE), "\"NotWorthy\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^off-topic^"), Pattern.MULTILINE), "\"Off-topic\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^puke^"), Pattern.MULTILINE), "\"Puke\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^shout^"), Pattern.MULTILINE), "\"Shout\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^slurp^"), Pattern.MULTILINE), "\"Slurp\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^superconfused^"), Pattern.MULTILINE), "\"SuperConfused\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^superinnocent^"), Pattern.MULTILINE), "\"SuperInnocent\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^cellPhone^"), Pattern.MULTILINE), "\"CellPhone\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^idiot^"), Pattern.MULTILINE), "\"Idiot\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^knuppel^"), Pattern.MULTILINE), "\"Knuppel\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^tickedOff^"), Pattern.MULTILINE), "\"TickedOff\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^peace^"), Pattern.MULTILINE), "\"Peace\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^suspicious^"), Pattern.MULTILINE), "\"Suspicious\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^caffine^"), Pattern.MULTILINE), "\"Caffine\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^argue^"), Pattern.MULTILINE), "\"argue\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^banned2^"), Pattern.MULTILINE), "\"banned2\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^banned^"), Pattern.MULTILINE), "\"banned\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^bath^"), Pattern.MULTILINE), "\"bath\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^beg^"), Pattern.MULTILINE), "\"beg\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^bluescreen^"), Pattern.MULTILINE), "\"bluescreen\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^boil^"), Pattern.MULTILINE), "\"boil\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^bye^"), Pattern.MULTILINE), "\"bye\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^callmerip^"), Pattern.MULTILINE), "\"callmerip\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^carnaval^"), Pattern.MULTILINE), "\"carnaval\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^clap^"), Pattern.MULTILINE), "\"clap\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^coffepot^"), Pattern.MULTILINE), "\"coffepot\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^crap^"), Pattern.MULTILINE), "\"crap\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^curses^"), Pattern.MULTILINE), "\"curses\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^funny^"), Pattern.MULTILINE), "\"funny\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^guitar^"), Pattern.MULTILINE), "\"guitar\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^kissy^"), Pattern.MULTILINE), "\"kissy\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^band^"), Pattern.MULTILINE), "\"band\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^ivres^"), Pattern.MULTILINE), "\"ivres\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^kaloe^"), Pattern.MULTILINE), "\"kaloe\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^kremala^"), Pattern.MULTILINE), "\"kremala\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^moon^"), Pattern.MULTILINE), "\"moon\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^mopping^"), Pattern.MULTILINE), "\"mopping\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^mountza^"), Pattern.MULTILINE), "\"mountza\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^pcsleep^"), Pattern.MULTILINE), "\"pcsleep\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^pinokio^"), Pattern.MULTILINE), "\"pinokio\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^poke^"), Pattern.MULTILINE), "\"poke\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^seestars^"), Pattern.MULTILINE), "\"seestars\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^sfyri^"), Pattern.MULTILINE), "\"sfyri\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^spam^"), Pattern.MULTILINE), "\"spam\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^super^"), Pattern.MULTILINE), "\"super\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^tafos^"), Pattern.MULTILINE), "\"tafos\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^tomato^"), Pattern.MULTILINE), "\"tomato\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^ytold^"), Pattern.MULTILINE), "\"ytold\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^beer^"), Pattern.MULTILINE), "\"beer\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^yue^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^eatpaper^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^fritz^"), Pattern.MULTILINE), "\"ο"); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^wade^"), Pattern.MULTILINE), "\"o"); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^lypi^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^aytoxeir^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^victory^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^filarakia^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^hat^"), Pattern.MULTILINE), "\"bonjour\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^miss^"), Pattern.MULTILINE), "\"bonjour2\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^rolfmao^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^lock^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^que^"), Pattern.MULTILINE), "\"question\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^shifty^"), Pattern.MULTILINE), "\"shifty\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^shy^"), Pattern.MULTILINE), "\"shy\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^music_listen^"), Pattern.MULTILINE), "\"music_listenning\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^bagface^"), Pattern.MULTILINE), "\"bag_face\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^rotate^"), Pattern.MULTILINE), "\"rotation\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^love^"), Pattern.MULTILINE), "\"love\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^speech^"), Pattern.MULTILINE), "\"speech\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^facepalm^"), Pattern.MULTILINE), "\"\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^shocked^"), Pattern.MULTILINE), "\"shocked\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^ex_shocked^"), Pattern.MULTILINE), "\"extremely_shocked\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^smurf^"), Pattern.MULTILINE), "\"smurf\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^monster^"), Pattern.MULTILINE), "\"monster\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^pig^"), Pattern.MULTILINE), "\"pig\""); + tagToHtmlMap.put(Pattern.compile(Pattern.quote("^lol^"), Pattern.MULTILINE), "\"lol\""); + + //Needs priority over the rest tags + final Pattern pattern = Pattern.compile(Pattern.quote("::)"), Pattern.MULTILINE); + Matcher matcher = pattern.matcher(emojiTagedString); + emojiTagedString = matcher.replaceAll("\"Roll"); + + for (Pattern patternKey : tagToHtmlMap.keySet()) { + matcher = patternKey.matcher(emojiTagedString); + emojiTagedString = matcher.replaceAll(tagToHtmlMap.get(patternKey)); + } + + return emojiTagedString; + } }