Browse Source

Convert to kotlin

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
d7462109db
  1. 54
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  2. 6
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
  3. 4
      app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.java
  4. 30
      app/src/main/java/awais/instagrabber/managers/ThreadManager.java
  5. 43
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/AnimatedMediaBroadcastOptions.kt
  6. 108
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/BroadcastOptions.kt
  7. 49
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/LinkBroadcastOptions.kt
  8. 8
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt
  9. 44
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/PhotoBroadcastOptions.kt
  10. 51
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/ReactionBroadcastOptions.kt
  11. 49
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/StoryReplyBroadcastOptions.kt
  12. 34
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/TextBroadcastOptions.kt
  13. 51
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VideoBroadcastOptions.kt
  14. 51
      app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VoiceBroadcastOptions.kt
  15. 4
      app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.java
  16. 83
      app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.java

54
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -58,7 +58,6 @@ import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
@ -86,7 +85,7 @@ import awais.instagrabber.models.stickers.SliderModel;
import awais.instagrabber.models.stickers.SwipeUpModel;
import awais.instagrabber.repositories.requests.StoryViewerOptions;
import awais.instagrabber.repositories.requests.StoryViewerOptions.Type;
import awais.instagrabber.repositories.requests.directmessages.BroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.StoryStickerResponse;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -233,35 +232,32 @@ public class StoryViewerFragment extends Fragment {
return;
}
final DirectThread thread = response.body();
try {
final Call<DirectThreadBroadcastResponse> request = directMessagesService
.broadcastStoryReply(BroadcastOptions.ThreadIdOrUserIds.of(thread.getThreadId()),
input.getText().toString(),
currentStory.getStoryMediaId(),
String.valueOf(currentStory.getUserId()));
request.enqueue(new Callback<DirectThreadBroadcastResponse>() {
@Override
public void onResponse(@NonNull final Call<DirectThreadBroadcastResponse> call,
@NonNull final Response<DirectThreadBroadcastResponse> response) {
if (!response.isSuccessful()) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show();
final Call<DirectThreadBroadcastResponse> request = directMessagesService.broadcastStoryReply(
ThreadIdOrUserIds.of(thread.getThreadId()),
input.getText().toString(),
currentStory.getStoryMediaId(),
String.valueOf(currentStory.getUserId())
);
request.enqueue(new Callback<DirectThreadBroadcastResponse>() {
@Override
public void onResponse(@NonNull final Call<DirectThreadBroadcastResponse> call,
@NonNull final Response<DirectThreadBroadcastResponse> response) {
if (!response.isSuccessful()) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
@Override
public void onFailure(@NonNull final Call<DirectThreadBroadcastResponse> call, @NonNull final Throwable t) {
try {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
Log.e(TAG, "onFailure: ", t);
} catch (Throwable ignored) {
}
Toast.makeText(context, R.string.answered_story, Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(@NonNull final Call<DirectThreadBroadcastResponse> call, @NonNull final Throwable t) {
try {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
Log.e(TAG, "onFailure: ", t);
} catch (Throwable ignored) {
}
});
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Error", e);
}
}
});
}
@Override

6
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java

@ -266,7 +266,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
@Override
public void onReaction(final DirectItem item, final Emoji emoji) {
if (item == null) return;
if (item == null || emoji == null) return;
final LiveData<Resource<Object>> resourceLiveData = viewModel.sendReaction(item, emoji);
if (resourceLiveData != null) {
resourceLiveData.observe(getViewLifecycleOwner(), directItemResource -> handleSentMessage(resourceLiveData));
@ -1487,7 +1487,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
if (reactionDialogFragment != null) {
reactionDialogFragment.dismiss();
}
if (reaction == null) return;
if (itemId == null || reaction == null) return;
if (reaction.getSenderId() == viewModel.getViewerId()) {
final LiveData<Resource<Object>> resourceLiveData = viewModel.sendDeleteReaction(itemId);
if (resourceLiveData != null) {
@ -1509,7 +1509,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
@Override
public void onClick(final View view, final Emoji emoji) {
if (addReactionItem == null) return;
if (addReactionItem == null || emoji == null) return;
final LiveData<Resource<Object>> resourceLiveData = viewModel.sendReaction(addReactionItem, emoji);
if (resourceLiveData != null) {
resourceLiveData.observe(getViewLifecycleOwner(), directItemResource -> handleSentMessage(resourceLiveData));

4
app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.java

@ -19,7 +19,7 @@ import java.util.UUID;
import java.util.function.Function;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.requests.directmessages.BroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -220,7 +220,7 @@ public final class DirectMessagesManager {
data.postValue(Resource.loading(null));
final Call<DirectThreadBroadcastResponse> request = service.broadcastMediaShare(
UUID.randomUUID().toString(),
BroadcastOptions.ThreadIdOrUserIds.of(threadId),
ThreadIdOrUserIds.of(threadId),
mediaId
);
request.enqueue(new Callback<DirectThreadBroadcastResponse>() {

30
app/src/main/java/awais/instagrabber/managers/ThreadManager.java

@ -40,7 +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.directmessages.BroadcastOptions.ThreadIdOrUserIds;
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds;
import awais.instagrabber.repositories.responses.FriendshipChangeResponse;
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse;
import awais.instagrabber.repositories.responses.User;
@ -485,8 +485,8 @@ public final class ThreadManager {
inboxManager.addItemsToThread(threadId, index, items);
}
private void addReaction(final DirectItem item, final Emoji emoji) {
if (item == null || emoji == null || currentUser == null) return;
private void addReaction(@NonNull final DirectItem item, @NonNull final Emoji emoji) {
if (currentUser == null) return;
final boolean isLike = emoji.getUnicode().equals("❤️");
DirectItemReactions reactions = item.getReactions();
if (reactions == null) {
@ -737,7 +737,8 @@ public final class ThreadManager {
}
@NonNull
public LiveData<Resource<Object>> sendReaction(final DirectItem item, final Emoji emoji) {
public LiveData<Resource<Object>> sendReaction(@NonNull final DirectItem item,
@NonNull final Emoji emoji) {
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
final Long userId = getCurrentUserId(data);
if (userId == null) {
@ -752,13 +753,23 @@ public final class ThreadManager {
if (!emoji.getUnicode().equals("❤️")) {
emojiUnicode = emoji.getUnicode();
}
final String itemId = item.getItemId();
if (itemId == null) {
data.postValue(Resource.error("itemId is null", null));
return data;
}
final Call<DirectThreadBroadcastResponse> request = service.broadcastReaction(
clientContext, threadIdOrUserIds, item.getItemId(), emojiUnicode, false);
clientContext,
threadIdOrUserIds,
itemId,
emojiUnicode,
false
);
handleBroadcastReactionRequest(data, item, request);
return data;
}
public LiveData<Resource<Object>> sendDeleteReaction(final String itemId) {
public LiveData<Resource<Object>> sendDeleteReaction(@NonNull final String itemId) {
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
final DirectItem item = getItem(itemId);
if (item == null) {
@ -773,7 +784,12 @@ public final class ThreadManager {
}
removeReaction(item);
final String clientContext = UUID.randomUUID().toString();
final Call<DirectThreadBroadcastResponse> request = service.broadcastReaction(clientContext, threadIdOrUserIds, item.getItemId(), null, true);
final String itemId1 = item.getItemId();
if (itemId1 == null) {
data.postValue(Resource.error("itemId is null", null));
return data;
}
final Call<DirectThreadBroadcastResponse> request = service.broadcastReaction(clientContext, threadIdOrUserIds, itemId1, null, true);
handleBroadcastReactionRequest(data, item, request);
return data;
}

43
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/AnimatedMediaBroadcastOptions.kt

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

108
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/BroadcastOptions.kt

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

49
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/LinkBroadcastOptions.kt

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

8
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt

@ -3,7 +3,7 @@ package awais.instagrabber.repositories.requests.directmessages
import awais.instagrabber.models.enums.BroadcastItemType
class MediaShareBroadcastOptions(
clientContext: String?,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
val mediaId: String
) : BroadcastOptions(
@ -11,8 +11,6 @@ class MediaShareBroadcastOptions(
threadIdOrUserIds,
BroadcastItemType.MEDIA_SHARE
) {
override fun getFormMap(): Map<String, String> {
return mapOf("media_id" to mediaId)
}
override val formMap: Map<String, String>
get() = mapOf("media_id" to mediaId)
}

44
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/PhotoBroadcastOptions.kt

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

51
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/ReactionBroadcastOptions.kt

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

49
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/StoryReplyBroadcastOptions.kt

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

34
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/TextBroadcastOptions.kt

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

51
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VideoBroadcastOptions.kt

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

51
app/src/main/java/awais/instagrabber/repositories/requests/directmessages/VoiceBroadcastOptions.kt

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

4
app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.java

@ -214,11 +214,11 @@ public class DirectThreadViewModel extends AndroidViewModel {
voiceRecorder = null;
}
public LiveData<Resource<Object>> sendReaction(final DirectItem item, final Emoji emoji) {
public LiveData<Resource<Object>> sendReaction(@NonNull final DirectItem item, @NonNull final Emoji emoji) {
return threadManager.sendReaction(item, emoji);
}
public LiveData<Resource<Object>> sendDeleteReaction(final String itemId) {
public LiveData<Resource<Object>> sendDeleteReaction(@NonNull final String itemId) {
return threadManager.sendDeleteReaction(itemId);
}

83
app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.java

@ -7,7 +7,6 @@ import com.google.common.collect.ImmutableMap;
import org.json.JSONArray;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@ -19,13 +18,13 @@ import java.util.stream.Collectors;
import awais.instagrabber.repositories.DirectMessagesRepository;
import awais.instagrabber.repositories.requests.directmessages.AnimatedMediaBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.BroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.BroadcastOptions.ThreadIdOrUserIds;
import awais.instagrabber.repositories.requests.directmessages.LinkBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.MediaShareBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.PhotoBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.ReactionBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.StoryReplyBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.TextBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds;
import awais.instagrabber.repositories.requests.directmessages.VideoBroadcastOptions;
import awais.instagrabber.repositories.requests.directmessages.VoiceBroadcastOptions;
import awais.instagrabber.repositories.responses.directmessages.DirectBadgeCount;
@ -121,73 +120,77 @@ public class DirectMessagesService extends BaseService {
return repository.fetchUnseenCount();
}
public Call<DirectThreadBroadcastResponse> broadcastText(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String text,
final String repliedToItemId,
final String repliedToClientContext) {
public Call<DirectThreadBroadcastResponse> broadcastText(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String text,
@Nullable final String repliedToItemId,
@Nullable final String repliedToClientContext) {
final List<String> urls = TextUtils.extractUrls(text);
if (!urls.isEmpty()) {
return broadcastLink(clientContext, threadIdOrUserIds, text, urls, repliedToItemId, repliedToClientContext);
}
final TextBroadcastOptions broadcastOptions = new TextBroadcastOptions(clientContext, threadIdOrUserIds, text);
broadcastOptions.setRepliedToItemId(repliedToItemId);
broadcastOptions.setRepliedToClientContext(repliedToClientContext);
if (repliedToItemId != null && repliedToClientContext != null) {
broadcastOptions.setRepliedToItemId(repliedToItemId);
broadcastOptions.setRepliedToClientContext(repliedToClientContext);
}
return broadcast(broadcastOptions);
}
public Call<DirectThreadBroadcastResponse> broadcastLink(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String linkText,
final List<String> urls,
final String repliedToItemId,
final String repliedToClientContext) {
public Call<DirectThreadBroadcastResponse> broadcastLink(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String linkText,
@NonNull final List<String> urls,
@Nullable final String repliedToItemId,
@Nullable final String repliedToClientContext) {
final LinkBroadcastOptions broadcastOptions = new LinkBroadcastOptions(clientContext, threadIdOrUserIds, linkText, urls);
broadcastOptions.setRepliedToItemId(repliedToItemId);
broadcastOptions.setRepliedToClientContext(repliedToClientContext);
if (repliedToItemId != null && repliedToClientContext != null) {
broadcastOptions.setRepliedToItemId(repliedToItemId);
broadcastOptions.setRepliedToClientContext(repliedToClientContext);
}
return broadcast(broadcastOptions);
}
public Call<DirectThreadBroadcastResponse> broadcastPhoto(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String uploadId) {
public Call<DirectThreadBroadcastResponse> broadcastPhoto(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String uploadId) {
return broadcast(new PhotoBroadcastOptions(clientContext, threadIdOrUserIds, true, uploadId));
}
public Call<DirectThreadBroadcastResponse> broadcastVideo(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String uploadId,
final String videoResult,
public Call<DirectThreadBroadcastResponse> broadcastVideo(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String uploadId,
@NonNull final String videoResult,
final boolean sampled) {
return broadcast(new VideoBroadcastOptions(clientContext, threadIdOrUserIds, videoResult, uploadId, sampled));
}
public Call<DirectThreadBroadcastResponse> broadcastVoice(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String uploadId,
final List<Float> waveform,
public Call<DirectThreadBroadcastResponse> broadcastVoice(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String uploadId,
@NonNull final List<Float> waveform,
final int samplingFreq) {
return broadcast(new VoiceBroadcastOptions(clientContext, threadIdOrUserIds, uploadId, waveform, samplingFreq));
}
public Call<DirectThreadBroadcastResponse> broadcastStoryReply(final ThreadIdOrUserIds threadIdOrUserIds,
final String text,
final String mediaId,
final String reelId) throws UnsupportedEncodingException {
public Call<DirectThreadBroadcastResponse> broadcastStoryReply(@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String text,
@NonNull final String mediaId,
@NonNull final String reelId) {
return broadcast(new StoryReplyBroadcastOptions(UUID.randomUUID().toString(), threadIdOrUserIds, text, mediaId, reelId));
}
public Call<DirectThreadBroadcastResponse> broadcastReaction(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final String itemId,
final String emoji,
public Call<DirectThreadBroadcastResponse> broadcastReaction(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final String itemId,
@Nullable final String emoji,
final boolean delete) {
return broadcast(new ReactionBroadcastOptions(clientContext, threadIdOrUserIds, itemId, emoji, delete));
}
public Call<DirectThreadBroadcastResponse> broadcastAnimatedMedia(final String clientContext,
final ThreadIdOrUserIds threadIdOrUserIds,
final GiphyGif giphyGif) {
public Call<DirectThreadBroadcastResponse> broadcastAnimatedMedia(@NonNull final String clientContext,
@NonNull final ThreadIdOrUserIds threadIdOrUserIds,
@NonNull final GiphyGif giphyGif) {
return broadcast(new AnimatedMediaBroadcastOptions(clientContext, threadIdOrUserIds, giphyGif));
}
@ -456,8 +459,10 @@ public class DirectMessagesService extends BaseService {
return repository.declineRequest(threadId, form);
}
@Nullable
public Call<DirectItemSeenResponse> markAsSeen(@NonNull final String threadId,
@NonNull final DirectItem directItem) {
if (directItem.getItemId() == null) return null;
final ImmutableMap<String, String> form = ImmutableMap.<String, String>builder()
.put("_csrftoken", csrfToken)
.put("_uuid", deviceUuid)

Loading…
Cancel
Save