From 02cb1f5db5ed6ae2cb15553746247bcf1f463607 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 12 Jun 2021 08:54:00 +0900 Subject: [PATCH] Add StoriesRepository to ProfileFragmentViewModel constructor --- .../fragments/main/ProfileFragment.java | 1 + .../viewmodels/ProfileFragmentViewModel.kt | 12 +++++-- .../ProfileFragmentViewModelTest.kt | 35 ++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) 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 bab46640..6863fab0 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -347,6 +347,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory( UserRepository.Companion.getInstance(), FriendshipRepository.Companion.getInstance(), + StoriesRepository.Companion.getInstance(), this, getArguments() )).get(ProfileFragmentViewModel.class); diff --git a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt index bb468653..3d18bcce 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt @@ -7,12 +7,14 @@ import androidx.savedstate.SavedStateRegistryOwner import awais.instagrabber.repositories.responses.User import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.webservices.FriendshipRepository +import awais.instagrabber.webservices.StoriesRepository import awais.instagrabber.webservices.UserRepository class ProfileFragmentViewModel( state: SavedStateHandle, userRepository: UserRepository, friendshipRepository: FriendshipRepository, + storiesRepository: StoriesRepository, ) : ViewModel() { private val _profile = MutableLiveData() val profile: LiveData = _profile @@ -24,7 +26,7 @@ class ProfileFragmentViewModel( private set init { - Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository") + Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository") } } @@ -32,6 +34,7 @@ class ProfileFragmentViewModel( class ProfileFragmentViewModelFactory( private val userRepository: UserRepository, private val friendshipRepository: FriendshipRepository, + private val storiesRepository: StoriesRepository, owner: SavedStateRegistryOwner, defaultArgs: Bundle? = null, ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @@ -40,6 +43,11 @@ class ProfileFragmentViewModelFactory( modelClass: Class, handle: SavedStateHandle, ): T { - return ProfileFragmentViewModel(handle, userRepository, friendshipRepository) as T + return ProfileFragmentViewModel( + handle, + userRepository, + friendshipRepository, + storiesRepository + ) as T } } diff --git a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt index c116dea1..fb64cf4e 100644 --- a/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt +++ b/app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt @@ -3,9 +3,11 @@ package awais.instagrabber.viewmodels import androidx.lifecycle.SavedStateHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import awais.instagrabber.repositories.FriendshipService +import awais.instagrabber.repositories.StoriesService import awais.instagrabber.repositories.UserService import awais.instagrabber.repositories.responses.* import awais.instagrabber.webservices.FriendshipRepository +import awais.instagrabber.webservices.StoriesRepository import awais.instagrabber.webservices.UserRepository import org.junit.Test import org.junit.runner.RunWith @@ -48,6 +50,36 @@ internal class ProfileFragmentViewModelTest { } } + private val storiesService = object: StoriesService { + override suspend fun fetch(mediaId: Long): String { + TODO("Not yet implemented") + } + + override suspend fun getFeedStories(): String { + TODO("Not yet implemented") + } + + override suspend fun fetchHighlights(uid: Long): String { + TODO("Not yet implemented") + } + + override suspend fun fetchArchive(queryParams: Map): String { + TODO("Not yet implemented") + } + + override suspend fun getUserStory(url: String): String { + TODO("Not yet implemented") + } + + override suspend fun respondToSticker(storyId: String, stickerId: String, action: String, form: Map): StoryStickerResponse { + TODO("Not yet implemented") + } + + override suspend fun seen(queryParams: Map, form: Map): String { + TODO("Not yet implemented") + } + } + @Test fun testNoUsernameNoCurrentUser() { val state = SavedStateHandle( @@ -57,6 +89,7 @@ internal class ProfileFragmentViewModelTest { ) val userRepository = UserRepository(userService) val friendshipRepository = FriendshipRepository(friendshipService) - val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository) + val storiesRepository = StoriesRepository(storiesService) + val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository, storiesRepository) } } \ No newline at end of file