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 3ff3cc7a..e233ae1c 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
@@ -28,67 +28,12 @@ import timber.log.Timber;
* parameter.
*/
public class TopicTask extends AsyncTask {
- //----------------------------input data-----------------------------
private TopicTaskObserver topicTaskObserver;
private OnTopicTaskCompleted finishListener;
- //-----------------------------output data----------------------------
- private ResultCode resultCode;
- /**
- * Holds this topic's title. At first this gets the value of the topic title that came with
- * bundle and is rendered in the toolbar while parsing this topic. Later, if a different topic
- * title is parsed from the html source, it gets updated.
- */
- private String topicTitle;
- /**
- * This topic's reply url
- */
- private String replyPageUrl;
- //Topic's info related
- private String topicTreeAndMods;
- private String topicViewers;
-
- private ArrayList newPostsList;
- /**
- * The topicId of the loaded page
- */
- private int loadedPageTopicId = -1;
- /**
- * The index of the post that has focus
- */
- private int focusedPostIndex = 0;
- /**
- * A list of the requested topic's pages urls
- */
- private SparseArray pagesUrls = new SparseArray<>();
- //-------------------------------------(possibly) update data------------------------------
- /**
- * Holds current page's index (starting from 1, not 0)
- */
- private int currentPageIndex;
- /**
- * Holds the requested topic's number of pages
- */
- private int pageCount;
- /**
- * Holds this topic's base url. For example a topic with url similar to
- * "https://www.thmmy.gr/smf/index.php?topic=1.15;topicseen" or
- * "https://www.thmmy.gr/smf/index.php?topic=1.msg1#msg1"
- * has the base url "https://www.thmmy.gr/smf/index.php?topic=1"
- */
- private String baseUrl;
- /**
- * The url of the last page that was attempted to be loaded
- */
- private String lastPageLoadAttemptedUrl;
-
- // first load or reload constructor
+
public TopicTask(TopicTaskObserver topicTaskObserver, OnTopicTaskCompleted finishListener) {
this.topicTaskObserver = topicTaskObserver;
this.finishListener = finishListener;
- this.baseUrl = "";
- this.currentPageIndex = 1;
- this.pageCount = 1;
- this.lastPageLoadAttemptedUrl = "";
}
@Override
@@ -98,6 +43,18 @@ public class TopicTask extends AsyncTask {
@Override
protected TopicTaskResult doInBackground(String... strings) {
+ String topicTitle = null;
+ String topicTreeAndMods = "";
+ String topicViewers = "";
+ ArrayList newPostsList = null;
+ int loadedPageTopicId = -1;
+ int focusedPostIndex = 0;
+ SparseArray pagesUrls = new SparseArray<>();
+ int currentPageIndex = 1;
+ int pageCount = 1;
+ String baseUrl = "";
+ String lastPageLoadAttemptedUrl = "";
+
Document topic = null;
String newPageUrl = strings[0];
@@ -112,15 +69,15 @@ public class TopicTask extends AsyncTask {
postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#")));
}
}
- if (!Objects.equals(lastPageLoadAttemptedUrl, "")) topicTitle = null;
lastPageLoadAttemptedUrl = newPageUrl;
if (strings[0].substring(0, strings[0].lastIndexOf(".")).contains("topic="))
baseUrl = strings[0].substring(0, strings[0].lastIndexOf(".")); //New topic's base url
- replyPageUrl = null;
+ String replyPageUrl = null;
Request request = new Request.Builder()
.url(newPageUrl)
.build();
+ ResultCode resultCode;
try {
Response response = BaseApplication.getInstance().getClient().newCall(request).execute();
topic = Jsoup.parse(response.body().string());
@@ -175,10 +132,12 @@ public class TopicTask extends AsyncTask {
Timber.i(e, "IO Exception");
resultCode = ResultCode.NETWORK_ERROR;
} catch (Exception e) {
- if (isUnauthorized(topic))
+ if (isUnauthorized(topic)) {
resultCode = ResultCode.UNAUTHORIZED;
- Timber.e(e, "Parsing Error");
- resultCode = ResultCode.PARSING_ERROR;
+ } else {
+ Timber.e(e, "Parsing Error");
+ resultCode = ResultCode.PARSING_ERROR;
+ }
}
return new TopicTaskResult(resultCode, baseUrl, topicTitle, replyPageUrl, newPostsList,
loadedPageTopicId, currentPageIndex, pageCount, focusedPostIndex, topicTreeAndMods,
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 65b1d996..f9b76736 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
@@ -9,10 +9,47 @@ import gr.thmmy.mthmmy.model.Post;
public class TopicTaskResult {
private final TopicTask.ResultCode resultCode;
- private final String baseUrl, topicTitle, replyPageUrl;
+ /**
+ * Holds this topic's base url. For example a topic with url similar to
+ * "https://www.thmmy.gr/smf/index.php?topic=1.15;topicseen" or
+ * "https://www.thmmy.gr/smf/index.php?topic=1.msg1#msg1"
+ * has the base url "https://www.thmmy.gr/smf/index.php?topic=1"
+ */
+ private final String baseUrl;
+ /**
+ * Holds this topic's title. At first this gets the value of the topic title that came with
+ * bundle and is rendered in the toolbar while parsing this topic. Later, if a different topic
+ * title is parsed from the html source, it gets updated.
+ */
+ private final String topicTitle;
+ /**
+ * This topic's reply url
+ */
+ private final String replyPageUrl;
private final ArrayList newPostsList;
- private final int loadedPageTopicId, currentPageIndex, pageCount, focusedPostIndex;
- private final String topicTreeAndMods, topicViewers, lastPageLoadAttemptedUrl;
+ /**
+ * The topicId of the loaded page
+ */
+ private final int loadedPageTopicId;
+ /**
+ * Holds current page's index (starting from 1, not 0)
+ */
+ private final int currentPageIndex;
+ /**
+ * Holds the requested topic's number of pages
+ */
+ private final int pageCount;
+ /**
+ * The index of the post that has focus
+ */
+ private final int focusedPostIndex;
+ //Topic's info related
+ private final String topicTreeAndMods;
+ private final String topicViewers;
+ /**
+ * The url of the last page that was attempted to be loaded
+ */
+ private final String lastPageLoadAttemptedUrl;
private final SparseArray pagesUrls;
public TopicTaskResult(TopicTask.ResultCode resultCode, String baseUrl, String topicTitle,