1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

Convert to kotlin

This commit is contained in:
Ammar Githam 2021-05-25 00:41:07 +09:00
parent c3e31ab81b
commit c18e1ddb93
11 changed files with 81 additions and 286 deletions

View File

@ -220,7 +220,7 @@ public final class InboxManager {
} }
this.inbox.postValue(Resource.success(inbox)); this.inbox.postValue(Resource.success(inbox));
cursor = inbox.getOldestCursor(); cursor = inbox.getOldestCursor();
hasOlder = inbox.hasOlder(); hasOlder = inbox.getHasOlder();
pendingRequestsTotal.postValue(response.getPendingRequestsTotal()); pendingRequestsTotal.postValue(response.getPendingRequestsTotal());
} }

View File

@ -40,6 +40,7 @@ import awais.instagrabber.models.Resource.Status;
import awais.instagrabber.models.UploadVideoOptions; import awais.instagrabber.models.UploadVideoOptions;
import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.repositories.requests.UploadFinishOptions; import awais.instagrabber.repositories.requests.UploadFinishOptions;
import awais.instagrabber.repositories.requests.VideoOptions;
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds; import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds;
import awais.instagrabber.repositories.responses.FriendshipChangeResponse; import awais.instagrabber.repositories.responses.FriendshipChangeResponse;
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse; import awais.instagrabber.repositories.responses.FriendshipRestrictResponse;
@ -694,9 +695,11 @@ public final class ThreadManager {
public void onUploadComplete(final MediaUploader.MediaUploadResponse response) { public void onUploadComplete(final MediaUploader.MediaUploadResponse response) {
// Log.d(TAG, "onUploadComplete: " + response); // Log.d(TAG, "onUploadComplete: " + response);
if (handleInvalidResponse(data, response)) return; if (handleInvalidResponse(data, response)) return;
final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions() final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions(
.setUploadId(uploadDmVoiceOptions.getUploadId()) uploadDmVoiceOptions.getUploadId(),
.setSourceType("4"); "4",
null
);
final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions); final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions);
uploadFinishRequest.enqueue(new Callback<String>() { uploadFinishRequest.enqueue(new Callback<String>() {
@Override @Override
@ -1082,10 +1085,11 @@ public final class ThreadManager {
public void onUploadComplete(final MediaUploader.MediaUploadResponse response) { public void onUploadComplete(final MediaUploader.MediaUploadResponse response) {
// Log.d(TAG, "onUploadComplete: " + response); // Log.d(TAG, "onUploadComplete: " + response);
if (handleInvalidResponse(data, response)) return; if (handleInvalidResponse(data, response)) return;
final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions() final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions(
.setUploadId(uploadDmVideoOptions.getUploadId()) uploadDmVideoOptions.getUploadId(),
.setSourceType("2") "2",
.setVideoOptions(new UploadFinishOptions.VideoOptions().setLength(duration / 1000f)); new VideoOptions(duration / 1000f, Collections.emptyList(), 0, false)
);
final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions); final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions);
uploadFinishRequest.enqueue(new Callback<String>() { uploadFinishRequest.enqueue(new Callback<String>() {
@Override @Override

View File

@ -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<Clip> 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<Clip> getClips() {
return clips;
}
public VideoOptions setClips(final List<Clip> 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<String, Object> 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;
}
}
}

View File

@ -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<Clip> = emptyList(),
val posterFrameIndex: Int = 0,
val isAudioMuted: Boolean = false
) {
val map: Map<String, Any>
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
)

View File

@ -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;
}
}

View File

@ -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
)

View File

@ -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<DirectThread> 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<DirectThread> 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<DirectThread> getThreads() {
return threads;
}
public void setThreads(final List<DirectThread> 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();
}
}

View File

@ -0,0 +1,15 @@
package awais.instagrabber.repositories.responses.directmessages
data class DirectInbox(
var threads: List<DirectThread>? = 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()
}
}

View File

@ -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;
}
}

View File

@ -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,
)

View File

@ -21,7 +21,9 @@ import java.util.UUID;
import awais.instagrabber.models.Comment; import awais.instagrabber.models.Comment;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.MediaRepository; import awais.instagrabber.repositories.MediaRepository;
import awais.instagrabber.repositories.requests.Clip;
import awais.instagrabber.repositories.requests.UploadFinishOptions; import awais.instagrabber.repositories.requests.UploadFinishOptions;
import awais.instagrabber.repositories.requests.VideoOptions;
import awais.instagrabber.repositories.responses.LikersResponse; import awais.instagrabber.repositories.responses.LikersResponse;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.MediaInfoResponse; import awais.instagrabber.repositories.responses.MediaInfoResponse;
@ -443,13 +445,9 @@ public class MediaService extends BaseService {
public Call<String> uploadFinish(@NonNull final UploadFinishOptions options) { public Call<String> uploadFinish(@NonNull final UploadFinishOptions options) {
if (options.getVideoOptions() != null) { if (options.getVideoOptions() != null) {
final UploadFinishOptions.VideoOptions videoOptions = options.getVideoOptions(); final VideoOptions videoOptions = options.getVideoOptions();
if (videoOptions.getClips() == null) { if (videoOptions.getClips().isEmpty()) {
videoOptions.setClips(Collections.singletonList( videoOptions.setClips(Collections.singletonList(new Clip(videoOptions.getLength(), options.getSourceType())));
new UploadFinishOptions.Clip()
.setLength(videoOptions.getLength())
.setSourceType(options.getSourceType())
));
} }
} }
final String timezoneOffset = String.valueOf(DateUtils.getTimezoneOffset()); final String timezoneOffset = String.valueOf(DateUtils.getTimezoneOffset());