|
@ -6,6 +6,9 @@ import org.jsoup.nodes.Document; |
|
|
import org.jsoup.nodes.Element; |
|
|
import org.jsoup.nodes.Element; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
import java.net.URLDecoder; |
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.activities.topic.TopicParser; |
|
|
import gr.thmmy.mthmmy.activities.topic.TopicParser; |
|
@ -41,18 +44,27 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> { |
|
|
@Override |
|
|
@Override |
|
|
protected TopicTaskResult doInBackground(String... strings) { |
|
|
protected TopicTaskResult doInBackground(String... strings) { |
|
|
Document topic = null; |
|
|
Document topic = null; |
|
|
|
|
|
|
|
|
String newPageUrl = strings[0]; |
|
|
String newPageUrl = strings[0]; |
|
|
|
|
|
|
|
|
|
|
|
//TODO: Perhaps decode all URLs app-wide (i.e. in BaseApplication)?
|
|
|
|
|
|
try { |
|
|
|
|
|
//Decodes e.g. any %3B to ;
|
|
|
|
|
|
newPageUrl = URLDecoder.decode(newPageUrl, StandardCharsets.UTF_8.displayName()); |
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
Timber.e(e, "Unsupported Encoding"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//Finds the index of message focus if present
|
|
|
//Finds the index of message focus if present
|
|
|
int postFocus = 0; |
|
|
int postFocus = 0; |
|
|
{ |
|
|
|
|
|
|
|
|
//TODO: Better parseInt handling - may rarely fail
|
|
|
if (newPageUrl.contains("msg")) { |
|
|
if (newPageUrl.contains("msg")) { |
|
|
String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); |
|
|
String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); |
|
|
if (tmp.contains(";")) |
|
|
if (tmp.contains(";")) |
|
|
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(";"))); |
|
|
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(';'))); |
|
|
else if (tmp.contains("#")) |
|
|
else if (tmp.contains("#")) |
|
|
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#"))); |
|
|
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf('#'))); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Request request = new Request.Builder() |
|
|
Request request = new Request.Builder() |
|
@ -120,10 +132,10 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private boolean isUnauthorized(Document document) { |
|
|
private boolean isUnauthorized(Document document) { |
|
|
return document != null && document.select("body:contains(The topic or board you" + |
|
|
return document != null && !document.select("body:contains(The topic or board you" + |
|
|
" are looking for appears to be either missing or off limits to you.)," + |
|
|
" are looking for appears to be either missing or off limits to you.)," + |
|
|
"body:contains(Το θέμα ή πίνακας που ψάχνετε ή δεν υπάρχει ή δεν " + |
|
|
"body:contains(Το θέμα ή πίνακας που ψάχνετε ή δεν υπάρχει ή δεν " + |
|
|
"είναι προσβάσιμο από εσάς.)").size() > 0; |
|
|
"είναι προσβάσιμο από εσάς.)").isEmpty(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|