Convert some retrofit response classes to kotlin

This commit is contained in:
Ammar Githam 2021-05-23 06:26:33 +09:00
parent dde8fd37e3
commit 13bfc9cb84
32 changed files with 443 additions and 1509 deletions

View File

@ -144,7 +144,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple
}
setupReply(item, messageDirection);
setReactions(item, position);
if (item.getRepliedToMessage() == null && item.showForwardAttribution()) {
if (item.getRepliedToMessage() == null && item.getShowForwardAttribution()) {
setForwardInfo(messageDirection);
}
}
@ -193,7 +193,9 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple
if (showMessageInfo()) {
binding.messageInfo.setVisibility(View.VISIBLE);
binding.deliveryStatus.setVisibility(messageDirection == MessageDirection.OUTGOING ? View.VISIBLE : View.GONE);
binding.messageTime.setText(DateFormat.getTimeFormat(itemView.getContext()).format(item.getDate()));
if (item.getDate() != null) {
binding.messageTime.setText(DateFormat.getTimeFormat(itemView.getContext()).format(item.getDate()));
}
if (messageDirection == MessageDirection.OUTGOING) {
if (item.isPending()) {
binding.deliveryStatus.setImageResource(R.drawable.ic_check_24);

View File

@ -140,7 +140,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
if (result == null) return;
if (result instanceof String) {
final String collection = (String) result;
handleSaveUnsaveResourceLiveData(viewModel.toggleSave(collection, viewModel.getMedia().hasViewerSaved()));
handleSaveUnsaveResourceLiveData(viewModel.toggleSave(collection, viewModel.getMedia().getHasViewerSaved()));
}
// clear result
backStackSavedStateResultLiveData.postValue(null);
@ -313,7 +313,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
binding.getRoot().postDelayed(this::showCountTooltip, 1000);
}
});
if (!viewModel.getMedia().isCommentsDisabled()) {
if (!viewModel.getMedia().getCommentsDisabled()) {
viewModel.getCommentCount().observe(getViewLifecycleOwner(), count -> {
bottom.commentsCount.setNumber(getSafeCount(count));
binding.getRoot().postDelayed(() -> bottom.commentsCount.setAnimateChanges(true), 1000);
@ -395,7 +395,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
}
private void setupComment() {
if (!viewModel.hasPk() || viewModel.getMedia().isCommentsDisabled()) {
if (!viewModel.hasPk() || viewModel.getMedia().getCommentsDisabled()) {
bottom.comment.setVisibility(View.GONE);
// bottom.commentsCount.setVisibility(View.GONE);
return;
@ -493,7 +493,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
private void unsuccessfulLike() {
final int errorTextResId;
final Media media = viewModel.getMedia();
if (!media.hasLiked()) {
if (!media.getHasLiked()) {
Log.e(TAG, "like unsuccessful!");
errorTextResId = R.string.like_unsuccessful;
} else {
@ -526,7 +526,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
private void setupSave() {
originalSaveColorStateList = bottom.save.getIconTint();
if (!viewModel.isLoggedIn() || !viewModel.hasPk() || !viewModel.getMedia().canViewerSave()) {
if (!viewModel.isLoggedIn() || !viewModel.hasPk() || !viewModel.getMedia().getCanViewerSave()) {
bottom.save.setVisibility(View.GONE);
return;
}
@ -564,7 +564,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
private void unsuccessfulSave() {
final int errorTextResId;
final Media media = viewModel.getMedia();
if (!media.hasViewerSaved()) {
if (!media.getHasViewerSaved()) {
Log.e(TAG, "save unsuccessful!");
errorTextResId = R.string.save_unsuccessful;
} else {
@ -1350,7 +1350,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
// binding.captionToggle.setVisibility(View.VISIBLE);
bottom.share.setVisibility(View.VISIBLE);
}
if (viewModel.hasPk() && !viewModel.getMedia().isCommentsDisabled()) {
if (viewModel.hasPk() && !viewModel.getMedia().getCommentsDisabled()) {
bottom.comment.setVisibility(View.VISIBLE);
bottom.commentsCount.setVisibility(View.VISIBLE);
}

View File

@ -1,57 +0,0 @@
package awais.instagrabber.repositories.responses;
import java.io.Serializable;
import java.util.Objects;
public class AnimatedMediaFixedHeight implements Serializable {
private final int height;
private final int width;
private final String mp4;
private final String url;
private final String webp;
public AnimatedMediaFixedHeight(final int height, final int width, final String mp4, final String url, final String webp) {
this.height = height;
this.width = width;
this.mp4 = mp4;
this.url = url;
this.webp = webp;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public String getMp4() {
return mp4;
}
public String getUrl() {
return url;
}
public String getWebp() {
return webp;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final AnimatedMediaFixedHeight that = (AnimatedMediaFixedHeight) o;
return height == that.height &&
width == that.width &&
Objects.equals(mp4, that.mp4) &&
Objects.equals(url, that.url) &&
Objects.equals(webp, that.webp);
}
@Override
public int hashCode() {
return Objects.hash(height, width, mp4, url, webp);
}
}

View File

@ -0,0 +1,5 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class AnimatedMediaFixedHeight(val height: Int, val width: Int, val mp4: String?, val url: String?, val webp: String?) : Serializable

View File

@ -1,29 +0,0 @@
package awais.instagrabber.repositories.responses;
import java.io.Serializable;
import java.util.Objects;
public class AnimatedMediaImages implements Serializable {
private final AnimatedMediaFixedHeight fixedHeight;
public AnimatedMediaImages(final AnimatedMediaFixedHeight fixedHeight) {
this.fixedHeight = fixedHeight;
}
public AnimatedMediaFixedHeight getFixedHeight() {
return fixedHeight;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final AnimatedMediaImages that = (AnimatedMediaImages) o;
return Objects.equals(fixedHeight, that.fixedHeight);
}
@Override
public int hashCode() {
return Objects.hash(fixedHeight);
}
}

View File

@ -0,0 +1,5 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class AnimatedMediaImages(val fixedHeight: AnimatedMediaFixedHeight?) : Serializable

View File

@ -1,62 +0,0 @@
package awais.instagrabber.repositories.responses;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
public class Audio implements Serializable {
private final String audioSrc;
private final long duration;
private final List<Float> waveformData;
private final int waveformSamplingFrequencyHz;
private final long audioSrcExpirationTimestampUs;
public Audio(final String audioSrc,
final long duration,
final List<Float> waveformData,
final int waveformSamplingFrequencyHz,
final long audioSrcExpirationTimestampUs) {
this.audioSrc = audioSrc;
this.duration = duration;
this.waveformData = waveformData;
this.waveformSamplingFrequencyHz = waveformSamplingFrequencyHz;
this.audioSrcExpirationTimestampUs = audioSrcExpirationTimestampUs;
}
public String getAudioSrc() {
return audioSrc;
}
public long getDuration() {
return duration;
}
public List<Float> getWaveformData() {
return waveformData;
}
public int getWaveformSamplingFrequencyHz() {
return waveformSamplingFrequencyHz;
}
public long getAudioSrcExpirationTimestampUs() {
return audioSrcExpirationTimestampUs;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Audio audio = (Audio) o;
return duration == audio.duration &&
waveformSamplingFrequencyHz == audio.waveformSamplingFrequencyHz &&
audioSrcExpirationTimestampUs == audio.audioSrcExpirationTimestampUs &&
Objects.equals(audioSrc, audio.audioSrc) &&
Objects.equals(waveformData, audio.waveformData);
}
@Override
public int hashCode() {
return Objects.hash(audioSrc, duration, waveformData, waveformSamplingFrequencyHz, audioSrcExpirationTimestampUs);
}
}

View File

@ -0,0 +1,11 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class Audio(
val audioSrc: String?,
val duration: Long,
val waveformData: List<Float>?,
val waveformSamplingFrequencyHz: Int,
val audioSrcExpirationTimestampUs: Long
) : Serializable

View File

@ -1,22 +0,0 @@
package awais.instagrabber.repositories.responses;
import java.util.List;
public class AymlResponse {
private final AymlUserList newSuggestedUsers;
private final AymlUserList suggestedUsers;
public AymlResponse(final AymlUserList newSuggestedUsers,
final AymlUserList suggestedUsers) {
this.newSuggestedUsers = newSuggestedUsers;
this.suggestedUsers = suggestedUsers;
}
public AymlUserList getNewSuggestedUsers() {
return newSuggestedUsers;
}
public AymlUserList getSuggestedUsers() {
return suggestedUsers;
}
}

View File

@ -0,0 +1,14 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class AymlResponse(val newSuggestedUsers: AymlUserList?, val suggestedUsers: AymlUserList?) : Serializable
data class AymlUser(
val user: User?,
val algorithm: String?,
val socialContext: String?,
val uuid: String?
) : Serializable
data class AymlUserList(val suggestions: List<AymlUser>?) : Serializable

View File

@ -1,34 +0,0 @@
package awais.instagrabber.repositories.responses;
public class AymlUser {
private final User user;
private final String algorithm;
private final String socialContext;
private final String uuid;
public AymlUser(final User user,
final String algorithm,
final String socialContext,
final String uuid) {
this.user = user;
this.algorithm = algorithm;
this.socialContext = socialContext;
this.uuid = uuid;
}
public User getUser() {
return user;
}
public String getAlgorithm() {
return algorithm;
}
public String getSocialContext() {
return socialContext;
}
public String getUuid() {
return uuid;
}
}

View File

@ -1,15 +0,0 @@
package awais.instagrabber.repositories.responses;
import java.util.List;
public class AymlUserList {
private final List<AymlUser> suggestions;
public AymlUserList(final List<AymlUser> suggestions) {
this.suggestions = suggestions;
}
public List<AymlUser> getSuggestions() {
return suggestions;
}
}

View File

@ -1,88 +0,0 @@
package awais.instagrabber.repositories.responses;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Objects;
public class Caption implements Serializable {
private long mPk;
private final long userId;
private String text;
public Caption(final long userId, final String text) {
this.userId = userId;
this.text = text;
}
public long getPk() {
return mPk;
}
public void setPk(final long pk) {
this.mPk = pk;
}
public long getUserId() {
return userId;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Caption caption = (Caption) o;
return mPk == caption.mPk &&
userId == caption.userId &&
Objects.equals(text, caption.text);
}
@Override
public int hashCode() {
return Objects.hash(mPk, userId, text);
}
public static class CaptionDeserializer implements JsonDeserializer<Caption> {
private static final String TAG = CaptionDeserializer.class.getSimpleName();
@Override
public Caption deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final Caption caption = new Gson().fromJson(json, Caption.class);
final JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("pk")) {
JsonElement elem = jsonObject.get("pk");
if (elem != null && !elem.isJsonNull()) {
if (!elem.isJsonPrimitive()) return caption;
String pkString = elem.getAsString();
if (pkString.contains("_")) {
pkString = pkString.substring(0, pkString.indexOf("_"));
}
try {
caption.setPk(Long.parseLong(pkString));
} catch (NumberFormatException e) {
Log.e(TAG, "deserialize: ", e);
}
}
}
return caption;
}
}
}

View File

@ -0,0 +1,5 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class Caption(var pk: Long = 0, val userId: Long, var text: String) : Serializable

View File

@ -1,31 +0,0 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
public class FriendshipChangeResponse {
private final FriendshipStatus friendshipStatus;
private final String status;
public FriendshipChangeResponse(final FriendshipStatus friendshipStatus,
final String status) {
this.friendshipStatus = friendshipStatus;
this.status = status;
}
public FriendshipStatus getFriendshipStatus() {
return friendshipStatus;
}
public String getStatus() {
return status;
}
@NonNull
@Override
public String toString() {
return "FriendshipChangeResponse{" +
"friendshipStatus=" + friendshipStatus +
", status='" + status + '\'' +
'}';
}
}

View File

@ -0,0 +1,3 @@
package awais.instagrabber.repositories.responses
data class FriendshipChangeResponse(val friendshipStatus: FriendshipStatus?, val status: String?)

View File

@ -1,79 +0,0 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
import java.util.List;
import java.util.Objects;
import awais.instagrabber.models.FollowModel;
import awais.instagrabber.utils.TextUtils;
public class FriendshipListFetchResponse {
private String nextMaxId;
private String status;
private List<FollowModel> items;
public FriendshipListFetchResponse(final String nextMaxId,
final String status,
final List<FollowModel> items) {
this.nextMaxId = nextMaxId;
this.status = status;
this.items = items;
}
public boolean isMoreAvailable() {
return !TextUtils.isEmpty(nextMaxId);
}
public String getNextMaxId() {
return nextMaxId;
}
public FriendshipListFetchResponse setNextMaxId(final String nextMaxId) {
this.nextMaxId = nextMaxId;
return this;
}
public String getStatus() {
return status;
}
public FriendshipListFetchResponse setStatus(final String status) {
this.status = status;
return this;
}
public List<FollowModel> getItems() {
return items;
}
public FriendshipListFetchResponse setItems(final List<FollowModel> items) {
this.items = items;
return this;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final FriendshipListFetchResponse that = (FriendshipListFetchResponse) o;
return Objects.equals(nextMaxId, that.nextMaxId) &&
Objects.equals(status, that.status) &&
Objects.equals(items, that.items);
}
@Override
public int hashCode() {
return Objects.hash(nextMaxId, status, items);
}
@NonNull
@Override
public String toString() {
return "FriendshipRepoListFetchResponse{" +
"nextMaxId='" + nextMaxId + '\'' +
", status='" + status + '\'' +
", items=" + items +
'}';
}
}

View File

@ -0,0 +1,27 @@
package awais.instagrabber.repositories.responses
import awais.instagrabber.models.FollowModel
data class FriendshipListFetchResponse(
var nextMaxId: String?,
var status: String?,
var items: List<FollowModel>?
) {
val isMoreAvailable: Boolean
get() = !nextMaxId.isNullOrBlank()
fun setNextMaxId(nextMaxId: String): FriendshipListFetchResponse {
this.nextMaxId = nextMaxId
return this
}
fun setStatus(status: String): FriendshipListFetchResponse {
this.status = status
return this
}
fun setItems(items: List<FollowModel>): FriendshipListFetchResponse {
this.items = items
return this
}
}

View File

@ -1,32 +0,0 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
import java.util.List;
public class FriendshipRestrictResponse {
private final List<User> users;
private final String status;
public FriendshipRestrictResponse(final List<User> users, final String status) {
this.users = users;
this.status = status;
}
public List<User> getUsers() {
return users;
}
public String getStatus() {
return status;
}
@NonNull
@Override
public String toString() {
return "FriendshipRestrictResponse{" +
"users=" + users +
", status='" + status + '\'' +
'}';
}
}

View File

@ -0,0 +1,3 @@
package awais.instagrabber.repositories.responses
data class FriendshipRestrictResponse(val users: List<User>?, val status: String?)

View File

@ -1,121 +0,0 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
import java.io.Serializable;
import java.util.Objects;
public class FriendshipStatus implements Serializable {
private final boolean following;
private final boolean followedBy;
private final boolean blocking;
private final boolean muting;
private final boolean isPrivate;
private final boolean incomingRequest;
private final boolean outgoingRequest;
private final boolean isBestie;
private final boolean isRestricted;
private final boolean isMutingReel;
public FriendshipStatus(final boolean following,
final boolean followedBy,
final boolean blocking,
final boolean muting,
final boolean isPrivate,
final boolean incomingRequest,
final boolean outgoingRequest,
final boolean isBestie,
final boolean isRestricted,
final boolean isMutingReel) {
this.following = following;
this.followedBy = followedBy;
this.blocking = blocking;
this.muting = muting;
this.isPrivate = isPrivate;
this.incomingRequest = incomingRequest;
this.outgoingRequest = outgoingRequest;
this.isBestie = isBestie;
this.isRestricted = isRestricted;
this.isMutingReel = isMutingReel;
}
public boolean isFollowing() {
return following;
}
public boolean isFollowedBy() {
return followedBy;
}
public boolean isBlocking() {
return blocking;
}
public boolean isMuting() {
return muting;
}
public boolean isPrivate() {
return isPrivate;
}
public boolean isIncomingRequest() {
return incomingRequest;
}
public boolean isOutgoingRequest() {
return outgoingRequest;
}
public boolean isBestie() {
return isBestie;
}
public boolean isRestricted() {
return isRestricted;
}
public boolean isMutingReel() {
return isMutingReel;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final FriendshipStatus that = (FriendshipStatus) o;
return following == that.following &&
followedBy == that.followedBy &&
blocking == that.blocking &&
muting == that.muting &&
isPrivate == that.isPrivate &&
incomingRequest == that.incomingRequest &&
outgoingRequest == that.outgoingRequest &&
isBestie == that.isBestie &&
isRestricted == that.isRestricted &&
isMutingReel == that.isMutingReel;
}
@Override
public int hashCode() {
return Objects.hash(following, followedBy, blocking, muting, isPrivate, incomingRequest, outgoingRequest, isBestie, isRestricted,
isMutingReel);
}
@NonNull
@Override
public String toString() {
return "FriendshipStatus{" +
"following=" + following +
", followedBy=" + followedBy +
", blocking=" + blocking +
", muting=" + muting +
", isPrivate=" + isPrivate +
", incomingRequest=" + incomingRequest +
", outgoingRequest=" + outgoingRequest +
", isBestie=" + isBestie +
", isRestricted=" + isRestricted +
", isMutingReel=" + isMutingReel +
'}';
}
}

View File

@ -0,0 +1,16 @@
package awais.instagrabber.repositories.responses
import java.io.Serializable
data class FriendshipStatus(
val isFollowing: Boolean,
val isFollowedBy: Boolean,
val isBlocking: Boolean,
val isMuting: Boolean,
val isPrivate: Boolean,
val isIncomingRequest: Boolean,
val isOutgoingRequest: Boolean,
val isBestie: Boolean,
val isRestricted: Boolean,
val isMutingReel: Boolean
) : Serializable

View File

@ -1,332 +0,0 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.feed.EndOfFeedDemarcator;
import awais.instagrabber.utils.Utils;
public class Media implements Serializable {
private final String pk;
private final String id;
private final String code;
private final long takenAt;
private final User user;
private final MediaItemType mediaType;
private final boolean canViewerReshare;
private final boolean commentLikesEnabled;
private final boolean commentsDisabled;
private final long nextMaxId;
private final long commentCount;
private final ImageVersions2 imageVersions2;
private final int originalWidth;
private final int originalHeight;
private long likeCount;
private boolean hasLiked;
private final boolean isReelMedia;
private final List<VideoVersion> videoVersions;
private final boolean hasAudio;
private final double videoDuration;
private final long viewCount;
private Caption caption;
private final boolean canViewerSave;
private final Audio audio;
private final String title;
private final Location location;
private final Usertags usertags;
private final List<Media> carouselMedia;
private boolean isSidecarChild;
private boolean hasViewerSaved;
private final Map<String, Object> injected;
private final EndOfFeedDemarcator endOfFeedDemarcator;
private String dateString;
public Media(final String pk,
final String id,
final String code,
final long takenAt,
final User user,
final boolean canViewerReshare,
final ImageVersions2 imageVersions2,
final int originalWidth,
final int originalHeight,
final MediaItemType mediaType,
final boolean commentLikesEnabled,
final boolean commentsDisabled,
final long nextMaxId,
final long commentCount,
final long likeCount,
final boolean hasLiked,
final boolean isReelMedia,
final List<VideoVersion> videoVersions,
final boolean hasAudio,
final double videoDuration,
final long viewCount,
final Caption caption,
final boolean canViewerSave,
final Audio audio,
final String title,
final List<Media> carouselMedia,
final Location location,
final Usertags usertags,
final boolean isSidecarChild,
final boolean hasViewerSaved,
final Map<String, Object> injected,
final EndOfFeedDemarcator endOfFeedDemarcator) {
this.pk = pk;
this.id = id;
this.code = code;
this.takenAt = takenAt;
this.user = user;
this.canViewerReshare = canViewerReshare;
this.imageVersions2 = imageVersions2;
this.originalWidth = originalWidth;
this.originalHeight = originalHeight;
this.mediaType = mediaType;
this.commentLikesEnabled = commentLikesEnabled;
this.commentsDisabled = commentsDisabled;
this.nextMaxId = nextMaxId;
this.commentCount = commentCount;
this.likeCount = likeCount;
this.hasLiked = hasLiked;
this.isReelMedia = isReelMedia;
this.videoVersions = videoVersions;
this.hasAudio = hasAudio;
this.videoDuration = videoDuration;
this.viewCount = viewCount;
this.caption = caption;
this.canViewerSave = canViewerSave;
this.audio = audio;
this.title = title;
this.carouselMedia = carouselMedia;
this.location = location;
this.usertags = usertags;
this.isSidecarChild = isSidecarChild;
this.hasViewerSaved = hasViewerSaved;
this.injected = injected;
this.endOfFeedDemarcator = endOfFeedDemarcator;
}
public String getPk() {
return pk;
}
public String getId() {
return id;
}
public String getCode() {
return code;
}
public long getTakenAt() {
return takenAt;
}
@Nullable
public User getUser() {
return user;
}
public boolean canViewerReshare() {
return canViewerReshare;
}
public ImageVersions2 getImageVersions2() {
return imageVersions2;
}
public int getOriginalWidth() {
return originalWidth;
}
public int getOriginalHeight() {
return originalHeight;
}
public MediaItemType getMediaType() {
return mediaType;
}
public boolean isReelMedia() {
return isReelMedia;
}
public List<VideoVersion> getVideoVersions() {
return videoVersions;
}
public boolean isHasAudio() {
return hasAudio;
}
public Caption getCaption() {
return caption;
}
public Audio getAudio() {
return audio;
}
public String getTitle() {
return title;
}
public List<Media> getCarouselMedia() {
return carouselMedia;
}
public boolean isCommentLikesEnabled() {
return commentLikesEnabled;
}
public boolean isCommentsDisabled() {
return commentsDisabled;
}
public long getNextMaxId() {
return nextMaxId;
}
public long getCommentCount() {
return commentCount;
}
public long getLikeCount() {
return likeCount;
}
public boolean hasLiked() {
return hasLiked;
}
public double getVideoDuration() {
return videoDuration;
}
public long getViewCount() {
return viewCount;
}
public boolean canViewerSave() {
return canViewerSave;
}
public Location getLocation() {
return location;
}
public Usertags getUsertags() {
return usertags;
}
public void setIsSidecarChild(boolean isSidecarChild) {
this.isSidecarChild = isSidecarChild;
}
public boolean isSidecarChild() {
return isSidecarChild;
}
public boolean hasViewerSaved() {
return hasViewerSaved;
}
public boolean isInjected() {
return injected != null;
}
@Nullable
public String getDate() {
if (takenAt <= 0) {
return null;
}
if (dateString == null) {
dateString = Utils.datetimeParser.format(new Date(takenAt * 1000L));
}
return dateString;
}
public EndOfFeedDemarcator getEndOfFeedDemarcator() {
return endOfFeedDemarcator;
}
public void setHasLiked(final boolean liked) {
this.hasLiked = liked;
}
public void setLikeCount(final long likeCount) {
this.likeCount = likeCount;
}
public void setHasViewerSaved(final boolean hasViewerSaved) {
this.hasViewerSaved = hasViewerSaved;
}
public void setPostCaption(final String caption) {
Caption caption1 = getCaption();
if (caption1 == null) {
final User user = getUser();
if (user == null) return;
caption1 = new Caption(user.getPk(), caption);
this.caption = caption1;
return;
}
caption1.setText(caption);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Media media = (Media) o;
return takenAt == media.takenAt &&
canViewerReshare == media.canViewerReshare &&
commentLikesEnabled == media.commentLikesEnabled &&
commentsDisabled == media.commentsDisabled &&
nextMaxId == media.nextMaxId &&
commentCount == media.commentCount &&
originalWidth == media.originalWidth &&
originalHeight == media.originalHeight &&
likeCount == media.likeCount &&
hasLiked == media.hasLiked &&
isReelMedia == media.isReelMedia &&
hasAudio == media.hasAudio &&
Double.compare(media.videoDuration, videoDuration) == 0 &&
viewCount == media.viewCount &&
canViewerSave == media.canViewerSave &&
isSidecarChild == media.isSidecarChild &&
hasViewerSaved == media.hasViewerSaved &&
Objects.equals(pk, media.pk) &&
Objects.equals(id, media.id) &&
Objects.equals(code, media.code) &&
Objects.equals(user, media.user) &&
mediaType == media.mediaType &&
Objects.equals(imageVersions2, media.imageVersions2) &&
Objects.equals(videoVersions, media.videoVersions) &&
Objects.equals(caption, media.caption) &&
Objects.equals(audio, media.audio) &&
Objects.equals(title, media.title) &&
Objects.equals(location, media.location) &&
Objects.equals(usertags, media.usertags) &&
Objects.equals(carouselMedia, media.carouselMedia) &&
Objects.equals(injected, media.injected) &&
Objects.equals(endOfFeedDemarcator, media.endOfFeedDemarcator) &&
Objects.equals(dateString, media.dateString);
}
@Override
public int hashCode() {
return Objects.hash(pk, id, code, takenAt, user, mediaType, canViewerReshare, commentLikesEnabled, commentsDisabled, nextMaxId, commentCount,
imageVersions2, originalWidth, originalHeight, likeCount, hasLiked, isReelMedia, videoVersions, hasAudio, videoDuration,
viewCount, caption, canViewerSave, audio, title, location, usertags, carouselMedia, isSidecarChild, hasViewerSaved,
injected, endOfFeedDemarcator, dateString);
}
}

View File

@ -0,0 +1,71 @@
package awais.instagrabber.repositories.responses
import awais.instagrabber.models.enums.MediaItemType
import awais.instagrabber.repositories.responses.feed.EndOfFeedDemarcator
import awais.instagrabber.utils.Utils
import java.io.Serializable
import java.util.*
data class Media(
val pk: String? = null,
val id: String? = null,
val code: String? = null,
val takenAt: Long = -1,
val user: User? = null,
val canViewerReshare: Boolean = false,
val imageVersions2: ImageVersions2? = null,
val originalWidth: Int = 0,
val originalHeight: Int = 0,
val mediaType: MediaItemType? = null,
val commentLikesEnabled: Boolean = false,
val commentsDisabled: Boolean = false,
val nextMaxId: Long = -1,
val commentCount: Long = 0,
var likeCount: Long = 0,
var hasLiked: Boolean = false,
val isReelMedia: Boolean = false,
val videoVersions: List<VideoVersion>? = null,
val hasAudio: Boolean = false,
val videoDuration: Double = 0.0,
val viewCount: Long = 0,
var caption: Caption? = null,
val canViewerSave: Boolean = false,
val audio: Audio? = null,
val title: String? = null,
val carouselMedia: List<Media>? = null,
val location: Location? = null,
val usertags: Usertags? = null,
var isSidecarChild: Boolean = false,
var hasViewerSaved: Boolean = false,
private val injected: Map<String, Any>? = null,
val endOfFeedDemarcator: EndOfFeedDemarcator? = null
) : Serializable {
private var dateString: String? = null
fun isInjected(): Boolean {
return injected != null
}
// TODO use extension once all usages are converted to kotlin
// val date: String by lazy {
// if (takenAt <= 0) "" else Utils.datetimeParser.format(Date(takenAt * 1000L))
// }
val date: String
get() {
if (takenAt <= 0) return ""
if (dateString != null) return dateString ?: ""
dateString = Utils.datetimeParser.format(Date(takenAt * 1000L))
return dateString ?: ""
}
fun setPostCaption(caption: String?) {
var caption1: Caption? = this.caption
if (caption1 == null) {
user ?: return
caption1 = Caption(userId = user.pk, text = caption ?: "")
this.caption = caption1
return
}
caption1.text = caption ?: ""
}
}

View File

@ -1,306 +0,0 @@
package awais.instagrabber.repositories.responses.directmessages;
import androidx.annotation.NonNull;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
public class DirectItem implements Cloneable, Serializable {
private String itemId;
private final long userId;
private long timestamp;
private final DirectItemType itemType;
private final String text;
private final String like;
private final DirectItemLink link;
private final String clientContext;
private final DirectItemReelShare reelShare;
private final DirectItemStoryShare storyShare;
private final Media mediaShare;
private final User profile;
private final DirectItemPlaceholder placeholder;
private final Media media;
private final List<Media> previewMedias;
private final DirectItemActionLog actionLog;
private final DirectItemVideoCallEvent videoCallEvent;
private final DirectItemClip clip;
private final DirectItemFelixShare felixShare;
private final DirectItemVisualMedia visualMedia;
private final DirectItemAnimatedMedia animatedMedia;
private DirectItemReactions reactions;
private final DirectItem repliedToMessage;
private final DirectItemVoiceMedia voiceMedia;
private final Location location;
private final DirectItemXma xma;
private final int hideInThread;
private Date date;
private boolean isPending;
private final boolean showForwardAttribution;
private LocalDateTime localDateTime;
public DirectItem(final String itemId,
final long userId,
final long timestamp,
final DirectItemType itemType,
final String text,
final String like,
final DirectItemLink link,
final String clientContext,
final DirectItemReelShare reelShare,
final DirectItemStoryShare storyShare,
final Media mediaShare,
final User profile,
final DirectItemPlaceholder placeholder,
final Media media,
final List<Media> previewMedias,
final DirectItemActionLog actionLog,
final DirectItemVideoCallEvent videoCallEvent,
final DirectItemClip clip,
final DirectItemFelixShare felixShare,
final DirectItemVisualMedia visualMedia,
final DirectItemAnimatedMedia animatedMedia,
final DirectItemReactions reactions,
final DirectItem repliedToMessage,
final DirectItemVoiceMedia voiceMedia,
final Location location,
final DirectItemXma xma,
final int hideInThread,
final boolean showForwardAttribution) {
this.itemId = itemId;
this.userId = userId;
this.timestamp = timestamp;
this.itemType = itemType;
this.text = text;
this.like = like;
this.link = link;
this.clientContext = clientContext;
this.reelShare = reelShare;
this.storyShare = storyShare;
this.mediaShare = mediaShare;
this.profile = profile;
this.placeholder = placeholder;
this.media = media;
this.previewMedias = previewMedias;
this.actionLog = actionLog;
this.videoCallEvent = videoCallEvent;
this.clip = clip;
this.felixShare = felixShare;
this.visualMedia = visualMedia;
this.animatedMedia = animatedMedia;
this.reactions = reactions;
this.repliedToMessage = repliedToMessage;
this.voiceMedia = voiceMedia;
this.location = location;
this.xma = xma;
this.hideInThread = hideInThread;
this.showForwardAttribution = showForwardAttribution;
}
public String getItemId() {
return itemId;
}
public long getUserId() {
return userId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
this.date = null;
}
public DirectItemType getItemType() {
return itemType;
}
public String getText() {
return text;
}
public DirectItemLink getLink() {
return link;
}
public String getClientContext() {
return clientContext;
}
public DirectItemReelShare getReelShare() {
return reelShare;
}
public User getProfile() {
return profile;
}
public DirectItemPlaceholder getPlaceholder() {
return placeholder;
}
public Media getMediaShare() {
return mediaShare;
}
public String getLike() {
return like;
}
public Media getMedia() {
return media;
}
public List<Media> getPreviewMedias() {
return previewMedias;
}
public DirectItemStoryShare getStoryShare() {
return storyShare;
}
public DirectItemActionLog getActionLog() {
return actionLog;
}
public DirectItemVideoCallEvent getVideoCallEvent() {
return videoCallEvent;
}
public DirectItemClip getClip() {
return clip;
}
public DirectItemFelixShare getFelixShare() {
return felixShare;
}
public DirectItemVisualMedia getVisualMedia() {
return visualMedia;
}
public DirectItemAnimatedMedia getAnimatedMedia() {
return animatedMedia;
}
public DirectItemReactions getReactions() {
return reactions;
}
public DirectItem getRepliedToMessage() {
return repliedToMessage;
}
public DirectItemVoiceMedia getVoiceMedia() {
return voiceMedia;
}
public Location getLocation() {
return location;
}
public DirectItemXma getXma() {
return xma;
}
public int getHideInThread() {
return hideInThread;
}
public Date getDate() {
if (date == null) {
date = new Date(timestamp / 1000);
}
return date;
}
public LocalDateTime getLocalDateTime() {
if (localDateTime == null) {
localDateTime = Instant.ofEpochMilli(timestamp / 1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
return localDateTime;
}
public void setItemId(final String itemId) {
this.itemId = itemId;
}
public boolean isPending() {
return isPending;
}
public void setPending(final boolean pending) {
isPending = pending;
}
public void setReactions(final DirectItemReactions reactions) {
this.reactions = reactions;
}
public boolean showForwardAttribution() {
return showForwardAttribution;
}
@NonNull
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final DirectItem that = (DirectItem) o;
return userId == that.userId &&
timestamp == that.timestamp &&
hideInThread == that.hideInThread &&
isPending == that.isPending &&
showForwardAttribution == that.showForwardAttribution &&
Objects.equals(itemId, that.itemId) &&
itemType == that.itemType &&
Objects.equals(text, that.text) &&
Objects.equals(like, that.like) &&
Objects.equals(link, that.link) &&
Objects.equals(clientContext, that.clientContext) &&
Objects.equals(reelShare, that.reelShare) &&
Objects.equals(storyShare, that.storyShare) &&
Objects.equals(mediaShare, that.mediaShare) &&
Objects.equals(profile, that.profile) &&
Objects.equals(placeholder, that.placeholder) &&
Objects.equals(media, that.media) &&
Objects.equals(previewMedias, that.previewMedias) &&
Objects.equals(actionLog, that.actionLog) &&
Objects.equals(videoCallEvent, that.videoCallEvent) &&
Objects.equals(clip, that.clip) &&
Objects.equals(felixShare, that.felixShare) &&
Objects.equals(visualMedia, that.visualMedia) &&
Objects.equals(animatedMedia, that.animatedMedia) &&
Objects.equals(reactions, that.reactions) &&
Objects.equals(repliedToMessage, that.repliedToMessage) &&
Objects.equals(voiceMedia, that.voiceMedia) &&
Objects.equals(location, that.location) &&
Objects.equals(xma, that.xma) &&
Objects.equals(date, that.date);
}
@Override
public int hashCode() {
return Objects
.hash(itemId, userId, timestamp, itemType, text, like, link, clientContext, reelShare, storyShare, mediaShare, profile, placeholder,
media, previewMedias, actionLog, videoCallEvent, clip, felixShare, visualMedia, animatedMedia, reactions, repliedToMessage,
voiceMedia, location, xma, hideInThread, date, isPending, showForwardAttribution);
}
}

View File

@ -0,0 +1,74 @@
package awais.instagrabber.repositories.responses.directmessages
import awais.instagrabber.models.enums.DirectItemType
import awais.instagrabber.repositories.responses.Location
import awais.instagrabber.repositories.responses.Media
import awais.instagrabber.repositories.responses.User
import java.io.Serializable
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.util.*
data class DirectItem(
var itemId: String? = null,
val userId: Long = 0,
private var timestamp: Long = 0,
val itemType: DirectItemType? = null,
val text: String? = null,
val like: String? = null,
val link: DirectItemLink? = null,
val clientContext: String? = null,
val reelShare: DirectItemReelShare? = null,
val storyShare: DirectItemStoryShare? = null,
val mediaShare: Media? = null,
val profile: User? = null,
val placeholder: DirectItemPlaceholder? = null,
val media: Media? = null,
val previewMedias: List<Media>? = null,
val actionLog: DirectItemActionLog? = null,
val videoCallEvent: DirectItemVideoCallEvent? = null,
val clip: DirectItemClip? = null,
val felixShare: DirectItemFelixShare? = null,
val visualMedia: DirectItemVisualMedia? = null,
val animatedMedia: DirectItemAnimatedMedia? = null,
var reactions: DirectItemReactions? = null,
val repliedToMessage: DirectItem? = null,
val voiceMedia: DirectItemVoiceMedia? = null,
val location: Location? = null,
val xma: DirectItemXma? = null,
val hideInThread: Int? = 0,
val showForwardAttribution: Boolean = false
) : Cloneable, Serializable {
private var date: Date? = null
var isPending = false
var localDateTime: LocalDateTime? = null
get() {
if (field == null) {
field = Instant.ofEpochMilli(timestamp / 1000).atZone(ZoneId.systemDefault()).toLocalDateTime()
}
return field
}
private set
fun getTimestamp(): Long {
return timestamp
}
fun setTimestamp(timestamp: Long) {
this.timestamp = timestamp
date = null
}
fun getDate(): Date? {
if (date == null) {
date = Date(timestamp / 1000)
}
return date
}
@Throws(CloneNotSupportedException::class)
public override fun clone(): Any {
return super.clone()
}
}

View File

@ -0,0 +1,41 @@
package awais.instagrabber.repositories.serializers;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import awais.instagrabber.repositories.responses.Caption;
public class CaptionDeserializer implements JsonDeserializer<Caption> {
private static final String TAG = CaptionDeserializer.class.getSimpleName();
@Override
public Caption deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final Caption caption = new Gson().fromJson(json, Caption.class);
final JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("pk")) {
JsonElement elem = jsonObject.get("pk");
if (elem != null && !elem.isJsonNull()) {
if (!elem.isJsonPrimitive()) return caption;
String pkString = elem.getAsString();
if (pkString.contains("_")) {
pkString = pkString.substring(0, pkString.indexOf("_"));
}
try {
caption.setPk(Long.parseLong(pkString));
} catch (NumberFormatException e) {
Log.e(TAG, "deserialize: ", e);
}
}
}
return caption;
}
}

View File

@ -1,264 +0,0 @@
package awais.instagrabber.utils;
import android.net.Uri;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.AnimatedMediaImages;
import awais.instagrabber.repositories.responses.Audio;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.MediaCandidate;
import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemAnimatedMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVoiceMedia;
import awais.instagrabber.repositories.responses.giphy.GiphyGif;
public final class DirectItemFactory {
public static DirectItem createText(final long userId,
final String clientContext,
final String text,
final DirectItem repliedToMessage) {
return new DirectItem(
UUID.randomUUID().toString(),
userId,
System.currentTimeMillis() * 1000,
DirectItemType.TEXT,
text,
null,
null,
clientContext,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
repliedToMessage,
null,
null,
null,
0,
false);
}
public static DirectItem createImageOrVideo(final long userId,
final String clientContext,
final Uri uri,
final int width,
final int height,
final boolean isVideo) {
final ImageVersions2 imageVersions2 = new ImageVersions2(Collections.singletonList(new MediaCandidate(width, height, uri.toString())));
List<VideoVersion> videoVersions = null;
if (isVideo) {
final VideoVersion videoVersion = new VideoVersion(
null,
null,
width,
height,
uri.toString()
);
videoVersions = Collections.singletonList(videoVersion);
}
final Media media = new Media(
null,
UUID.randomUUID().toString(),
null,
-1,
null,
false,
imageVersions2,
width,
height,
isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE,
false,
false,
-1,
-1,
-1,
false,
false,
videoVersions,
false,
0f,
0,
null,
false,
null,
null,
null,
null,
null,
false,
false,
null,
null);
return new DirectItem(
UUID.randomUUID().toString(),
userId,
System.currentTimeMillis() * 1000,
DirectItemType.MEDIA,
null,
null,
null,
clientContext,
null,
null,
null,
null,
null,
media,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
0,
false);
}
public static DirectItem createVoice(final long userId,
final String clientContext,
final Uri uri,
final long duration,
final List<Float> waveform,
final int samplingFreq) {
final Audio audio = new Audio(
uri.toString(),
duration,
waveform,
samplingFreq,
0
);
final Media media = new Media(
null,
UUID.randomUUID().toString(),
null,
-1,
null,
false,
null,
0,
0,
MediaItemType.MEDIA_TYPE_VOICE,
false,
false,
-1,
0,
0,
false,
false,
null,
false,
0f,
0,
null,
false,
audio,
null,
null,
null,
null,
false,
false,
null,
null);
final DirectItemVoiceMedia voiceMedia = new DirectItemVoiceMedia(
media,
0,
"permanent"
);
return new DirectItem(
UUID.randomUUID().toString(),
userId,
System.currentTimeMillis() * 1000,
DirectItemType.VOICE_MEDIA,
null,
null,
null,
clientContext,
null,
null,
null,
null,
null,
media,
null,
null,
null,
null,
null,
null,
null,
null,
null,
voiceMedia,
null,
null,
0,
false);
}
public static DirectItem createAnimatedMedia(final long userId,
final String clientContext,
final GiphyGif giphyGif) {
final AnimatedMediaImages animatedImages = new AnimatedMediaImages(giphyGif.getImages().getFixedHeight());
final DirectItemAnimatedMedia animateMedia = new DirectItemAnimatedMedia(
giphyGif.getId(),
animatedImages,
false,
giphyGif.isSticker()
);
return new DirectItem(
UUID.randomUUID().toString(),
userId,
System.currentTimeMillis() * 1000,
DirectItemType.ANIMATED_MEDIA,
null,
null,
null,
clientContext,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
animateMedia,
null,
null,
null,
null,
null,
0,
false
);
}
}

View File

@ -0,0 +1,126 @@
@file:JvmName("DirectItemFactory")
package awais.instagrabber.utils
import android.net.Uri
import awais.instagrabber.models.enums.DirectItemType
import awais.instagrabber.models.enums.MediaItemType
import awais.instagrabber.repositories.responses.*
import awais.instagrabber.repositories.responses.directmessages.DirectItem
import awais.instagrabber.repositories.responses.directmessages.DirectItemAnimatedMedia
import awais.instagrabber.repositories.responses.directmessages.DirectItemVoiceMedia
import awais.instagrabber.repositories.responses.giphy.GiphyGif
import java.util.*
fun createText(
userId: Long,
clientContext: String?,
text: String?,
repliedToMessage: DirectItem?
): DirectItem {
return DirectItem(
itemId = UUID.randomUUID().toString(),
userId = userId,
timestamp = System.currentTimeMillis() * 1000,
itemType = DirectItemType.TEXT,
text = text,
clientContext = clientContext,
repliedToMessage = repliedToMessage,
)
}
fun createImageOrVideo(
userId: Long,
clientContext: String?,
uri: Uri,
width: Int,
height: Int,
isVideo: Boolean
): DirectItem {
val imageVersions2 = ImageVersions2(listOf(MediaCandidate(width, height, uri.toString())))
var videoVersions: List<VideoVersion>? = null
if (isVideo) {
val videoVersion = VideoVersion(
null,
null,
width,
height,
uri.toString()
)
videoVersions = listOf(videoVersion)
}
val media = Media(
id = UUID.randomUUID().toString(),
imageVersions2 = imageVersions2,
originalWidth = width,
originalHeight = height,
mediaType = if (isVideo) MediaItemType.MEDIA_TYPE_VIDEO else MediaItemType.MEDIA_TYPE_IMAGE,
videoVersions = videoVersions,
)
return DirectItem(
itemId = UUID.randomUUID().toString(),
userId = userId,
timestamp = System.currentTimeMillis() * 1000,
itemType = DirectItemType.MEDIA,
clientContext = clientContext,
media = media,
)
}
fun createVoice(
userId: Long,
clientContext: String?,
uri: Uri,
duration: Long,
waveform: List<Float>?,
samplingFreq: Int
): DirectItem {
val audio = Audio(
uri.toString(),
duration,
waveform,
samplingFreq,
0
)
val media = Media(
id = UUID.randomUUID().toString(),
mediaType = MediaItemType.MEDIA_TYPE_VOICE,
audio = audio,
)
val voiceMedia = DirectItemVoiceMedia(
media,
0,
"permanent"
)
return DirectItem(
itemId = UUID.randomUUID().toString(),
userId = userId,
timestamp = System.currentTimeMillis() * 1000,
itemType = DirectItemType.VOICE_MEDIA,
clientContext = clientContext,
media = media,
voiceMedia = voiceMedia,
)
}
fun createAnimatedMedia(
userId: Long,
clientContext: String?,
giphyGif: GiphyGif
): DirectItem {
val animatedImages = AnimatedMediaImages(giphyGif.images.fixedHeight)
val animateMedia = DirectItemAnimatedMedia(
giphyGif.id,
animatedImages,
false,
giphyGif.isSticker
)
return DirectItem(
itemId = UUID.randomUUID().toString(),
userId = userId,
timestamp = System.currentTimeMillis() * 1000,
itemType = DirectItemType.ANIMATED_MEDIA,
clientContext = clientContext,
animatedMedia = animateMedia,
)
}

View File

@ -75,10 +75,10 @@ public final class ResponseBodyUtils {
if (lastIndexMain >= 0) return sources[lastIndexMain];
else if (lastIndexBase >= 0) return sources[lastIndexBase];
} catch (final Exception e) {
// if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityPost",
// new Pair<>("resourcesNull", resources == null),
// new Pair<>("isVideo", isVideo));
// if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityPost",
// new Pair<>("resourcesNull", resources == null),
// new Pair<>("isVideo", isVideo));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
}
return null;
@ -93,9 +93,9 @@ public final class ResponseBodyUtils {
src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, false);
if (src == null) return resources.getString("display_url");
} catch (final Exception e) {
// if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityImage",
// new Pair<>("resourcesNull", resources == null));
// if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityImage",
// new Pair<>("resourcesNull", resources == null));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
}
return src;
@ -731,8 +731,8 @@ public final class ResponseBodyUtils {
final List<MediaCandidate> candidates = new ArrayList<MediaCandidate>();
if (feedItem.has("display_resources") || feedItem.has("thumbnail_resources")) {
final JSONArray displayResources = feedItem.has("display_resources")
? feedItem.getJSONArray("display_resources")
: feedItem.getJSONArray("thumbnail_resources");
? feedItem.getJSONArray("display_resources")
: feedItem.getJSONArray("thumbnail_resources");
for (int i = 0; i < displayResources.length(); i++) {
final JSONObject displayResource = displayResources.getJSONObject(i);
candidates.add(new MediaCandidate(
@ -781,8 +781,9 @@ public final class ResponseBodyUtils {
);
}
final Caption caption = new Caption(
0,
userId,
captionText
captionText != null ? captionText : ""
);
final boolean isSlider = "GraphSidecar".equals(mediaType) && feedItem.has("edge_sidecar_to_children");
@ -802,7 +803,7 @@ public final class ResponseBodyUtils {
final JSONObject child = children.optJSONObject(i);
if (child == null) continue;
final Media media = parseGraphQLItem(child, null);
media.setIsSidecarChild(true);
media.setSidecarChild(true);
childItems.add(media);
}
}
@ -1087,15 +1088,16 @@ public final class ResponseBodyUtils {
if (candidates == null || candidates.isEmpty()) return null;
final boolean isSquare = Integer.compare(media.getOriginalWidth(), media.getOriginalHeight()) == 0;
final List<MediaCandidate> sortedCandidates = candidates.stream()
.sorted((c1, c2) -> Integer.compare(c2.getWidth(), c1.getWidth()))
.collect(Collectors.toList());
.sorted((c1, c2) -> Integer.compare(c2.getWidth(), c1.getWidth()))
.collect(Collectors.toList());
final List<MediaCandidate> filteredCandidates = sortedCandidates.stream()
.filter(c ->
c.getWidth() <= media.getOriginalWidth()
&& c.getWidth() <= type.getValue()
&& (isSquare || Integer.compare(c.getWidth(), c.getHeight()) != 0)
)
.collect(Collectors.toList());
.filter(c ->
c.getWidth() <= media.getOriginalWidth()
&& c.getWidth() <= type.getValue()
&& (isSquare || Integer
.compare(c.getWidth(), c.getHeight()) != 0)
)
.collect(Collectors.toList());
if (filteredCandidates.size() == 0) return sortedCandidates.get(0).getUrl();
final MediaCandidate candidate = filteredCandidates.get(0);
if (candidate == null) return null;

View File

@ -69,8 +69,8 @@ public class PostViewV2ViewModel extends ViewModel {
commentCount.postValue(media.getCommentCount());
viewCount.postValue(media.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? media.getViewCount() : null);
type.postValue(media.getMediaType());
liked.postValue(media.hasLiked());
saved.postValue(media.hasViewerSaved());
liked.postValue(media.getHasLiked());
saved.postValue(media.getHasViewerSaved());
initOptions();
}
@ -137,7 +137,7 @@ public class PostViewV2ViewModel extends ViewModel {
@NonNull
public LiveData<Resource<Object>> toggleLike() {
if (media.hasLiked()) {
if (media.getHasLiked()) {
return unlike();
}
return like();
@ -169,7 +169,7 @@ public class PostViewV2ViewModel extends ViewModel {
data.postValue(Resource.success(true));
final long currentLikesCount = media.getLikeCount();
final long updatedCount;
if (!media.hasLiked()) {
if (!media.getHasLiked()) {
updatedCount = currentLikesCount + 1;
media.setHasLiked(true);
} else {
@ -178,7 +178,7 @@ public class PostViewV2ViewModel extends ViewModel {
}
media.setLikeCount(updatedCount);
likeCount.postValue(updatedCount);
liked.postValue(media.hasLiked());
liked.postValue(media.getHasLiked());
}
@Override
@ -191,7 +191,7 @@ public class PostViewV2ViewModel extends ViewModel {
@NonNull
public LiveData<Resource<Object>> toggleSave() {
if (!media.hasViewerSaved()) {
if (!media.getHasViewerSaved()) {
return save(null, false);
}
return unsave();
@ -227,8 +227,8 @@ public class PostViewV2ViewModel extends ViewModel {
return;
}
data.postValue(Resource.success(true));
if (!ignoreSaveState) media.setHasViewerSaved(!media.hasViewerSaved());
saved.postValue(media.hasViewerSaved());
if (!ignoreSaveState) media.setHasViewerSaved(!media.getHasViewerSaved());
saved.postValue(media.getHasViewerSaved());
}
@Override

View File

@ -8,6 +8,7 @@ import java.io.File;
import awais.instagrabber.BuildConfig;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.serializers.CaptionDeserializer;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.interceptors.AddCookiesInterceptor;
import awais.instagrabber.webservices.interceptors.IgErrorsInterceptor;
@ -55,7 +56,7 @@ public final class RetrofitFactory {
.addInterceptor(igErrorsInterceptor);
final Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(Caption.class, new Caption.CaptionDeserializer())
.registerTypeAdapter(Caption.class, new CaptionDeserializer())
.setLenient()
.create();
builder = new Retrofit.Builder()