Fix images not shown in dm
This commit is contained in:
parent
6bd0b811b1
commit
b5e66e35bf
@ -2,9 +2,11 @@ package awais.instagrabber.adapters.viewholder.directmessages;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.text.HtmlCompat;
|
import androidx.core.text.HtmlCompat;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
||||||
@ -13,18 +15,24 @@ import awais.instagrabber.models.ProfileModel;
|
|||||||
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
||||||
import awais.instagrabber.models.direct_messages.DirectItemModel.DirectItemMediaModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel.DirectItemMediaModel;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT;
|
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT;
|
||||||
|
|
||||||
public class DirectMessageMediaShareViewHolder extends DirectMessageItemViewHolder {
|
public class DirectMessageMediaShareViewHolder extends DirectMessageItemViewHolder {
|
||||||
|
|
||||||
private final LayoutDmMediaShareBinding binding;
|
private final LayoutDmMediaShareBinding binding;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int maxWidth;
|
||||||
|
|
||||||
public DirectMessageMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
public DirectMessageMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
||||||
@NonNull final LayoutDmMediaShareBinding binding,
|
@NonNull final LayoutDmMediaShareBinding binding,
|
||||||
final View.OnClickListener onClickListener) {
|
final View.OnClickListener onClickListener) {
|
||||||
super(baseBinding, onClickListener);
|
super(baseBinding, onClickListener);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height);
|
||||||
|
maxWidth = (int) (Utils.displayMetrics.widthPixels * 0.8);
|
||||||
setItemView(binding.getRoot());
|
setItemView(binding.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +46,48 @@ public class DirectMessageMediaShareViewHolder extends DirectMessageItemViewHold
|
|||||||
"<small>" + context.getString(R.string.dms_inbox_media_shared_from, modelUser.getUsername()) + "</small>",
|
"<small>" + context.getString(R.string.dms_inbox_media_shared_from, modelUser.getUsername()) + "</small>",
|
||||||
FROM_HTML_MODE_COMPACT));
|
FROM_HTML_MODE_COMPACT));
|
||||||
}
|
}
|
||||||
|
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
|
||||||
|
mediaModel.getHeight(),
|
||||||
|
mediaModel.getWidth(),
|
||||||
|
maxHeight,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
|
||||||
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
||||||
final MediaItemType modelMediaType = mediaModel.getMediaType();
|
final MediaItemType modelMediaType = mediaModel.getMediaType();
|
||||||
binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO
|
binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO
|
||||||
|| modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
|| modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WidthHeight {
|
||||||
|
private final DirectItemMediaModel mediaModel;
|
||||||
|
private int height;
|
||||||
|
private int width;
|
||||||
|
|
||||||
|
public WidthHeight(final DirectItemMediaModel mediaModel) {this.mediaModel = mediaModel;}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WidthHeight invoke() {
|
||||||
|
height = mediaModel.getHeight();
|
||||||
|
width = mediaModel.getWidth();
|
||||||
|
// make height 500dp regardless
|
||||||
|
width = NumberUtils.getResultingWidth(maxHeight, height, width);
|
||||||
|
height = maxHeight;
|
||||||
|
if (width > maxWidth) {
|
||||||
|
height = NumberUtils.getResultingHeight(maxWidth, height, width);
|
||||||
|
width = maxWidth;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,53 @@
|
|||||||
package awais.instagrabber.adapters.viewholder.directmessages;
|
package awais.instagrabber.adapters.viewholder.directmessages;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
||||||
import awais.instagrabber.databinding.LayoutDmMediaBinding;
|
import awais.instagrabber.databinding.LayoutDmMediaBinding;
|
||||||
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
public class DirectMessageMediaViewHolder extends DirectMessageItemViewHolder {
|
public class DirectMessageMediaViewHolder extends DirectMessageItemViewHolder {
|
||||||
|
|
||||||
private final LayoutDmMediaBinding binding;
|
private final LayoutDmMediaBinding binding;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int maxWidth;
|
||||||
|
|
||||||
public DirectMessageMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
public DirectMessageMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
||||||
@NonNull final LayoutDmMediaBinding binding,
|
@NonNull final LayoutDmMediaBinding binding,
|
||||||
final View.OnClickListener onClickListener) {
|
final View.OnClickListener onClickListener) {
|
||||||
super(baseBinding, onClickListener);
|
super(baseBinding, onClickListener);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height);
|
||||||
|
maxWidth = (int) (Utils.displayMetrics.widthPixels * 0.8);
|
||||||
setItemView(binding.getRoot());
|
setItemView(binding.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final DirectItemModel directItemModel) {
|
public void bindItem(final DirectItemModel directItemModel) {
|
||||||
final DirectItemModel.DirectItemMediaModel mediaModel = directItemModel.getMediaModel();
|
final DirectItemModel.DirectItemMediaModel mediaModel = directItemModel.getMediaModel();
|
||||||
|
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
|
||||||
|
mediaModel.getHeight(),
|
||||||
|
mediaModel.getWidth(),
|
||||||
|
maxHeight,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
|
||||||
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
||||||
final MediaItemType modelMediaType = mediaModel.getMediaType();
|
final MediaItemType modelMediaType = mediaModel.getMediaType();
|
||||||
binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO
|
binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO || modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER
|
||||||
|| modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
? View.VISIBLE
|
||||||
|
: View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ package awais.instagrabber.adapters.viewholder.directmessages;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
||||||
@ -12,17 +14,23 @@ import awais.instagrabber.models.direct_messages.DirectItemModel;
|
|||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
import awais.instagrabber.models.enums.RavenExpiringMediaType;
|
import awais.instagrabber.models.enums.RavenExpiringMediaType;
|
||||||
import awais.instagrabber.models.enums.RavenMediaViewType;
|
import awais.instagrabber.models.enums.RavenMediaViewType;
|
||||||
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
public class DirectMessageRavenMediaViewHolder extends DirectMessageItemViewHolder {
|
public class DirectMessageRavenMediaViewHolder extends DirectMessageItemViewHolder {
|
||||||
|
|
||||||
private final LayoutDmRavenMediaBinding binding;
|
private final LayoutDmRavenMediaBinding binding;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int maxWidth;
|
||||||
|
|
||||||
public DirectMessageRavenMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
public DirectMessageRavenMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
||||||
@NonNull final LayoutDmRavenMediaBinding binding,
|
@NonNull final LayoutDmRavenMediaBinding binding,
|
||||||
final View.OnClickListener onClickListener) {
|
final View.OnClickListener onClickListener) {
|
||||||
super(baseBinding, onClickListener);
|
super(baseBinding, onClickListener);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height);
|
||||||
|
maxWidth = (int) (Utils.displayMetrics.widthPixels * 0.8);
|
||||||
binding.tvMessage.setVisibility(View.GONE);
|
binding.tvMessage.setVisibility(View.GONE);
|
||||||
setItemView(binding.getRoot());
|
setItemView(binding.getRoot());
|
||||||
}
|
}
|
||||||
@ -72,8 +80,19 @@ public class DirectMessageRavenMediaViewHolder extends DirectMessageItemViewHold
|
|||||||
if (ravenMediaViewType == RavenMediaViewType.PERMANENT || ravenMediaViewType == RavenMediaViewType.REPLAYABLE) {
|
if (ravenMediaViewType == RavenMediaViewType.PERMANENT || ravenMediaViewType == RavenMediaViewType.REPLAYABLE) {
|
||||||
final MediaItemType mediaType = mediaModel.getMediaType();
|
final MediaItemType mediaType = mediaModel.getMediaType();
|
||||||
textRes = -1;
|
textRes = -1;
|
||||||
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ||
|
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO || mediaType == MediaItemType.MEDIA_TYPE_SLIDER
|
||||||
mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
? View.VISIBLE
|
||||||
|
: View.GONE);
|
||||||
|
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
|
||||||
|
mediaModel.getHeight(),
|
||||||
|
mediaModel.getWidth(),
|
||||||
|
maxHeight,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
|
||||||
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
package awais.instagrabber.adapters.viewholder.directmessages;
|
package awais.instagrabber.adapters.viewholder.directmessages;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
||||||
import awais.instagrabber.databinding.LayoutDmRavenMediaBinding;
|
import awais.instagrabber.databinding.LayoutDmRavenMediaBinding;
|
||||||
import awais.instagrabber.interfaces.MentionClickListener;
|
import awais.instagrabber.interfaces.MentionClickListener;
|
||||||
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
public class DirectMessageReelShareViewHolder extends DirectMessageItemViewHolder {
|
public class DirectMessageReelShareViewHolder extends DirectMessageItemViewHolder {
|
||||||
|
|
||||||
private final LayoutDmRavenMediaBinding binding;
|
private final LayoutDmRavenMediaBinding binding;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int maxWidth;
|
||||||
|
|
||||||
public DirectMessageReelShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
public DirectMessageReelShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
||||||
@NonNull final LayoutDmRavenMediaBinding binding,
|
@NonNull final LayoutDmRavenMediaBinding binding,
|
||||||
@ -21,6 +28,8 @@ public class DirectMessageReelShareViewHolder extends DirectMessageItemViewHolde
|
|||||||
final MentionClickListener mentionClickListener) {
|
final MentionClickListener mentionClickListener) {
|
||||||
super(baseBinding, onClickListener);
|
super(baseBinding, onClickListener);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height);
|
||||||
|
maxWidth = (int) (Utils.displayMetrics.widthPixels * 0.8);
|
||||||
binding.tvMessage.setMentionClickListener(mentionClickListener);
|
binding.tvMessage.setMentionClickListener(mentionClickListener);
|
||||||
setItemView(binding.getRoot());
|
setItemView(binding.getRoot());
|
||||||
}
|
}
|
||||||
@ -42,6 +51,16 @@ public class DirectMessageReelShareViewHolder extends DirectMessageItemViewHolde
|
|||||||
} else {
|
} else {
|
||||||
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ||
|
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ||
|
||||||
mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
mediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE);
|
||||||
|
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
|
||||||
|
reelShareMedia.getHeight(),
|
||||||
|
reelShareMedia.getWidth(),
|
||||||
|
maxHeight,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
|
||||||
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
binding.ivMediaPreview.setImageURI(reelShareMedia.getThumbUrl());
|
binding.ivMediaPreview.setImageURI(reelShareMedia.getThumbUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,36 @@
|
|||||||
package awais.instagrabber.adapters.viewholder.directmessages;
|
package awais.instagrabber.adapters.viewholder.directmessages;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.text.HtmlCompat;
|
import androidx.core.text.HtmlCompat;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
import awais.instagrabber.databinding.LayoutDmBaseBinding;
|
||||||
import awais.instagrabber.databinding.LayoutDmStoryShareBinding;
|
import awais.instagrabber.databinding.LayoutDmStoryShareBinding;
|
||||||
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT;
|
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT;
|
||||||
|
|
||||||
public class DirectMessageStoryShareViewHolder extends DirectMessageItemViewHolder {
|
public class DirectMessageStoryShareViewHolder extends DirectMessageItemViewHolder {
|
||||||
|
|
||||||
private final LayoutDmStoryShareBinding binding;
|
private final LayoutDmStoryShareBinding binding;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int maxWidth;
|
||||||
|
|
||||||
public DirectMessageStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
public DirectMessageStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
|
||||||
@NonNull final LayoutDmStoryShareBinding binding,
|
@NonNull final LayoutDmStoryShareBinding binding,
|
||||||
final View.OnClickListener onClickListener) {
|
final View.OnClickListener onClickListener) {
|
||||||
super(baseBinding, onClickListener);
|
super(baseBinding, onClickListener);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height);
|
||||||
|
maxWidth = (int) (Utils.displayMetrics.widthPixels * 0.8);
|
||||||
binding.tvMessage.setVisibility(View.GONE);
|
binding.tvMessage.setVisibility(View.GONE);
|
||||||
setItemView(binding.getRoot());
|
setItemView(binding.getRoot());
|
||||||
}
|
}
|
||||||
@ -41,6 +50,16 @@ public class DirectMessageStoryShareViewHolder extends DirectMessageItemViewHold
|
|||||||
final DirectItemModel.DirectItemMediaModel reelShareMedia = reelShare.getMedia();
|
final DirectItemModel.DirectItemMediaModel reelShareMedia = reelShare.getMedia();
|
||||||
final MediaItemType mediaType = reelShareMedia.getMediaType();
|
final MediaItemType mediaType = reelShareMedia.getMediaType();
|
||||||
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? View.VISIBLE : View.GONE);
|
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? View.VISIBLE : View.GONE);
|
||||||
|
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
|
||||||
|
reelShareMedia.getHeight(),
|
||||||
|
reelShareMedia.getWidth(),
|
||||||
|
maxHeight,
|
||||||
|
maxWidth
|
||||||
|
);
|
||||||
|
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
|
||||||
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
|
binding.ivMediaPreview.requestLayout();
|
||||||
binding.ivMediaPreview.setImageURI(reelShareMedia.getThumbUrl());
|
binding.ivMediaPreview.setImageURI(reelShareMedia.getThumbUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +166,11 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
|
|
||||||
final MediaItemType mediaType = ResponseBodyUtils.getMediaItemType(media.getInt("media_type"));
|
final MediaItemType mediaType = ResponseBodyUtils.getMediaItemType(media.getInt("media_type"));
|
||||||
|
|
||||||
|
final ResponseBodyUtils.ThumbnailDetails thumbnailUrl = ResponseBodyUtils.getThumbnailUrl(media, mediaType);
|
||||||
final DiscoverItemModel model = new DiscoverItemModel(mediaType,
|
final DiscoverItemModel model = new DiscoverItemModel(mediaType,
|
||||||
media.getString("pk"),
|
media.getString("pk"),
|
||||||
media.getString("code"),
|
media.getString("code"),
|
||||||
ResponseBodyUtils.getThumbnailUrl(media, mediaType));
|
thumbnailUrl != null ? thumbnailUrl.url : null);
|
||||||
|
|
||||||
final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" +
|
final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" +
|
||||||
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/" + username) : ""));
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/" + username) : ""));
|
||||||
|
@ -139,11 +139,19 @@ public final class DirectItemModel implements Serializable, Comparable<DirectIte
|
|||||||
public final static class DirectItemAnimatedMediaModel implements Serializable {
|
public final static class DirectItemAnimatedMediaModel implements Serializable {
|
||||||
private final boolean isRandom, isSticker;
|
private final boolean isRandom, isSticker;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String gifUrl, webpUrl, mp4Url;
|
private final String gifUrl;
|
||||||
|
private final String webpUrl;
|
||||||
|
private final String mp4Url;
|
||||||
private final int height, width;
|
private final int height, width;
|
||||||
|
|
||||||
public DirectItemAnimatedMediaModel(final boolean isRandom, final boolean isSticker, final String id, final String gifUrl,
|
public DirectItemAnimatedMediaModel(final boolean isRandom,
|
||||||
final String webpUrl, final String mp4Url, final int height, final int width) {
|
final boolean isSticker,
|
||||||
|
final String id,
|
||||||
|
final String gifUrl,
|
||||||
|
final String webpUrl,
|
||||||
|
final String mp4Url,
|
||||||
|
final int height,
|
||||||
|
final int width) {
|
||||||
this.isRandom = isRandom;
|
this.isRandom = isRandom;
|
||||||
this.isSticker = isSticker;
|
this.isSticker = isSticker;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -370,11 +378,24 @@ public final class DirectItemModel implements Serializable, Comparable<DirectIte
|
|||||||
public final static class DirectItemMediaModel implements Serializable {
|
public final static class DirectItemMediaModel implements Serializable {
|
||||||
private final MediaItemType mediaType;
|
private final MediaItemType mediaType;
|
||||||
private final long expiringAt, pk;
|
private final long expiringAt, pk;
|
||||||
private final String id, thumbUrl, videoUrl, code;
|
private final String id;
|
||||||
|
private final String thumbUrl;
|
||||||
|
private final String videoUrl;
|
||||||
|
private final String code;
|
||||||
private final ProfileModel user;
|
private final ProfileModel user;
|
||||||
|
private final int height;
|
||||||
|
private final int width;
|
||||||
|
|
||||||
public DirectItemMediaModel(final MediaItemType mediaType, final long expiringAt, final long pk, final String id,
|
public DirectItemMediaModel(final MediaItemType mediaType,
|
||||||
final String thumbUrl, final String videoUrl, final ProfileModel user, final String code) {
|
final long expiringAt,
|
||||||
|
final long pk,
|
||||||
|
final String id,
|
||||||
|
final String thumbUrl,
|
||||||
|
final String videoUrl,
|
||||||
|
final ProfileModel user,
|
||||||
|
final String code,
|
||||||
|
final int height,
|
||||||
|
final int width) {
|
||||||
this.mediaType = mediaType;
|
this.mediaType = mediaType;
|
||||||
this.expiringAt = expiringAt;
|
this.expiringAt = expiringAt;
|
||||||
this.pk = pk;
|
this.pk = pk;
|
||||||
@ -383,6 +404,8 @@ public final class DirectItemModel implements Serializable, Comparable<DirectIte
|
|||||||
this.videoUrl = videoUrl;
|
this.videoUrl = videoUrl;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
this.height = height;
|
||||||
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaItemType getMediaType() {
|
public MediaItemType getMediaType() {
|
||||||
@ -419,6 +442,14 @@ public final class DirectItemModel implements Serializable, Comparable<DirectIte
|
|||||||
else return thumbUrl;
|
else return thumbUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static class DirectItemRavenMediaModel implements Serializable {
|
public final static class DirectItemRavenMediaModel implements Serializable {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package awais.instagrabber.utils;
|
package awais.instagrabber.utils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -53,4 +54,15 @@ public final class NumberUtils {
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static Pair<Integer, Integer> calculateWidthHeight(final int height, final int width, final int maxHeight, final int maxWidth) {
|
||||||
|
int tempWidth = NumberUtils.getResultingWidth(maxHeight, height, width);
|
||||||
|
int tempHeight = maxHeight;
|
||||||
|
if (width > maxWidth) {
|
||||||
|
tempHeight = NumberUtils.getResultingHeight(maxWidth, height, width);
|
||||||
|
tempWidth = maxWidth;
|
||||||
|
}
|
||||||
|
return new Pair<>(tempWidth, tempHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.models.ProfileModel;
|
import awais.instagrabber.models.ProfileModel;
|
||||||
@ -24,6 +23,8 @@ import awais.instagrabber.models.enums.RavenMediaViewType;
|
|||||||
import awaisomereport.LogCollector;
|
import awaisomereport.LogCollector;
|
||||||
|
|
||||||
public final class ResponseBodyUtils {
|
public final class ResponseBodyUtils {
|
||||||
|
private static final String TAG = "ResponseBodyUtils";
|
||||||
|
|
||||||
// isI: true if the content was requested from i.instagram.com instead of graphql
|
// isI: true if the content was requested from i.instagram.com instead of graphql
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getHighQualityPost(final JSONArray resources, final boolean isVideo, final boolean isI, final boolean low) {
|
public static String getHighQualityPost(final JSONArray resources, final boolean isVideo, final boolean isI, final boolean low) {
|
||||||
@ -103,37 +104,38 @@ public final class ResponseBodyUtils {
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getItemThumbnail(@NonNull final JSONArray jsonArray) {
|
public static ThumbnailDetails getItemThumbnail(@NonNull final JSONArray jsonArray) {
|
||||||
String thumbnail = null;
|
final ThumbnailDetails thumbnailDetails = new ThumbnailDetails();
|
||||||
final int imageResLen = jsonArray.length();
|
final int imageResLen = jsonArray.length();
|
||||||
|
|
||||||
for (int i = 0; i < imageResLen; ++i) {
|
for (int i = 0; i < imageResLen; ++i) {
|
||||||
final JSONObject imageResource = jsonArray.optJSONObject(i);
|
final JSONObject imageResource = jsonArray.optJSONObject(i);
|
||||||
try {
|
try {
|
||||||
final int width = imageResource.getInt("width");
|
// final float ratio = (float) height / width;
|
||||||
final int height = imageResource.getInt("height");
|
// if (ratio >= 0.95f && ratio <= 1.0f) {
|
||||||
final float ratio = Float.parseFloat(String.format(Locale.ENGLISH, "%.2f", (float) height / width));
|
thumbnailDetails.height = imageResource.getInt("height");
|
||||||
if (ratio >= 0.95f && ratio <= 1.0f) {
|
thumbnailDetails.width = imageResource.getInt("width");
|
||||||
thumbnail = imageResource.getString("url");
|
thumbnailDetails.url = imageResource.getString("url");
|
||||||
break;
|
break;
|
||||||
}
|
// }
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
if (Utils.logCollector != null)
|
if (Utils.logCollector != null)
|
||||||
Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getItemThumbnail");
|
Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getItemThumbnail");
|
||||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
if (BuildConfig.DEBUG) Log.e(TAG, "", e);
|
||||||
thumbnail = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if (TextUtils.isEmpty(thumbnail)) thumbnail = jsonArray.optJSONObject(0).optString("url");
|
||||||
|
return thumbnailDetails;
|
||||||
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(thumbnail)) thumbnail = jsonArray.optJSONObject(0).optString("url");
|
public static class ThumbnailDetails {
|
||||||
|
int width;
|
||||||
return thumbnail;
|
int height;
|
||||||
|
public String url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getThumbnailUrl(@NonNull final JSONObject mediaObj, final MediaItemType mediaType) throws Exception {
|
public static ThumbnailDetails getThumbnailUrl(@NonNull final JSONObject mediaObj, final MediaItemType mediaType) throws Exception {
|
||||||
String thumbnail = null;
|
ThumbnailDetails thumbnail = null;
|
||||||
|
|
||||||
if (mediaType == MediaItemType.MEDIA_TYPE_IMAGE || mediaType == MediaItemType.MEDIA_TYPE_VIDEO) {
|
if (mediaType == MediaItemType.MEDIA_TYPE_IMAGE || mediaType == MediaItemType.MEDIA_TYPE_VIDEO) {
|
||||||
final JSONObject imageVersions = mediaObj.optJSONObject("image_versions2");
|
final JSONObject imageVersions = mediaObj.optJSONObject("image_versions2");
|
||||||
if (imageVersions != null)
|
if (imageVersions != null)
|
||||||
@ -143,19 +145,18 @@ public final class ResponseBodyUtils {
|
|||||||
final JSONArray carouselMedia = mediaObj.optJSONArray("carousel_media");
|
final JSONArray carouselMedia = mediaObj.optJSONArray("carousel_media");
|
||||||
if (carouselMedia != null)
|
if (carouselMedia != null)
|
||||||
thumbnail = getItemThumbnail(carouselMedia.getJSONObject(0)
|
thumbnail = getItemThumbnail(carouselMedia.getJSONObject(0)
|
||||||
.getJSONObject("image_versions2").getJSONArray("candidates"));
|
.getJSONObject("image_versions2")
|
||||||
|
.getJSONArray("candidates"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVideoUrl(@NonNull final JSONObject mediaObj) throws Exception {
|
public static String getVideoUrl(@NonNull final JSONObject mediaObj) {
|
||||||
String thumbnail = null;
|
String thumbnail = null;
|
||||||
|
|
||||||
final JSONArray imageVersions = mediaObj.optJSONArray("video_versions");
|
final JSONArray imageVersions = mediaObj.optJSONArray("video_versions");
|
||||||
if (imageVersions != null)
|
if (imageVersions != null) {
|
||||||
thumbnail = getItemThumbnail(imageVersions);
|
thumbnail = getItemThumbnail(imageVersions).url;
|
||||||
|
}
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +194,18 @@ public final class ResponseBodyUtils {
|
|||||||
String id = mediaObj.optString("id");
|
String id = mediaObj.optString("id");
|
||||||
if (TextUtils.isEmpty(id)) id = null;
|
if (TextUtils.isEmpty(id)) id = null;
|
||||||
|
|
||||||
mediaModel = new DirectItemModel.DirectItemMediaModel(mediaType,
|
final ThumbnailDetails thumbnailDetails = getThumbnailUrl(mediaObj, mediaType);
|
||||||
|
mediaModel = new DirectItemModel.DirectItemMediaModel(
|
||||||
|
mediaType,
|
||||||
mediaObj.optLong("expiring_at"),
|
mediaObj.optLong("expiring_at"),
|
||||||
mediaObj.optLong("pk"),
|
mediaObj.optLong("pk"),
|
||||||
id,
|
id,
|
||||||
getThumbnailUrl(mediaObj, mediaType),
|
thumbnailDetails != null ? thumbnailDetails.url : null,
|
||||||
mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? getVideoUrl(mediaObj) : null,
|
mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? getVideoUrl(mediaObj) : null,
|
||||||
user,
|
user,
|
||||||
mediaObj.optString("code"));
|
mediaObj.optString("code"),
|
||||||
|
thumbnailDetails != null ? thumbnailDetails.height : 0,
|
||||||
|
thumbnailDetails != null ? thumbnailDetails.width : 0);
|
||||||
}
|
}
|
||||||
return mediaModel;
|
return mediaModel;
|
||||||
}
|
}
|
||||||
@ -314,7 +319,8 @@ public final class ResponseBodyUtils {
|
|||||||
final JSONObject animatedMedia = itemObject.getJSONObject("animated_media");
|
final JSONObject animatedMedia = itemObject.getJSONObject("animated_media");
|
||||||
final JSONObject stickerImage = animatedMedia.getJSONObject("images").getJSONObject("fixed_height");
|
final JSONObject stickerImage = animatedMedia.getJSONObject("images").getJSONObject("fixed_height");
|
||||||
|
|
||||||
animatedMediaModel = new DirectItemModel.DirectItemAnimatedMediaModel(animatedMedia.getBoolean("is_random"),
|
animatedMediaModel = new DirectItemModel.DirectItemAnimatedMediaModel(
|
||||||
|
animatedMedia.getBoolean("is_random"),
|
||||||
animatedMedia.getBoolean("is_sticker"),
|
animatedMedia.getBoolean("is_sticker"),
|
||||||
animatedMedia.getString("id"),
|
animatedMedia.getString("id"),
|
||||||
stickerImage.getString("url"),
|
stickerImage.getString("url"),
|
||||||
@ -340,8 +346,10 @@ public final class ResponseBodyUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
voiceMediaModel = new DirectItemModel.DirectItemVoiceMediaModel(voiceMedia.getString("id"),
|
voiceMediaModel = new DirectItemModel.DirectItemVoiceMediaModel(
|
||||||
audio.getString("audio_src"), audio.getLong("duration"),
|
voiceMedia.getString("id"),
|
||||||
|
audio.getString("audio_src"),
|
||||||
|
audio.getLong("duration"),
|
||||||
waveformData);
|
waveformData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -360,7 +368,8 @@ public final class ResponseBodyUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkModel = new DirectItemModel.DirectItemLinkModel(linkObj.getString("text"),
|
linkModel = new DirectItemModel.DirectItemLinkModel(
|
||||||
|
linkObj.getString("text"),
|
||||||
linkObj.getString("client_context"),
|
linkObj.getString("client_context"),
|
||||||
linkObj.optString("mutation_token"),
|
linkObj.optString("mutation_token"),
|
||||||
itemLinkContext);
|
itemLinkContext);
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:layout_marginTop="?actionBarSize"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/swipeRefreshLayout"
|
android:id="@+id/swipeRefreshLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/messageList"
|
android:id="@+id/messageList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:listitem="@layout/layout_dm_base"/>
|
tools:listitem="@layout/layout_dm_base" />
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.facebook.drawee.view.SimpleDraweeView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.facebook.drawee.view.SimpleDraweeView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/ivAnimatedMessage"
|
android:id="@+id/ivAnimatedMessage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/dm_media_img_max_height" />
|
||||||
android:maxHeight="@dimen/dm_media_img_max_height" />
|
|
@ -7,9 +7,7 @@
|
|||||||
<com.facebook.drawee.view.SimpleDraweeView
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
android:id="@+id/ivMediaPreview"
|
android:id="@+id/ivMediaPreview"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:maxHeight="@dimen/dm_media_img_max_height" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/typeIcon"
|
android:id="@+id/typeIcon"
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<argument
|
<argument
|
||||||
android:name="username"
|
android:name="username"
|
||||||
app:argType="string"
|
app:argType="string"
|
||||||
app:nullable="false" />
|
app:nullable="true" />
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<include app:graph="@navigation/location_nav_graph" />
|
<include app:graph="@navigation/location_nav_graph" />
|
||||||
|
Loading…
Reference in New Issue
Block a user