Browse Source

TopicTask crash fix

pull/70/head
Ezerous 5 years ago
parent
commit
6bd29c9dc7
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 17
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -1,7 +1,5 @@
package gr.thmmy.mthmmy.activities.profile; package gr.thmmy.mthmmy.activities.profile;
import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;

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

@ -11,6 +11,9 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.activities.topic.TopicParser; import gr.thmmy.mthmmy.activities.topic.TopicParser;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
@ -29,6 +32,8 @@ import timber.log.Timber;
* parameter.</p> * parameter.</p>
*/ */
public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> { public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
private static final Pattern msgPattern = Pattern.compile("msg(\\d+)");
private TopicTaskObserver topicTaskObserver; private TopicTaskObserver topicTaskObserver;
private OnTopicTaskCompleted finishListener; private OnTopicTaskCompleted finishListener;
@ -58,15 +63,9 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
//Finds the index of message focus if present //Finds the index of message focus if present
int postFocus = 0; int postFocus = 0;
Matcher matcher = msgPattern.matcher(newPageUrl);
//TODO: Better parseInt handling - may rarely fail if (matcher.find())
if (newPageUrl.contains("msg")) { postFocus = Integer.parseInt(Objects.requireNonNull(matcher.group(1)));
String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3);
if (tmp.contains(";"))
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(';')));
else if (tmp.contains("#"))
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf('#')));
}
Request request = new Request.Builder() Request request = new Request.Builder()
.url(newPageUrl) .url(newPageUrl)

Loading…
Cancel
Save