1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

re-implement viewing individual user stories

This commit is contained in:
Austin Huang 2021-07-06 15:30:37 -04:00
parent 379468d577
commit 7e9e3b0fbf
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 14 additions and 6 deletions

View File

@ -199,7 +199,7 @@ class StoryViewerFragment : Fragment() {
val type = options!!.type val type = options!!.type
if (currentFeedStoryIndex >= 0) { if (currentFeedStoryIndex >= 0) {
listViewModel = when (type) { listViewModel = when (type) {
StoryViewerOptions.Type.HIGHLIGHT -> { StoryViewerOptions.Type.HIGHLIGHT, StoryViewerOptions.Type.USER -> {
val pArgs = Bundle() val pArgs = Bundle()
pArgs.putString("username", options!!.name) pArgs.putString("username", options!!.name)
ViewModelProvider( ViewModelProvider(
@ -288,6 +288,15 @@ class StoryViewerFragment : Fragment() {
profileFragmentViewModel.userHighlights.observe(viewLifecycleOwner) {} profileFragmentViewModel.userHighlights.observe(viewLifecycleOwner) {}
liveModels = profileFragmentViewModel.highlights 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 -> { StoryViewerOptions.Type.FEED_STORY_POSITION -> {
val feedStoriesViewModel = listViewModel as FeedStoriesViewModel? val feedStoriesViewModel = listViewModel as FeedStoriesViewModel?
liveModels = feedStoriesViewModel!!.list liveModels = feedStoriesViewModel!!.list
@ -299,7 +308,6 @@ class StoryViewerFragment : Fragment() {
} }
} }
if (liveModels != null) liveModels.observe(viewLifecycleOwner, { models -> if (liveModels != null) liveModels.observe(viewLifecycleOwner, { models ->
Log.d("austin_debug", "models (observer): " + models)
storiesViewModel.getPagination().observe(fragmentActivity, { storiesViewModel.getPagination().observe(fragmentActivity, {
if (models != null) { if (models != null) {
when (it) { when (it) {
@ -381,7 +389,6 @@ class StoryViewerFragment : Fragment() {
StoryViewerOptions.Type.HIGHLIGHT -> { StoryViewerOptions.Type.HIGHLIGHT -> {
val profileFragmentViewModel = listViewModel as ProfileFragmentViewModel? val profileFragmentViewModel = listViewModel as ProfileFragmentViewModel?
val models = profileFragmentViewModel!!.highlights.value val models = profileFragmentViewModel!!.highlights.value
Log.d("austin_debug", "models (resetView): " + models)
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size || currentFeedStoryIndex < 0) { if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size || currentFeedStoryIndex < 0) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show()
return return

View File

@ -932,7 +932,7 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall
val action = ProfileFragmentDirections.actionProfileFragmentToStoryViewerFragment( val action = ProfileFragmentDirections.actionProfileFragmentToStoryViewerFragment(
StoryViewerOptions.forUser( StoryViewerOptions.forUser(
viewModel.profile.value?.data?.pk ?: return, viewModel.profile.value?.data?.pk ?: return,
viewModel.profile.value?.data?.fullName ?: return, viewModel.profile.value?.data?.username ?: return,
) )
) )
NavHostFragment.findNavController(this).navigate(action) NavHostFragment.findNavController(this).navigate(action)

View File

@ -29,7 +29,7 @@ interface StoriesService {
suspend fun getStories(@Path("type") type: String, @Path("id") id: String): ReelsResponse suspend fun getStories(@Path("type") type: String, @Path("id") id: String): ReelsResponse
@GET("/api/v1/feed/user/{id}/story/") @GET("/api/v1/feed/user/{id}/story/")
suspend fun getUserStories(@Path("id") id: String): ReelsResponse suspend fun getUserStories(@Path("id") id: Long): ReelsResponse
@FormUrlEncoded @FormUrlEncoded
@POST("/api/v1/media/{storyId}/{stickerId}/{action}/") @POST("/api/v1/media/{storyId}/{stickerId}/{action}/")

View File

@ -187,6 +187,7 @@ class ProfileFragmentViewModel(
} }
} }
} }
val stories: LiveData<List<Story>?> = userStories.map { if (it.data == null) listOf() else listOf(it.data) }
private val highlightsFetchControlledRunner = ControlledRunner<List<Story>?>() private val highlightsFetchControlledRunner = ControlledRunner<List<Story>?>()
val userHighlights: LiveData<Resource<List<Story>?>> = currentUserProfileActionLiveData.switchMap { currentUserAndProfilePair -> val userHighlights: LiveData<Resource<List<Story>?>> = currentUserProfileActionLiveData.switchMap { currentUserAndProfilePair ->

View File

@ -74,7 +74,7 @@ open class StoriesRepository(private val service: StoriesService) {
response.reels?.get(options.name) response.reels?.get(options.name)
} }
StoryViewerOptions.Type.USER -> { StoryViewerOptions.Type.USER -> {
val response = service.getUserStories(options.id.toString()) val response = service.getUserStories(options.id)
response.reel response.reel
} }
// should not reach beyond this point // should not reach beyond this point