From 8950ed488d6092e8df09624e51d57aa62c069cba Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 19 Feb 2021 17:59:05 -0500 Subject: [PATCH] actually fix #319 and also convert more hardcoded strings --- .../DirectInboxItemViewHolder.java | 4 +- .../DirectItemRavenMediaViewHolder.java | 15 +++--- .../DirectItemReelShareViewHolder.java | 6 +-- .../DirectItemStoryShareViewHolder.java | 9 ++-- .../directmessages/DirectItemViewHolder.java | 23 +++++---- .../fragments/StoryViewerFragment.java | 48 ++++++++++++++----- .../DirectMessageThreadFragment.java | 9 ++-- app/src/main/res/values/strings.xml | 26 ++++++++++ 8 files changed, 97 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java index a4e9042e..85373901 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java @@ -143,7 +143,7 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder { final long senderId = item.getUserId(); final DirectItemType itemType = item.getItemType(); String subtitle = null; - final String username = getUsername(thread.getUsers(), senderId, viewerId); + final String username = getUsername(thread.getUsers(), senderId, viewerId, resources); String message = ""; if (itemType == null) { message = resources.getString(R.string.dms_inbox_raven_message_unknown); @@ -230,7 +230,7 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder { if (viewerId == item.getUserId()) { // You mentioned the other person final long mentionedUserId = item.getReelShare().getMentionedUserId(); - final String otherUsername = getUsername(thread.getUsers(), mentionedUserId, viewerId); + final String otherUsername = getUsername(thread.getUsers(), mentionedUserId, viewerId, resources); subtitle = resources.getString(R.string.dms_inbox_mentioned_story_outgoing, otherUsername); } else { // They mentioned you diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java index 090bb689..1b68efa6 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java @@ -10,6 +10,7 @@ import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; +import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmRavenMediaBinding; @@ -118,28 +119,28 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder { if (viewMode != RavenMediaViewMode.PERMANENT) { final MediaItemType mediaType = media.getMediaType(); final boolean expired = media.getPk() == null; - final String info; + final int info; switch (mediaType) { case MEDIA_TYPE_IMAGE: if (expired) { - info = "Image has expired"; + info = R.string.raven_image_expired; break; } - info = "Image will expire when seen"; + info = R.string.raven_image_info; break; case MEDIA_TYPE_VIDEO: if (expired) { - info = "Video has expired"; + info = R.string.raven_video_expired; break; } - info = "Video will expire when seen"; + info = R.string.raven_video_info; break; default: if (expired) { - info = "Message has expired"; + info = R.string.raven_msg_expired; break; } - info = "Message will expire when seen"; + info = R.string.raven_msg_info; break; } binding.expiryInfo.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java index 9abcc8a7..7ae6b5d8 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java @@ -107,7 +107,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { private void setReply(final MessageDirection messageDirection, final DirectItemReelShare reelShare, final boolean isSelf) { - final String info = isSelf ? "You replied to their story" : "They replied to your story"; + final int info = isSelf ? R.string.replied_story_outgoing : R.string.replied_story_incoming; binding.shareInfo.setText(info); binding.reaction.setVisibility(View.GONE); final String text = reelShare.getText(); @@ -122,7 +122,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { final DirectItemReelShare reelShare, final boolean isSelf, final boolean expired) { - final String info = isSelf ? "You reacted to their story" : "They reacted to your story"; + final int info = isSelf ? R.string.reacted_story_outgoing : R.string.reacted_story_incoming; binding.shareInfo.setText(info); binding.message.setVisibility(View.GONE); final String text = reelShare.getText(); @@ -139,7 +139,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { } private void setMention(final boolean isSelf) { - final String info = isSelf ? "You mentioned them in your story" : "Mentioned you in their story"; + final int info = isSelf ? R.string.mentioned_story_outgoing : R.string.mentioned_story_incoming; binding.shareInfo.setText(info); binding.message.setVisibility(View.GONE); binding.reaction.setVisibility(View.GONE); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java index 869e0ca8..c5a81993 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java @@ -1,5 +1,6 @@ package awais.instagrabber.adapters.viewholder.directmessages; +import android.content.res.Resources; import android.view.View; import android.view.ViewGroup; @@ -11,6 +12,7 @@ import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; +import awais.instagrabber.R; import awais.instagrabber.adapters.DirectItemsAdapter.DirectItemCallback; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmStoryShareBinding; @@ -41,17 +43,18 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { @Override public void bindItem(final DirectItem item, final MessageDirection messageDirection) { - String format = "@%s's story"; + final Resources resources = itemView.getResources(); + int format = R.string.story_share; final String reelType = item.getStoryShare().getReelType(); if (reelType == null || item.getStoryShare().getMedia() == null) { setExpiredStoryInfo(item); return; } if (reelType.equals("highlight_reel")) { - format = "@%s's story highlight"; + format = R.string.story_share_highlight; } final User user = item.getStoryShare().getMedia().getUser(); - final String info = String.format(format, user != null ? user.getUsername() : ""); + final String info = resources.getString(format, user != null ? user.getUsername() : ""); binding.shareInfo.setText(info); binding.text.setVisibility(View.GONE); binding.ivMediaPreview.setController(null); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java index 739a4a66..571568bb 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java @@ -224,6 +224,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple final List users) { final DirectItem replied = item.getRepliedToMessage(); final DirectItemType itemType = replied.getItemType(); + final Resources resources = itemView.getResources(); String text = null; String url = null; switch (itemType) { @@ -243,7 +244,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple url = ResponseBodyUtils.getThumbUrl(replied.getVisualMedia().getMedia().getImageVersions2()); break; case VOICE_MEDIA: - text = "Voice message"; + text = resources.getString(R.string.voice_message); break; case MEDIA_SHARE: Media mediaShare = replied.getMediaShare(); @@ -282,7 +283,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple return; } setReplyGravity(messageDirection); - final String info = setReplyInfo(item, replied, users); + final String info = setReplyInfo(item, replied, users, resources); binding.replyInfo.setVisibility(View.VISIBLE); binding.replyInfo.setText(info); binding.quoteLine.setVisibility(View.VISIBLE); @@ -295,7 +296,6 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple } binding.replyImage.setVisibility(View.GONE); final Drawable background = binding.replyText.getBackground().mutate(); - final Resources resources = itemView.getResources(); background.setTint(replied.getUserId() != currentUser.getPk() ? resources.getColor(R.color.grey_600) : resources.getColor(R.color.deep_purple_400)); @@ -306,30 +306,33 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple private String setReplyInfo(final DirectItem item, final DirectItem replied, - final List users) { + final List users, + final Resources resources) { final long repliedToUserId = replied.getUserId(); if (repliedToUserId == item.getUserId() && item.getUserId() == currentUser.getPk()) { // User replied to own message - return "You replied to yourself"; + return resources.getString(R.string.replied_to_yourself); } if (repliedToUserId == item.getUserId()) { // opposite user replied to their own message - return "Replied to themself"; + return resources.getString(R.string.replied_to_themself); } final User user = getUser(repliedToUserId, users); final String repliedToUsername = user != null ? user.getUsername() : ""; if (item.getUserId() == currentUser.getPk()) { - return !thread.isGroup() ? "You replied" : String.format("You replied to %s", repliedToUsername); + return thread.isGroup() + ? resources.getString(R.string.replied_you_group, repliedToUsername) + : resources.getString(R.string.replied_you); } if (repliedToUserId == currentUser.getPk()) { - return "Replied to you"; + return resources.getString(R.string.replied_to_you); } - return String.format("Replied to %s", repliedToUsername); + return resources.getString(R.string.replied_group, repliedToUsername); } private void setForwardInfo(final MessageDirection direction) { binding.replyInfo.setVisibility(View.VISIBLE); - binding.replyInfo.setText(direction == MessageDirection.OUTGOING ? "You forwarded a message" : "Forwarded a message"); + binding.replyInfo.setText(direction == MessageDirection.OUTGOING ? R.string.forward_outgoing : R.string.forward_incoming); } private void setReplyGravity(final MessageDirection messageDirection) { diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index c7345228..ea38abe8 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -490,15 +490,21 @@ public class StoryViewerFragment extends Fragment { @Override public void onSuccess(final StoryStickerResponse result) { sticking = false; - poll.setMyChoice(w); - Toast.makeText(context, R.string.votef_story_poll, Toast.LENGTH_SHORT).show(); + try { + poll.setMyChoice(w); + Toast.makeText(context, R.string.votef_story_poll, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } @Override public void onFailure(final Throwable t) { sticking = false; Log.e(TAG, "Error responding", t); - Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + try { + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } }); } @@ -525,14 +531,20 @@ public class StoryViewerFragment extends Fragment { @Override public void onSuccess(final StoryStickerResponse result) { sticking = false; - Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); + try { + Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } @Override public void onFailure(final Throwable t) { sticking = false; Log.e(TAG, "Error responding", t); - Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + try { + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } }); }) @@ -565,15 +577,21 @@ public class StoryViewerFragment extends Fragment { @Override public void onSuccess(final StoryStickerResponse result) { sticking = false; - quiz.setMyChoice(w); - Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); - } + try { + quiz.setMyChoice(w); + Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} + } @Override public void onFailure(final Throwable t) { sticking = false; Log.e(TAG, "Error responding", t); - Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + try { + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } }); } @@ -631,15 +649,21 @@ public class StoryViewerFragment extends Fragment { @Override public void onSuccess(final StoryStickerResponse result) { sticking = false; - slider.setMyChoice(sliderValue); - Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); + try { + slider.setMyChoice(sliderValue); + Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } @Override public void onFailure(final Throwable t) { sticking = false; Log.e(TAG, "Error responding", t); - Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + try { + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + catch (Exception ignored) {} } }); }) diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index 0eb2fc61..7fa55fea 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -116,9 +116,6 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact private static final int STORAGE_PERM_REQUEST_CODE = 8020; private static final int AUDIO_RECORD_PERM_REQUEST_CODE = 1000; private static final int CAMERA_REQUEST_CODE = 200; - private static final String UPDATING_TITLE = "Updating..."; - private static final String MESSAGE_LABEL = "Message"; - private static final String HOLD_TO_RECORD_AUDIO_LABEL = "Press and hold to record audio"; private static final String TRANSLATION_Y = "translationY"; private DirectItemsAdapter itemsAdapter; @@ -567,7 +564,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact viewModel.getThreadTitle().observe(getViewLifecycleOwner(), this::setTitle); viewModel.getFetching().observe(getViewLifecycleOwner(), fetching -> { if (fetching) { - setTitle(UPDATING_TITLE); + setTitle(getString(R.string.dms_thread_updating)); return; } setTitle(viewModel.getThreadTitle().getValue()); @@ -876,7 +873,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact if (inputMode != null && inputMode == 1) return; final Context context = getContext(); if (context == null) return; - tooltip.setText(HOLD_TO_RECORD_AUDIO_LABEL); + tooltip.setText(R.string.dms_thread_audio_hint); setMicToSendIcon(); binding.recordView.setMinMillis(1000); binding.recordView.setOnRecordListener(new RecordView.OnRecordListener() { @@ -925,7 +922,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact } }); binding.recordView.setOnBasketAnimationEndListener(() -> { - binding.input.setHint(MESSAGE_LABEL); + binding.input.setHint(R.string.dms_thread_message_hint); binding.gallery.setVisibility(View.VISIBLE); binding.camera.setVisibility(View.VISIBLE); }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 433a642a..9b56d36e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -203,6 +203,9 @@ Suggested Screenshotted Cannot deliver + Message... + Press and hold to record audio + Updating... Great success! Leave chat Leave this chat? @@ -427,10 +430,33 @@ Reply Tap to remove Forward + You forwarded a message + Forwarded a message Add Send Replying to yourself Replying to %s + You replied to yourself + You replied to you + You replied + You replied to %s + Replied to %s + Replied to you + Replied to themself + You reacted to their story + Reacted to your story + You mentioned them in your story + Mentioned you in their story + You replied to their story + Replied to your story + Image has expired + Image will expire when seen + Video has expired + Video will expire when seen + Message has expired + Message will expire when seen + @%s\'s story + @%s\'s story highlight Photo Video Voice message