diff --git a/app/src/main/java/awais/instagrabber/adapters/HighlightsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/HighlightsAdapter.java index 41cbb3db..f97c6094 100755 --- a/app/src/main/java/awais/instagrabber/adapters/HighlightsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/HighlightsAdapter.java @@ -9,20 +9,20 @@ import androidx.recyclerview.widget.ListAdapter; import awais.instagrabber.adapters.viewholder.HighlightViewHolder; import awais.instagrabber.databinding.ItemHighlightBinding; -import awais.instagrabber.models.HighlightModel; +import awais.instagrabber.repositories.responses.stories.Story; -public final class HighlightsAdapter extends ListAdapter { +public final class HighlightsAdapter extends ListAdapter { private final OnHighlightClickListener clickListener; - private static final DiffUtil.ItemCallback diffCallback = new DiffUtil.ItemCallback() { + private static final DiffUtil.ItemCallback diffCallback = new DiffUtil.ItemCallback() { @Override - public boolean areItemsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { + public boolean areItemsTheSame(@NonNull final Story oldItem, @NonNull final Story newItem) { return oldItem.getId().equals(newItem.getId()); } @Override - public boolean areContentsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { + public boolean areContentsTheSame(@NonNull final Story oldItem, @NonNull final Story newItem) { return oldItem.getId().equals(newItem.getId()); } }; @@ -42,7 +42,7 @@ public final class HighlightsAdapter extends ListAdapter clickListener.onHighlightClick(highlightModel, position)); } @@ -50,6 +50,6 @@ public final class HighlightsAdapter extends ListAdapter { // if (listener == null) return; // listener.onFeedStoryClick(model, position); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index a4acc407..b67487b2 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -736,12 +736,12 @@ public class StoryViewerFragment extends Fragment { switch (type) { case HIGHLIGHT: { final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; - final List models = highlightsViewModel.getList().getValue(); + final List models = highlightsViewModel.getList().getValue(); if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size() || currentFeedStoryIndex < 0) { Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); return; } - final HighlightModel model = models.get(currentFeedStoryIndex); + final Story model = models.get(currentFeedStoryIndex); currentStoryMediaId = model.getId(); fetchOptions = StoryViewerOptions.forHighlight(model.getId()); highlightTitle = model.getTitle(); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 1f2d7638..2ef21ed6 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -73,7 +73,6 @@ import awais.instagrabber.fragments.UserSearchFragment; import awais.instagrabber.fragments.UserSearchFragmentDirections; import awais.instagrabber.managers.DirectMessagesManager; import awais.instagrabber.managers.InboxManager; -import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.models.enums.PostItemType; @@ -84,6 +83,7 @@ import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.UserProfileContextLink; import awais.instagrabber.repositories.responses.directmessages.RankedRecipient; +import awais.instagrabber.repositories.responses.stories.Story; import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; @@ -1121,7 +1121,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe if (highlightModels != null) { profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE); //noinspection unchecked - highlightsViewModel.getList().postValue((List) highlightModels); + highlightsViewModel.getList().postValue((List) highlightModels); } else { profileDetailsBinding.highlightsList.setVisibility(View.GONE); } diff --git a/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt b/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt index a55315e9..205830c0 100644 --- a/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt +++ b/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt @@ -13,7 +13,7 @@ interface StoriesService { suspend fun getFeedStories(): ReelsTrayResponse @GET("/api/v1/highlights/{uid}/highlights_tray/") - suspend fun fetchHighlights(@Path("uid") uid: Long): String + suspend fun fetchHighlights(@Path("uid") uid: Long): ReelsTrayResponse @GET("/api/v1/archive/reel/day_shells/") suspend fun fetchArchive(@QueryMap queryParams: Map): String diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/HdProfilePicUrlInfo.kt b/app/src/main/java/awais/instagrabber/repositories/responses/HdProfilePicUrlInfo.kt deleted file mode 100644 index e31a6027..00000000 --- a/app/src/main/java/awais/instagrabber/repositories/responses/HdProfilePicUrlInfo.kt +++ /dev/null @@ -1,5 +0,0 @@ -package awais.instagrabber.repositories.responses - -import java.io.Serializable - -data class HdProfilePicUrlInfo(val url: String, private val width: Int, private val height: Int) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/ImageUrl.kt b/app/src/main/java/awais/instagrabber/repositories/responses/ImageUrl.kt new file mode 100644 index 00000000..0c2362d1 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/ImageUrl.kt @@ -0,0 +1,5 @@ +package awais.instagrabber.repositories.responses + +import java.io.Serializable + +data class ImageUrl(val url: String, private val width: Int, private val height: Int) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/User.kt b/app/src/main/java/awais/instagrabber/repositories/responses/User.kt index b46e3dab..6f465fb6 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/User.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/User.kt @@ -27,7 +27,7 @@ data class User @JvmOverloads constructor( val externalUrl: String? = null, val usertagsCount: Long = 0, val publicEmail: String? = null, - val hdProfilePicUrlInfo: HdProfilePicUrlInfo? = null, + val hdProfilePicUrlInfo: ImageUrl? = null, val profileContext: String? = null, // "also followed by" your friends val profileContextLinksWithUserIds: List? = null, // ^ val socialContext: String? = null, // AYML diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/CoverMedia.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/CoverMedia.kt new file mode 100644 index 00000000..47d7a641 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/CoverMedia.kt @@ -0,0 +1,5 @@ +package awais.instagrabber.repositories.responses.stories + +import awais.instagrabber.repositories.responses.ImageUrl + +data class CoverMedia(val croppedImageVersion: ImageUrl) \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/Story.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/Story.kt index 81e3d0d1..57f8b095 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/Story.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/Story.kt @@ -1,19 +1,24 @@ package awais.instagrabber.repositories.responses.stories import java.io.Serializable -import awais.instagrabber.repositories.responses.Media import awais.instagrabber.repositories.responses.User import awais.instagrabber.utils.TextUtils data class Story( + // universal val id: String?, val latestReelMedia: Long?, // = timestamp var seen: Long?, val user: User?, + // for stories + val mediaCount: Int?, val muted: Boolean?, val hasBestiesMedia: Boolean?, - val mediaCount: Int?, val items: List?, // may be null + // for highlights + val coverMedia: CoverMedia?, + val title: String?, + // invented fields val broadcast: Broadcast? // does not naturally occur ) : Serializable { val dateTime: String diff --git a/app/src/main/java/awais/instagrabber/viewmodels/HighlightsViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/HighlightsViewModel.java index d78b9ef4..ccc8b843 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/HighlightsViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/HighlightsViewModel.java @@ -5,12 +5,12 @@ import androidx.lifecycle.ViewModel; import java.util.List; -import awais.instagrabber.models.HighlightModel; +import awais.instagrabber.repositories.responses.stories.Story; public class HighlightsViewModel extends ViewModel { - private MutableLiveData> list; + private MutableLiveData> list; - public MutableLiveData> getList() { + public MutableLiveData> getList() { if (list == null) { list = new MutableLiveData<>(); } diff --git a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt index bc0e185b..736cdc7b 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt @@ -8,7 +8,6 @@ import awais.instagrabber.db.entities.Favorite import awais.instagrabber.db.repositories.AccountRepository import awais.instagrabber.db.repositories.FavoriteRepository import awais.instagrabber.managers.DirectMessagesManager -import awais.instagrabber.models.HighlightModel import awais.instagrabber.models.Resource import awais.instagrabber.models.StoryModel import awais.instagrabber.models.enums.BroadcastItemType @@ -16,6 +15,7 @@ import awais.instagrabber.models.enums.FavoriteType import awais.instagrabber.repositories.requests.StoryViewerOptions import awais.instagrabber.repositories.responses.User import awais.instagrabber.repositories.responses.directmessages.RankedRecipient +import awais.instagrabber.repositories.responses.stories.Story import awais.instagrabber.utils.ControlledRunner import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.webservices.* @@ -119,9 +119,9 @@ class ProfileFragmentViewModel( } } - private val highlightsFetchControlledRunner = ControlledRunner?>() - val userHighlights: LiveData?>> = profile.switchMap { userResource -> - liveData?>>(context = viewModelScope.coroutineContext + ioDispatcher) { + private val highlightsFetchControlledRunner = ControlledRunner?>() + val userHighlights: LiveData?>> = profile.switchMap { userResource -> + liveData?>>(context = viewModelScope.coroutineContext + ioDispatcher) { // don't fetch if not logged in if (isLoggedIn.value != true) { emit(Resource.success(null)) @@ -165,7 +165,7 @@ class ProfileFragmentViewModel( StoryViewerOptions.forUser(fetchedUser.pk, fetchedUser.fullName) ) - private suspend fun fetchUserHighlights(fetchedUser: User): List = storiesRepository.fetchHighlights(fetchedUser.pk) + private suspend fun fetchUserHighlights(fetchedUser: User): List = storiesRepository.fetchHighlights(fetchedUser.pk) private suspend fun checkAndInsertFavorite(fetchedUser: User) { try { diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt b/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt index 89603777..d4f080cd 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt @@ -37,9 +37,11 @@ open class StoriesRepository(private val service: StoriesService) { broadcast.publishedTime, 0L, broadcast.broadcastOwner, + 1, broadcast.muted, false, // unclear - 1, + null, + null, null, broadcast ) @@ -49,25 +51,9 @@ open class StoriesRepository(private val service: StoriesService) { return sort(result.toList()) } - open suspend fun fetchHighlights(profileId: Long): List { + open suspend fun fetchHighlights(profileId: Long): List { val response = service.fetchHighlights(profileId) - val highlightsReel = JSONObject(response).getJSONArray("tray") - val length = highlightsReel.length() - val highlightModels: MutableList = ArrayList() - for (i in 0 until length) { - val highlightNode = highlightsReel.getJSONObject(i) - highlightModels.add( - HighlightModel( - highlightNode.getString("title"), - highlightNode.getString(Constants.EXTRAS_ID), - highlightNode.getJSONObject("cover_media") - .getJSONObject("cropped_image_version") - .getString("url"), - highlightNode.getLong("latest_reel_media"), - highlightNode.getInt("media_count") - ) - ) - } + val highlightModels = response.tray ?: listOf() return highlightModels } diff --git a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt index 471b9c2a..bdaf8515 100644 --- a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt +++ b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt @@ -11,13 +11,13 @@ import awais.instagrabber.db.entities.Favorite import awais.instagrabber.db.repositories.AccountRepository import awais.instagrabber.db.repositories.FavoriteRepository import awais.instagrabber.getOrAwaitValue -import awais.instagrabber.models.HighlightModel import awais.instagrabber.models.Resource import awais.instagrabber.models.StoryModel import awais.instagrabber.models.enums.FavoriteType import awais.instagrabber.repositories.requests.StoryViewerOptions import awais.instagrabber.repositories.responses.FriendshipStatus import awais.instagrabber.repositories.responses.User +import awais.instagrabber.repositories.responses.stories.Story import awais.instagrabber.webservices.* import kotlinx.coroutines.ExperimentalCoroutinesApi import org.json.JSONException @@ -296,7 +296,7 @@ internal class ProfileFragmentViewModelTest { ) ) val testUserStories = listOf(StoryModel()) - val testUserHighlights = listOf(HighlightModel()) + val testUserHighlights = listOf(Story()) val userRepository = object : UserRepository(UserServiceAdapter()) { override suspend fun getUsernameInfo(username: String): User = testPublicUser }