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