Browse Source

add logs in shoutbox tasks

pull/61/merge
Thodoris1999 6 years ago
parent
commit
8beb66b35b
  1. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java

8
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java

@ -22,6 +22,7 @@ import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.NetworkResultCodes; import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner { public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner {
@ -44,10 +45,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
} }
private void onShoutboxTaskSarted() { private void onShoutboxTaskSarted() {
Timber.i("Starting shoutbox task...");
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
} }
private void onSendShoutTaskStarted() { private void onSendShoutTaskStarted() {
Timber.i("Start sending a shout...");
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
} }
@ -56,10 +59,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
editorView.setEnabled(true); editorView.setEnabled(true);
progressBar.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) { if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear(); editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
} }
} }
@ -67,12 +72,15 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) {
progressBar.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) { if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shoutbox loaded successfully");
shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.setShouts(shoutbox.getShouts());
shoutAdapter.notifyDataSetChanged(); shoutAdapter.notifyDataSetChanged();
this.shoutbox = shoutbox; this.shoutbox = shoutbox;
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to retreive shoutbox due to network error");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
} else { } else {
Timber.wtf("Failed to retreive shoutbox due to unknown error");
Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show();
} }
} }

Loading…
Cancel
Save