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 c4dff2d7..d05f3945 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 @@ -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(); } }); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java index 28446874..ff31ee3a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java @@ -1,7 +1,6 @@ package gr.thmmy.mthmmy.activities.topic.tasks; import android.os.AsyncTask; -import android.util.SparseArray; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -9,13 +8,11 @@ import org.jsoup.nodes.Element; import java.io.IOException; import java.util.ArrayList; -import java.util.Objects; import gr.thmmy.mthmmy.activities.topic.TopicParser; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.ThmmyPage; -import gr.thmmy.mthmmy.utils.parsing.ParseException; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.Request; import okhttp3.Response; @@ -110,7 +107,6 @@ public class TopicTask extends AsyncTask { return new TopicTaskResult(ResultCode.SUCCESS, topicTitle, replyPageUrl, newPostsList, loadedPageTopicId, currentPageIndex, pageCount, focusedPostIndex, topicTreeAndMods, topicViewers); } catch (IOException e) { - Timber.i(e, "IO Exception"); return new TopicTaskResult(ResultCode.NETWORK_ERROR, null, null, null, 0, 0, 0, 0, null, null); } catch (Exception e) { @@ -118,7 +114,7 @@ public class TopicTask extends AsyncTask { return new TopicTaskResult(ResultCode.UNAUTHORIZED, null, null, null, 0, 0, 0, 0, null, null); } else { - Timber.e(e, "Parsing Error"); + Timber.e(e, "Topic parse failed"); return new TopicTaskResult(ResultCode.PARSING_ERROR, null, null, null, 0, 0, 0, 0, null, null); } 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 080414ab..1c52d540 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -22,6 +22,7 @@ import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; +import timber.log.Timber; public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTaskCompleted, PrepareForReply.OnPrepareForReplyFinished, PrepareForEditTask.OnPrepareEditFinished { @@ -85,6 +86,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa public void reloadPage() { if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); + Timber.i("Reloading page"); loadUrl(topicUrl); } @@ -93,6 +95,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa throw new NullPointerException("No page has been loaded yet!"); int pageRequested = pageIndicatorIndex.getValue() - 1; if (pageRequested != currentPageIndex - 1) { + Timber.i("Changing to page " + pageRequested + 1); loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(pageRequested * 15)); pageIndicatorIndex.setValue(pageRequested + 1); } else { @@ -105,6 +108,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa throw new NullPointerException("Topic task has not finished yet!"); stopLoading(); setPageIndicatorIndex(pageCount, true); + Timber.i("Preparing for reply"); currentPrepareForReplyTask = new PrepareForReply(prepareForReplyCallbacks, this, replyPageUrl.getValue()); currentPrepareForReplyTask.execute(toQuoteList.toArray(new Integer[0])); @@ -122,11 +126,13 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa includeAppSignature = prefs.getBoolean(SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY, true); } toQuoteList.clear(); + Timber.i("Posting reply"); new ReplyTask(replyFinishListener, includeAppSignature).execute(subject, reply, replyForm.getNumReplies(), replyForm.getSeqnum(), replyForm.getSc(), replyForm.getTopic()); } public void deletePost(String postDeleteUrl) { + Timber.i("Deleting post"); new DeleteTask(deleteTaskCallbacks).execute(postDeleteUrl); } @@ -134,6 +140,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (replyPageUrl.getValue() == null) throw new NullPointerException("Topic task has not finished yet!"); stopLoading(); + Timber.i("Preparing for edit"); currentPrepareForEditTask = new PrepareForEditTask(prepareForEditCallbacks, this, position, replyPageUrl.getValue()); currentPrepareForEditTask.execute(postEditURL); @@ -143,6 +150,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (prepareForEditResult.getValue() == null) throw new NullPointerException("Edit preparation was not found!"); PrepareForEditResult editResult = prepareForEditResult.getValue(); + Timber.i("Editing post"); new EditTask(editTaskCallbacks, position).execute(editResult.getCommitEditUrl(), message, editResult.getNumReplies(), editResult.getSeqnum(), editResult.getSc(), subject, editResult.getTopic()); } @@ -154,15 +162,18 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa */ public void stopLoading() { if (currentTopicTask != null && currentTopicTask.getStatus() == AsyncTask.Status.RUNNING) { + Timber.i("Canceling topic task"); currentTopicTask.cancel(true); pageIndicatorIndex.setValue(currentPageIndex); topicTaskObserver.onTopicTaskCancelled(); } if (currentPrepareForEditTask != null && currentPrepareForEditTask.getStatus() == AsyncTask.Status.RUNNING) { + Timber.i("Canceling prepare for edit task"); currentPrepareForEditTask.cancel(true); prepareForEditCallbacks.onPrepareEditCancelled(); } if (currentPrepareForReplyTask != null && currentPrepareForReplyTask.getStatus() == AsyncTask.Status.RUNNING) { + Timber.i("Canceling prepare for reply task"); currentPrepareForReplyTask.cancel(true); prepareForReplyCallbacks.onPrepareForReplyCancelled(); }