From 5f2c7f20bbd2e7ad9d48ca44c946e08e307db7b8 Mon Sep 17 00:00:00 2001 From: oogee Date: Thu, 29 Nov 2018 20:31:12 +0200 Subject: [PATCH] fix RWPB --- .../activities/topic/TopicActivity.java | 12 +++------- .../mthmmy/viewmodel/TopicViewModel.java | 24 +++++++++---------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 64b9fcdd..5602bacb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -540,23 +540,17 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo break; case NEW_REPLY_WHILE_POSTING: Timber.i("New reply while writing a reply"); - Post reply = (Post) topicItems.get(topicItems.size() - 1); + 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, R.style.AppTheme_Dark_Dialog); builder.setMessage("A new reply was posted before you completed your new post." + " Please review it and send your reply again") .setNeutralButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss()) .show(); + viewModel.prepareForReply(); }; - viewModel.reloadPageThen(addReply); + viewModel.resetPageThen(addReply); break; default: Timber.w("Post reply unsuccessful"); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index a9e255f6..1bbfa9c8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -104,27 +104,27 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa 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 the url before refreshing */ public void resetPage() { 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)); } + 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() { if (pageIndicatorIndex.getValue() == null) throw new NullPointerException("No page has been loaded yet!");