Ammar Githam
4 years ago
16 changed files with 270 additions and 399 deletions
-
54app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
6app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
-
4app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.java
-
30app/src/main/java/awais/instagrabber/managers/ThreadManager.java
-
41app/src/main/java/awais/instagrabber/repositories/requests/directmessages/AnimatedMediaBroadcastOptions.kt
-
106app/src/main/java/awais/instagrabber/repositories/requests/directmessages/BroadcastOptions.kt
-
47app/src/main/java/awais/instagrabber/repositories/requests/directmessages/LinkBroadcastOptions.kt
-
8app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt
-
42app/src/main/java/awais/instagrabber/repositories/requests/directmessages/PhotoBroadcastOptions.kt
-
49app/src/main/java/awais/instagrabber/repositories/requests/directmessages/ReactionBroadcastOptions.kt
-
47app/src/main/java/awais/instagrabber/repositories/requests/directmessages/StoryReplyBroadcastOptions.kt
-
32app/src/main/java/awais/instagrabber/repositories/requests/directmessages/TextBroadcastOptions.kt
-
49app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VideoBroadcastOptions.kt
-
49app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VoiceBroadcastOptions.kt
-
4app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.java
-
83app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.java
@ -1,27 +1,20 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
import awais.instagrabber.repositories.responses.giphy.GiphyGif |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
import awais.instagrabber.repositories.responses.giphy.GiphyGif; |
|||
|
|||
public class AnimatedMediaBroadcastOptions extends BroadcastOptions { |
|||
|
|||
private final GiphyGif giphyGif; |
|||
|
|||
public AnimatedMediaBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final GiphyGif giphyGif) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.ANIMATED_MEDIA); |
|||
this.giphyGif = giphyGif; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
final Map<String, String> form = new HashMap<>(); |
|||
form.put("is_sticker", String.valueOf(giphyGif.isSticker())); |
|||
form.put("id", giphyGif.getId()); |
|||
return form; |
|||
} |
|||
class AnimatedMediaBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val giphyGif: GiphyGif |
|||
) : BroadcastOptions( |
|||
clientContext, |
|||
threadIdOrUserIds, |
|||
BroadcastItemType.ANIMATED_MEDIA |
|||
) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"is_sticker" to giphyGif.isSticker.toString(), |
|||
"id" to giphyGif.id |
|||
) |
|||
} |
@ -1,86 +1,34 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public abstract class BroadcastOptions { |
|||
|
|||
private final String clientContext; |
|||
private final ThreadIdOrUserIds threadIdOrUserIds; |
|||
private final BroadcastItemType itemType; |
|||
|
|||
private String repliedToItemId; |
|||
private String repliedToClientContext; |
|||
|
|||
public BroadcastOptions(final String clientContext, |
|||
@NonNull final ThreadIdOrUserIds threadIdOrUserIds, |
|||
@NonNull final BroadcastItemType itemType) { |
|||
this.clientContext = clientContext; |
|||
this.threadIdOrUserIds = threadIdOrUserIds; |
|||
this.itemType = itemType; |
|||
} |
|||
|
|||
public String getClientContext() { |
|||
return clientContext; |
|||
} |
|||
|
|||
public String getThreadId() { |
|||
return threadIdOrUserIds.getThreadId(); |
|||
} |
|||
|
|||
public List<String> getUserIds() { |
|||
return threadIdOrUserIds.getUserIds(); |
|||
} |
|||
|
|||
public BroadcastItemType getItemType() { |
|||
return itemType; |
|||
} |
|||
|
|||
public abstract Map<String, String> getFormMap(); |
|||
|
|||
public String getRepliedToItemId() { |
|||
return repliedToItemId; |
|||
} |
|||
|
|||
public void setRepliedToItemId(final String repliedToItemId) { |
|||
this.repliedToItemId = repliedToItemId; |
|||
} |
|||
|
|||
public String getRepliedToClientContext() { |
|||
return repliedToClientContext; |
|||
} |
|||
|
|||
public void setRepliedToClientContext(final String repliedToClientContext) { |
|||
this.repliedToClientContext = repliedToClientContext; |
|||
} |
|||
|
|||
public static final class ThreadIdOrUserIds { |
|||
private final String threadId; |
|||
private final List<String> userIds; |
|||
|
|||
private ThreadIdOrUserIds(final String threadId, final List<String> userIds) { |
|||
this.threadId = threadId; |
|||
this.userIds = userIds; |
|||
} |
|||
|
|||
public static ThreadIdOrUserIds of(final String threadId) { |
|||
return new ThreadIdOrUserIds(threadId, null); |
|||
} |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
sealed class BroadcastOptions( |
|||
val clientContext: String, |
|||
private val threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val itemType: BroadcastItemType |
|||
) { |
|||
var repliedToItemId: String? = null |
|||
var repliedToClientContext: String? = null |
|||
val threadId: String? |
|||
get() = threadIdOrUserIds.threadId |
|||
val userIds: List<String>? |
|||
get() = threadIdOrUserIds.userIds |
|||
|
|||
abstract val formMap: Map<String, String> |
|||
} |
|||
|
|||
public static ThreadIdOrUserIds of(final List<String> userIds) { |
|||
return new ThreadIdOrUserIds(null, userIds); |
|||
} |
|||
// TODO convert to data class once usages are migrated to kotlin |
|||
class ThreadIdOrUserIds(val threadId: String? = null, val userIds: List<String>? = null) { |
|||
|
|||
public String getThreadId() { |
|||
return threadId; |
|||
companion object { |
|||
@JvmStatic |
|||
fun of(threadId: String?): ThreadIdOrUserIds { |
|||
return ThreadIdOrUserIds(threadId, null) |
|||
} |
|||
|
|||
public List<String> getUserIds() { |
|||
return userIds; |
|||
@JvmStatic |
|||
fun of(userIds: List<String>?): ThreadIdOrUserIds { |
|||
return ThreadIdOrUserIds(null, userIds) |
|||
} |
|||
} |
|||
} |
@ -1,32 +1,21 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import com.google.common.collect.ImmutableMap; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
import org.json.JSONArray |
|||
|
|||
import org.json.JSONArray; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public class LinkBroadcastOptions extends BroadcastOptions { |
|||
private final String linkText; |
|||
private final List<String> urls; |
|||
|
|||
public LinkBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String linkText, |
|||
final List<String> urls) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.LINK); |
|||
this.linkText = linkText; |
|||
this.urls = urls; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
return ImmutableMap.of( |
|||
"link_text", linkText, |
|||
"link_urls", new JSONArray(urls).toString() |
|||
); |
|||
} |
|||
class LinkBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val linkText: String, |
|||
val urls: List<String> |
|||
) : BroadcastOptions( |
|||
clientContext, |
|||
threadIdOrUserIds, |
|||
BroadcastItemType.LINK |
|||
) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"link_text" to linkText, |
|||
"link_urls" to JSONArray(urls).toString() |
|||
) |
|||
} |
@ -1,28 +1,20 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public class PhotoBroadcastOptions extends BroadcastOptions { |
|||
final boolean allowFullAspectRatio; |
|||
final String uploadId; |
|||
|
|||
public PhotoBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final boolean allowFullAspectRatio, |
|||
final String uploadId) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.IMAGE); |
|||
this.allowFullAspectRatio = allowFullAspectRatio; |
|||
this.uploadId = uploadId; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
final Map<String, String> form = new HashMap<>(); |
|||
form.put("allow_full_aspect_ratio", String.valueOf(allowFullAspectRatio)); |
|||
form.put("upload_id", uploadId); |
|||
return form; |
|||
} |
|||
class PhotoBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val allowFullAspectRatio: Boolean, |
|||
val uploadId: String |
|||
) : BroadcastOptions( |
|||
clientContext, |
|||
threadIdOrUserIds, |
|||
BroadcastItemType.IMAGE |
|||
) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"allow_full_aspect_ratio" to allowFullAspectRatio.toString(), |
|||
"upload_id" to uploadId |
|||
) |
|||
} |
@ -1,36 +1,19 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
import awais.instagrabber.utils.TextUtils; |
|||
|
|||
public class ReactionBroadcastOptions extends BroadcastOptions { |
|||
private final String itemId; |
|||
private final String emoji; |
|||
private final boolean delete; |
|||
|
|||
public ReactionBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String itemId, |
|||
final String emoji, |
|||
final boolean delete) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.REACTION); |
|||
this.itemId = itemId; |
|||
this.emoji = emoji; |
|||
this.delete = delete; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
final Map<String, String> form = new HashMap<>(); |
|||
form.put("item_id", itemId); |
|||
form.put("reaction_status", delete ? "deleted" : "created"); |
|||
form.put("reaction_type", "like"); |
|||
if (!TextUtils.isEmpty(emoji)) { |
|||
form.put("emoji", emoji); |
|||
} |
|||
return form; |
|||
} |
|||
class ReactionBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val itemId: String, |
|||
val emoji: String?, |
|||
val delete: Boolean |
|||
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.REACTION) { |
|||
override val formMap: Map<String, String> |
|||
get() = listOfNotNull( |
|||
"item_id" to itemId, |
|||
"reaction_status" to if (delete) "deleted" else "created", |
|||
"reaction_type" to "like", |
|||
if (!emoji.isNullOrBlank()) "emoji" to emoji else null, |
|||
).toMap() |
|||
} |
@ -1,34 +1,19 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
import awais.instagrabber.utils.TextUtils; |
|||
|
|||
public class StoryReplyBroadcastOptions extends BroadcastOptions { |
|||
private final String text, mediaId, reelId; |
|||
|
|||
public StoryReplyBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String text, |
|||
final String mediaId, |
|||
final String reelId) |
|||
throws UnsupportedEncodingException { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.REELSHARE); |
|||
this.text = text; |
|||
this.mediaId = mediaId; |
|||
this.reelId = reelId; // or user id, usually same |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
final Map<String, String> form = new HashMap<>(); |
|||
form.put("text", text); |
|||
form.put("media_id", mediaId); |
|||
form.put("reel_id", reelId); |
|||
form.put("entry", "reel"); |
|||
return form; |
|||
} |
|||
class StoryReplyBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val text: String, |
|||
val mediaId: String, |
|||
val reelId: String // or user id, usually same |
|||
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.REELSHARE) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"text" to text, |
|||
"media_id" to mediaId, |
|||
"reel_id" to reelId, |
|||
"entry" to "reel", |
|||
) |
|||
} |
@ -1,22 +1,16 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import java.util.Collections; |
|||
import java.util.Map; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public class TextBroadcastOptions extends BroadcastOptions { |
|||
private final String text; |
|||
|
|||
public TextBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String text) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.TEXT); |
|||
this.text = text; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
return Collections.singletonMap("text", text); |
|||
} |
|||
class TextBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val text: String |
|||
) : BroadcastOptions( |
|||
clientContext, |
|||
threadIdOrUserIds, |
|||
BroadcastItemType.TEXT |
|||
) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf("text" to text) |
|||
} |
@ -1,33 +1,22 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import com.google.common.collect.ImmutableMap; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
|
|||
import java.util.Map; |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public class VideoBroadcastOptions extends BroadcastOptions { |
|||
private final String videoResult; |
|||
private final String uploadId; |
|||
private final boolean sampled; |
|||
|
|||
public VideoBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String videoResult, |
|||
final String uploadId, |
|||
final boolean sampled) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.VIDEO); |
|||
this.videoResult = videoResult; |
|||
this.uploadId = uploadId; |
|||
this.sampled = sampled; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
return ImmutableMap.<String, String>of( |
|||
"video_result", videoResult, |
|||
"upload_id", uploadId, |
|||
"sampled", String.valueOf(sampled) |
|||
); |
|||
} |
|||
class VideoBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val videoResult: String, |
|||
val uploadId: String, |
|||
val sampled: Boolean |
|||
) : BroadcastOptions( |
|||
clientContext, |
|||
threadIdOrUserIds, |
|||
BroadcastItemType.VIDEO |
|||
) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"video_result" to videoResult, |
|||
"upload_id" to uploadId, |
|||
"sampled" to sampled.toString() |
|||
) |
|||
} |
@ -1,36 +1,19 @@ |
|||
package awais.instagrabber.repositories.requests.directmessages; |
|||
package awais.instagrabber.repositories.requests.directmessages |
|||
|
|||
import com.google.common.collect.ImmutableMap; |
|||
import awais.instagrabber.models.enums.BroadcastItemType |
|||
import org.json.JSONArray |
|||
|
|||
import org.json.JSONArray; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import awais.instagrabber.models.enums.BroadcastItemType; |
|||
|
|||
public class VoiceBroadcastOptions extends BroadcastOptions { |
|||
private final List<Float> waveform; |
|||
private final String uploadId; |
|||
private final int waveformSamplingFrequencyHz; |
|||
|
|||
public VoiceBroadcastOptions(final String clientContext, |
|||
final ThreadIdOrUserIds threadIdOrUserIds, |
|||
final String uploadId, |
|||
final List<Float> waveform, |
|||
final int waveformSamplingFrequencyHz) { |
|||
super(clientContext, threadIdOrUserIds, BroadcastItemType.VOICE); |
|||
this.waveform = waveform; |
|||
this.uploadId = uploadId; |
|||
this.waveformSamplingFrequencyHz = waveformSamplingFrequencyHz; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, String> getFormMap() { |
|||
return ImmutableMap.<String, String>of( |
|||
"waveform", new JSONArray(waveform).toString(), |
|||
"upload_id", uploadId, |
|||
"waveform_sampling_frequency_hz", String.valueOf(waveformSamplingFrequencyHz) |
|||
); |
|||
} |
|||
class VoiceBroadcastOptions( |
|||
clientContext: String, |
|||
threadIdOrUserIds: ThreadIdOrUserIds, |
|||
val uploadId: String, |
|||
val waveform: List<Float>, |
|||
val waveformSamplingFrequencyHz: Int |
|||
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.VOICE) { |
|||
override val formMap: Map<String, String> |
|||
get() = mapOf( |
|||
"waveform" to JSONArray(waveform).toString(), |
|||
"upload_id" to uploadId, |
|||
"waveform_sampling_frequency_hz" to waveformSamplingFrequencyHz.toString() |
|||
) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue