diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-07-17 08:13:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-07-17 08:13:55 +0000 |
commit | d06f66975e40ebbf599ea66ed4c9794de085a890 (patch) | |
tree | 459758016f6666d0ebb941b3067cc27dc9679e69 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 7d1aa07b9d581c08bb2ca02b09880e78a37cac40 (diff) | |
download | infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar.gz infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar.bz2 infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar.lz infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar.xz infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.tar.zst infinity-for-reddit-d06f66975e40ebbf599ea66ed4c9794de085a890.zip |
Add a boolean variable isSendingMessage to avoid sending multiple messages before the first message is sent in ViewPrivateMessageActivity. When the message is being sent, the send button will have a secondary text color. Use wrap_content for comment content in item_comment.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
4 files changed, 97 insertions, 59 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java index ea162250..80cff550 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java @@ -92,6 +92,9 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit private String mUserAvatar; private ArrayList<ProvideUserAvatarCallback> mProvideUserAvatarCallbacks; private LoadUserDataAsyncTask mLoadUserDataAsyncTask; + private boolean isSendingMessage = false; + private int mSecondaryTextColor; + private int mSendMessageIconColor; @Override protected void onCreate(Bundle savedInstanceState) { @@ -114,9 +117,6 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit Intent intent = getIntent(); privateMessage = intent.getParcelableExtra(EXTRA_PRIVATE_MESSAGE); - if (privateMessage != null) { - mToolbar.setTitle(privateMessage.getSubject()); - } setSupportActionBar(mToolbar); setToolbarGoToTop(mToolbar); @@ -151,6 +151,23 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit } private void bindView() { + if (privateMessage != null) { + if (privateMessage.getAuthor().equals(mAccountName)) { + mToolbar.setTitle(privateMessage.getDestination()); + mToolbar.setOnClickListener(view -> { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getDestination()); + startActivity(intent); + }); + } else { + mToolbar.setTitle(privateMessage.getAuthor()); + mToolbar.setOnClickListener(view -> { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getAuthor()); + startActivity(intent); + }); + } + } mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, mSharedPreferences, getResources().getConfiguration().locale, privateMessage, mAccountName, mCustomThemeWrapper); mLinearLayoutManager = new LinearLayoutManager(this); @@ -159,63 +176,72 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit mRecyclerView.setAdapter(mAdapter); goToBottom(); mSendImageView.setOnClickListener(view -> { - if (!mEditText.getText().toString().equals("")) { - //Send Message - if (privateMessage != null) { - Message replyTo; - ArrayList<Message> replies = privateMessage.getReplies(); - if (replies != null && !replies.isEmpty()) { - replyTo = replies.get(replies.size() - 1); - } else { - replyTo = privateMessage; - } - if (replyTo != null) { - ReplyMessage.replyMessage(mEditText.getText().toString(), replyTo.getFullname(), - getResources().getConfiguration().locale, mOauthRetrofit, mAccessToken, - new ReplyMessage.ReplyMessageListener() { - @Override - public void replyMessageSuccess(Message message) { - if (mAdapter != null) { - mAdapter.addReply(message); - } - goToBottom(); - mEditText.setText(""); - EventBus.getDefault().post(new RepliedToPrivateMessageEvent(message, getIntent().getIntExtra(EXTRA_MESSAGE_POSITION, -1))); - } - - @Override - public void replyMessageFailed(String errorMessage) { - if (errorMessage != null && !errorMessage.equals("")) { - Snackbar.make(mCoordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show(); - } else { - Snackbar.make(mCoordinatorLayout, R.string.reply_message_failed, Snackbar.LENGTH_LONG).show(); - } - } - }); - StringBuilder fullnames = new StringBuilder(); - if (privateMessage.isNew()) { - fullnames.append(privateMessage.getFullname()).append(","); - } + if (!isSendingMessage) { + if (!mEditText.getText().toString().equals("")) { + //Send Message + if (privateMessage != null) { + Message replyTo; + ArrayList<Message> replies = privateMessage.getReplies(); if (replies != null && !replies.isEmpty()) { - for (Message m : replies) { - if (m.isNew()) { - fullnames.append(m).append(","); - } - } + replyTo = replies.get(replies.size() - 1); + } else { + replyTo = privateMessage; } - if (fullnames.length() > 0) { - fullnames.deleteCharAt(fullnames.length() - 1); - ReadMessage.readMessage(mOauthRetrofit, mAccessToken, fullnames.toString(), - new ReadMessage.ReadMessageListener() { + if (replyTo != null) { + isSendingMessage = true; + mSendImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + ReplyMessage.replyMessage(mEditText.getText().toString(), replyTo.getFullname(), + getResources().getConfiguration().locale, mOauthRetrofit, mAccessToken, + new ReplyMessage.ReplyMessageListener() { @Override - public void readSuccess() {} + public void replyMessageSuccess(Message message) { + if (mAdapter != null) { + mAdapter.addReply(message); + } + goToBottom(); + mEditText.setText(""); + mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + isSendingMessage = false; + EventBus.getDefault().post(new RepliedToPrivateMessageEvent(message, getIntent().getIntExtra(EXTRA_MESSAGE_POSITION, -1))); + } @Override - public void readFailed() {} + public void replyMessageFailed(String errorMessage) { + if (errorMessage != null && !errorMessage.equals("")) { + Snackbar.make(mCoordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show(); + } else { + Snackbar.make(mCoordinatorLayout, R.string.reply_message_failed, Snackbar.LENGTH_LONG).show(); + } + mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + isSendingMessage = false; + } }); + StringBuilder fullnames = new StringBuilder(); + if (privateMessage.isNew()) { + fullnames.append(privateMessage.getFullname()).append(","); + } + if (replies != null && !replies.isEmpty()) { + for (Message m : replies) { + if (m.isNew()) { + fullnames.append(m).append(","); + } + } + } + if (fullnames.length() > 0) { + fullnames.deleteCharAt(fullnames.length() - 1); + ReadMessage.readMessage(mOauthRetrofit, mAccessToken, fullnames.toString(), + new ReadMessage.ReadMessageListener() { + @Override + public void readSuccess() {} + + @Override + public void readFailed() {} + }); + } + } else { + isSendingMessage = false; + Snackbar.make(mCoordinatorLayout, R.string.error_getting_message, Snackbar.LENGTH_LONG).show(); } - } else { - Snackbar.make(mCoordinatorLayout, R.string.error_getting_message, Snackbar.LENGTH_LONG).show(); } } } @@ -285,9 +311,11 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); mDivider.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); mEditText.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); - mEditText.setHintTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + mSecondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); + mEditText.setHintTextColor(mSecondaryTextColor); mEditTextLinearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - mSendImageView.setColorFilter(mCustomThemeWrapper.getSendMessageIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); + mSendMessageIconColor = mCustomThemeWrapper.getSendMessageIconColor(); + mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/Message.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/Message.java index a53b11f2..771d675e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/Message.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/Message.java @@ -20,6 +20,7 @@ public class Message implements Parcelable { private String fullname; private String subject; private String author; + private String destination; private String parentFullName; private String title; private String body; @@ -34,9 +35,9 @@ public class Message implements Parcelable { private ArrayList<Message> replies; Message(String kind, String subredditName, String subredditNamePrefixed, String id, String fullname, - String subject, String author, String parentFullName, String title, String body, String context, - String distinguished, String formattedTime, boolean wasComment, boolean isNew, int score, - int nComments, long timeUTC) { + String subject, String author, String destination, String parentFullName, String title, String body, + String context, String distinguished, String formattedTime, boolean wasComment, boolean isNew, + int score, int nComments, long timeUTC) { this.kind = kind; this.subredditName = subredditName; this.subredditNamePrefixed = subredditNamePrefixed; @@ -44,6 +45,7 @@ public class Message implements Parcelable { this.fullname = fullname; this.subject = subject; this.author = author; + this.destination = destination; this.parentFullName = parentFullName; this.title = title; this.body = body; @@ -66,6 +68,7 @@ public class Message implements Parcelable { fullname = in.readString(); subject = in.readString(); author = in.readString(); + destination = in.readString(); parentFullName = in.readString(); title = in.readString(); body = in.readString(); @@ -120,6 +123,10 @@ public class Message implements Parcelable { return author; } + public String getDestination() { + return destination; + } + public String getParentFullName() { return parentFullName; } @@ -197,6 +204,7 @@ public class Message implements Parcelable { parcel.writeString(fullname); parcel.writeString(subject); parcel.writeString(author); + parcel.writeString(destination); parcel.writeString(parentFullName); parcel.writeString(title); parcel.writeString(body); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ParseMessage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ParseMessage.java index 6d489703..410d1886 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ParseMessage.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ParseMessage.java @@ -60,6 +60,7 @@ public class ParseMessage { String fullname = rawMessageJSON.getString(JSONUtils.NAME_KEY); String subject = rawMessageJSON.getString(JSONUtils.SUBJECT_KEY); String author = rawMessageJSON.getString(JSONUtils.AUTHOR_KEY); + String destination = rawMessageJSON.getString(JSONUtils.DEST_KEY); String parentFullname = rawMessageJSON.getString(JSONUtils.PARENT_ID_KEY); String title = rawMessageJSON.has(JSONUtils.LINK_TITLE_KEY) ? rawMessageJSON.getString(JSONUtils.LINK_TITLE_KEY) : null; String body = Utils.modifyMarkdown(rawMessageJSON.getString(JSONUtils.BODY_KEY)); @@ -84,7 +85,7 @@ public class ParseMessage { } Message message = new Message(kind, subredditName, subredditNamePrefixed, id, fullname, subject, - author, parentFullname, title, body, context, distinguished, formattedTime, + author, destination, parentFullname, title, body, context, distinguished, formattedTime, wasComment, isNew, score, nComments, timeUTC); if (replies != null) { message.setReplies(replies); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index 28c6ddfe..1c47eb2a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -121,4 +121,5 @@ public class JSONUtils { public static final String S_KEY = "s"; public static final String X_KEY = "x"; public static final String Y_KEY = "y"; + public static final String DEST_KEY = "dest"; } |