|
|
@ -196,6 +196,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
|
|
|
|
paginationEnabled(false); |
|
|
|
|
|
|
|
Timber.i("Starting initial topic load"); |
|
|
|
viewModel.loadUrl(topicPageUrl); |
|
|
|
} |
|
|
|
|
|
|
@ -468,10 +469,13 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
public void onDeleteTaskFinished(boolean result) { |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
|
|
|
|
if (result) |
|
|
|
if (result) { |
|
|
|
Timber.i("Post deleted successfully"); |
|
|
|
viewModel.reloadPage(); |
|
|
|
else |
|
|
|
} else { |
|
|
|
Timber.w("Failed to delete post"); |
|
|
|
Toast.makeText(getBaseContext(), "Delete failed!", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
viewModel.setReplyFinishListener(new ReplyTask.ReplyTaskCallbacks() { |
|
|
@ -491,15 +495,18 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
|
|
|
|
if (success) { |
|
|
|
Timber.i("Post reply successful"); |
|
|
|
replyFAB.show(); |
|
|
|
bottomNavBar.setVisibility(View.VISIBLE); |
|
|
|
viewModel.setWritingReply(false); |
|
|
|
if ((postsList.get(postsList.size() - 1).getPostNumber() + 1) % 15 == 0) { |
|
|
|
Timber.i("Reply was posted in new page. Switching to last page."); |
|
|
|
viewModel.loadUrl(ParseHelpers.getBaseURL(viewModel.getTopicUrl()) + "." + 2147483647); |
|
|
|
} else { |
|
|
|
viewModel.reloadPage(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Timber.w("Post reply unsuccessful"); |
|
|
|
Toast.makeText(getBaseContext(), "Post failed!", Toast.LENGTH_SHORT).show(); |
|
|
|
recyclerView.getChildAt(postsList.size() - 1).setAlpha(1); |
|
|
|
recyclerView.getChildAt(postsList.size() - 1).setEnabled(true); |
|
|
@ -534,6 +541,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
|
|
|
|
if (result) { |
|
|
|
Timber.i("Post edit successful"); |
|
|
|
postsList.get(position).setPostType(Post.TYPE_POST); |
|
|
|
topicAdapter.notifyItemChanged(position); |
|
|
|
replyFAB.show(); |
|
|
@ -541,6 +549,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
viewModel.setEditingPost(false); |
|
|
|
viewModel.reloadPage(); |
|
|
|
} else { |
|
|
|
Timber.i("Post edit unsuccessful"); |
|
|
|
Toast.makeText(getBaseContext(), "Edit failed!", Toast.LENGTH_SHORT).show(); |
|
|
|
recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setAlpha(1); |
|
|
|
recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setEnabled(true); |
|
|
@ -599,9 +608,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
switch (resultCode) { |
|
|
|
case SUCCESS: |
|
|
|
Timber.i("Successfully loaded topic with URL %s", viewModel.getTopicUrl()); |
|
|
|
paginationEnabled(true); |
|
|
|
break; |
|
|
|
case NETWORK_ERROR: |
|
|
|
Timber.w("Network error on loaded page"); |
|
|
|
if (viewModel.getPostsList().getValue() == null) { |
|
|
|
// no page has been loaded yet. Give user the ability to refresh
|
|
|
|
recyclerView.setVisibility(View.GONE); |
|
|
@ -623,6 +634,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
} |
|
|
|
break; |
|
|
|
case UNAUTHORIZED: |
|
|
|
Timber.w("Requested topic was unauthorized"); |
|
|
|
recyclerView.setVisibility(View.GONE); |
|
|
|
TextView errorTextview = findViewById(R.id.error_textview); |
|
|
|
errorTextview.setText(getString(R.string.unauthorized_topic_error)); |
|
|
@ -630,7 +642,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
break; |
|
|
|
default: |
|
|
|
//Parse failed - should never happen
|
|
|
|
Timber.d("Parse failed!"); //TODO report ParseException!!!
|
|
|
|
Timber.wtf("Parse failed!"); //TODO report ParseException!!!
|
|
|
|
Toast.makeText(getBaseContext(), "Fatal Error", Toast.LENGTH_SHORT).show(); |
|
|
|
finish(); |
|
|
|
break; |
|
|
@ -639,6 +651,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
viewModel.getPrepareForReplyResult().observe(this, prepareForReplyResult -> { |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
if (prepareForReplyResult != null && prepareForReplyResult.isSuccessful()) { |
|
|
|
Timber.i("Prepare for reply successful"); |
|
|
|
//prepare for a reply
|
|
|
|
viewModel.setWritingReply(true); |
|
|
|
postsList.add(Post.newQuickReply()); |
|
|
@ -647,12 +660,14 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
replyFAB.hide(); |
|
|
|
bottomNavBar.setVisibility(View.GONE); |
|
|
|
} else { |
|
|
|
Timber.i("Prepare for reply unsuccessful"); |
|
|
|
Snackbar.make(findViewById(R.id.main_content), getString(R.string.generic_network_error), Snackbar.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
}); |
|
|
|
viewModel.getPrepareForEditResult().observe(this, result -> { |
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
if (result != null && result.isSuccessful()) { |
|
|
|
Timber.i("Prepare for edit successful"); |
|
|
|
viewModel.setEditingPost(true); |
|
|
|
postsList.get(result.getPosition()).setPostType(Post.TYPE_EDIT); |
|
|
|
topicAdapter.notifyItemChanged(result.getPosition()); |
|
|
@ -660,6 +675,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
replyFAB.hide(); |
|
|
|
bottomNavBar.setVisibility(View.GONE); |
|
|
|
} else { |
|
|
|
Timber.i("Prepare for edit unsuccessful"); |
|
|
|
Snackbar.make(findViewById(R.id.main_content), getString(R.string.generic_network_error), Snackbar.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
}); |
|
|
|