From c18e1ddb93302eb25f11e1e8fbc52c4efa631535 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 00:41:07 +0900 Subject: [PATCH] Convert to kotlin --- .../instagrabber/managers/InboxManager.java | 2 +- .../instagrabber/managers/ThreadManager.java | 18 +-- .../requests/UploadFinishOptions.java | 114 ------------------ .../requests/UploadFinishOptions.kt | 27 +++++ .../directmessages/DirectBadgeCount.java | 31 ----- .../directmessages/DirectBadgeCount.kt | 8 ++ .../responses/directmessages/DirectInbox.java | 62 ---------- .../responses/directmessages/DirectInbox.kt | 15 +++ .../directmessages/DirectInboxResponse.java | 64 ---------- .../directmessages/DirectInboxResponse.kt | 14 +++ .../webservices/MediaService.java | 12 +- 11 files changed, 81 insertions(+), 286 deletions(-) delete mode 100644 app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.java create mode 100644 app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.kt delete mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.java create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.kt delete mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.java create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.kt delete mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.java create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.kt diff --git a/app/src/main/java/awais/instagrabber/managers/InboxManager.java b/app/src/main/java/awais/instagrabber/managers/InboxManager.java index eb54b8e2..073343cd 100644 --- a/app/src/main/java/awais/instagrabber/managers/InboxManager.java +++ b/app/src/main/java/awais/instagrabber/managers/InboxManager.java @@ -220,7 +220,7 @@ public final class InboxManager { } this.inbox.postValue(Resource.success(inbox)); cursor = inbox.getOldestCursor(); - hasOlder = inbox.hasOlder(); + hasOlder = inbox.getHasOlder(); pendingRequestsTotal.postValue(response.getPendingRequestsTotal()); } diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index 1a463d2d..780c1897 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -40,6 +40,7 @@ import awais.instagrabber.models.Resource.Status; import awais.instagrabber.models.UploadVideoOptions; import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.repositories.requests.UploadFinishOptions; +import awais.instagrabber.repositories.requests.VideoOptions; import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds; import awais.instagrabber.repositories.responses.FriendshipChangeResponse; import awais.instagrabber.repositories.responses.FriendshipRestrictResponse; @@ -694,9 +695,11 @@ public final class ThreadManager { public void onUploadComplete(final MediaUploader.MediaUploadResponse response) { // Log.d(TAG, "onUploadComplete: " + response); if (handleInvalidResponse(data, response)) return; - final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions() - .setUploadId(uploadDmVoiceOptions.getUploadId()) - .setSourceType("4"); + final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions( + uploadDmVoiceOptions.getUploadId(), + "4", + null + ); final Call uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions); uploadFinishRequest.enqueue(new Callback() { @Override @@ -1082,10 +1085,11 @@ public final class ThreadManager { public void onUploadComplete(final MediaUploader.MediaUploadResponse response) { // Log.d(TAG, "onUploadComplete: " + response); if (handleInvalidResponse(data, response)) return; - final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions() - .setUploadId(uploadDmVideoOptions.getUploadId()) - .setSourceType("2") - .setVideoOptions(new UploadFinishOptions.VideoOptions().setLength(duration / 1000f)); + final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions( + uploadDmVideoOptions.getUploadId(), + "2", + new VideoOptions(duration / 1000f, Collections.emptyList(), 0, false) + ); final Call uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions); uploadFinishRequest.enqueue(new Callback() { @Override diff --git a/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.java b/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.java deleted file mode 100644 index 6d9ee259..00000000 --- a/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.java +++ /dev/null @@ -1,114 +0,0 @@ -package awais.instagrabber.repositories.requests; - -import com.google.common.collect.ImmutableMap; - -import java.util.List; -import java.util.Map; - -public class UploadFinishOptions { - private String uploadId; - private String sourceType; - private VideoOptions videoOptions; - - public String getUploadId() { - return uploadId; - } - - public UploadFinishOptions setUploadId(final String uploadId) { - this.uploadId = uploadId; - return this; - } - - public String getSourceType() { - return sourceType; - } - - public UploadFinishOptions setSourceType(final String sourceType) { - this.sourceType = sourceType; - return this; - } - - public VideoOptions getVideoOptions() { - return videoOptions; - } - - public UploadFinishOptions setVideoOptions(final VideoOptions videoOptions) { - this.videoOptions = videoOptions; - return this; - } - - public static class VideoOptions { - private float length; - private List clips; - private int posterFrameIndex; - private boolean audioMuted; - - public float getLength() { - return length; - } - - public VideoOptions setLength(final float length) { - this.length = length; - return this; - } - - public List getClips() { - return clips; - } - - public VideoOptions setClips(final List clips) { - this.clips = clips; - return this; - } - - public int getPosterFrameIndex() { - return posterFrameIndex; - } - - public VideoOptions setPosterFrameIndex(final int posterFrameIndex) { - this.posterFrameIndex = posterFrameIndex; - return this; - } - - public boolean isAudioMuted() { - return audioMuted; - } - - public VideoOptions setAudioMuted(final boolean audioMuted) { - this.audioMuted = audioMuted; - return this; - } - - public Map getMap() { - return ImmutableMap.of( - "length", length, - "clips", clips, - "poster_frame_index", posterFrameIndex, - "audio_muted", audioMuted - ); - } - } - - public static class Clip { - private float length; - private String sourceType; - - public float getLength() { - return length; - } - - public Clip setLength(final float length) { - this.length = length; - return this; - } - - public String getSourceType() { - return sourceType; - } - - public Clip setSourceType(final String sourceType) { - this.sourceType = sourceType; - return this; - } - } -} diff --git a/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.kt b/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.kt new file mode 100644 index 00000000..6f14a2b9 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/requests/UploadFinishOptions.kt @@ -0,0 +1,27 @@ +package awais.instagrabber.repositories.requests + +data class UploadFinishOptions( + val uploadId: String, + val sourceType: String, + val videoOptions: VideoOptions? = null +) + +data class VideoOptions( + val length: Float = 0f, + var clips: List = emptyList(), + val posterFrameIndex: Int = 0, + val isAudioMuted: Boolean = false +) { + val map: Map + get() = mapOf( + "length" to length, + "clips" to clips, + "poster_frame_index" to posterFrameIndex, + "audio_muted" to isAudioMuted + ) +} + +data class Clip( + val length: Float = 0f, + val sourceType: String +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.java deleted file mode 100644 index 05d0b380..00000000 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.java +++ /dev/null @@ -1,31 +0,0 @@ -package awais.instagrabber.repositories.responses.directmessages; - -public class DirectBadgeCount { - private final long userId; - private final int badgeCount; - private final long badgeCountAtMs; - private final String status; - - public DirectBadgeCount(final long userId, final int badgeCount, final long badgeCountAtMs, final String status) { - this.userId = userId; - this.badgeCount = badgeCount; - this.badgeCountAtMs = badgeCountAtMs; - this.status = status; - } - - public long getUserId() { - return userId; - } - - public int getBadgeCount() { - return badgeCount; - } - - public long getBadgeCountAtMs() { - return badgeCountAtMs; - } - - public String getStatus() { - return status; - } -} diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.kt new file mode 100644 index 00000000..e04966a8 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectBadgeCount.kt @@ -0,0 +1,8 @@ +package awais.instagrabber.repositories.responses.directmessages + +data class DirectBadgeCount( + val userId: Long = 0, + val badgeCount: Int = 0, + val badgeCountAtMs: Long = 0, + val status: String? = null +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.java deleted file mode 100644 index bf6db660..00000000 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.java +++ /dev/null @@ -1,62 +0,0 @@ -package awais.instagrabber.repositories.responses.directmessages; - -import androidx.annotation.NonNull; - -import java.util.List; - -public class DirectInbox implements Cloneable { - private List threads; - private final boolean hasOlder; - private final int unseenCount; - private final String unseenCountTs; - private final String oldestCursor; - private final boolean blendedInboxEnabled; - - public DirectInbox(final List threads, - final boolean hasOlder, - final int unseenCount, - final String unseenCountTs, - final String oldestCursor, - final boolean blendedInboxEnabled) { - this.threads = threads; - this.hasOlder = hasOlder; - this.unseenCount = unseenCount; - this.unseenCountTs = unseenCountTs; - this.oldestCursor = oldestCursor; - this.blendedInboxEnabled = blendedInboxEnabled; - } - - public List getThreads() { - return threads; - } - - public void setThreads(final List threads) { - this.threads = threads; - } - - public boolean hasOlder() { - return hasOlder; - } - - public int getUnseenCount() { - return unseenCount; - } - - public String getUnseenCountTs() { - return unseenCountTs; - } - - public String getOldestCursor() { - return oldestCursor; - } - - public boolean isBlendedInboxEnabled() { - return blendedInboxEnabled; - } - - @NonNull - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } -} diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.kt new file mode 100644 index 00000000..2de859b4 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInbox.kt @@ -0,0 +1,15 @@ +package awais.instagrabber.repositories.responses.directmessages + +data class DirectInbox( + var threads: List? = emptyList(), + val hasOlder: Boolean = false, + val unseenCount: Int = 0, + val unseenCountTs: String? = null, + val oldestCursor: String? = null, + val blendedInboxEnabled: Boolean +) : Cloneable { + @Throws(CloneNotSupportedException::class) + public override fun clone(): Any { + return super.clone() + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.java deleted file mode 100644 index 9db0b2a5..00000000 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.java +++ /dev/null @@ -1,64 +0,0 @@ -package awais.instagrabber.repositories.responses.directmessages; - -import awais.instagrabber.repositories.responses.User; - -public class DirectInboxResponse { - private final User viewer; - private final DirectInbox inbox; - private final long seqId; - private final long snapshotAtMs; - private final int pendingRequestsTotal; - private final boolean hasPendingTopRequests; - private final User mostRecentInviter; - private final String status; - - public DirectInboxResponse(final User viewer, - final DirectInbox inbox, - final long seqId, - final long snapshotAtMs, - final int pendingRequestsTotal, - final boolean hasPendingTopRequests, - final User mostRecentInviter, - final String status) { - this.viewer = viewer; - this.inbox = inbox; - this.seqId = seqId; - this.snapshotAtMs = snapshotAtMs; - this.pendingRequestsTotal = pendingRequestsTotal; - this.hasPendingTopRequests = hasPendingTopRequests; - this.mostRecentInviter = mostRecentInviter; - this.status = status; - } - - public User getViewer() { - return viewer; - } - - public DirectInbox getInbox() { - return inbox; - } - - public long getSeqId() { - return seqId; - } - - public long getSnapshotAtMs() { - return snapshotAtMs; - } - - public int getPendingRequestsTotal() { - return pendingRequestsTotal; - } - - public boolean hasPendingTopRequests() { - return hasPendingTopRequests; - } - - public User getMostRecentInviter() { - return mostRecentInviter; - } - - public String getStatus() { - return status; - } -} diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.kt new file mode 100644 index 00000000..3b91af8b --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectInboxResponse.kt @@ -0,0 +1,14 @@ +package awais.instagrabber.repositories.responses.directmessages + +import awais.instagrabber.repositories.responses.User + +data class DirectInboxResponse( + val viewer: User? = null, + val inbox: DirectInbox? = null, + val seqId: Long = 0, + val snapshotAtMs: Long = 0, + val pendingRequestsTotal: Int = 0, + val hasPendingTopRequests: Boolean = false, + val mostRecentInviter: User? = null, + val status: String? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/webservices/MediaService.java b/app/src/main/java/awais/instagrabber/webservices/MediaService.java index 8eac4b35..b2090d0f 100644 --- a/app/src/main/java/awais/instagrabber/webservices/MediaService.java +++ b/app/src/main/java/awais/instagrabber/webservices/MediaService.java @@ -21,7 +21,9 @@ import java.util.UUID; import awais.instagrabber.models.Comment; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.MediaRepository; +import awais.instagrabber.repositories.requests.Clip; import awais.instagrabber.repositories.requests.UploadFinishOptions; +import awais.instagrabber.repositories.requests.VideoOptions; import awais.instagrabber.repositories.responses.LikersResponse; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.MediaInfoResponse; @@ -443,13 +445,9 @@ public class MediaService extends BaseService { public Call uploadFinish(@NonNull final UploadFinishOptions options) { if (options.getVideoOptions() != null) { - final UploadFinishOptions.VideoOptions videoOptions = options.getVideoOptions(); - if (videoOptions.getClips() == null) { - videoOptions.setClips(Collections.singletonList( - new UploadFinishOptions.Clip() - .setLength(videoOptions.getLength()) - .setSourceType(options.getSourceType()) - )); + final VideoOptions videoOptions = options.getVideoOptions(); + if (videoOptions.getClips().isEmpty()) { + videoOptions.setClips(Collections.singletonList(new Clip(videoOptions.getLength(), options.getSourceType()))); } } final String timezoneOffset = String.valueOf(DateUtils.getTimezoneOffset());