From 438ec314595631e90fc8ae54d3d0585d534ea0d5 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 12 Nov 2018 00:35:35 +0200 Subject: [PATCH] Voting chart & email deobfuscation improvements --- .../mthmmy/activities/topic/TopicAdapter.java | 4 +++- .../activities/topic/tasks/TopicTask.java | 6 ++---- .../activities/topic/tasks/TopicTaskResult.java | 8 ++++---- .../mthmmy/utils/parsing/ParseHelpers.java | 17 +++++++++++------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 577b272f..cbf6f9d4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -184,7 +184,7 @@ class TopicAdapter extends RecyclerView.Adapter { }); holder.submitButton.setVisibility(View.VISIBLE); // put a warning instead of a question - holder.question.setText("This topic contains a poll that is not supported in mthmmy"); + holder.question.setText("This topic contains a poll that is not supported in mTHMMY"); return; } @@ -788,6 +788,8 @@ class TopicAdapter extends RecyclerView.Adapter { hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); errorTextview = itemView.findViewById(R.id.error_too_many_checked); voteChart = itemView.findViewById(R.id.vote_chart); + voteChart.setScaleEnabled(false); + voteChart.setTouchEnabled(false); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java index b711698a..a4aeef61 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java @@ -77,14 +77,12 @@ public class TopicTask extends AsyncTask { //Finds topic title if missing String topicTitle = topic.select("td[id=top_subject]").first().text(); - if (topicTitle.contains("Topic:")) { + if (topicTitle.contains("Topic:")) topicTitle = topicTitle.substring(topicTitle.indexOf("Topic:") + 7 , topicTitle.indexOf("(Read") - 2); - } else { + else topicTitle = topicTitle.substring(topicTitle.indexOf("Θέμα:") + 6 , topicTitle.indexOf("(Αναγνώστηκε") - 2); - Timber.d("Parsed title: %s", topicTitle); - } //Finds current page's index int currentPageIndex = TopicParser.parseCurrentPageIndex(topic, language); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java index 9381ada8..89d5cb5c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java @@ -37,10 +37,10 @@ public class TopicTaskResult { private final String topicTreeAndMods; private final String topicViewers; - public TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, - String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, - int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, - String topicViewers) { + TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, + String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, + int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, + String topicViewers) { this.resultCode = resultCode; this.topicTitle = topicTitle; this.replyPageUrl = replyPageUrl; 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 022d9896..fe5d2ac3 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 @@ -200,22 +200,27 @@ public class ParseHelpers { */ public static Document parse(String html){ Document document = Jsoup.parse(html); - deobfuscateElements(document.select("span.__cf_email__"), true); + deobfuscateElements(document.select("span.__cf_email__,a.__cf_email__"), true); return document; } /** - * Use this method instead of parse() if you are targetting specific elements + * Use this method instead of parse() if you are targeting specific elements */ public static void deobfuscateElements(Elements elements, boolean found){ if(!found) - elements = elements.select("span.__cf_email__"); + elements = elements.select("span.__cf_email__,a.__cf_email__"); for (Element obfuscatedElement : elements) { String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); - Element parent = obfuscatedElement.parent(); - if (parent.is("a")&&parent.attr("href").contains("email-protection")) - parent.attr("href", "mailto:"+deobfuscatedEmail); + 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); + obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); } }