Browse Source

crash fix when topic is destroyed before a first load, minor improvements

pull/43/head
Thodoris1999 7 years ago
parent
commit
f97c2d8811
  1. 16
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

16
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -104,7 +104,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
if (replyPageUrl.getValue() == null) if (replyPageUrl.getValue() == null)
throw new NullPointerException("Topic task has not finished yet!"); throw new NullPointerException("Topic task has not finished yet!");
stopLoading(); stopLoading();
setPageIndicatorIndex(getPageCount(), true); setPageIndicatorIndex(pageCount, true);
currentPrepareForReplyTask = new PrepareForReply(prepareForReplyCallbacks, this, currentPrepareForReplyTask = new PrepareForReply(prepareForReplyCallbacks, this,
replyPageUrl.getValue()); replyPageUrl.getValue());
currentPrepareForReplyTask.execute(toQuoteList.toArray(new Integer[0])); currentPrepareForReplyTask.execute(toQuoteList.toArray(new Integer[0]));
@ -155,7 +155,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
public void stopLoading() { public void stopLoading() {
if (currentTopicTask != null && currentTopicTask.getStatus() == AsyncTask.Status.RUNNING) { if (currentTopicTask != null && currentTopicTask.getStatus() == AsyncTask.Status.RUNNING) {
currentTopicTask.cancel(true); currentTopicTask.cancel(true);
pageIndicatorIndex.setValue(getCurrentPageIndex()); pageIndicatorIndex.setValue(currentPageIndex);
topicTaskObserver.onTopicTaskCancelled(); topicTaskObserver.onTopicTaskCancelled();
} }
if (currentPrepareForEditTask != null && currentPrepareForEditTask.getStatus() == AsyncTask.Status.RUNNING) { if (currentPrepareForEditTask != null && currentPrepareForEditTask.getStatus() == AsyncTask.Status.RUNNING) {
@ -208,10 +208,10 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
public void incrementPageRequestValue(int step, boolean changePage) { public void incrementPageRequestValue(int step, boolean changePage) {
if (pageIndicatorIndex.getValue() == null) if (pageIndicatorIndex.getValue() == null)
throw new NullPointerException("No page has been loaded yet!"); throw new NullPointerException("No page has been loaded yet!");
if (pageIndicatorIndex.getValue() <= getPageCount() - step) { if (pageIndicatorIndex.getValue() <= pageCount - step) {
pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() + step); pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() + step);
} else } else
pageIndicatorIndex.setValue(getPageCount()); pageIndicatorIndex.setValue(pageCount);
if (changePage) performPageChange(); if (changePage) performPageChange();
} }
@ -368,10 +368,8 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
} }
public String getBuildedQuotes() { public String getBuildedQuotes() {
if (prepareForReplyResult.getValue() != null) { if (prepareForReplyResult.getValue() == null)
return prepareForReplyResult.getValue().getBuildedQuotes(); throw new NullPointerException("Reply preparation was not found");
} else { return prepareForReplyResult.getValue().getBuildedQuotes();
return "";
}
} }
} }

Loading…
Cancel
Save