From 981cd693bfb4359d26991ced923f4024e7da33d9 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 24 May 2021 20:04:32 +0900 Subject: [PATCH 01/15] Remove the last usage of Date. austinhuang0131/barinsta#1309 --- .../DirectInboxItemViewHolder.java | 4 +-- .../awais/instagrabber/db/Converters.java | 11 ------- .../awais/instagrabber/utils/TextUtils.kt | 33 +++++++++---------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java index 2755cf32..2b0596b6 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectInboxItemViewHolder.java @@ -17,11 +17,9 @@ import java.util.List; import awais.instagrabber.R; import awais.instagrabber.adapters.DirectMessageInboxAdapter.OnItemClickListener; import awais.instagrabber.databinding.LayoutDmInboxItemBinding; -import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectThread; -import awais.instagrabber.repositories.responses.directmessages.DirectThreadDirectStory; import awais.instagrabber.utils.DMUtils; import awais.instagrabber.utils.TextUtils; @@ -136,7 +134,7 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder { private void setDateTime(@NonNull final DirectItem item) { final long timestamp = item.getTimestamp() / 1000; - final String dateTimeString = TextUtils.getRelativeDateTimeString(itemView.getContext(), timestamp); + final String dateTimeString = TextUtils.getRelativeDateTimeString(timestamp); binding.tvDate.setText(dateTimeString); } diff --git a/app/src/main/java/awais/instagrabber/db/Converters.java b/app/src/main/java/awais/instagrabber/db/Converters.java index c852b920..f2f2c0fb 100644 --- a/app/src/main/java/awais/instagrabber/db/Converters.java +++ b/app/src/main/java/awais/instagrabber/db/Converters.java @@ -6,21 +6,10 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; -//import java.util.Date; import awais.instagrabber.models.enums.FavoriteType; public class Converters { -// @TypeConverter -// public static Date fromTimestamp(Long value) { -// return value == null ? null : new Date(value); -// } -// -// @TypeConverter -// public static Long dateToTimestamp(Date date) { -// return date == null ? null : date.getTime(); -// } - @TypeConverter public static FavoriteType fromFavoriteTypeString(String value) { try { diff --git a/app/src/main/java/awais/instagrabber/utils/TextUtils.kt b/app/src/main/java/awais/instagrabber/utils/TextUtils.kt index c4e71e2d..8da94d3e 100644 --- a/app/src/main/java/awais/instagrabber/utils/TextUtils.kt +++ b/app/src/main/java/awais/instagrabber/utils/TextUtils.kt @@ -1,14 +1,14 @@ package awais.instagrabber.utils -import android.content.Context -import android.text.format.DateFormat -import android.text.format.DateUtils import android.util.Patterns -import java.time.format.DateTimeFormatter +import java.time.Duration import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle import java.util.* +import kotlin.math.absoluteValue object TextUtils { var datetimeParser: DateTimeFormatter = DateTimeFormatter.ofPattern("") @@ -40,22 +40,19 @@ object TextUtils { } else String.format(Locale.ENGLISH, "%02d:%02d", min, sec) } - @JvmStatic - fun getRelativeDateTimeString(context: Context?, from: Long): String { - val now = Date() - val then = Date(from) - val days = daysBetween(from, now.time) - return if (days == 0) { - DateFormat.getTimeFormat(context).format(then) - } else DateFormat.getDateFormat(context).format(then) - } + private val timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) + private val dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) - private fun daysBetween(d1: Long, d2: Long): Int { - return ((d2 - d1) / DateUtils.DAY_IN_MILLIS).toInt() + @JvmStatic + fun getRelativeDateTimeString(from: Long): String { + val now = LocalDateTime.now() + val then = LocalDateTime.ofInstant(Instant.ofEpochMilli(from), ZoneId.systemDefault()) + val days = Duration.between(now, then).toDays().absoluteValue + return then.format(if (days == 0L) timeFormatter else dateFormatter) } @JvmStatic - fun extractUrls(text: String?): List { + fun extractUrls(text: String): List { if (isEmpty(text)) return emptyList() val matcher = Patterns.WEB_URL.matcher(text) val urls: MutableList = ArrayList() @@ -87,8 +84,8 @@ object TextUtils { @JvmStatic fun epochSecondToString(epochSecond: Long): String { return LocalDateTime.ofInstant( - Instant.ofEpochSecond(epochSecond), - ZoneId.systemDefault() + Instant.ofEpochSecond(epochSecond), + ZoneId.systemDefault() ).format(datetimeParser) } From 5b10ecbd9d4569c3c8f7c4a0159904a5676dc68c Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 24 May 2021 20:29:05 +0900 Subject: [PATCH 02/15] Added some todo --- .../instagrabber/utils/ResponseBodyUtils.java | 668 +----------------- .../webservices/GraphQLService.java | 6 + 2 files changed, 8 insertions(+), 666 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index e4fb5101..333defa8 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -14,7 +14,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import awais.instagrabber.BuildConfig; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.stickers.PollModel; @@ -30,7 +29,6 @@ import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.MediaCandidate; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.VideoVersion; -//import awaisomereport.LogCollector; public final class ResponseBodyUtils { private static final String TAG = "ResponseBodyUtils"; @@ -75,11 +73,7 @@ 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 (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); + Log.e(TAG, "", e); } return null; } @@ -93,587 +87,11 @@ 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 (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); + Log.e(TAG, "", e); } return src; } - // public static String getLowQualityImage(final JSONObject resources) { - // String src = null; - // try { - // src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, true); - // } catch (final Exception e) { - // if (Utils.logCollector != null) - // Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getLowQualityImage", - // new Pair<>("resourcesNull", resources == null)); - // if (BuildConfig.DEBUG) Log.e(TAG, "Error in getLowQualityImage", e); - // } - // return src; - // } - - // public static ThumbnailDetails getItemThumbnail(@NonNull final JSONArray jsonArray) { - // final ThumbnailDetails thumbnailDetails = new ThumbnailDetails(); - // final int imageResLen = jsonArray.length(); - // for (int i = 0; i < imageResLen; ++i) { - // final JSONObject imageResource = jsonArray.optJSONObject(i); - // try { - // // final float ratio = (float) height / width; - // // if (ratio >= 0.95f && ratio <= 1.0f) { - // thumbnailDetails.height = imageResource.getInt("height"); - // thumbnailDetails.width = imageResource.getInt("width"); - // thumbnailDetails.url = imageResource.getString("url"); - // break; - // // } - // } catch (final Exception e) { - // if (Utils.logCollector != null) - // Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getItemThumbnail"); - // if (BuildConfig.DEBUG) Log.e(TAG, "", e); - // } - // } - // // if (TextUtils.isEmpty(thumbnail)) thumbnail = jsonArray.optJSONObject(0).optString("url"); - // return thumbnailDetails; - // } - - // public static class ThumbnailDetails { - // int width; - // int height; - // public String url; - // } - - // @Nullable - // public static ThumbnailDetails getThumbnailUrl(@NonNull final JSONObject mediaObj, final MediaItemType mediaType) throws Exception { - // ThumbnailDetails thumbnail = null; - // if (mediaType == MediaItemType.MEDIA_TYPE_IMAGE || mediaType == MediaItemType.MEDIA_TYPE_VIDEO) { - // final JSONObject imageVersions = mediaObj.optJSONObject("image_versions2"); - // if (imageVersions != null) - // thumbnail = getItemThumbnail(imageVersions.getJSONArray("candidates")); - // - // } else if (mediaType == MediaItemType.MEDIA_TYPE_SLIDER) { - // final JSONArray carouselMedia = mediaObj.optJSONArray("carousel_media"); - // if (carouselMedia != null) - // thumbnail = getItemThumbnail(carouselMedia.getJSONObject(0) - // .getJSONObject("image_versions2") - // .getJSONArray("candidates")); - // } - // return thumbnail; - // } - - // public static String getVideoUrl(@NonNull final JSONObject mediaObj) { - // String url = null; - // final JSONArray videoVersions = mediaObj.optJSONArray("video_versions"); - // if (videoVersions == null) { - // return null; - // } - // int largestWidth = 0; - // for (int i = 0; i < videoVersions.length(); i++) { - // final JSONObject videoVersionJson = videoVersions.optJSONObject(i); - // if (videoVersionJson == null) { - // continue; - // } - // final int width = videoVersionJson.optInt("width"); - // if (largestWidth == 0 || width > largestWidth) { - // largestWidth = width; - // url = videoVersionJson.optString("url"); - // } - // } - // return url; - // } - - // @Nullable - // public static MediaItemType getMediaItemType(final int mediaType) { - // if (mediaType == 1) return MediaItemType.MEDIA_TYPE_IMAGE; - // if (mediaType == 2) return MediaItemType.MEDIA_TYPE_VIDEO; - // if (mediaType == 8) return MediaItemType.MEDIA_TYPE_SLIDER; - // if (mediaType == 11) return MediaItemType.MEDIA_TYPE_VOICE; - // return null; - // } - - // public static DirectItemModel.DirectItemMediaModel getDirectMediaModel(final JSONObject mediaObj) throws Exception { - // final DirectItemModel.DirectItemMediaModel mediaModel; - // if (mediaObj == null) mediaModel = null; - // else { - // final JSONObject userObj = mediaObj.optJSONObject("user"); - // - // ProfileModel user = null; - // if (userObj != null) { - // user = new ProfileModel( - // userObj.getBoolean("is_private"), - // false, - // userObj.optBoolean("is_verified"), - // String.valueOf(userObj.get("pk")), - // userObj.getString("username"), - // userObj.getString("full_name"), - // null, null, - // userObj.getString("profile_pic_url"), - // null, 0, 0, 0, false, false, false, false, false); - // } - // - // final MediaItemType mediaType = getMediaItemType(mediaObj.optInt("media_type", -1)); - // - // String id = mediaObj.optString("id"); - // if (TextUtils.isEmpty(id)) id = null; - // - // final ThumbnailDetails thumbnailDetails = getThumbnailUrl(mediaObj, mediaType); - // mediaModel = new DirectItemModel.DirectItemMediaModel( - // mediaType, - // mediaObj.optLong("expiring_at"), - // mediaObj.optLong("pk"), - // id, - // thumbnailDetails != null ? thumbnailDetails.url : null, - // mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? getVideoUrl(mediaObj) : null, - // user, - // mediaObj.optString("code"), - // thumbnailDetails != null ? thumbnailDetails.height : 0, - // thumbnailDetails != null ? thumbnailDetails.width : 0); - // } - // return mediaModel; - // } - // - // private static DirectItemType getDirectItemType(final String itemType) { - // if ("placeholder".equals(itemType)) return DirectItemType.PLACEHOLDER; - // if ("media".equals(itemType)) return DirectItemType.MEDIA; - // if ("link".equals(itemType)) return DirectItemType.LINK; - // if ("like".equals(itemType)) return DirectItemType.LIKE; - // if ("reel_share".equals(itemType)) return DirectItemType.REEL_SHARE; - // if ("media_share".equals(itemType)) return DirectItemType.MEDIA_SHARE; - // if ("action_log".equals(itemType)) return DirectItemType.ACTION_LOG; - // if ("raven_media".equals(itemType)) return DirectItemType.RAVEN_MEDIA; - // if ("profile".equals(itemType)) return DirectItemType.PROFILE; - // if ("video_call_event".equals(itemType)) return DirectItemType.VIDEO_CALL_EVENT; - // if ("animated_media".equals(itemType)) return DirectItemType.ANIMATED_MEDIA; - // if ("voice_media".equals(itemType)) return DirectItemType.VOICE_MEDIA; - // if ("story_share".equals(itemType)) return DirectItemType.STORY_SHARE; - // if ("clip".equals(itemType)) return DirectItemType.CLIP; - // if ("felix_share".equals(itemType)) return DirectItemType.FELIX_SHARE; - // return DirectItemType.TEXT; - // } - // - // @NonNull - // public static InboxThreadModel createInboxThreadModel(@NonNull final JSONObject data, final boolean inThreadView) throws Exception { - // final InboxReadState readState = data.getInt("read_state") == 0 ? InboxReadState.STATE_READ : InboxReadState.STATE_UNREAD; - // final String threadType = data.getString("thread_type"); // they're all "private", group is identified by boolean "is_group" - // - // final String threadId = data.getString("thread_id"); - // final String threadV2Id = data.getString("thread_v2_id"); - // final String threadTitle = data.getString("thread_title"); - // - // final String threadNewestCursor = data.optString("newest_cursor"); - // final String threadOldestCursor = data.optString("oldest_cursor"); - // final String threadNextCursor = data.has("next_cursor") ? data.getString("next_cursor") : null; - // final String threadPrevCursor = data.has("prev_cursor") ? data.getString("prev_cursor") : null; - // - // final boolean threadHasOlder = data.getBoolean("has_older"); - // final long unreadCount = data.optLong("read_state", 0); - // - // final long lastActivityAt = data.optLong("last_activity_at"); - // final boolean named = data.optBoolean("named"); - // final boolean muted = data.optBoolean("muted"); - // final boolean isPin = data.optBoolean("is_pin"); - // final boolean isSpam = data.optBoolean("is_spam"); - // final boolean isGroup = data.optBoolean("is_group"); - // final boolean pending = data.optBoolean("pending"); - // final boolean archived = data.optBoolean("archived"); - // final boolean canonical = data.optBoolean("canonical"); - // - // final JSONArray users = data.getJSONArray("users"); - // final int usersLen = users.length(); - // final JSONArray leftusers = data.optJSONArray("left_users"); - // final int leftusersLen = leftusers == null ? 0 : leftusers.length(); - // final JSONArray admins = data.getJSONArray("admin_user_ids"); - // final int adminsLen = admins.length(); - // - // final ProfileModel[] userModels = new ProfileModel[usersLen]; - // for (int j = 0; j < usersLen; ++j) { - // final JSONObject userObject = users.getJSONObject(j); - // userModels[j] = new ProfileModel(userObject.optBoolean("is_private"), - // false, - // userObject.optBoolean("is_verified"), - // String.valueOf(userObject.get("pk")), - // userObject.optString("username"), // optional cuz fb users - // userObject.getString("full_name"), - // null, null, - // userObject.getString("profile_pic_url"), - // null, 0, 0, 0, false, false, false, false, false); - // } - // - // final ProfileModel[] leftuserModels = new ProfileModel[leftusersLen]; - // for (int j = 0; j < leftusersLen; ++j) { - // final JSONObject userObject = leftusers.getJSONObject(j); - // leftuserModels[j] = new ProfileModel(userObject.getBoolean("is_private"), - // false, - // userObject.optBoolean("is_verified"), - // String.valueOf(userObject.get("pk")), - // userObject.getString("username"), - // userObject.getString("full_name"), - // null, null, - // userObject.getString("profile_pic_url"), - // null, 0, 0, 0, false, false, false, false, false); - // } - // - // final Long[] adminIDs = new Long[adminsLen]; - // for (int j = 0; j < adminsLen; ++j) { - // adminIDs[j] = admins.getLong(j); - // } - // - // final JSONArray items = data.getJSONArray("items"); - // final int itemsLen = items.length(); - // - // final ArrayList itemModels = new ArrayList<>(itemsLen); - // for (int i = 0; i < itemsLen; ++i) { - // final JSONObject itemObject = items.getJSONObject(i); - // - // CharSequence text = null; - // ProfileModel profileModel = null; - // DirectItemModel.DirectItemLinkModel linkModel = null; - // DirectItemModel.DirectItemMediaModel directMedia = null; - // DirectItemModel.DirectItemReelShareModel reelShareModel = null; - // DirectItemModel.DirectItemActionLogModel actionLogModel = null; - // DirectItemModel.DirectItemAnimatedMediaModel animatedMediaModel = null; - // DirectItemModel.DirectItemVoiceMediaModel voiceMediaModel = null; - // DirectItemModel.DirectItemRavenMediaModel ravenMediaModel = null; - // DirectItemModel.DirectItemVideoCallEventModel videoCallEventModel = null; - // - // final DirectItemType itemType = getDirectItemType(itemObject.getString("item_type")); - // switch (itemType) { - // case ANIMATED_MEDIA: { - // final JSONObject animatedMedia = itemObject.getJSONObject("animated_media"); - // final JSONObject stickerImage = animatedMedia.getJSONObject("images").getJSONObject("fixed_height"); - // - // animatedMediaModel = new DirectItemModel.DirectItemAnimatedMediaModel( - // animatedMedia.getBoolean("is_random"), - // animatedMedia.getBoolean("is_sticker"), - // animatedMedia.getString("id"), - // stickerImage.getString("url"), - // stickerImage.optString("webp"), - // stickerImage.optString("mp4"), - // stickerImage.getInt("height"), - // stickerImage.getInt("width")); - // } - // break; - // - // case VOICE_MEDIA: { - // final JSONObject voiceMedia = itemObject.getJSONObject("voice_media").getJSONObject("media"); - // final JSONObject audio = voiceMedia.getJSONObject("audio"); - // - // int[] waveformData = null; - // final JSONArray waveformDataArray = audio.optJSONArray("waveform_data"); - // if (waveformDataArray != null) { - // final int waveformDataLen = waveformDataArray.length(); - // waveformData = new int[waveformDataLen]; - // // 0.011775206 - // for (int j = 0; j < waveformDataLen; ++j) { - // waveformData[j] = (int) (waveformDataArray.optDouble(j) * 10); - // } - // } - // - // voiceMediaModel = new DirectItemModel.DirectItemVoiceMediaModel( - // voiceMedia.getString("id"), - // audio.getString("audio_src"), - // audio.getLong("duration"), - // waveformData); - // } - // break; - // - // case LINK: { - // final JSONObject linkObj = itemObject.getJSONObject("link"); - // - // DirectItemModel.DirectItemLinkContext itemLinkContext = null; - // final JSONObject linkContext = linkObj.optJSONObject("link_context"); - // if (linkContext != null) { - // itemLinkContext = new DirectItemModel.DirectItemLinkContext( - // linkContext.getString("link_url"), - // linkContext.optString("link_title"), - // linkContext.optString("link_summary"), - // linkContext.optString("link_image_url") - // ); - // } - // - // linkModel = new DirectItemModel.DirectItemLinkModel( - // linkObj.getString("text"), - // linkObj.getString("client_context"), - // linkObj.optString("mutation_token"), - // itemLinkContext); - // } - // break; - // - // case REEL_SHARE: { - // final JSONObject reelShare = itemObject.getJSONObject("reel_share"); - // reelShareModel = new DirectItemModel.DirectItemReelShareModel( - // reelShare.optBoolean("is_reel_persisted"), - // reelShare.getLong("reel_owner_id"), - // reelShare.getJSONObject("media").getJSONObject("user").getString("username"), - // reelShare.getString("text"), - // reelShare.getString("type"), - // reelShare.getString("reel_type"), - // reelShare.optString("reel_name"), - // reelShare.optString("reel_id"), - // getDirectMediaModel(reelShare.optJSONObject("media"))); - // } - // break; - // - // case RAVEN_MEDIA: { - // final JSONObject visualMedia = itemObject.getJSONObject("visual_media"); - // - // final JSONArray seenUserIdsArray = visualMedia.getJSONArray("seen_user_ids"); - // final int seenUsersLen = seenUserIdsArray.length(); - // final String[] seenUserIds = new String[seenUsersLen]; - // for (int j = 0; j < seenUsersLen; j++) - // seenUserIds[j] = seenUserIdsArray.getString(j); - // - // DirectItemModel.RavenExpiringMediaActionSummaryModel expiringSummaryModel = null; - // final JSONObject actionSummary = visualMedia.optJSONObject("expiring_media_action_summary"); - // if (actionSummary != null) - // expiringSummaryModel = new DirectItemModel.RavenExpiringMediaActionSummaryModel( - // actionSummary.getLong("timestamp"), actionSummary.getInt("count"), - // getExpiringMediaType(actionSummary.getString("type"))); - // - // final RavenMediaViewType viewType; - // final String viewMode = visualMedia.getString("view_mode"); - // switch (viewMode) { - // case "replayable": - // viewType = RavenMediaViewType.REPLAYABLE; - // break; - // case "permanent": - // viewType = RavenMediaViewType.PERMANENT; - // break; - // case "once": - // default: - // viewType = RavenMediaViewType.ONCE; - // } - // - // ravenMediaModel = new DirectItemModel.DirectItemRavenMediaModel( - // visualMedia.optLong(viewType == RavenMediaViewType.PERMANENT ? "url_expire_at_secs" : "replay_expiring_at_us"), - // visualMedia.optInt("playback_duration_secs"), - // visualMedia.getInt("seen_count"), - // seenUserIds, - // viewType, - // getDirectMediaModel(visualMedia.optJSONObject("media")), - // expiringSummaryModel); - // - // } - // break; - // - // case VIDEO_CALL_EVENT: { - // final JSONObject videoCallEvent = itemObject.getJSONObject("video_call_event"); - // videoCallEventModel = new DirectItemModel.DirectItemVideoCallEventModel(videoCallEvent.optLong("vc_id"), - // videoCallEvent.optBoolean("thread_has_audio_only_call"), - // videoCallEvent.getString("action"), - // videoCallEvent.getString("description")); - // } - // break; - // - // case PROFILE: { - // final JSONObject profile = itemObject.getJSONObject("profile"); - // profileModel = new ProfileModel(profile.getBoolean("is_private"), - // false, - // profile.getBoolean("is_verified"), - // Long.toString(profile.getLong("pk")), - // profile.getString("username"), - // profile.getString("full_name"), - // null, null, - // profile.getString("profile_pic_url"), - // null, 0, 0, 0, false, false, false, false, false); - // } - // break; - // - // case PLACEHOLDER: - // final JSONObject placeholder = itemObject.getJSONObject("placeholder"); - // text = placeholder.getString("title") + "
" + placeholder.getString("message") + ""; - // break; - // - // case ACTION_LOG: - // if (inThreadView && itemObject.optInt("hide_in_thread", 0) != 0) - // continue; - // final JSONObject actionLog = itemObject.getJSONObject("action_log"); - // String desc = actionLog.getString("description"); - // JSONArray bold = actionLog.getJSONArray("bold"); - // for (int q = 0; q < bold.length(); ++q) { - // JSONObject boldItem = bold.getJSONObject(q); - // desc = desc.substring(0, boldItem.getInt("start") + q * 7) + "" - // + desc.substring(boldItem.getInt("start") + q * 7, boldItem.getInt("end") + q * 7) - // + "" + desc.substring(boldItem.getInt("end") + q * 7); - // } - // actionLogModel = new DirectItemModel.DirectItemActionLogModel(desc); - // break; - // - // case MEDIA_SHARE: - // directMedia = getDirectMediaModel(itemObject.getJSONObject("media_share")); - // break; - // - // case CLIP: - // directMedia = getDirectMediaModel(itemObject.getJSONObject("clip").getJSONObject("clip")); - // break; - // - // case FELIX_SHARE: - // directMedia = getDirectMediaModel(itemObject.getJSONObject("felix_share").getJSONObject("video")); - // break; - // - // case MEDIA: - // directMedia = getDirectMediaModel(itemObject.optJSONObject("media")); - // break; - // - // case LIKE: - // text = itemObject.getString("like"); - // break; - // - // case STORY_SHARE: - // final JSONObject storyShare = itemObject.getJSONObject("story_share"); - // if (!storyShare.has("media")) - // text = "" + storyShare.optString("message") + ""; - // else { - // reelShareModel = new DirectItemModel.DirectItemReelShareModel( - // storyShare.optBoolean("is_reel_persisted"), - // storyShare.getJSONObject("media").getJSONObject("user").getLong("pk"), - // storyShare.getJSONObject("media").getJSONObject("user").getString("username"), - // storyShare.getString("text"), - // storyShare.getString("story_share_type"), - // storyShare.getString("reel_type"), - // storyShare.optString("reel_name"), - // storyShare.optString("reel_id"), - // getDirectMediaModel(storyShare.optJSONObject("media"))); - // } - // break; - // - // case TEXT: - // if (!itemObject.has("text")) - // Log.d("AWAISKING_APP", "itemObject: " + itemObject); // todo - // text = itemObject.optString("text"); - // break; - // } - // - // String[] liked = null; - // if (!itemObject.isNull("reactions") && !itemObject.getJSONObject("reactions").isNull("likes")) { - // JSONArray rawLiked = itemObject.getJSONObject("reactions").getJSONArray("likes"); - // liked = new String[rawLiked.length()]; - // for (int l = 0; l < rawLiked.length(); ++l) { - // liked[l] = String.valueOf(rawLiked.getJSONObject(l).getLong("sender_id")); - // } - // } - // - // itemModels.add(new DirectItemModel( - // itemObject.getLong("user_id"), - // itemObject.getLong("timestamp"), - // itemObject.getString("item_id"), - // liked, - // itemType, - // text, - // linkModel, - // profileModel, - // reelShareModel, - // directMedia, - // actionLogModel, - // voiceMediaModel, - // ravenMediaModel, - // videoCallEventModel, - // animatedMediaModel)); - // } - // - // itemModels.trimToSize(); - // - // return new InboxThreadModel(readState, threadId, threadV2Id, threadType, threadTitle, - // threadNewestCursor, threadOldestCursor, threadNextCursor, threadPrevCursor, - // null, // todo - // userModels, leftuserModels, adminIDs, - // itemModels.toArray(new DirectItemModel[0]), - // muted, isPin, named, canonical, - // pending, threadHasOlder, unreadCount, isSpam, isGroup, archived, lastActivityAt); - // } - // - // private static RavenExpiringMediaType getExpiringMediaType(final String type) { - // if ("raven_sent".equals(type)) return RavenExpiringMediaType.RAVEN_SENT; - // if ("raven_opened".equals(type)) return RavenExpiringMediaType.RAVEN_OPENED; - // if ("raven_blocked".equals(type)) return RavenExpiringMediaType.RAVEN_BLOCKED; - // if ("raven_sending".equals(type)) return RavenExpiringMediaType.RAVEN_SENDING; - // if ("raven_replayed".equals(type)) return RavenExpiringMediaType.RAVEN_REPLAYED; - // if ("raven_delivered".equals(type)) return RavenExpiringMediaType.RAVEN_DELIVERED; - // if ("raven_suggested".equals(type)) return RavenExpiringMediaType.RAVEN_SUGGESTED; - // if ("raven_screenshot".equals(type)) return RavenExpiringMediaType.RAVEN_SCREENSHOT; - // if ("raven_cannot_deliver".equals(type)) return RavenExpiringMediaType.RAVEN_CANNOT_DELIVER; - // //if ("raven_unknown".equals(type)) [default?] - // return RavenExpiringMediaType.RAVEN_UNKNOWN; - // } - - // public static FeedModel parseItem(final JSONObject itemJson) throws JSONException { - // if (itemJson == null) { - // return null; - // } - // ProfileModel profileModel = null; - // if (itemJson.has("user")) { - // final JSONObject user = itemJson.getJSONObject("user"); - // final JSONObject friendshipStatus = user.optJSONObject("friendship_status"); - // boolean following = false; - // boolean restricted = false; - // boolean requested = false; - // if (friendshipStatus != null) { - // following = friendshipStatus.optBoolean("following"); - // requested = friendshipStatus.optBoolean("outgoing_request"); - // restricted = friendshipStatus.optBoolean("is_restricted"); - // } - // profileModel = new ProfileModel( - // user.optBoolean("is_private"), - // false, // if you can see it then you def follow - // user.optBoolean("is_verified"), - // user.getString("pk"), - // user.getString(Constants.EXTRAS_USERNAME), - // user.optString("full_name"), - // null, - // null, - // user.getString("profile_pic_url"), - // null, - // 0, - // 0, - // 0, - // following, - // false, - // restricted, - // false, - // requested); - // } - // final JSONObject captionJson = itemJson.optJSONObject("caption"); - // final JSONObject locationJson = itemJson.optJSONObject("location"); - // final MediaItemType mediaType = ResponseBodyUtils.getMediaItemType(itemJson.optInt("media_type")); - // if (mediaType == null) { - // return null; - // } - // final FeedModel.Builder feedModelBuilder = new FeedModel.Builder() - // .setItemType(mediaType) - // .setProfileModel(profileModel) - // .setPostId(itemJson.getString(Constants.EXTRAS_ID)) - // .setThumbnailUrl(mediaType != MediaItemType.MEDIA_TYPE_SLIDER ? ResponseBodyUtils.getLowQualityImage(itemJson) : null) - // .setShortCode(itemJson.getString("code")) - // .setPostCaption(captionJson != null ? captionJson.optString("text") : "") - // .setCaptionId(captionJson != null ? captionJson.optString("pk") : null) - // .setCommentsCount(itemJson.optInt("comment_count")) - // .setTimestamp(itemJson.optLong("taken_at", -1)) - // .setLiked(itemJson.optBoolean("has_liked")) - // .setBookmarked(itemJson.optBoolean("has_viewer_saved")) - // .setLikesCount(itemJson.optInt("like_count")) - // .setLocationName(locationJson != null ? locationJson.optString("name") : null) - // .setLocationId(locationJson != null ? String.valueOf(locationJson.optLong("pk")) : null) - // .setImageHeight(itemJson.optInt("original_height")) - // .setImageWidth(itemJson.optInt("original_width")); - // switch (mediaType) { - // case MEDIA_TYPE_VIDEO: - // final long videoViews = itemJson.optLong("view_count", 0); - // feedModelBuilder.setViewCount(videoViews) - // .setDisplayUrl(ResponseBodyUtils.getVideoUrl(itemJson)); - // break; - // case MEDIA_TYPE_IMAGE: - // feedModelBuilder.setDisplayUrl(ResponseBodyUtils.getHighQualityImage(itemJson)); - // break; - // case MEDIA_TYPE_SLIDER: - // final List childPosts = getChildPosts(itemJson); - // feedModelBuilder.setSliderItems(childPosts) - // .setImageHeight(childPosts.get(0).getHeight()) - // .setImageWidth(childPosts.get(0).getWidth()); - // break; - // } - // return feedModelBuilder.build(); - // } - // the "user" argument can be null, it's used because instagram redacts user details from responses public static Media parseGraphQLItem(final JSONObject itemJson, final User backup) throws JSONException { if (itemJson == null) { @@ -859,88 +277,6 @@ public final class ResponseBodyUtils { ); } - // private static List getChildPosts(final JSONObject mediaJson) throws JSONException { - // if (mediaJson == null) { - // return Collections.emptyList(); - // } - // final JSONArray carouselMedia = mediaJson.optJSONArray("carousel_media"); - // if (carouselMedia == null) { - // return Collections.emptyList(); - // } - // final List children = new ArrayList<>(); - // for (int i = 0; i < carouselMedia.length(); i++) { - // final JSONObject childJson = carouselMedia.optJSONObject(i); - // final PostChild childPost = getChildPost(childJson); - // if (childPost != null) { - // children.add(childPost); - // } - // } - // return children; - // } - - // private static PostChild getChildPost(final JSONObject childJson) throws JSONException { - // if (childJson == null) { - // return null; - // } - // final MediaItemType mediaType = ResponseBodyUtils.getMediaItemType(childJson.optInt("media_type")); - // if (mediaType == null) { - // return null; - // } - // final PostChild.Builder builder = new PostChild.Builder(); - // switch (mediaType) { - // case MEDIA_TYPE_VIDEO: - // builder.setDisplayUrl(ResponseBodyUtils.getVideoUrl(childJson)); - // break; - // case MEDIA_TYPE_IMAGE: - // builder.setDisplayUrl(ResponseBodyUtils.getHighQualityImage(childJson)); - // break; - // } - // return builder.setItemType(mediaType) - // .setPostId(childJson.getString("id")) - // .setThumbnailUrl(ResponseBodyUtils.getLowQualityImage(childJson)) - // .setHeight(childJson.optInt("original_height")) - // .setWidth(childJson.optInt("original_width")) - // .build(); - // } - - // this is for graphql - // @NonNull - // private static List getSliderItems(final JSONArray children) throws JSONException { - // final List sliderItems = new ArrayList<>(); - // for (int j = 0; j < children.length(); ++j) { - // final JSONObject childNode = children.optJSONObject(j).getJSONObject("node"); - // final boolean isChildVideo = childNode.optBoolean("is_video"); - // int height = 0; - // int width = 0; - // final JSONObject dimensions = childNode.optJSONObject("dimensions"); - // if (dimensions != null) { - // height = dimensions.optInt("height"); - // width = dimensions.optInt("width"); - // } - // String thumbnailUrl = null; - // try { - // thumbnailUrl = childNode.getJSONArray("display_resources") - // .getJSONObject(0) - // .getString("src"); - // } catch (JSONException ignored) {} - // final PostChild sliderItem = new PostChild.Builder() - // .setItemType(isChildVideo ? MediaItemType.MEDIA_TYPE_VIDEO - // : MediaItemType.MEDIA_TYPE_IMAGE) - // .setPostId(childNode.getString(Constants.EXTRAS_ID)) - // .setDisplayUrl(isChildVideo ? childNode.getString("video_url") - // : childNode.getString("display_url")) - // .setThumbnailUrl(thumbnailUrl != null ? thumbnailUrl - // : childNode.getString("display_url")) - // .setVideoViews(childNode.optLong("video_view_count", 0)) - // .setHeight(height) - // .setWidth(width) - // .build(); - // // Log.d(TAG, "getSliderItems: sliderItem: " + sliderItem); - // sliderItems.add(sliderItem); - // } - // return sliderItems; - // } - public static StoryModel parseStoryItem(final JSONObject data, final boolean isLocOrHashtag, final String username) throws JSONException { diff --git a/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java b/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java index a686a621..9c56110c 100644 --- a/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java +++ b/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java @@ -52,6 +52,7 @@ public class GraphQLService extends BaseService { return instance; } + // TODO convert string response to a response class private void fetch(final String queryHash, final String variables, final String arg1, @@ -194,6 +195,7 @@ public class GraphQLService extends BaseService { return new PostsFetchResponse(items, hasNextPage, endCursor); } + // TODO convert string response to a response class public void fetchCommentLikers(final String commentId, final String endCursor, final ServiceCallback callback) { @@ -273,6 +275,7 @@ public class GraphQLService extends BaseService { return repository.fetch(queryMap); } + // TODO convert string response to a response class public void fetchUser(final String username, final ServiceCallback callback) { final Call request = repository.getUser(username); @@ -357,6 +360,7 @@ public class GraphQLService extends BaseService { }); } + // TODO convert string response to a response class public void fetchPost(final String shortcode, final ServiceCallback callback) { final Call request = repository.getPost(shortcode); @@ -391,6 +395,7 @@ public class GraphQLService extends BaseService { }); } + // TODO convert string response to a response class public void fetchTag(final String tag, final ServiceCallback callback) { final Call request = repository.getTag(tag); @@ -431,6 +436,7 @@ public class GraphQLService extends BaseService { }); } + // TODO convert string response to a response class public void fetchLocation(final long locationId, final ServiceCallback callback) { final Call request = repository.getLocation(locationId); From 4b6ab15e26d0a13555fc9509547925d9425986d8 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 24 May 2021 22:49:32 +0900 Subject: [PATCH 03/15] Fix a variable name, add logging to upload video request and handle non json errors correctly. --- .../instagrabber/models/UploadVideoOptions.kt | 2 +- .../instagrabber/utils/MediaUploadHelper.kt | 39 +++++++++---------- .../instagrabber/utils/MediaUploader.java | 1 + .../interceptors/IgErrorsInterceptor.java | 15 ++++++- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt b/app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt index 1c5a25a8..d0baa4eb 100644 --- a/app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt +++ b/app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt @@ -11,7 +11,7 @@ data class UploadVideoOptions( val height: Int = 0, val isSideCar: Boolean = false, // Stories - val isForAlbum: Boolean = false, + val forAlbum: Boolean = false, val isDirect: Boolean = false, val isDirectVoice: Boolean = false, val isForDirectStory: Boolean = false, diff --git a/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt b/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt index 31ed2f67..cdbdca8a 100644 --- a/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt +++ b/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt @@ -30,27 +30,24 @@ private fun createPhotoRuploadParams(options: UploadPhotoOptions): Map { - val retryContextString = retryContextString - return listOfNotNull( - "retry_context" to retryContextString, - "media_type" to "2", - "xsharing_user_ids" to "[]", - "upload_id" to options.uploadId, - "upload_media_width" to options.width.toString(), - "upload_media_height" to options.height.toString(), - "upload_media_duration_ms" to options.duration.toString(), - if (options.isSideCar) "is_sidecar" to "1" else null, - if (options.isForAlbum) "for_album" to "1" else null, - if (options.isDirect) "direct_v2" to "1" else null, - *(if (options.isForDirectStory) arrayOf( - "for_direct_story" to "1", - "content_tags" to "" - ) else emptyArray()), - if (options.isIgtvVideo) "is_igtv_video" to "1" else null, - if (options.isDirectVoice) "is_direct_voice" to "1" else null, - ).toMap() -} +private fun createVideoRuploadParams(options: UploadVideoOptions): Map = listOfNotNull( + "retry_context" to retryContextString, + "media_type" to "2", + "xsharing_user_ids" to "[]", + "upload_id" to options.uploadId, + "upload_media_width" to options.width.toString(), + "upload_media_height" to options.height.toString(), + "upload_media_duration_ms" to options.duration.toString(), + if (options.isSideCar) "is_sidecar" to "1" else null, + if (options.forAlbum) "for_album" to "1" else null, + if (options.isDirect) "direct_v2" to "1" else null, + *(if (options.isForDirectStory) arrayOf( + "for_direct_story" to "1", + "content_tags" to "" + ) else emptyArray()), + if (options.isIgtvVideo) "is_igtv_video" to "1" else null, + if (options.isDirectVoice) "is_direct_voice" to "1" else null, +).toMap() val retryContextString: String get() { diff --git a/app/src/main/java/awais/instagrabber/utils/MediaUploader.java b/app/src/main/java/awais/instagrabber/utils/MediaUploader.java index 2b197e8c..3045e7e5 100644 --- a/app/src/main/java/awais/instagrabber/utils/MediaUploader.java +++ b/app/src/main/java/awais/instagrabber/utils/MediaUploader.java @@ -110,6 +110,7 @@ public final class MediaUploader { @NonNull final OnMediaUploadCompleteListener listener) { try { final OkHttpClient client = new OkHttpClient.Builder() + // .addInterceptor(new LoggingInterceptor()) .addInterceptor(new AddCookiesInterceptor()) .followRedirects(false) .followSslRedirects(false) diff --git a/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java b/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java index cf08b9dc..83c91d0d 100644 --- a/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java +++ b/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.fragment.app.FragmentManager; +import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; @@ -70,8 +71,18 @@ public class IgErrorsInterceptor implements Interceptor { try { final String bodyString = body.string(); Log.d(TAG, "checkError: " + bodyString); - final JSONObject jsonObject = new JSONObject(bodyString); - String message = jsonObject.optString("message"); + JSONObject jsonObject = null; + try { + jsonObject = new JSONObject(bodyString); + } catch (JSONException e) { + Log.e(TAG, "checkError: ", e); + } + String message; + if (jsonObject != null) { + message = jsonObject.optString("message"); + } else { + message = bodyString; + } if (!TextUtils.isEmpty(message)) { message = message.toLowerCase(); switch (message) { From c3e31ab81b0573b39cb519f0a1b4f0762e8a86ee Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 24 May 2021 23:40:08 +0900 Subject: [PATCH 04/15] Fix dm video upload --- app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt b/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt index cdbdca8a..bca3e36e 100644 --- a/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt +++ b/app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt @@ -83,7 +83,7 @@ fun createUploadDmVideoOptions( duration, width, height, - true, + isDirect = true, mediaType = MediaItemType.MEDIA_TYPE_VIDEO, ) } From c18e1ddb93302eb25f11e1e8fbc52c4efa631535 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 00:41:07 +0900 Subject: [PATCH 05/15] 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()); From bc6fdd03d9da1c6b4ebdb4a0c74b3cc04c942957 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 00:43:20 +0900 Subject: [PATCH 06/15] null checks and try with resources --- .../awais/instagrabber/managers/InboxManager.java | 5 +++-- .../awais/instagrabber/managers/ThreadManager.java | 3 +-- .../java/awais/instagrabber/utils/BitmapUtils.java | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/managers/InboxManager.java b/app/src/main/java/awais/instagrabber/managers/InboxManager.java index 073343cd..82019161 100644 --- a/app/src/main/java/awais/instagrabber/managers/InboxManager.java +++ b/app/src/main/java/awais/instagrabber/managers/InboxManager.java @@ -198,7 +198,7 @@ public final class InboxManager { hasOlder = false; return; } - if (!response.getStatus().equals("ok")) { + if (!Objects.equals(response.getStatus(), "ok")) { Log.e(TAG, "DM inbox fetch response: status not ok"); inbox.postValue(Resource.error(R.string.generic_not_ok_response, getCurrentDirectInbox())); hasOlder = false; @@ -209,12 +209,13 @@ public final class InboxManager { viewer = response.getViewer(); } final DirectInbox inbox = response.getInbox(); + if (inbox == null) return; if (!TextUtils.isEmpty(cursor)) { final DirectInbox currentDirectInbox = getCurrentDirectInbox(); if (currentDirectInbox != null) { List threads = currentDirectInbox.getThreads(); threads = threads == null ? new LinkedList<>() : new LinkedList<>(threads); - threads.addAll(inbox.getThreads()); + threads.addAll(inbox.getThreads() == null ? Collections.emptyList() : inbox.getThreads()); inbox.setThreads(threads); } } diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index 780c1897..21c50a83 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -16,7 +16,6 @@ import com.google.common.collect.Iterables; import org.json.JSONObject; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.HttpURLConnection; import java.util.ArrayList; @@ -1008,7 +1007,7 @@ public final class ThreadManager { return; } sendPhoto(data, uri, dimensions.first, dimensions.second); - } catch (FileNotFoundException e) { + } catch (IOException e) { data.postValue(Resource.error(e.getMessage(), null)); Log.e(TAG, "sendPhoto: ", e); } diff --git a/app/src/main/java/awais/instagrabber/utils/BitmapUtils.java b/app/src/main/java/awais/instagrabber/utils/BitmapUtils.java index 5a4783d0..49137b71 100644 --- a/app/src/main/java/awais/instagrabber/utils/BitmapUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/BitmapUtils.java @@ -17,7 +17,6 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -243,13 +242,15 @@ public final class BitmapUtils { * @return dimensions of the image */ public static Pair decodeDimensions(@NonNull final ContentResolver contentResolver, - @NonNull final Uri uri) throws FileNotFoundException { + @NonNull final Uri uri) throws IOException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, options); - return (options.outWidth == -1 || options.outHeight == -1) - ? null - : new Pair<>(options.outWidth, options.outHeight); + try (final InputStream stream = contentResolver.openInputStream(uri)) { + BitmapFactory.decodeStream(stream, null, options); + return (options.outWidth == -1 || options.outHeight == -1) + ? null + : new Pair<>(options.outWidth, options.outHeight); + } } public static File convertToJpegAndSaveToFile(@NonNull final Bitmap bitmap, @Nullable final File file) throws IOException { From 54a03e0d2bda218211b3841e5badff2d82ce0e3e Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 01:22:59 +0900 Subject: [PATCH 07/15] Rename .java to .kt --- .../{DirectItemActionLog.java => DirectItemActionLog.kt} | 0 .../{DirectItemAnimatedMedia.java => DirectItemAnimatedMedia.kt} | 0 .../{DirectItemEmojiReaction.java => DirectItemEmojiReaction.kt} | 0 .../directmessages/{DirectItemLink.java => DirectItemLink.kt} | 0 .../{DirectItemLinkContext.java => DirectItemLinkContext.kt} | 0 .../{DirectItemPlaceholder.java => DirectItemPlaceholder.kt} | 0 .../{DirectItemReactions.java => DirectItemReactions.kt} | 0 .../{DirectItemSeenResponse.java => DirectItemSeenResponse.kt} | 0 ...{DirectItemVideoCallEvent.java => DirectItemVideoCallEvent.kt} | 0 .../{DirectItemVoiceMedia.java => DirectItemVoiceMedia.kt} | 0 .../directmessages/{DirectItemXma.java => DirectItemXma.kt} | 0 ...eadBroadcastResponse.java => DirectThreadBroadcastResponse.kt} | 0 ...adata.java => DirectThreadBroadcastResponseMessageMetadata.kt} | 0 ...sponsePayload.java => DirectThreadBroadcastResponsePayload.kt} | 0 ...{DirectThreadFeedResponse.java => DirectThreadFeedResponse.kt} | 0 .../{DirectThreadLastSeenAt.java => DirectThreadLastSeenAt.kt} | 0 .../directmessages/{ThreadContext.java => ThreadContext.kt} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemActionLog.java => DirectItemActionLog.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemAnimatedMedia.java => DirectItemAnimatedMedia.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemEmojiReaction.java => DirectItemEmojiReaction.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemLink.java => DirectItemLink.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemLinkContext.java => DirectItemLinkContext.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemPlaceholder.java => DirectItemPlaceholder.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemReactions.java => DirectItemReactions.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemSeenResponse.java => DirectItemSeenResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemVideoCallEvent.java => DirectItemVideoCallEvent.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemVoiceMedia.java => DirectItemVoiceMedia.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemXma.java => DirectItemXma.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadBroadcastResponse.java => DirectThreadBroadcastResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadBroadcastResponseMessageMetadata.java => DirectThreadBroadcastResponseMessageMetadata.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadBroadcastResponsePayload.java => DirectThreadBroadcastResponsePayload.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadFeedResponse.java => DirectThreadFeedResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadLastSeenAt.java => DirectThreadLastSeenAt.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{ThreadContext.java => ThreadContext.kt} (100%) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt From eab6fea0abb13ecc7f8e3d0847c5857f8765d8f1 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 01:22:59 +0900 Subject: [PATCH 08/15] Convert to kotlin --- .../DirectItemActionLogViewHolder.java | 9 +- .../DirectItemVideoCallEventViewHolder.java | 6 +- .../DirectItemXmaViewHolder.java | 7 +- .../instagrabber/managers/ThreadManager.java | 2 +- .../directmessages/DirectItemActionLog.kt | 97 ++------------- .../directmessages/DirectItemAnimatedMedia.kt | 60 ++-------- .../directmessages/DirectItemEmojiReaction.kt | 66 ++-------- .../directmessages/DirectItemLink.kt | 59 ++------- .../directmessages/DirectItemLinkContext.kt | 59 ++------- .../directmessages/DirectItemPlaceholder.kt | 50 ++------ .../directmessages/DirectItemReactions.kt | 69 ++--------- .../directmessages/DirectItemSeenResponse.kt | 100 +--------------- .../DirectItemSeenResponsePayload.kt | 3 + .../DirectItemVideoCallEvent.kt | 69 ++--------- .../directmessages/DirectItemVoiceMedia.kt | 51 ++------ .../responses/directmessages/DirectItemXma.kt | 113 ++---------------- .../DirectThreadBroadcastResponse.kt | 64 ++-------- ...tThreadBroadcastResponseMessageMetadata.kt | 62 ++-------- .../DirectThreadBroadcastResponsePayload.kt | 50 ++------ .../DirectThreadFeedResponse.kt | 23 +--- .../directmessages/DirectThreadLastSeenAt.kt | 40 +------ .../responses/directmessages/TextRange.kt | 10 ++ .../responses/directmessages/ThreadContext.kt | 40 +------ 23 files changed, 158 insertions(+), 951 deletions(-) create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponsePayload.kt create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/directmessages/TextRange.kt diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java index 45c83805..c212efbf 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java @@ -22,6 +22,7 @@ import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemActionLog; import awais.instagrabber.repositories.responses.directmessages.DirectThread; +import awais.instagrabber.repositories.responses.directmessages.TextRange; import awais.instagrabber.utils.TextUtils; public class DirectItemActionLogViewHolder extends DirectItemViewHolder { @@ -45,16 +46,16 @@ public class DirectItemActionLogViewHolder extends DirectItemViewHolder { final DirectItemActionLog actionLog = directItemModel.getActionLog(); final String text = actionLog.getDescription(); final SpannableStringBuilder sb = new SpannableStringBuilder(text); - final List bold = actionLog.getBold(); + final List bold = actionLog.getBold(); if (bold != null && !bold.isEmpty()) { - for (final DirectItemActionLog.TextRange textRange : bold) { + for (final TextRange textRange : bold) { final StyleSpan boldStyleSpan = new StyleSpan(Typeface.BOLD); sb.setSpan(boldStyleSpan, textRange.getStart(), textRange.getEnd(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); } } - final List textAttributes = actionLog.getTextAttributes(); + final List textAttributes = actionLog.getTextAttributes(); if (textAttributes != null && !textAttributes.isEmpty()) { - for (final DirectItemActionLog.TextRange textAttribute : textAttributes) { + for (final TextRange textAttribute : textAttributes) { if (!TextUtils.isEmpty(textAttribute.getColor())) { final ForegroundColorSpan colorSpan = new ForegroundColorSpan(itemView.getResources().getColor(R.color.deep_orange_400)); sb.setSpan(colorSpan, textAttribute.getStart(), textAttribute.getEnd(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java index 77a43a5a..4c56922a 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java @@ -17,9 +17,9 @@ import awais.instagrabber.databinding.LayoutDmActionLogBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; -import awais.instagrabber.repositories.responses.directmessages.DirectItemActionLog; import awais.instagrabber.repositories.responses.directmessages.DirectItemVideoCallEvent; import awais.instagrabber.repositories.responses.directmessages.DirectThread; +import awais.instagrabber.repositories.responses.directmessages.TextRange; import awais.instagrabber.utils.TextUtils; public class DirectItemVideoCallEventViewHolder extends DirectItemViewHolder { @@ -41,9 +41,9 @@ public class DirectItemVideoCallEventViewHolder extends DirectItemViewHolder { final DirectItemVideoCallEvent videoCallEvent = directItemModel.getVideoCallEvent(); final String text = videoCallEvent.getDescription(); final SpannableStringBuilder sb = new SpannableStringBuilder(text); - final List textAttributes = videoCallEvent.getTextAttributes(); + final List textAttributes = videoCallEvent.getTextAttributes(); if (textAttributes != null && !textAttributes.isEmpty()) { - for (final DirectItemActionLog.TextRange textAttribute : textAttributes) { + for (final TextRange textAttribute : textAttributes) { if (!TextUtils.isEmpty(textAttribute.getColor())) { final ForegroundColorSpan colorSpan = new ForegroundColorSpan(itemView.getResources().getColor(R.color.deep_orange_400)); sb.setSpan(colorSpan, textAttribute.getStart(), textAttribute.getEnd(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemXmaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemXmaViewHolder.java index adee0226..d6420bda 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemXmaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemXmaViewHolder.java @@ -15,6 +15,7 @@ import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemXma; import awais.instagrabber.repositories.responses.directmessages.DirectThread; +import awais.instagrabber.repositories.responses.directmessages.XmaUrlInfo; import awais.instagrabber.utils.NullSafePair; import awais.instagrabber.utils.NumberUtils; @@ -35,13 +36,13 @@ public class DirectItemXmaViewHolder extends DirectItemViewHolder { @Override public void bindItem(final DirectItem item, final MessageDirection messageDirection) { final DirectItemXma xma = item.getXma(); - final DirectItemXma.XmaUrlInfo playableUrlInfo = xma.getPlayableUrlInfo(); - final DirectItemXma.XmaUrlInfo previewUrlInfo = xma.getPreviewUrlInfo(); + final XmaUrlInfo playableUrlInfo = xma.getPlayableUrlInfo(); + final XmaUrlInfo previewUrlInfo = xma.getPreviewUrlInfo(); if (playableUrlInfo == null && previewUrlInfo == null) { binding.ivAnimatedMessage.setController(null); return; } - final DirectItemXma.XmaUrlInfo urlInfo = playableUrlInfo != null ? playableUrlInfo : previewUrlInfo; + final XmaUrlInfo urlInfo = playableUrlInfo != null ? playableUrlInfo : previewUrlInfo; final String url = urlInfo.getUrl(); final NullSafePair widthHeight = NumberUtils.calculateWidthHeight( urlInfo.getHeight(), diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index 21c50a83..b479b427 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -49,7 +49,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemEmojiReaction; import awais.instagrabber.repositories.responses.directmessages.DirectItemReactions; import awais.instagrabber.repositories.responses.directmessages.DirectItemSeenResponse; -import awais.instagrabber.repositories.responses.directmessages.DirectItemSeenResponse.DirectItemSeenResponsePayload; +import awais.instagrabber.repositories.responses.directmessages.DirectItemSeenResponsePayload; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThreadBroadcastResponse; import awais.instagrabber.repositories.responses.directmessages.DirectThreadBroadcastResponseMessageMetadata; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt index c6b40581..320e4092 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.kt @@ -1,92 +1,9 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.List; -import java.util.Objects; +import java.io.Serializable -public class DirectItemActionLog implements Serializable { - private final String description; - private final List bold; - private final List textAttributes; - - public DirectItemActionLog(final String description, - final List bold, - final List textAttributes) { - this.description = description; - this.bold = bold; - this.textAttributes = textAttributes; - } - - public String getDescription() { - return description; - } - - public List getBold() { - return bold; - } - - public List getTextAttributes() { - return textAttributes; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemActionLog that = (DirectItemActionLog) o; - return Objects.equals(description, that.description) && - Objects.equals(bold, that.bold) && - Objects.equals(textAttributes, that.textAttributes); - } - - @Override - public int hashCode() { - return Objects.hash(description, bold, textAttributes); - } - - public static class TextRange implements Serializable { - private final int start; - private final int end; - private final String color; - private final String intent; - - public TextRange(final int start, final int end, final String color, final String intent) { - this.start = start; - this.end = end; - this.color = color; - this.intent = intent; - } - - public int getStart() { - return start; - } - - public int getEnd() { - return end; - } - - public String getColor() { - return color; - } - - public String getIntent() { - return intent; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final TextRange textRange = (TextRange) o; - return start == textRange.start && - end == textRange.end && - Objects.equals(color, textRange.color) && - Objects.equals(intent, textRange.intent); - } - - @Override - public int hashCode() { - return Objects.hash(start, end, color, intent); - } - } -} +data class DirectItemActionLog( + val description: String? = null, + val bold: List? = null, + val textAttributes: List? = null +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt index b948726c..085943ec 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.kt @@ -1,53 +1,11 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.AnimatedMediaImages +import java.io.Serializable -import awais.instagrabber.repositories.responses.AnimatedMediaImages; - -public final class DirectItemAnimatedMedia implements Serializable { - private final String id; - private final AnimatedMediaImages images; - private final boolean isRandom; - private final boolean isSticker; - - public DirectItemAnimatedMedia(final String id, final AnimatedMediaImages images, final boolean isRandom, final boolean isSticker) { - - this.id = id; - this.images = images; - this.isRandom = isRandom; - this.isSticker = isSticker; - } - - public String getId() { - return id; - } - - public AnimatedMediaImages getImages() { - return images; - } - - public boolean isRandom() { - return isRandom; - } - - public boolean isSticker() { - return isSticker; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemAnimatedMedia that = (DirectItemAnimatedMedia) o; - return isRandom == that.isRandom && - isSticker == that.isSticker && - Objects.equals(id, that.id) && - Objects.equals(images, that.images); - } - - @Override - public int hashCode() { - return Objects.hash(id, images, isRandom, isSticker); - } -} +data class DirectItemAnimatedMedia( + val id: String? = null, + val images: AnimatedMediaImages? = null, + val isRandom: Boolean = false, + val isSticker: Boolean = false, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt index 068c17f6..a0620406 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemEmojiReaction.kt @@ -1,60 +1,10 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectItemEmojiReaction implements Serializable { - private final long senderId; - private final long timestamp; - private final String emoji; - private final String superReactType; - - public DirectItemEmojiReaction(final long senderId, final long timestamp, final String emoji, final String superReactType) { - this.senderId = senderId; - this.timestamp = timestamp; - this.emoji = emoji; - this.superReactType = superReactType; - } - - public long getSenderId() { - return senderId; - } - - public long getTimestamp() { - return timestamp; - } - - public String getEmoji() { - return emoji; - } - - public String getSuperReactType() { - return superReactType; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemEmojiReaction that = (DirectItemEmojiReaction) o; - return senderId == that.senderId && - timestamp == that.timestamp && - Objects.equals(emoji, that.emoji) && - Objects.equals(superReactType, that.superReactType); - } - - @Override - public int hashCode() { - return Objects.hash(senderId, timestamp, emoji, superReactType); - } - - @Override - public String toString() { - return "DirectItemEmojiReaction{" + - "senderId=" + senderId + - ", timestamp=" + timestamp + - ", emoji='" + emoji + '\'' + - ", superReactType='" + superReactType + '\'' + - '}'; - } -} +data class DirectItemEmojiReaction( + val senderId: Long = 0, + val timestamp: Long = 0, + val emoji: String? = null, + val superReactType: String? = null +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt index d4d1915e..f190568c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.kt @@ -1,53 +1,10 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectItemLink implements Serializable { - private final String text; - private final DirectItemLinkContext linkContext; - private final String clientContext; - private final String mutationToken; - - public DirectItemLink(final String text, - final DirectItemLinkContext linkContext, - final String clientContext, - final String mutationToken) { - this.text = text; - this.linkContext = linkContext; - this.clientContext = clientContext; - this.mutationToken = mutationToken; - } - - public String getText() { - return text; - } - - public DirectItemLinkContext getLinkContext() { - return linkContext; - } - - public String getClientContext() { - return clientContext; - } - - public String getMutationToken() { - return mutationToken; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemLink that = (DirectItemLink) o; - return Objects.equals(text, that.text) && - Objects.equals(linkContext, that.linkContext) && - Objects.equals(clientContext, that.clientContext) && - Objects.equals(mutationToken, that.mutationToken); - } - - @Override - public int hashCode() { - return Objects.hash(text, linkContext, clientContext, mutationToken); - } -} +data class DirectItemLink( + val text: String? = null, + val linkContext: DirectItemLinkContext? = null, + val clientContext: String? = null, + val mutationToken: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt index 6f31a711..5190208d 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.kt @@ -1,53 +1,10 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectItemLinkContext implements Serializable { - private final String linkUrl; - private final String linkTitle; - private final String linkSummary; - private final String linkImageUrl; - - public DirectItemLinkContext(final String linkUrl, - final String linkTitle, - final String linkSummary, - final String linkImageUrl) { - this.linkUrl = linkUrl; - this.linkTitle = linkTitle; - this.linkSummary = linkSummary; - this.linkImageUrl = linkImageUrl; - } - - public String getLinkUrl() { - return linkUrl; - } - - public String getLinkTitle() { - return linkTitle; - } - - public String getLinkSummary() { - return linkSummary; - } - - public String getLinkImageUrl() { - return linkImageUrl; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemLinkContext that = (DirectItemLinkContext) o; - return Objects.equals(linkUrl, that.linkUrl) && - Objects.equals(linkTitle, that.linkTitle) && - Objects.equals(linkSummary, that.linkSummary) && - Objects.equals(linkImageUrl, that.linkImageUrl); - } - - @Override - public int hashCode() { - return Objects.hash(linkUrl, linkTitle, linkSummary, linkImageUrl); - } -} +data class DirectItemLinkContext( + val linkUrl: String? = null, + val linkTitle: String? = null, + val linkSummary: String? = null, + val linkImageUrl: String? = null +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt index 5c309504..d01006ec 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.kt @@ -1,45 +1,9 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectItemPlaceholder implements Serializable { - private final boolean isLinked; - private final String title; - private final String message; - - public DirectItemPlaceholder(final boolean isLinked, - final String title, - final String message) { - this.isLinked = isLinked; - this.title = title; - this.message = message; - } - - public boolean isLinked() { - return isLinked; - } - - public String getTitle() { - return title; - } - - public String getMessage() { - return message; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemPlaceholder that = (DirectItemPlaceholder) o; - return isLinked == that.isLinked && - Objects.equals(title, that.title) && - Objects.equals(message, that.message); - } - - @Override - public int hashCode() { - return Objects.hash(isLinked, title, message); - } -} +data class DirectItemPlaceholder( + val isLinked: Boolean = false, + val title: String? = null, + val message: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt index 30d3cf6c..5f08c499 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReactions.kt @@ -1,62 +1,13 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; +import java.io.Serializable -import java.io.Serializable; -import java.util.List; -import java.util.Objects; - -public class DirectItemReactions implements Cloneable, Serializable { - private List emojis; - private List likes; - - public DirectItemReactions(final List emojis, - final List likes) { - this.emojis = emojis; - this.likes = likes; +data class DirectItemReactions( + var emojis: List? = null, + var likes: List? = null, +) : Cloneable, Serializable { + @Throws(CloneNotSupportedException::class) + public override fun clone(): Any { + return super.clone() } - - public List getEmojis() { - return emojis; - } - - public List getLikes() { - return likes; - } - - public void setLikes(final List likes) { - this.likes = likes; - } - - public void setEmojis(final List emojis) { - this.emojis = emojis; - } - - @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 DirectItemReactions that = (DirectItemReactions) o; - return Objects.equals(emojis, that.emojis) && - Objects.equals(likes, that.likes); - } - - @Override - public int hashCode() { - return Objects.hash(emojis, likes); - } - - @Override - public String toString() { - return "DirectItemReactions{" + - "emojis=" + emojis + - ", likes=" + likes + - '}'; - } -} +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt index e1c88dab..85d27381 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponse.kt @@ -1,95 +1,7 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; - -import java.util.Objects; - -public class DirectItemSeenResponse { - private final String action; - private final DirectItemSeenResponsePayload payload; - private final String status; - - public DirectItemSeenResponse(final String action, final DirectItemSeenResponsePayload payload, final String status) { - this.action = action; - this.payload = payload; - this.status = status; - } - - public String getAction() { - return action; - } - - public DirectItemSeenResponsePayload getPayload() { - return payload; - } - - public String getStatus() { - return status; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemSeenResponse that = (DirectItemSeenResponse) o; - return Objects.equals(action, that.action) && - Objects.equals(payload, that.payload) && - Objects.equals(status, that.status); - } - - @Override - public int hashCode() { - return Objects.hash(action, payload, status); - } - - @NonNull - @Override - public String toString() { - return "DirectItemSeenResponse{" + - "action='" + action + '\'' + - ", payload=" + payload + - ", status='" + status + '\'' + - '}'; - } - - public static class DirectItemSeenResponsePayload { - private final int count; - private final String timestamp; - - public DirectItemSeenResponsePayload(final int count, final String timestamp) { - this.count = count; - this.timestamp = timestamp; - } - - public int getCount() { - return count; - } - - public String getTimestamp() { - return timestamp; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemSeenResponsePayload that = (DirectItemSeenResponsePayload) o; - return count == that.count && - Objects.equals(timestamp, that.timestamp); - } - - @Override - public int hashCode() { - return Objects.hash(count, timestamp); - } - - @NonNull - @Override - public String toString() { - return "DirectItemSeenResponsePayload{" + - "count=" + count + - ", timestamp='" + timestamp + '\'' + - '}'; - } - } -} +data class DirectItemSeenResponse( + val action: String? = null, + val payload: DirectItemSeenResponsePayload? = null, + val status: String? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponsePayload.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponsePayload.kt new file mode 100644 index 00000000..9bbdb553 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemSeenResponsePayload.kt @@ -0,0 +1,3 @@ +package awais.instagrabber.repositories.responses.directmessages + +data class DirectItemSeenResponsePayload(val count: Int = 0, val timestamp: String? = null) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt index da68d633..ae1ea0ad 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.kt @@ -1,62 +1,11 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.List; -import java.util.Objects; +import java.io.Serializable -public final class DirectItemVideoCallEvent implements Serializable { - private final String action; - private final String encodedServerDataInfo; - private final String description; - private final boolean threadHasAudioOnlyCall; - private final List textAttributes; - - public DirectItemVideoCallEvent(final String action, - final String encodedServerDataInfo, - final String description, - final boolean threadHasAudioOnlyCall, - final List textAttributes) { - this.action = action; - this.encodedServerDataInfo = encodedServerDataInfo; - this.description = description; - this.threadHasAudioOnlyCall = threadHasAudioOnlyCall; - this.textAttributes = textAttributes; - } - - public String getAction() { - return action; - } - - public String getEncodedServerDataInfo() { - return encodedServerDataInfo; - } - - public String getDescription() { - return description; - } - - public boolean isThreadHasAudioOnlyCall() { - return threadHasAudioOnlyCall; - } - - public List getTextAttributes() { - return textAttributes; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemVideoCallEvent that = (DirectItemVideoCallEvent) o; - return threadHasAudioOnlyCall == that.threadHasAudioOnlyCall && - Objects.equals(action, that.action) && - Objects.equals(encodedServerDataInfo, that.encodedServerDataInfo) && - Objects.equals(description, that.description) && - Objects.equals(textAttributes, that.textAttributes); - } - - @Override - public int hashCode() { - return Objects.hash(action, encodedServerDataInfo, description, threadHasAudioOnlyCall, textAttributes); - } -} +data class DirectItemVideoCallEvent( + val action: String? = null, + val encodedServerDataInfo: String? = null, + val description: String? = null, + val threadHasAudioOnlyCall: Boolean = false, + val textAttributes: List? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt index 006fa509..4ab35e24 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.kt @@ -1,45 +1,10 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemVoiceMedia implements Serializable { - private final Media media; - private final int seenCount; - private final String viewMode; - - public DirectItemVoiceMedia(final Media media, final int seenCount, final String viewMode) { - this.media = media; - this.seenCount = seenCount; - this.viewMode = viewMode; - } - - public Media getMedia() { - return media; - } - - public int getSeenCount() { - return seenCount; - } - - public String getViewMode() { - return viewMode; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemVoiceMedia that = (DirectItemVoiceMedia) o; - return seenCount == that.seenCount && - Objects.equals(media, that.media) && - Objects.equals(viewMode, that.viewMode); - } - - @Override - public int hashCode() { - return Objects.hash(media, seenCount, viewMode); - } -} +data class DirectItemVoiceMedia( + val media: Media? = null, + val seenCount: Int = 0, + val viewMode: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt index 518e6efc..e28bbb9e 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemXma.kt @@ -1,104 +1,15 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; +import java.io.Serializable -import java.io.Serializable; -import java.util.Objects; +data class DirectItemXma( + val previewUrlInfo: XmaUrlInfo? = null, + val playableUrlInfo: XmaUrlInfo? = null, +) : Serializable -public class DirectItemXma { - private final XmaUrlInfo previewUrlInfo; - private final XmaUrlInfo playableUrlInfo; - - public DirectItemXma(final XmaUrlInfo previewUrlInfo, final XmaUrlInfo playableUrlInfo) { - this.previewUrlInfo = previewUrlInfo; - this.playableUrlInfo = playableUrlInfo; - } - - public XmaUrlInfo getPreviewUrlInfo() { - return previewUrlInfo; - } - - public XmaUrlInfo getPlayableUrlInfo() { - return playableUrlInfo; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemXma that = (DirectItemXma) o; - return Objects.equals(previewUrlInfo, that.previewUrlInfo) && - Objects.equals(playableUrlInfo, that.playableUrlInfo); - } - - @Override - public int hashCode() { - return Objects.hash(previewUrlInfo, playableUrlInfo); - } - - @NonNull - @Override - public String toString() { - return "DirectItemXma{" + - "previewUrlInfo=" + previewUrlInfo + - ", playableUrlInfo=" + playableUrlInfo + - '}'; - } - - public static class XmaUrlInfo implements Serializable { - private final String url; - private final long urlExpirationTimestampUs; - private final int width; - private final int height; - - public XmaUrlInfo(final String url, final long urlExpirationTimestampUs, final int width, final int height) { - this.url = url; - this.urlExpirationTimestampUs = urlExpirationTimestampUs; - this.width = width; - this.height = height; - } - - public String getUrl() { - return url; - } - - public long getUrlExpirationTimestampUs() { - return urlExpirationTimestampUs; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final XmaUrlInfo that = (XmaUrlInfo) o; - return urlExpirationTimestampUs == that.urlExpirationTimestampUs && - width == that.width && - height == that.height && - Objects.equals(url, that.url); - } - - @Override - public int hashCode() { - return Objects.hash(url, urlExpirationTimestampUs, width, height); - } - - @NonNull - @Override - public String toString() { - return "XmaUrlInfo{" + - "url='" + url + '\'' + - ", urlExpirationTimestampUs=" + urlExpirationTimestampUs + - ", width=" + width + - ", height=" + height + - '}'; - } - } -} +data class XmaUrlInfo( + val url: String? = null, + val urlExpirationTimestampUs: Long = 0, + val width: Int = 0, + val height: Int = 0, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt index 0acf4929..0669450d 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponse.kt @@ -1,57 +1,9 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; - -import java.util.List; - -public class DirectThreadBroadcastResponse { - private final String action; - private final String statusCode; - private final DirectThreadBroadcastResponsePayload payload; - private final List messageMetadata; - private final String status; - - public DirectThreadBroadcastResponse(final String action, - final String statusCode, - final DirectThreadBroadcastResponsePayload payload, - final List messageMetadata, - final String status) { - this.action = action; - this.statusCode = statusCode; - this.payload = payload; - this.messageMetadata = messageMetadata; - this.status = status; - } - - public String getAction() { - return action; - } - - public String getStatusCode() { - return statusCode; - } - - public DirectThreadBroadcastResponsePayload getPayload() { - return payload; - } - - public List getMessageMetadata() { - return messageMetadata; - } - - public String getStatus() { - return status; - } - - @NonNull - @Override - public String toString() { - return "DirectThreadBroadcastResponse{" + - "action='" + action + '\'' + - ", statusCode='" + statusCode + '\'' + - ", payload=" + payload + - ", messageMetadata=" + messageMetadata + - ", status='" + status + '\'' + - '}'; - } -} +data class DirectThreadBroadcastResponse( + val action: String? = null, + val statusCode: String? = null, + val payload: DirectThreadBroadcastResponsePayload? = null, + val messageMetadata: List? = null, + val status: String? = null +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt index 1025aab3..720ab2de 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponseMessageMetadata.kt @@ -1,55 +1,9 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.util.List; - -public class DirectThreadBroadcastResponseMessageMetadata { - private final String clientContext; - private final String itemId; - private final long timestamp; - private final String threadId; - private final List participantIds; - - - public DirectThreadBroadcastResponseMessageMetadata(final String clientContext, - final String itemId, - final long timestamp, - final String threadId, - final List participantIds) { - this.clientContext = clientContext; - this.itemId = itemId; - this.timestamp = timestamp; - this.threadId = threadId; - this.participantIds = participantIds; - } - - public String getClientContext() { - return clientContext; - } - - public String getItemId() { - return itemId; - } - - public long getTimestamp() { - return timestamp; - } - - public String getThreadId() { - return threadId; - } - - public List getParticipantIds() { - return participantIds; - } - - @Override - public String toString() { - return "DirectThreadBroadcastResponseMessageMetadata{" + - "clientContext='" + clientContext + '\'' + - ", itemId='" + itemId + '\'' + - ", timestamp=" + timestamp + - ", threadId='" + threadId + '\'' + - ", participantIds=" + participantIds + - '}'; - } -} +data class DirectThreadBroadcastResponseMessageMetadata( + val clientContext: String? = null, + val itemId: String? = null, + val timestamp: Long = 0, + val threadId: String? = null, + val participantIds: List? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt index 35b160a2..ca4655f9 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadBroadcastResponsePayload.kt @@ -1,44 +1,8 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -public class DirectThreadBroadcastResponsePayload { - private final String clientContext; - private final String itemId; - private final long timestamp; - private final String threadId; - - public DirectThreadBroadcastResponsePayload(final String clientContext, - final String itemId, - final long timestamp, - final String threadId) { - this.clientContext = clientContext; - this.itemId = itemId; - this.timestamp = timestamp; - this.threadId = threadId; - } - - public String getClientContext() { - return clientContext; - } - - public String getItemId() { - return itemId; - } - - public long getTimestamp() { - return timestamp; - } - - public String getThreadId() { - return threadId; - } - - @Override - public String toString() { - return "DirectThreadBroadcastResponsePayload{" + - "clientContext='" + clientContext + '\'' + - ", itemId='" + itemId + '\'' + - ", timestamp=" + timestamp + - ", threadId='" + threadId + '\'' + - '}'; - } -} +data class DirectThreadBroadcastResponsePayload( + val clientContext: String? = null, + val itemId: String? = null, + val timestamp: Long = 0, + val threadId: String? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt index 0101aa50..19f7451e 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadFeedResponse.kt @@ -1,19 +1,6 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -public class DirectThreadFeedResponse { - private final DirectThread thread; - private final String status; - - public DirectThreadFeedResponse(final DirectThread thread, final String status) { - this.thread = thread; - this.status = status; - } - - public DirectThread getThread() { - return thread; - } - - public String getStatus() { - return status; - } -} +data class DirectThreadFeedResponse( + val thread: DirectThread? = null, + val status: String? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt index 83eda360..14547b40 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.kt @@ -1,36 +1,8 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectThreadLastSeenAt implements Serializable { - private final String timestamp; - private final String itemId; - - public DirectThreadLastSeenAt(final String timestamp, final String itemId) { - this.timestamp = timestamp; - this.itemId = itemId; - } - - public String getTimestamp() { - return timestamp; - } - - public String getItemId() { - return itemId; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectThreadLastSeenAt that = (DirectThreadLastSeenAt) o; - return Objects.equals(timestamp, that.timestamp) && - Objects.equals(itemId, that.itemId); - } - - @Override - public int hashCode() { - return Objects.hash(timestamp, itemId); - } -} +data class DirectThreadLastSeenAt( + val timestamp: String? = null, + val itemId: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/TextRange.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/TextRange.kt new file mode 100644 index 00000000..2cea10bc --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/TextRange.kt @@ -0,0 +1,10 @@ +package awais.instagrabber.repositories.responses.directmessages + +import java.io.Serializable + +data class TextRange( + val start: Int = 0, + val end: Int = 0, + val color: String? = null, + val intent: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt index c44c0e29..60369140 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/ThreadContext.kt @@ -1,36 +1,8 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class ThreadContext implements Serializable { - private final int type; - private final String text; - - public ThreadContext(final int type, final String text) { - this.type = type; - this.text = text; - } - - public int getType() { - return type; - } - - public String getText() { - return text; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final ThreadContext that = (ThreadContext) o; - return type == that.type && - Objects.equals(text, that.text); - } - - @Override - public int hashCode() { - return Objects.hash(type, text); - } -} +data class ThreadContext( + val type: Int = 0, + val text: String? = null, +) : Serializable \ No newline at end of file From ebe6a176f1ef24b0ec5c10fe37bccbed9190528d Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 01:58:37 +0900 Subject: [PATCH 09/15] Rename .java to .kt --- .../directmessages/{DirectItemClip.java => DirectItemClip.kt} | 0 .../{DirectItemFelixShare.java => DirectItemFelixShare.kt} | 0 .../{DirectItemReelShare.java => DirectItemReelShare.kt} | 0 ...lShareReactionInfo.java => DirectItemReelShareReactionInfo.kt} | 0 .../{DirectItemStoryShare.java => DirectItemStoryShare.kt} | 0 .../{DirectItemVisualMedia.java => DirectItemVisualMedia.kt} | 0 .../directmessages/{DirectThread.java => DirectThread.kt} | 0 ...lsChangeResponse.java => DirectThreadDetailsChangeResponse.kt} | 0 .../{DirectThreadDirectStory.java => DirectThreadDirectStory.kt} | 0 ...tsResponse.java => DirectThreadParticipantRequestsResponse.kt} | 0 .../directmessages/{RankedRecipient.java => RankedRecipient.kt} | 0 ...{RankedRecipientsResponse.java => RankedRecipientsResponse.kt} | 0 ...MediaActionSummary.java => RavenExpiringMediaActionSummary.kt} | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemClip.java => DirectItemClip.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemFelixShare.java => DirectItemFelixShare.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemReelShare.java => DirectItemReelShare.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemReelShareReactionInfo.java => DirectItemReelShareReactionInfo.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemStoryShare.java => DirectItemStoryShare.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectItemVisualMedia.java => DirectItemVisualMedia.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThread.java => DirectThread.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadDetailsChangeResponse.java => DirectThreadDetailsChangeResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadDirectStory.java => DirectThreadDirectStory.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{DirectThreadParticipantRequestsResponse.java => DirectThreadParticipantRequestsResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{RankedRecipient.java => RankedRecipient.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{RankedRecipientsResponse.java => RankedRecipientsResponse.kt} (100%) rename app/src/main/java/awais/instagrabber/repositories/responses/directmessages/{RavenExpiringMediaActionSummary.java => RavenExpiringMediaActionSummary.kt} (100%) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java rename to app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt From 841c3bdbda6482d0e7cf668c304f602fe775f966 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 01:58:37 +0900 Subject: [PATCH 10/15] Convert to kotlin --- .../instagrabber/managers/ThreadManager.java | 10 +- .../directmessages/DirectItemClip.kt | 33 +- .../directmessages/DirectItemFelixShare.kt | 33 +- .../directmessages/DirectItemReelShare.kt | 98 +---- .../DirectItemReelShareReactionInfo.kt | 40 +- .../directmessages/DirectItemStoryShare.kt | 89 +--- .../directmessages/DirectItemVisualMedia.kt | 102 +---- .../responses/directmessages/DirectThread.kt | 413 ++---------------- .../DirectThreadDetailsChangeResponse.kt | 23 +- .../directmessages/DirectThreadDirectStory.kt | 41 +- ...DirectThreadParticipantRequestsResponse.kt | 82 +--- .../directmessages/RankedRecipient.kt | 59 +-- .../RankedRecipientsResponse.kt | 58 +-- .../RavenExpiringMediaActionSummary.kt | 92 ++-- .../instagrabber/services/DMSyncService.java | 2 +- .../awais/instagrabber/utils/DMUtils.java | 3 +- .../viewmodels/DirectSettingsViewModel.java | 2 +- .../webservices/DiscoverService.java | 4 +- 18 files changed, 193 insertions(+), 991 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index b479b427..df3b9ff8 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -195,7 +195,7 @@ public final class ThreadManager { .orElse(null); if (thread != null) { cursor = thread.getOldestCursor(); - hasOlder = thread.hasOlder(); + hasOlder = thread.getHasOlder(); } return thread; })); @@ -229,7 +229,7 @@ public final class ThreadManager { })); pending = distinctUntilChanged(map(thread, t -> { if (t == null) return true; - return t.isPending(); + return t.getPending(); })); adminUserIds = distinctUntilChanged(map(thread, t -> { if (t == null) return Collections.emptyList(); @@ -249,15 +249,15 @@ public final class ThreadManager { })); isMuted = distinctUntilChanged(map(thread, t -> { if (t == null) return false; - return t.isMuted(); + return t.getMuted(); })); isApprovalRequiredToJoin = distinctUntilChanged(map(thread, t -> { if (t == null) return false; - return t.isApprovalRequiredForNewMembers(); + return t.getApprovalRequiredForNewMembers(); })); isMentionsMuted = distinctUntilChanged(map(thread, t -> { if (t == null) return false; - return t.isMentionsMuted(); + return t.getMentionsMuted(); })); pendingRequestsCount = distinctUntilChanged(map(pendingRequests, p -> { if (p == null) return 0; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt index 0568220d..a1419699 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.kt @@ -1,31 +1,6 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemClip implements Serializable { - private final Media clip; - - public DirectItemClip(final Media clip) { - this.clip = clip; - } - - public Media getClip() { - return clip; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemClip that = (DirectItemClip) o; - return Objects.equals(clip, that.clip); - } - - @Override - public int hashCode() { - return Objects.hash(clip); - } -} +data class DirectItemClip(val clip: Media? = null) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt index f230027c..83029a15 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.kt @@ -1,31 +1,6 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemFelixShare implements Serializable { - private final Media video; - - public DirectItemFelixShare(final Media video) { - this.video = video; - } - - public Media getVideo() { - return video; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemFelixShare that = (DirectItemFelixShare) o; - return Objects.equals(video, that.video); - } - - @Override - public int hashCode() { - return Objects.hash(video); - } -} +data class DirectItemFelixShare(val video: Media? = null) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt index 1e434dc4..4bba98b1 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.kt @@ -1,87 +1,15 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemReelShare implements Serializable { - private final String text; - private final String type; - private final long reelOwnerId; - private final long mentionedUserId; - private final boolean isReelPersisted; - private final String reelType; - private final Media media; - private final DirectItemReelShareReactionInfo reactionInfo; - - public DirectItemReelShare(final String text, - final String type, - final long reelOwnerId, - final long mentionedUserId, - final boolean isReelPersisted, - final String reelType, - final Media media, - final DirectItemReelShareReactionInfo reactionInfo) { - this.text = text; - this.type = type; - this.reelOwnerId = reelOwnerId; - this.mentionedUserId = mentionedUserId; - this.isReelPersisted = isReelPersisted; - this.reelType = reelType; - this.media = media; - this.reactionInfo = reactionInfo; - } - - public String getText() { - return text; - } - - public String getType() { - return type; - } - - public long getReelOwnerId() { - return reelOwnerId; - } - - public boolean isReelPersisted() { - return isReelPersisted; - } - - public String getReelType() { - return reelType; - } - - public Media getMedia() { - return media; - } - - public DirectItemReelShareReactionInfo getReactionInfo() { - return reactionInfo; - } - - public long getMentionedUserId() { - return mentionedUserId; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemReelShare that = (DirectItemReelShare) o; - return reelOwnerId == that.reelOwnerId && - mentionedUserId == that.mentionedUserId && - isReelPersisted == that.isReelPersisted && - Objects.equals(text, that.text) && - Objects.equals(type, that.type) && - Objects.equals(reelType, that.reelType) && - Objects.equals(media, that.media) && - Objects.equals(reactionInfo, that.reactionInfo); - } - - @Override - public int hashCode() { - return Objects.hash(text, type, reelOwnerId, mentionedUserId, isReelPersisted, reelType, media, reactionInfo); - } -} +data class DirectItemReelShare( + val text: String? = null, + val type: String? = null, + val reelOwnerId: Long = 0, + val mentionedUserId: Long = 0, + val isReelPersisted: Boolean = false, + val reelType: String? = null, + val media: Media? = null, + val reactionInfo: DirectItemReelShareReactionInfo? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt index e515ca2e..8d0aed9c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.kt @@ -1,36 +1,8 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import java.io.Serializable -public class DirectItemReelShareReactionInfo implements Serializable { - private final String emoji; - private final String intensity; - - public DirectItemReelShareReactionInfo(final String emoji, final String intensity) { - this.emoji = emoji; - this.intensity = intensity; - } - - public String getEmoji() { - return emoji; - } - - public String getIntensity() { - return intensity; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemReelShareReactionInfo that = (DirectItemReelShareReactionInfo) o; - return Objects.equals(emoji, that.emoji) && - Objects.equals(intensity, that.intensity); - } - - @Override - public int hashCode() { - return Objects.hash(emoji, intensity); - } -} +data class DirectItemReelShareReactionInfo( + val emoji: String? = null, + val intensity: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt index 0e618b85..c5e669bb 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.kt @@ -1,79 +1,14 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemStoryShare implements Serializable { - private final String reelId; - private final String reelType; - private final String text; - private final boolean isReelPersisted; - private final Media media; - private final String title; - private final String message; - - public DirectItemStoryShare(final String reelId, - final String reelType, - final String text, - final boolean isReelPersisted, - final Media media, - final String title, - final String message) { - this.reelId = reelId; - this.reelType = reelType; - this.text = text; - this.isReelPersisted = isReelPersisted; - this.media = media; - this.title = title; - this.message = message; - } - - public String getReelId() { - return reelId; - } - - public String getReelType() { - return reelType; - } - - public String getText() { - return text; - } - - public boolean isReelPersisted() { - return isReelPersisted; - } - - public Media getMedia() { - return media; - } - - public String getTitle() { - return title; - } - - public String getMessage() { - return message; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemStoryShare that = (DirectItemStoryShare) o; - return isReelPersisted == that.isReelPersisted && - Objects.equals(reelId, that.reelId) && - Objects.equals(reelType, that.reelType) && - Objects.equals(text, that.text) && - Objects.equals(media, that.media) && - Objects.equals(title, that.title) && - Objects.equals(message, that.message); - } - - @Override - public int hashCode() { - return Objects.hash(reelId, reelType, text, isReelPersisted, media, title, message); - } -} +data class DirectItemStoryShare( + val reelId: String? = null, + val reelType: String? = null, + val text: String? = null, + val isReelPersisted: Boolean = false, + val media: Media? = null, + val title: String? = null, + val message: String? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt index 2e6bf7e7..5534e1bf 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.kt @@ -1,90 +1,16 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.List; -import java.util.Objects; +import awais.instagrabber.models.enums.RavenMediaViewMode +import awais.instagrabber.repositories.responses.Media +import java.io.Serializable -import awais.instagrabber.models.enums.RavenMediaViewMode; -import awais.instagrabber.repositories.responses.Media; - -public class DirectItemVisualMedia implements Serializable { - private final long urlExpireAtSecs; - private final int playbackDurationSecs; - private final List seenUserIds; - private final RavenMediaViewMode viewMode; - private final int seenCount; - private final long replayExpiringAtUs; - private final RavenExpiringMediaActionSummary expiringMediaActionSummary; - private final Media media; - - public DirectItemVisualMedia(final long urlExpireAtSecs, - final int playbackDurationSecs, - final List seenUserIds, - final RavenMediaViewMode viewMode, - final int seenCount, - final long replayExpiringAtUs, - final RavenExpiringMediaActionSummary expiringMediaActionSummary, - final Media media) { - this.urlExpireAtSecs = urlExpireAtSecs; - this.playbackDurationSecs = playbackDurationSecs; - this.seenUserIds = seenUserIds; - this.viewMode = viewMode; - this.seenCount = seenCount; - this.replayExpiringAtUs = replayExpiringAtUs; - this.expiringMediaActionSummary = expiringMediaActionSummary; - this.media = media; - } - - public long getUrlExpireAtSecs() { - return urlExpireAtSecs; - } - - public int getPlaybackDurationSecs() { - return playbackDurationSecs; - } - - public List getSeenUserIds() { - return seenUserIds; - } - - public RavenMediaViewMode getViewMode() { - return viewMode; - } - - public int getSeenCount() { - return seenCount; - } - - public long getReplayExpiringAtUs() { - return replayExpiringAtUs; - } - - public RavenExpiringMediaActionSummary getExpiringMediaActionSummary() { - return expiringMediaActionSummary; - } - - public Media getMedia() { - return media; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectItemVisualMedia media1 = (DirectItemVisualMedia) o; - return urlExpireAtSecs == media1.urlExpireAtSecs && - playbackDurationSecs == media1.playbackDurationSecs && - seenCount == media1.seenCount && - replayExpiringAtUs == media1.replayExpiringAtUs && - Objects.equals(seenUserIds, media1.seenUserIds) && - viewMode == media1.viewMode && - Objects.equals(expiringMediaActionSummary, media1.expiringMediaActionSummary) && - Objects.equals(media, media1.media); - } - - @Override - public int hashCode() { - return Objects - .hash(urlExpireAtSecs, playbackDurationSecs, seenUserIds, viewMode, seenCount, replayExpiringAtUs, expiringMediaActionSummary, media); - } -} +data class DirectItemVisualMedia( + val urlExpireAtSecs: Long = 0, + val playbackDurationSecs: Int = 0, + val seenUserIds: List? = null, + val viewMode: RavenMediaViewMode? = null, + val seenCount: Int = 0, + val replayExpiringAtUs: Long = 0, + val expiringMediaActionSummary: RavenExpiringMediaActionSummary? = null, + val media: Media? = null, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt index 1f6ffd66..65094c70 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThread.kt @@ -1,372 +1,49 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; +import awais.instagrabber.repositories.responses.User +import java.io.Serializable -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import java.util.Objects; +data class DirectThread( + val threadId: String? = null, + val threadV2Id: String? = null, + var users: List? = null, + var leftUsers: List? = null, + var adminUserIds: List? = null, + var items: List? = null, + val lastActivityAt: Long = 0, + var muted: Boolean = false, + val isPin: Boolean = false, + val named: Boolean = false, + val canonical: Boolean = false, + var pending: Boolean = false, + val archived: Boolean = false, + val valuedRequest: Boolean = false, + val threadType: String? = null, + val viewerId: Long = 0, + val threadTitle: String? = null, + val pendingScore: String? = null, + val folder: Long = 0, + val vcMuted: Boolean = false, + val isGroup: Boolean = false, + var mentionsMuted: Boolean = false, + val inviter: User? = null, + val hasOlder: Boolean = false, + val hasNewer: Boolean = false, + var lastSeenAt: Map? = null, + val newestCursor: String? = null, + val oldestCursor: String? = null, + val isSpam: Boolean = false, + val lastPermanentItem: DirectItem? = null, + val directStory: DirectThreadDirectStory? = null, + var approvalRequiredForNewMembers: Boolean = false, + var inputMode: Int = 0, + val threadContextItems: List? = null +) : Serializable, Cloneable { + var isTemp = false -import awais.instagrabber.repositories.responses.User; + val firstDirectItem: DirectItem? + get() = items?.firstNotNullOfOrNull { it } -public class DirectThread implements Serializable, Cloneable { - private final String threadId; - private final String threadV2Id; - private List users; - private List leftUsers; - private List adminUserIds; - private List items; - private final long lastActivityAt; - private boolean muted; - private final boolean isPin; - private final boolean named; - private final boolean canonical; - private boolean pending; - private final boolean archived; - private final boolean valuedRequest; - private final String threadType; - private final long viewerId; - private final String threadTitle; - private final String pendingScore; - private final long folder; - private final boolean vcMuted; - private final boolean isGroup; - private boolean mentionsMuted; - private final User inviter; - private final boolean hasOlder; - private final boolean hasNewer; - private Map lastSeenAt; - private final String newestCursor; - private final String oldestCursor; - private final boolean isSpam; - private final DirectItem lastPermanentItem; - private final DirectThreadDirectStory directStory; - private boolean approvalRequiredForNewMembers; - private int inputMode; - private final List threadContextItems; - private boolean isTemp; - - public DirectThread(final String threadId, - final String threadV2Id, - final List users, - final List leftUsers, - final List adminUserIds, - final List items, - final long lastActivityAt, - final boolean muted, - final boolean isPin, - final boolean named, - final boolean canonical, - final boolean pending, - final boolean archived, - final boolean valuedRequest, - final String threadType, - final long viewerId, - final String threadTitle, - final String pendingScore, - final long folder, - final boolean vcMuted, - final boolean isGroup, - final boolean mentionsMuted, - final User inviter, - final boolean hasOlder, - final boolean hasNewer, - final Map lastSeenAt, - final String newestCursor, - final String oldestCursor, - final boolean isSpam, - final DirectItem lastPermanentItem, - final DirectThreadDirectStory directStory, - final boolean approvalRequiredForNewMembers, - final int inputMode, - final List threadContextItems) { - this.threadId = threadId; - this.threadV2Id = threadV2Id; - this.users = users; - this.leftUsers = leftUsers; - this.adminUserIds = adminUserIds; - this.items = items; - this.lastActivityAt = lastActivityAt; - this.muted = muted; - this.isPin = isPin; - this.named = named; - this.canonical = canonical; - this.pending = pending; - this.archived = archived; - this.valuedRequest = valuedRequest; - this.threadType = threadType; - this.viewerId = viewerId; - this.threadTitle = threadTitle; - this.pendingScore = pendingScore; - this.folder = folder; - this.vcMuted = vcMuted; - this.isGroup = isGroup; - this.mentionsMuted = mentionsMuted; - this.inviter = inviter; - this.hasOlder = hasOlder; - this.hasNewer = hasNewer; - this.lastSeenAt = lastSeenAt; - this.newestCursor = newestCursor; - this.oldestCursor = oldestCursor; - this.isSpam = isSpam; - this.lastPermanentItem = lastPermanentItem; - this.directStory = directStory; - this.approvalRequiredForNewMembers = approvalRequiredForNewMembers; - this.inputMode = inputMode; - this.threadContextItems = threadContextItems; - } - - public String getThreadId() { - return threadId; - } - - public String getThreadV2Id() { - return threadV2Id; - } - - public List getUsers() { - return users; - } - - public void setUsers(final List users) { - this.users = users; - } - - public List getLeftUsers() { - return leftUsers; - } - - public void setLeftUsers(final List leftUsers) { - this.leftUsers = leftUsers; - } - - public List getAdminUserIds() { - return adminUserIds; - } - - public void setAdminUserIds(final List adminUserIds) { - this.adminUserIds = adminUserIds; - } - - public List getItems() { - return items; - } - - public void setItems(final List items) { - this.items = items; - } - - public long getLastActivityAt() { - return lastActivityAt; - } - - public boolean isMuted() { - return muted; - } - - public void setMuted(final boolean muted) { - this.muted = muted; - } - - public boolean isPin() { - return isPin; - } - - public boolean isNamed() { - return named; - } - - public boolean isCanonical() { - return canonical; - } - - public boolean isPending() { - return pending; - } - - public void setPending(final boolean pending) { - this.pending = pending; - } - - public boolean isArchived() { - return archived; - } - - public boolean isValuedRequest() { - return valuedRequest; - } - - public String getThreadType() { - return threadType; - } - - public long getViewerId() { - return viewerId; - } - - public String getThreadTitle() { - return threadTitle; - } - - public String getPendingScore() { - return pendingScore; - } - - public long getFolder() { - return folder; - } - - public boolean isVcMuted() { - return vcMuted; - } - - public boolean isGroup() { - return isGroup; - } - - public boolean isMentionsMuted() { - return mentionsMuted; - } - - public void setMentionsMuted(final boolean mentionsMuted) { - this.mentionsMuted = mentionsMuted; - } - - public User getInviter() { - return inviter; - } - - public boolean hasOlder() { - return hasOlder; - } - - public boolean hasNewer() { - return hasNewer; - } - - public Map getLastSeenAt() { - return lastSeenAt; - } - - public void setLastSeenAt(final Map lastSeenAt) { - this.lastSeenAt = lastSeenAt; - } - - public String getNewestCursor() { - return newestCursor; - } - - public String getOldestCursor() { - return oldestCursor; - } - - public boolean isSpam() { - return isSpam; - } - - public DirectItem getLastPermanentItem() { - return lastPermanentItem; - } - - public DirectThreadDirectStory getDirectStory() { - return directStory; - } - - public boolean isApprovalRequiredForNewMembers() { - return approvalRequiredForNewMembers; - } - - public void setApprovalRequiredForNewMembers(final boolean approvalRequiredForNewMembers) { - this.approvalRequiredForNewMembers = approvalRequiredForNewMembers; - } - - public int getInputMode() { - return inputMode; - } - - public void setInputMode(final int inputMode) { - this.inputMode = inputMode; - } - - public List getThreadContextItems() { - return threadContextItems; - } - - public boolean isTemp() { - return isTemp; - } - - public void setTemp(final boolean isTemp) { - this.isTemp = isTemp; - } - - @Nullable - public DirectItem getFirstDirectItem() { - DirectItem firstItem = null; - if (!items.isEmpty()) { - int position = 0; - while (firstItem == null && position < items.size()) { - firstItem = items.get(position); - position++; - } - } - return firstItem; - } - - @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 DirectThread that = (DirectThread) o; - return lastActivityAt == that.lastActivityAt && - muted == that.muted && - isPin == that.isPin && - named == that.named && - canonical == that.canonical && - pending == that.pending && - archived == that.archived && - valuedRequest == that.valuedRequest && - viewerId == that.viewerId && - folder == that.folder && - vcMuted == that.vcMuted && - isGroup == that.isGroup && - mentionsMuted == that.mentionsMuted && - hasOlder == that.hasOlder && - hasNewer == that.hasNewer && - isSpam == that.isSpam && - approvalRequiredForNewMembers == that.approvalRequiredForNewMembers && - inputMode == that.inputMode && - Objects.equals(threadId, that.threadId) && - Objects.equals(threadV2Id, that.threadV2Id) && - Objects.equals(users, that.users) && - Objects.equals(leftUsers, that.leftUsers) && - Objects.equals(adminUserIds, that.adminUserIds) && - Objects.equals(items, that.items) && - Objects.equals(threadType, that.threadType) && - Objects.equals(threadTitle, that.threadTitle) && - Objects.equals(pendingScore, that.pendingScore) && - Objects.equals(inviter, that.inviter) && - Objects.equals(lastSeenAt, that.lastSeenAt) && - Objects.equals(newestCursor, that.newestCursor) && - Objects.equals(oldestCursor, that.oldestCursor) && - Objects.equals(lastPermanentItem, that.lastPermanentItem) && - Objects.equals(directStory, that.directStory) && - Objects.equals(threadContextItems, that.threadContextItems); - } - - @Override - public int hashCode() { - return Objects - .hash(threadId, threadV2Id, users, leftUsers, adminUserIds, items, lastActivityAt, muted, isPin, named, canonical, pending, archived, - valuedRequest, threadType, viewerId, threadTitle, pendingScore, folder, vcMuted, isGroup, mentionsMuted, inviter, hasOlder, - hasNewer, lastSeenAt, newestCursor, oldestCursor, isSpam, lastPermanentItem, directStory, approvalRequiredForNewMembers, - inputMode, threadContextItems); - } -} + @Throws(CloneNotSupportedException::class) + public override fun clone(): Any = super.clone() +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt index 416fc284..9bc25fde 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDetailsChangeResponse.kt @@ -1,19 +1,6 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -public class DirectThreadDetailsChangeResponse { - private final DirectThread thread; - private final String status; - - public DirectThreadDetailsChangeResponse(final DirectThread thread, final String status) { - this.thread = thread; - this.status = status; - } - - public DirectThread getThread() { - return thread; - } - - public String getStatus() { - return status; - } -} +data class DirectThreadDetailsChangeResponse( + val thread: DirectThread? = null, + val status: String? = null +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt index 8f1db622..47d0bd0d 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.kt @@ -1,37 +1,8 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.List; -import java.util.Objects; +import java.io.Serializable -public class DirectThreadDirectStory implements Serializable { - private final List items; - private final int unseenCount; - - public DirectThreadDirectStory(final List items, final int unseenCount) { - this.items = items; - this.unseenCount = unseenCount; - } - - public List getItems() { - return items; - } - - public int getUnseenCount() { - return unseenCount; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final DirectThreadDirectStory that = (DirectThreadDirectStory) o; - return unseenCount == that.unseenCount && - Objects.equals(items, that.items); - } - - @Override - public int hashCode() { - return Objects.hash(items, unseenCount); - } -} +data class DirectThreadDirectStory( + val items: List? = null, + val unseenCount: Int = 0, +) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt index d02bae90..0afac9d7 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadParticipantRequestsResponse.kt @@ -1,70 +1,16 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import androidx.annotation.NonNull; +import awais.instagrabber.repositories.responses.User +import java.io.Serializable -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import awais.instagrabber.repositories.responses.User; - -public class DirectThreadParticipantRequestsResponse implements Serializable, Cloneable { - private List users; - private final Map requesterUsernames; - private final String cursor; - private final int totalThreadParticipants; - private int totalParticipantRequests; - private final String status; - - public DirectThreadParticipantRequestsResponse(final List users, - final Map requesterUsernames, - final String cursor, - final int totalThreadParticipants, - final int totalParticipantRequests, - final String status) { - this.users = users; - this.requesterUsernames = requesterUsernames; - this.cursor = cursor; - this.totalThreadParticipants = totalThreadParticipants; - this.totalParticipantRequests = totalParticipantRequests; - this.status = status; - } - - public List getUsers() { - return users; - } - - public void setUsers(final List users) { - this.users = users; - } - - public Map getRequesterUsernames() { - return requesterUsernames; - } - - public String getCursor() { - return cursor; - } - - public int getTotalThreadParticipants() { - return totalThreadParticipants; - } - - public int getTotalParticipantRequests() { - return totalParticipantRequests; - } - - public void setTotalParticipantRequests(final int totalParticipantRequests) { - this.totalParticipantRequests = totalParticipantRequests; - } - - public String getStatus() { - return status; - } - - @NonNull - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } -} +data class DirectThreadParticipantRequestsResponse( + var users: List? = null, + val requesterUsernames: Map? = null, + val cursor: String? = null, + val totalThreadParticipants: Int = 0, + var totalParticipantRequests: Int = 0, + val status: String? = null, +) : Serializable, Cloneable { + @Throws(CloneNotSupportedException::class) + public override fun clone(): Any = super.clone() +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt index cd36639f..a01ba31a 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipient.kt @@ -1,46 +1,21 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.io.Serializable; -import java.util.Objects; +import awais.instagrabber.repositories.responses.User +import java.io.Serializable -import awais.instagrabber.repositories.responses.User; +data class RankedRecipient( + val user: User? = null, + val thread: DirectThread? = null, +) : Serializable { + companion object { + @JvmStatic + fun of(user: User): RankedRecipient { + return RankedRecipient(user = user) + } -public class RankedRecipient implements Serializable { - private final User user; - private final DirectThread thread; - - public RankedRecipient(final User user, final DirectThread thread) { - this.user = user; - this.thread = thread; + @JvmStatic + fun of(thread: DirectThread): RankedRecipient { + return RankedRecipient(thread = thread) + } } - - public User getUser() { - return user; - } - - public DirectThread getThread() { - return thread; - } - - public static RankedRecipient of(final User user) { - return new RankedRecipient(user, null); - } - - public static RankedRecipient of(final DirectThread thread) { - return new RankedRecipient(null, thread); - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final RankedRecipient that = (RankedRecipient) o; - return Objects.equals(user, that.user) && - Objects.equals(thread, that.thread); - } - - @Override - public int hashCode() { - return Objects.hash(user, thread); - } -} +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt index 2c0b2885..c65d8bc3 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RankedRecipientsResponse.kt @@ -1,50 +1,10 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import java.util.List; - -public class RankedRecipientsResponse { - private final List rankedRecipients; - private final long expires; - private final boolean filtered; - private final String requestId; - private final String rankToken; - private final String status; - - public RankedRecipientsResponse(final List rankedRecipients, - final long expires, - final boolean filtered, - final String requestId, - final String rankToken, - final String status) { - this.rankedRecipients = rankedRecipients; - this.expires = expires; - this.filtered = filtered; - this.requestId = requestId; - this.rankToken = rankToken; - this.status = status; - } - - public List getRankedRecipients() { - return rankedRecipients; - } - - public long getExpires() { - return expires; - } - - public boolean isFiltered() { - return filtered; - } - - public String getRequestId() { - return requestId; - } - - public String getRankToken() { - return rankToken; - } - - public String getStatus() { - return status; - } -} +data class RankedRecipientsResponse( + val rankedRecipients: List? = null, + val expires: Long = 0, + val filtered: Boolean = false, + val requestId: String? = null, + val rankToken: String? = null, + val status: String? = null, +) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt index da60b4bf..c5c332d6 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.kt @@ -1,69 +1,43 @@ -package awais.instagrabber.repositories.responses.directmessages; +package awais.instagrabber.repositories.responses.directmessages -import com.google.gson.annotations.SerializedName; +import com.google.gson.annotations.SerializedName +import java.io.Serializable -import java.io.Serializable; -import java.util.Objects; +data class RavenExpiringMediaActionSummary( + val timestamp: Long = 0, + val count: Int = 0, + val type: ActionType? = null, +) : Serializable -public final class RavenExpiringMediaActionSummary implements Serializable { - private final ActionType type; - private final long timestamp; - private final int count; +// thanks to http://github.com/warifp/InstagramAutoPostImageUrl/blob/master/vendor/mgp25/instagram-php/src/Response/Model/ActionBadge.php +enum class ActionType { + @SerializedName("raven_delivered") + DELIVERED, - public RavenExpiringMediaActionSummary(final long timestamp, final int count, final ActionType type) { - this.timestamp = timestamp; - this.count = count; - this.type = type; - } + @SerializedName("raven_sent") + SENT, - public long getTimestamp() { - return timestamp; - } + @SerializedName("raven_opened") + OPENED, - public int getCount() { - return count; - } + @SerializedName("raven_screenshot") + SCREENSHOT, - public ActionType getType() { - return type; - } + @SerializedName("raven_replayed") + REPLAYED, - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final RavenExpiringMediaActionSummary that = (RavenExpiringMediaActionSummary) o; - return timestamp == that.timestamp && - count == that.count && - type == that.type; - } + @SerializedName("raven_cannot_deliver") + CANNOT_DELIVER, - @Override - public int hashCode() { - return Objects.hash(type, timestamp, count); - } + @SerializedName("raven_sending") + SENDING, - // thanks to http://github.com/warifp/InstagramAutoPostImageUrl/blob/master/vendor/mgp25/instagram-php/src/Response/Model/ActionBadge.php - public enum ActionType { - @SerializedName("raven_delivered") - DELIVERED, - @SerializedName("raven_sent") - SENT, - @SerializedName("raven_opened") - OPENED, - @SerializedName("raven_screenshot") - SCREENSHOT, - @SerializedName("raven_replayed") - REPLAYED, - @SerializedName("raven_cannot_deliver") - CANNOT_DELIVER, - @SerializedName("raven_sending") - SENDING, - @SerializedName("raven_blocked") - BLOCKED, - @SerializedName("raven_unknown") - UNKNOWN, - @SerializedName("raven_suggested") - SUGGESTED, - } -} + @SerializedName("raven_blocked") + BLOCKED, + + @SerializedName("raven_unknown") + UNKNOWN, + + @SerializedName("raven_suggested") + SUGGESTED, +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/services/DMSyncService.java b/app/src/main/java/awais/instagrabber/services/DMSyncService.java index 63ae752a..a5df0cd5 100644 --- a/app/src/main/java/awais/instagrabber/services/DMSyncService.java +++ b/app/src/main/java/awais/instagrabber/services/DMSyncService.java @@ -91,7 +91,7 @@ public class DMSyncService extends LifecycleService { return; } for (final DirectThread thread : threads) { - if (thread.isMuted()) continue; + if (thread.getMuted()) continue; final boolean read = DMUtils.isRead(thread); if (read) continue; final List unreadMessages = getUnreadMessages(thread); diff --git a/app/src/main/java/awais/instagrabber/utils/DMUtils.java b/app/src/main/java/awais/instagrabber/utils/DMUtils.java index 44cab81b..f315c906 100644 --- a/app/src/main/java/awais/instagrabber/utils/DMUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DMUtils.java @@ -15,6 +15,7 @@ import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; +import awais.instagrabber.repositories.responses.directmessages.ActionType; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemAnimatedMedia; import awais.instagrabber.repositories.responses.directmessages.DirectItemReelShare; @@ -267,7 +268,7 @@ public final class DMUtils { final DirectItemVisualMedia visualMedia = item.getVisualMedia(); final RavenExpiringMediaActionSummary summary = visualMedia.getExpiringMediaActionSummary(); if (summary != null) { - final RavenExpiringMediaActionSummary.ActionType expiringMediaType = summary.getType(); + final ActionType expiringMediaType = summary.getType(); int textRes = 0; switch (expiringMediaType) { case DELIVERED: diff --git a/app/src/main/java/awais/instagrabber/viewmodels/DirectSettingsViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/DirectSettingsViewModel.java index bd918d7f..6f292bc2 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/DirectSettingsViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/DirectSettingsViewModel.java @@ -80,7 +80,7 @@ public class DirectSettingsViewModel extends AndroidViewModel { // final List adminUserIds = thread.getAdminUserIds(); // this.adminUserIds.postValue(adminUserIds); // viewerIsAdmin = adminUserIds.contains(viewerId); - // muted.postValue(thread.isMuted()); + // muted.postValue(thread.getMuted()); // mentionsMuted.postValue(thread.isMentionsMuted()); // approvalRequiredToJoin.postValue(thread.isApprovalRequiredForNewMembers()); // isPending.postValue(thread.isPending()); diff --git a/app/src/main/java/awais/instagrabber/webservices/DiscoverService.java b/app/src/main/java/awais/instagrabber/webservices/DiscoverService.java index 880ae526..6f00df93 100644 --- a/app/src/main/java/awais/instagrabber/webservices/DiscoverService.java +++ b/app/src/main/java/awais/instagrabber/webservices/DiscoverService.java @@ -107,7 +107,7 @@ public class DiscoverService extends BaseService { // } // final String type = clusterJson.optString("type"); // final boolean canMute = clusterJson.optBoolean("can_mute"); - // final boolean isMuted = clusterJson.optBoolean("is_muted"); + // final boolean getMuted = clusterJson.optBoolean("is_muted"); // final JSONObject coverMediaJson = clusterJson.optJSONObject("cover_media"); // final int rankedPosition = clusterJson.optInt("ranked_position"); // final FeedModel feedModel = parseClusterCover(coverMediaJson); @@ -116,7 +116,7 @@ public class DiscoverService extends BaseService { // title, // type, // canMute, - // isMuted, + // getMuted, // rankedPosition, // feedModel // ); From ce31554687b37aeca7a2a796187633b372455c59 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 02:08:46 +0900 Subject: [PATCH 11/15] Fix Caption de-serialization --- .../awais/instagrabber/repositories/responses/Caption.kt | 7 +++++-- .../repositories/serializers/CaptionDeserializer.java | 2 +- .../awais/instagrabber/viewmodels/PostViewV2ViewModel.java | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/Caption.kt b/app/src/main/java/awais/instagrabber/repositories/responses/Caption.kt index eebc6655..48be369c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/Caption.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/Caption.kt @@ -2,6 +2,9 @@ package awais.instagrabber.repositories.responses import java.io.Serializable -data class Caption(val userId: Long, var text: String?) : Serializable { - var pk: Long = 0 +data class Caption( + val userId: Long = 0, + var text: String? = null, +) : Serializable { + var pk: String? = null } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/serializers/CaptionDeserializer.java b/app/src/main/java/awais/instagrabber/repositories/serializers/CaptionDeserializer.java index 0bd796ab..9db0278d 100644 --- a/app/src/main/java/awais/instagrabber/repositories/serializers/CaptionDeserializer.java +++ b/app/src/main/java/awais/instagrabber/repositories/serializers/CaptionDeserializer.java @@ -30,7 +30,7 @@ public class CaptionDeserializer implements JsonDeserializer { pkString = pkString.substring(0, pkString.indexOf("_")); } try { - caption.setPk(Long.parseLong(pkString)); + caption.setPk(pkString); } catch (NumberFormatException e) { Log.e(TAG, "deserialize: ", e); } diff --git a/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.java index 653428b9..6b9466bc 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.java @@ -272,7 +272,7 @@ public class PostViewV2ViewModel extends ViewModel { data.postValue(Resource.loading(null)); final Caption value = caption.getValue(); if (value == null) return data; - mediaService.translate(String.valueOf(value.getPk()), "1", new ServiceCallback() { + mediaService.translate(value.getPk(), "1", new ServiceCallback() { @Override public void onSuccess(final String result) { if (TextUtils.isEmpty(result)) { From 7f21eed5cf90c3465557947bed059ac82d47da07 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 06:45:07 +0900 Subject: [PATCH 12/15] Rename .java to .kt --- .../fragments/{FavoritesFragment.java => FavoritesFragment.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/awais/instagrabber/fragments/{FavoritesFragment.java => FavoritesFragment.kt} (100%) diff --git a/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.java b/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.java rename to app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt From d284a1901ed8a21d43824dbdbde5a10c9fcde743 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 06:45:07 +0900 Subject: [PATCH 13/15] Convert FavoritesFragment to kotlin --- .../fragments/FavoritesFragment.kt | 233 ++++++++---------- 1 file changed, 104 insertions(+), 129 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt b/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt index a7804de0..3f7c5271 100644 --- a/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt @@ -1,159 +1,134 @@ -package awais.instagrabber.fragments; +package awais.instagrabber.fragments -import android.content.Context; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; +import android.content.DialogInterface +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import androidx.navigation.fragment.NavHostFragment +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import awais.instagrabber.R +import awais.instagrabber.adapters.FavoritesAdapter +import awais.instagrabber.databinding.FragmentFavoritesBinding +import awais.instagrabber.db.datasources.FavoriteDataSource +import awais.instagrabber.db.entities.Favorite +import awais.instagrabber.db.repositories.FavoriteRepository +import awais.instagrabber.db.repositories.RepositoryCallback +import awais.instagrabber.models.enums.FavoriteType +import awais.instagrabber.utils.extensions.TAG +import awais.instagrabber.viewmodels.FavoritesViewModel +import com.google.android.material.dialog.MaterialAlertDialogBuilder -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProvider; -import androidx.navigation.NavController; -import androidx.navigation.fragment.NavHostFragment; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; +class FavoritesFragment : Fragment() { + private var shouldRefresh = true -import com.google.android.material.dialog.MaterialAlertDialogBuilder; + private lateinit var binding: FragmentFavoritesBinding + private lateinit var root: RecyclerView + private lateinit var favoritesViewModel: FavoritesViewModel + private lateinit var favoriteRepository: FavoriteRepository + private lateinit var adapter: FavoritesAdapter -import java.util.List; - -import awais.instagrabber.R; -import awais.instagrabber.adapters.FavoritesAdapter; -import awais.instagrabber.databinding.FragmentFavoritesBinding; -import awais.instagrabber.db.datasources.FavoriteDataSource; -import awais.instagrabber.db.entities.Favorite; -import awais.instagrabber.db.repositories.FavoriteRepository; -import awais.instagrabber.db.repositories.RepositoryCallback; -import awais.instagrabber.viewmodels.FavoritesViewModel; - -public class FavoritesFragment extends Fragment { - private static final String TAG = "FavoritesFragment"; - - private boolean shouldRefresh = true; - private FragmentFavoritesBinding binding; - private RecyclerView root; - private FavoritesViewModel favoritesViewModel; - private FavoritesAdapter adapter; - private FavoriteRepository favoriteRepository; - - @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final Context context = getContext(); - if (context == null) return; - favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context)); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val context = context ?: return + favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context)) + favoritesViewModel = ViewModelProvider(this).get(FavoritesViewModel::class.java) } - @NonNull - @Override - public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - if (root != null) { - shouldRefresh = false; - return root; + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + if (this::root.isInitialized) { + shouldRefresh = false + return root } - binding = FragmentFavoritesBinding.inflate(getLayoutInflater()); - root = binding.getRoot(); - binding.favoriteList.setLayoutManager(new LinearLayoutManager(getContext())); - return root; + binding = FragmentFavoritesBinding.inflate(layoutInflater) + root = binding.root + binding.favoriteList.layoutManager = LinearLayoutManager(context) + return root } - @Override - public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { - if (!shouldRefresh) return; - init(); - shouldRefresh = false; + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + if (!shouldRefresh) return + init() + shouldRefresh = false } - @Override - public void onResume() { - super.onResume(); - if (favoritesViewModel == null || adapter == null) return; + override fun onResume() { + super.onResume() + if (!this::adapter.isInitialized) return // refresh list every time in onViewStateRestored since it is cheaper than implementing pull down to refresh - favoritesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); - favoriteRepository.getAllFavorites(new RepositoryCallback>() { - @Override - public void onSuccess(final List favorites) { - favoritesViewModel.getList().postValue(favorites); + favoritesViewModel.list.observe(viewLifecycleOwner, { list: List? -> adapter.submitList(list) }) + favoriteRepository.getAllFavorites(object : RepositoryCallback> { + override fun onSuccess(favorites: List) { + favoritesViewModel.list.postValue(favorites) } - @Override - public void onDataNotAvailable() {} - }); + override fun onDataNotAvailable() {} + }) } - private void init() { - favoritesViewModel = new ViewModelProvider(this).get(FavoritesViewModel.class); - adapter = new FavoritesAdapter(model -> { - // navigate - switch (model.getType()) { - case USER: { - final String username = model.getQuery(); + private fun init() { + adapter = FavoritesAdapter({ model: Favorite -> + when (model.type) { + FavoriteType.USER -> { + val username = model.query // Log.d(TAG, "username: " + username); - final NavController navController = NavHostFragment.findNavController(this); - final Bundle bundle = new Bundle(); - bundle.putString("username", "@" + username); - navController.navigate(R.id.action_global_profileFragment, bundle); - break; + val navController = NavHostFragment.findNavController(this) + val bundle = Bundle() + bundle.putString("username", "@$username") + navController.navigate(R.id.action_global_profileFragment, bundle) } - case LOCATION: { - final String locationId = model.getQuery(); + FavoriteType.LOCATION -> { + val locationId = model.query // Log.d(TAG, "locationId: " + locationId); - final NavController navController = NavHostFragment.findNavController(this); - final Bundle bundle = new Bundle(); + val navController = NavHostFragment.findNavController(this) + val bundle = Bundle() try { - bundle.putLong("locationId", Long.parseLong(locationId)); - navController.navigate(R.id.action_global_locationFragment, bundle); - } catch (Exception e) { - Log.e(TAG, "init: ", e); - return; + bundle.putLong("locationId", locationId.toLong()) + navController.navigate(R.id.action_global_locationFragment, bundle) + } catch (e: Exception) { + Log.e(TAG, "init: ", e) } - break; } - case HASHTAG: { - final String hashtag = model.getQuery(); + FavoriteType.HASHTAG -> { + val hashtag = model.query // Log.d(TAG, "hashtag: " + hashtag); - final NavController navController = NavHostFragment.findNavController(this); - final Bundle bundle = new Bundle(); - bundle.putString("hashtag", "#" + hashtag); - navController.navigate(R.id.action_global_hashTagFragment, bundle); - break; + val navController = NavHostFragment.findNavController(this) + val bundle = Bundle() + bundle.putString("hashtag", "#$hashtag") + navController.navigate(R.id.action_global_hashTagFragment, bundle) + } + else -> { } - default: - // do nothing } - }, model -> { + }, { model: Favorite -> // delete - final Context context = getContext(); - if (context == null) return false; - new MaterialAlertDialogBuilder(context) - .setMessage(getString(R.string.quick_access_confirm_delete, model.getQuery())) - .setPositiveButton(R.string.yes, (d, which) -> favoriteRepository - .deleteFavorite(model.getQuery(), model.getType(), new RepositoryCallback() { - @Override - public void onSuccess(final Void result) { - d.dismiss(); - favoriteRepository.getAllFavorites(new RepositoryCallback>() { - @Override - public void onSuccess(final List result) { - favoritesViewModel.getList().postValue(result); - } - - @Override - public void onDataNotAvailable() {} - }); + val context = context ?: return@FavoritesAdapter false + MaterialAlertDialogBuilder(context) + .setMessage(getString(R.string.quick_access_confirm_delete, model.query)) + .setPositiveButton(R.string.yes) { d: DialogInterface, _: Int -> + favoriteRepository.deleteFavorite(model.query, model.type, object : RepositoryCallback { + override fun onSuccess(result: Void) { + d.dismiss() + favoriteRepository.getAllFavorites(object : RepositoryCallback> { + override fun onSuccess(result: List) { + favoritesViewModel.list.postValue(result) } - @Override - public void onDataNotAvailable() {} - })) - .setNegativeButton(R.string.no, null) - .show(); - return true; - }); - binding.favoriteList.setAdapter(adapter); + override fun onDataNotAvailable() {} + }) + } + override fun onDataNotAvailable() {} + }) + } + .setNegativeButton(R.string.no, null) + .show() + true + }) + binding.favoriteList.adapter = adapter } -} +} \ No newline at end of file From 39687136dc9538cc068e1709dea86a7c2a8a5551 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 07:36:47 +0900 Subject: [PATCH 14/15] Rename .java to .kt --- .../viewmodels/{FavoritesViewModel.java => FavoritesViewModel.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/awais/instagrabber/viewmodels/{FavoritesViewModel.java => FavoritesViewModel.kt} (100%) diff --git a/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt similarity index 100% rename from app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.java rename to app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt From 77965f9634aa2ebf610d71159f1ba9e836689120 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 25 May 2021 07:36:47 +0900 Subject: [PATCH 15/15] Convert FavoritesViewModel to kotlin and optimise code --- app/build.gradle | 2 + .../fragments/FavoritesFragment.kt | 38 +------------ .../viewmodels/FavoritesViewModel.kt | 57 ++++++++++++++----- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1cd7be8c..0841a8e0 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -182,6 +182,8 @@ dependencies { def core_version = "1.6.0-beta01" implementation "androidx.core:core:$core_version" + implementation "androidx.fragment:fragment-ktx:1.3.4" + // Room def room_version = "2.3.0" implementation "androidx.room:room-runtime:$room_version" diff --git a/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt b/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt index 3f7c5271..04e97e26 100644 --- a/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt @@ -7,17 +7,14 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModelProvider +import androidx.fragment.app.viewModels import androidx.navigation.fragment.NavHostFragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import awais.instagrabber.R import awais.instagrabber.adapters.FavoritesAdapter import awais.instagrabber.databinding.FragmentFavoritesBinding -import awais.instagrabber.db.datasources.FavoriteDataSource import awais.instagrabber.db.entities.Favorite -import awais.instagrabber.db.repositories.FavoriteRepository -import awais.instagrabber.db.repositories.RepositoryCallback import awais.instagrabber.models.enums.FavoriteType import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.viewmodels.FavoritesViewModel @@ -28,16 +25,9 @@ class FavoritesFragment : Fragment() { private lateinit var binding: FragmentFavoritesBinding private lateinit var root: RecyclerView - private lateinit var favoritesViewModel: FavoritesViewModel - private lateinit var favoriteRepository: FavoriteRepository private lateinit var adapter: FavoritesAdapter - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - val context = context ?: return - favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context)) - favoritesViewModel = ViewModelProvider(this).get(FavoritesViewModel::class.java) - } + private val favoritesViewModel: FavoritesViewModel by viewModels() override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { if (this::root.isInitialized) { @@ -61,13 +51,6 @@ class FavoritesFragment : Fragment() { if (!this::adapter.isInitialized) return // refresh list every time in onViewStateRestored since it is cheaper than implementing pull down to refresh favoritesViewModel.list.observe(viewLifecycleOwner, { list: List? -> adapter.submitList(list) }) - favoriteRepository.getAllFavorites(object : RepositoryCallback> { - override fun onSuccess(favorites: List) { - favoritesViewModel.list.postValue(favorites) - } - - override fun onDataNotAvailable() {} - }) } private fun init() { @@ -109,22 +92,7 @@ class FavoritesFragment : Fragment() { val context = context ?: return@FavoritesAdapter false MaterialAlertDialogBuilder(context) .setMessage(getString(R.string.quick_access_confirm_delete, model.query)) - .setPositiveButton(R.string.yes) { d: DialogInterface, _: Int -> - favoriteRepository.deleteFavorite(model.query, model.type, object : RepositoryCallback { - override fun onSuccess(result: Void) { - d.dismiss() - favoriteRepository.getAllFavorites(object : RepositoryCallback> { - override fun onSuccess(result: List) { - favoritesViewModel.list.postValue(result) - } - - override fun onDataNotAvailable() {} - }) - } - - override fun onDataNotAvailable() {} - }) - } + .setPositiveButton(R.string.yes) { d: DialogInterface, _: Int -> favoritesViewModel.delete(model) { d.dismiss() } } .setNegativeButton(R.string.no, null) .show() true diff --git a/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt index bb865b88..8a2feb3a 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/FavoritesViewModel.kt @@ -1,19 +1,48 @@ -package awais.instagrabber.viewmodels; +package awais.instagrabber.viewmodels -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; +import android.app.Application +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import awais.instagrabber.db.datasources.FavoriteDataSource +import awais.instagrabber.db.entities.Favorite +import awais.instagrabber.db.repositories.FavoriteRepository +import awais.instagrabber.db.repositories.RepositoryCallback -import java.util.List; +class FavoritesViewModel(application: Application) : AndroidViewModel(application) { + private val _list = MutableLiveData>() + val list: LiveData> = _list -import awais.instagrabber.db.entities.Favorite; + private val favoriteRepository: FavoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(application)) -public class FavoritesViewModel extends ViewModel { - private MutableLiveData> list; - - public MutableLiveData> getList() { - if (list == null) { - list = new MutableLiveData<>(); - } - return list; + init { + fetch() } -} + + fun fetch() { + favoriteRepository.getAllFavorites(object : RepositoryCallback> { + override fun onSuccess(favorites: List?) { + _list.postValue(favorites ?: emptyList()) + } + + override fun onDataNotAvailable() {} + }) + } + + fun delete(favorite: Favorite, onSuccess: () -> Unit) { + favoriteRepository.deleteFavorite(favorite.query, favorite.type, object : RepositoryCallback { + override fun onSuccess(result: Void?) { + onSuccess() + favoriteRepository.getAllFavorites(object : RepositoryCallback> { + override fun onSuccess(result: List?) { + _list.postValue(result ?: emptyList()) + } + + override fun onDataNotAvailable() {} + }) + } + + override fun onDataNotAvailable() {} + }) + } +} \ No newline at end of file