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;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
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.nio.charset.StandardCharsets;
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.base.BaseApplication;
@ -29,6 +32,8 @@ import timber.log.Timber;
* parameter.</p>
*/
public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
private static final Pattern msgPattern = Pattern.compile("msg(\\d+)");
private TopicTaskObserver topicTaskObserver;
private OnTopicTaskCompleted finishListener;
@ -58,15 +63,9 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
//Finds the index of message focus if present
int postFocus = 0;
//TODO: Better parseInt handling - may rarely fail
if (newPageUrl.contains("msg")) {
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('#')));
}
Matcher matcher = msgPattern.matcher(newPageUrl);
if (matcher.find())
postFocus = Integer.parseInt(Objects.requireNonNull(matcher.group(1)));
Request request = new Request.Builder()
.url(newPageUrl)

Loading…
Cancel
Save