Browse Source

organize code for readability

legacy
Ammar Githam 4 years ago
parent
commit
86b9feda4a
  1. 52
      app/src/main/java/awais/instagrabber/activities/DirectMessageThread.java

52
app/src/main/java/awais/instagrabber/activities/DirectMessageThread.java

@ -37,10 +37,15 @@ import awais.instagrabber.utils.Utils;
public final class DirectMessageThread extends BaseLanguageActivity { public final class DirectMessageThread extends BaseLanguageActivity {
private DirectItemModel directItemModel; private DirectItemModel directItemModel;
private String threadid;
private String endCursor;
private ActivityDmsBinding dmsBinding;
private MessageItemsAdapter messageItemsAdapter;
private final ProfileModel myProfileHolder = ProfileModel.getDefaultProfileModel(); private final ProfileModel myProfileHolder = ProfileModel.getDefaultProfileModel();
private final ArrayList<ProfileModel> users = new ArrayList<>(), leftusers = new ArrayList<>();
private final ArrayList<ProfileModel> users = new ArrayList<>();
private final ArrayList<ProfileModel> leftusers = new ArrayList<>();
private final ArrayList<DirectItemModel> directItemModels = new ArrayList<>(); private final ArrayList<DirectItemModel> directItemModels = new ArrayList<>();
private String threadid;
private final FetchListener<InboxThreadModel> fetchListener = new FetchListener<InboxThreadModel>() { private final FetchListener<InboxThreadModel> fetchListener = new FetchListener<InboxThreadModel>() {
@Override @Override
public void doBefore() { public void doBefore() {
@ -80,9 +85,25 @@ public final class DirectMessageThread extends BaseLanguageActivity {
dmsBinding.swipeRefreshLayout.setRefreshing(false); dmsBinding.swipeRefreshLayout.setRefreshing(false);
} }
}; };
private String endCursor;
private ActivityDmsBinding dmsBinding;
private MessageItemsAdapter messageItemsAdapter;
private final View.OnClickListener newCommentListener = v -> {
if (Utils.isEmpty(dmsBinding.commentText.getText().toString()) && v == dmsBinding.commentSend)
Toast.makeText(getApplicationContext(), R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show();
else if (v == dmsBinding.commentSend) {
final CommentAction action = new CommentAction(dmsBinding.commentText.getText().toString(), threadid);
action.setOnTaskCompleteListener(result -> {
if (!result) {
Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
dmsBinding.commentText.setText("");
dmsBinding.commentText.clearFocus();
directItemModels.clear();
messageItemsAdapter.notifyDataSetChanged();
new UserInboxFetcher(threadid, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
action.execute();
}
};
@Override @Override
protected void onCreate(@Nullable final Bundle savedInstanceState) { protected void onCreate(@Nullable final Bundle savedInstanceState) {
@ -194,25 +215,4 @@ public final class DirectMessageThread extends BaseLanguageActivity {
private void searchUsername(final String text) { private void searchUsername(final String text) {
startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text));
} }
private final View.OnClickListener newCommentListener = v -> {
if (Utils.isEmpty(dmsBinding.commentText.getText().toString()) && v == dmsBinding.commentSend)
Toast.makeText(getApplicationContext(), R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show();
else if (v == dmsBinding.commentSend) {
final CommentAction action = new CommentAction(dmsBinding.commentText.getText().toString(), threadid);
action.setOnTaskCompleteListener(result -> {
if (!result) {
Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
dmsBinding.commentText.setText("");
dmsBinding.commentText.clearFocus();
directItemModels.clear();
messageItemsAdapter.notifyDataSetChanged();
new UserInboxFetcher(threadid, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
action.execute();
}
};
} }
Loading…
Cancel
Save