Browse Source

Voting chart & email deobfuscation improvements

pull/61/merge
Ezerous 6 years ago
parent
commit
438ec31459
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java
  4. 11
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

4
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -184,7 +184,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
holder.submitButton.setVisibility(View.VISIBLE); holder.submitButton.setVisibility(View.VISIBLE);
// put a warning instead of a question // 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; return;
} }
@ -788,6 +788,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button); hidePollResultsButton = itemView.findViewById(R.id.show_poll_options_button);
errorTextview = itemView.findViewById(R.id.error_too_many_checked); errorTextview = itemView.findViewById(R.id.error_too_many_checked);
voteChart = itemView.findViewById(R.id.vote_chart); voteChart = itemView.findViewById(R.id.vote_chart);
voteChart.setScaleEnabled(false);
voteChart.setTouchEnabled(false);
} }
} }

6
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java

@ -77,14 +77,12 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
//Finds topic title if missing //Finds topic title if missing
String topicTitle = topic.select("td[id=top_subject]").first().text(); 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 = topicTitle.substring(topicTitle.indexOf("Topic:") + 7
, topicTitle.indexOf("(Read") - 2); , topicTitle.indexOf("(Read") - 2);
} else { else
topicTitle = topicTitle.substring(topicTitle.indexOf("Θέμα:") + 6 topicTitle = topicTitle.substring(topicTitle.indexOf("Θέμα:") + 6
, topicTitle.indexOf("(Αναγνώστηκε") - 2); , topicTitle.indexOf("(Αναγνώστηκε") - 2);
Timber.d("Parsed title: %s", topicTitle);
}
//Finds current page's index //Finds current page's index
int currentPageIndex = TopicParser.parseCurrentPageIndex(topic, language); int currentPageIndex = TopicParser.parseCurrentPageIndex(topic, language);

2
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java

@ -37,7 +37,7 @@ public class TopicTaskResult {
private final String topicTreeAndMods; private final String topicTreeAndMods;
private final String topicViewers; private final String topicViewers;
public TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle,
String replyPageUrl, ArrayList<TopicItem> newPostsList, int loadedPageTopicId, String replyPageUrl, ArrayList<TopicItem> newPostsList, int loadedPageTopicId,
int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods,
String topicViewers) { String topicViewers) {

11
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

@ -200,22 +200,27 @@ public class ParseHelpers {
*/ */
public static Document parse(String html){ public static Document parse(String html){
Document document = Jsoup.parse(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; 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){ public static void deobfuscateElements(Elements elements, boolean found){
if(!found) if(!found)
elements = elements.select("span.__cf_email__"); elements = elements.select("span.__cf_email__,a.__cf_email__");
for (Element obfuscatedElement : elements) { for (Element obfuscatedElement : elements) {
String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail"));
if(obfuscatedElement.is("span")){
Element parent = obfuscatedElement.parent(); Element parent = obfuscatedElement.parent();
if (parent.is("a")&&parent.attr("href").contains("email-protection")) if (parent.is("a")&&parent.attr("href").contains("email-protection"))
parent.attr("href", "mailto:"+deobfuscatedEmail); parent.attr("href", "mailto:"+deobfuscatedEmail);
}
else if (obfuscatedElement.attr("href").contains("email-protection"))
obfuscatedElement.attr("href", "mailto:"+deobfuscatedEmail);
obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, ""));
} }
} }

Loading…
Cancel
Save