From 7e9e3b0fbf1be152f982c4299c7e07610a677780 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 6 Jul 2021 15:30:37 -0400 Subject: [PATCH] re-implement viewing individual user stories --- .../instagrabber/fragments/StoryViewerFragment.kt | 13 ++++++++++--- .../instagrabber/fragments/main/ProfileFragment.kt | 2 +- .../instagrabber/repositories/StoriesService.kt | 2 +- .../viewmodels/ProfileFragmentViewModel.kt | 1 + .../instagrabber/webservices/StoriesRepository.kt | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt index b3512d22..6d0d4fdd 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt @@ -199,7 +199,7 @@ class StoryViewerFragment : Fragment() { val type = options!!.type if (currentFeedStoryIndex >= 0) { listViewModel = when (type) { - StoryViewerOptions.Type.HIGHLIGHT -> { + StoryViewerOptions.Type.HIGHLIGHT, StoryViewerOptions.Type.USER -> { val pArgs = Bundle() pArgs.putString("username", options!!.name) ViewModelProvider( @@ -288,6 +288,15 @@ class StoryViewerFragment : Fragment() { profileFragmentViewModel.userHighlights.observe(viewLifecycleOwner) {} liveModels = profileFragmentViewModel.highlights } + StoryViewerOptions.Type.USER -> { + val profileFragmentViewModel = listViewModel as ProfileFragmentViewModel? + appStateViewModel.currentUserLiveData.observe( + viewLifecycleOwner, profileFragmentViewModel!!::setCurrentUser + ) + profileFragmentViewModel.currentUserProfileActionLiveData.observe(viewLifecycleOwner) {} + profileFragmentViewModel.userStories.observe(viewLifecycleOwner) {} + liveModels = profileFragmentViewModel.stories + } StoryViewerOptions.Type.FEED_STORY_POSITION -> { val feedStoriesViewModel = listViewModel as FeedStoriesViewModel? liveModels = feedStoriesViewModel!!.list @@ -299,7 +308,6 @@ class StoryViewerFragment : Fragment() { } } if (liveModels != null) liveModels.observe(viewLifecycleOwner, { models -> - Log.d("austin_debug", "models (observer): " + models) storiesViewModel.getPagination().observe(fragmentActivity, { if (models != null) { when (it) { @@ -381,7 +389,6 @@ class StoryViewerFragment : Fragment() { StoryViewerOptions.Type.HIGHLIGHT -> { val profileFragmentViewModel = listViewModel as ProfileFragmentViewModel? val models = profileFragmentViewModel!!.highlights.value - Log.d("austin_debug", "models (resetView): " + models) if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size || currentFeedStoryIndex < 0) { Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show() return diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt index 21f0d5d9..ab731719 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt @@ -932,7 +932,7 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall val action = ProfileFragmentDirections.actionProfileFragmentToStoryViewerFragment( StoryViewerOptions.forUser( viewModel.profile.value?.data?.pk ?: return, - viewModel.profile.value?.data?.fullName ?: return, + viewModel.profile.value?.data?.username ?: return, ) ) NavHostFragment.findNavController(this).navigate(action) diff --git a/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt b/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt index f7793767..c8920d74 100644 --- a/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt +++ b/app/src/main/java/awais/instagrabber/repositories/StoriesService.kt @@ -29,7 +29,7 @@ interface StoriesService { suspend fun getStories(@Path("type") type: String, @Path("id") id: String): ReelsResponse @GET("/api/v1/feed/user/{id}/story/") - suspend fun getUserStories(@Path("id") id: String): ReelsResponse + suspend fun getUserStories(@Path("id") id: Long): ReelsResponse @FormUrlEncoded @POST("/api/v1/media/{storyId}/{stickerId}/{action}/") diff --git a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt index ffbf5b90..013cfd48 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt @@ -187,6 +187,7 @@ class ProfileFragmentViewModel( } } } + val stories: LiveData?> = userStories.map { if (it.data == null) listOf() else listOf(it.data) } private val highlightsFetchControlledRunner = ControlledRunner?>() val userHighlights: LiveData?>> = currentUserProfileActionLiveData.switchMap { currentUserAndProfilePair -> diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt b/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt index e3713df1..205983c9 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt @@ -74,7 +74,7 @@ open class StoriesRepository(private val service: StoriesService) { response.reels?.get(options.name) } StoryViewerOptions.Type.USER -> { - val response = service.getUserStories(options.id.toString()) + val response = service.getUserStories(options.id) response.reel } // should not reach beyond this point