Browse Source

fix RWPB

pull/61/merge
oogee 6 years ago
parent
commit
5f2c7f20bb
  1. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 24
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

12
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -540,23 +540,17 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
break; break;
case NEW_REPLY_WHILE_POSTING: case NEW_REPLY_WHILE_POSTING:
Timber.i("New reply while writing a reply"); Timber.i("New reply while writing a reply");
Post reply = (Post) topicItems.get(topicItems.size() - 1);
Runnable addReply = () -> { Runnable addReply = () -> {
viewModel.setWritingReply(true);
topicItems.add(Post.newQuickReply(reply.getSubject(), reply.getContent()));
topicAdapter.notifyItemInserted(topicItems.size());
recyclerView.scrollToPosition(topicItems.size() - 1);
replyFAB.hide();
replyFAB.setTag(false);
bottomNavBar.setVisibility(View.GONE);
AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this,
R.style.AppTheme_Dark_Dialog); R.style.AppTheme_Dark_Dialog);
builder.setMessage("A new reply was posted before you completed your new post." + builder.setMessage("A new reply was posted before you completed your new post." +
" Please review it and send your reply again") " Please review it and send your reply again")
.setNeutralButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss()) .setNeutralButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss())
.show(); .show();
viewModel.prepareForReply();
}; };
viewModel.reloadPageThen(addReply); viewModel.resetPageThen(addReply);
break; break;
default: default:
Timber.w("Post reply unsuccessful"); Timber.w("Post reply unsuccessful");

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

@ -104,27 +104,27 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
loadUrl(topicUrl); loadUrl(topicUrl);
} }
public void reloadPageThen(Runnable runnable) {
if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!");
Timber.i("Reloading page");
stopLoading();
currentTopicTask = new TopicTask(topicTaskObserver, result -> {
TopicViewModel.this.onTopicTaskCompleted(result);
runnable.run();
});
currentTopicTask.execute(topicUrl);
}
/** /**
* In contrast to {@link TopicViewModel#reloadPage()} this method gets rid of any arguments * In contrast to {@link TopicViewModel#reloadPage()} this method gets rid of any arguments
* in the url before refreshing * in the url before refreshing
*/ */
public void resetPage() { public void resetPage() {
if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!");
Timber.i("Reseting page"); Timber.i("Resetting page");
loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15)); loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15));
} }
public void resetPageThen(Runnable runnable) {
if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!");
Timber.i("Resetting page");
stopLoading();
currentTopicTask = new TopicTask(topicTaskObserver, result -> {
TopicViewModel.this.onTopicTaskCompleted(result);
runnable.run();
});
currentTopicTask.execute(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15));
}
public void loadPageIndicated() { public void loadPageIndicated() {
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!");

Loading…
Cancel
Save