Browse Source

actually fix #319 and also convert more hardcoded strings

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
8950ed488d
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 4
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java
  2. 15
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java
  3. 6
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java
  4. 9
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java
  5. 23
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java
  6. 48
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  7. 9
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
  8. 26
      app/src/main/res/values/strings.xml

4
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

15
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);

6
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);

9
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);

23
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<User> 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<User> users) {
final List<User> 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) {

48
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) {}
}
});
})

9
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);
});

26
app/src/main/res/values/strings.xml

@ -203,6 +203,9 @@
<string name="dms_inbox_raven_media_suggested">Suggested</string>
<string name="dms_inbox_raven_media_screenshot">Screenshotted</string>
<string name="dms_inbox_raven_media_cant_deliver">Cannot deliver</string>
<string name="dms_thread_message_hint">Message...</string>
<string name="dms_thread_audio_hint">Press and hold to record audio</string>
<string name="dms_thread_updating">Updating...</string>
<string name="dms_action_success">Great success!</string>
<string name="dms_action_leave">Leave chat</string>
<string name="dms_action_leave_question">Leave this chat?</string>
@ -427,10 +430,33 @@
<string name="reply">Reply</string>
<string name="tap_to_remove">Tap to remove</string>
<string name="forward">Forward</string>
<string name="forward_outgoing">You forwarded a message</string>
<string name="forward_incoming">Forwarded a message</string>
<string name="add">Add</string>
<string name="send">Send</string>
<string name="replying_to_yourself">Replying to yourself</string>
<string name="replying_to_user">Replying to %s</string>
<string name="replied_to_yourself">You replied to yourself</string>
<string name="replied_you_to_you">You replied to you</string>
<string name="replied_you">You replied</string>
<string name="replied_you_group">You replied to %s</string>
<string name="replied_group">Replied to %s</string>
<string name="replied_to_you">Replied to you</string>
<string name="replied_to_themself">Replied to themself</string>
<string name="reacted_story_outgoing">You reacted to their story</string>
<string name="reacted_story_incoming">Reacted to your story</string>
<string name="mentioned_story_outgoing">You mentioned them in your story</string>
<string name="mentioned_story_incoming">Mentioned you in their story</string>
<string name="replied_story_outgoing">You replied to their story</string>
<string name="replied_story_incoming">Replied to your story</string>
<string name="raven_image_expired">Image has expired</string>
<string name="raven_image_info">Image will expire when seen</string>
<string name="raven_video_expired">Video has expired</string>
<string name="raven_video_info">Video will expire when seen</string>
<string name="raven_msg_expired">Message has expired</string>
<string name="raven_msg_info">Message will expire when seen</string>
<string name="story_share">@%s\'s story</string>
<string name="story_share_highlight">@%s\'s story highlight</string>
<string name="photo">Photo</string>
<string name="video">Video</string>
<string name="voice_message">Voice message</string>

Loading…
Cancel
Save