From 7dc3732e3ec6c3eeb46b7d3c95265b3448adb88b Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 23 May 2021 17:10:49 +0900 Subject: [PATCH] Convert to kotlin --- .../fragments/StoryViewerFragment.java | 6 +- .../awais/instagrabber/models/StoryModel.kt | 194 +++--------------- .../models/enums/BroadcastItemType.kt | 18 +- .../instagrabber/models/enums/FavoriteType.kt | 8 +- .../models/enums/IntentModelType.kt | 6 +- .../models/enums/NotificationType.kt | 40 ++-- .../instagrabber/models/enums/PostItemType.kt | 16 +- .../models/enums/SuggestionType.kt | 8 +- 8 files changed, 64 insertions(+), 232 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 8e64b335..4aa6ec74 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -980,7 +980,7 @@ public class StoryViewerFragment extends Fragment { downloadVisible = true; menuDownload.setVisible(true); } - if (currentStory.canReply() && menuDm != null) { + if (currentStory.getCanReply() && menuDm != null) { dmVisible = true; menuDm.setVisible(true); } @@ -1021,7 +1021,7 @@ public class StoryViewerFragment extends Fragment { downloadVisible = true; menuDownload.setVisible(true); } - if (currentStory.canReply() && menuDm != null) { + if (currentStory.getCanReply() && menuDm != null) { dmVisible = true; menuDm.setVisible(true); } @@ -1041,7 +1041,7 @@ public class StoryViewerFragment extends Fragment { downloadVisible = true; menuDownload.setVisible(true); } - if (currentStory.canReply() && menuDm != null) { + if (currentStory.getCanReply() && menuDm != null) { dmVisible = true; menuDm.setVisible(true); } diff --git a/app/src/main/java/awais/instagrabber/models/StoryModel.kt b/app/src/main/java/awais/instagrabber/models/StoryModel.kt index ab1def43..c863df70 100755 --- a/app/src/main/java/awais/instagrabber/models/StoryModel.kt +++ b/app/src/main/java/awais/instagrabber/models/StoryModel.kt @@ -1,167 +1,29 @@ -package awais.instagrabber.models; - -import java.io.Serializable; - -import awais.instagrabber.models.enums.MediaItemType; -import awais.instagrabber.models.stickers.PollModel; -import awais.instagrabber.models.stickers.QuestionModel; -import awais.instagrabber.models.stickers.QuizModel; -import awais.instagrabber.models.stickers.SliderModel; -import awais.instagrabber.models.stickers.SwipeUpModel; - -public final class StoryModel implements Serializable { - private final String storyMediaId; - private final String storyUrl; - private String thumbnail; - private final String username; - private final long userId; - private final MediaItemType itemType; - private final long timestamp; - private String videoUrl; - private String tappableShortCode; - private String tappableId; - private String spotify; - private PollModel poll; - private QuestionModel question; - private SliderModel slider; - private QuizModel quiz; - private SwipeUpModel swipeUp; - private String[] mentions; - private int position; - private boolean isCurrentSlide = false; - private final boolean canReply; - - public StoryModel(final String storyMediaId, final String storyUrl, final String thumbnail, final MediaItemType itemType, - final long timestamp, final String username, final long userId, final boolean canReply) { - this.storyMediaId = storyMediaId; - this.storyUrl = storyUrl; - this.thumbnail = thumbnail; - this.itemType = itemType; - this.timestamp = timestamp; - this.username = username; - this.userId = userId; - this.canReply = canReply; - } - - public String getStoryUrl() { - return storyUrl; - } - - public String getThumbnail() { - return thumbnail; - } - - public String getStoryMediaId() { - return storyMediaId; - } - - public MediaItemType getItemType() { - return itemType; - } - - public long getTimestamp() { - return timestamp; - } - - public String getVideoUrl() { - return videoUrl; - } - - public String getTappableShortCode() { - return tappableShortCode; - } - - public PollModel getPoll() { - return poll; - } - - public QuestionModel getQuestion() { - return question; - } - - public SliderModel getSlider() { - return slider; - } - - public QuizModel getQuiz() { - return quiz; - } - - public SwipeUpModel getSwipeUp() { return swipeUp;} - - public String[] getMentions() { - return mentions; - } - - public int getPosition() { - return position; - } - - public void setThumbnail(final String thumbnail) { - this.thumbnail = thumbnail; - } - - public void setVideoUrl(final String videoUrl) { - this.videoUrl = videoUrl; - } - - public String getSpotify() { - return spotify; - } - - public void setSpotify(final String spotify) { - this.spotify = spotify; - } - - public void setTappableShortCode(final String tappableShortCode) { - this.tappableShortCode = tappableShortCode; - } - - public void setPoll(final PollModel poll) { - this.poll = poll; - } - - public void setQuestion(final QuestionModel question) { - this.question = question; - } - - public void setSlider(final SliderModel slider) { - this.slider = slider; - } - - public void setQuiz(final QuizModel quiz) { - this.quiz = quiz; - } - - public void setMentions(final String[] mentions) { - this.mentions = mentions; - } - - public void setSwipeUp(final SwipeUpModel swipeUp) { - this.swipeUp = swipeUp; - } - - public void setPosition(final int position) { - this.position = position; - } - - public void setCurrentSlide(final boolean currentSlide) { - this.isCurrentSlide = currentSlide; - } - - public boolean isCurrentSlide() { - return isCurrentSlide; - } - - public boolean canReply() { - return canReply; - } - - public String getUsername() { - return username; - } - - public long getUserId() { - return userId; - } +package awais.instagrabber.models + +import awais.instagrabber.models.enums.MediaItemType +import awais.instagrabber.models.stickers.* +import java.io.Serializable + +data class StoryModel( + val storyMediaId: String?, + val storyUrl: String?, + var thumbnail: String?, + val itemType: MediaItemType?, + val timestamp: Long, + val username: String?, + val userId: Long, + val canReply: Boolean +) : Serializable { + var videoUrl: String? = null + var tappableShortCode: String? = null + val tappableId: String? = null + var spotify: String? = null + var poll: PollModel? = null + var question: QuestionModel? = null + var slider: SliderModel? = null + var quiz: QuizModel? = null + var swipeUp: SwipeUpModel? = null + var mentions: Array? = null + var position = 0 + var isCurrentSlide = false } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/BroadcastItemType.kt b/app/src/main/java/awais/instagrabber/models/enums/BroadcastItemType.kt index 5b2fe11e..2e6c9f77 100644 --- a/app/src/main/java/awais/instagrabber/models/enums/BroadcastItemType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/BroadcastItemType.kt @@ -1,6 +1,6 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -public enum BroadcastItemType { +enum class BroadcastItemType(val value: String) { TEXT("text"), REACTION("reaction"), REELSHARE("reel_share"), @@ -9,15 +9,5 @@ public enum BroadcastItemType { VIDEO("configure_video"), VOICE("share_voice"), ANIMATED_MEDIA("animated_media"), - MEDIA_SHARE("media_share"); - - private final String value; - - BroadcastItemType(final String value) { - this.value = value; - } - - public String getValue() { - return value; - } -} + MEDIA_SHARE("media_share"), +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/FavoriteType.kt b/app/src/main/java/awais/instagrabber/models/enums/FavoriteType.kt index 536ac05f..b452b1bb 100644 --- a/app/src/main/java/awais/instagrabber/models/enums/FavoriteType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/FavoriteType.kt @@ -1,8 +1,8 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -public enum FavoriteType { - TOP, // used just for searching +enum class FavoriteType { + TOP, // used just for searching USER, HASHTAG, LOCATION, -} +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.kt b/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.kt index b9424a4f..c39e2c14 100755 --- a/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.kt @@ -1,9 +1,9 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -public enum IntentModelType { +enum class IntentModelType { UNKNOWN, USERNAME, POST, HASHTAG, - LOCATION + LOCATION, } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/NotificationType.kt b/app/src/main/java/awais/instagrabber/models/enums/NotificationType.kt index 4a9e89a8..1b1bfaa7 100755 --- a/app/src/main/java/awais/instagrabber/models/enums/NotificationType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/NotificationType.kt @@ -1,41 +1,31 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import java.io.Serializable -public enum NotificationType implements Serializable { - // story_type +enum class NotificationType(val itemType: Int) : Serializable { LIKE(60), FOLLOW(101), - COMMENT(12), // NOT TESTED + COMMENT(12), // NOT TESTED COMMENT_MENTION(66), - TAGGED(102), // NOT TESTED + TAGGED(102), // NOT TESTED COMMENT_LIKE(13), TAGGED_COMMENT(14), RESPONDED_STORY(213), REQUEST(75), - // aymf - arbitrary, misspelled as ayml but eh AYML(9999); - private final int itemType; - private static final Map map = new HashMap<>(); + companion object { + private val map: MutableMap = mutableMapOf() - static { - for (NotificationType type : NotificationType.values()) { - map.put(type.itemType, type); + @JvmStatic + fun valueOfType(itemType: Int): NotificationType? { + return map[itemType] } - } - - NotificationType(final int itemType) { - this.itemType = itemType; - } - public int getItemType() { - return itemType; - } - - public static NotificationType valueOfType(final int itemType) { - return map.get(itemType); + init { + for (type in values()) { + map[type.itemType] = type + } + } } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/PostItemType.kt b/app/src/main/java/awais/instagrabber/models/enums/PostItemType.kt index 4e651a51..58bedc17 100644 --- a/app/src/main/java/awais/instagrabber/models/enums/PostItemType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/PostItemType.kt @@ -1,15 +1,7 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -import java.io.Serializable; +import java.io.Serializable -public enum PostItemType implements Serializable { - MAIN, - DISCOVER, - FEED, - SAVED, - COLLECTION, - LIKED, - TAGGED, - HASHTAG, - LOCATION +enum class PostItemType : Serializable { + MAIN, DISCOVER, FEED, SAVED, COLLECTION, LIKED, TAGGED, HASHTAG, LOCATION } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/enums/SuggestionType.kt b/app/src/main/java/awais/instagrabber/models/enums/SuggestionType.kt index eb38e033..e24f542c 100755 --- a/app/src/main/java/awais/instagrabber/models/enums/SuggestionType.kt +++ b/app/src/main/java/awais/instagrabber/models/enums/SuggestionType.kt @@ -1,7 +1,5 @@ -package awais.instagrabber.models.enums; +package awais.instagrabber.models.enums -public enum SuggestionType { - TYPE_USER, - TYPE_HASHTAG, - TYPE_LOCATION +enum class SuggestionType { + TYPE_USER, TYPE_HASHTAG, TYPE_LOCATION } \ No newline at end of file