1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-12 17:57:29 +00:00

Add StoriesRepository to ProfileFragmentViewModel constructor

This commit is contained in:
Ammar Githam 2021-06-12 08:54:00 +09:00
parent 3d69148d9b
commit 02cb1f5db5
3 changed files with 45 additions and 3 deletions

View File

@ -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);

View File

@ -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<User?>()
val profile: LiveData<User?> = _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<T>,
handle: SavedStateHandle,
): T {
return ProfileFragmentViewModel(handle, userRepository, friendshipRepository) as T
return ProfileFragmentViewModel(
handle,
userRepository,
friendshipRepository,
storiesRepository
) as T
}
}

View File

@ -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, String>): 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<String, String>): StoryStickerResponse {
TODO("Not yet implemented")
}
override suspend fun seen(queryParams: Map<String, String>, form: Map<String, String>): 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)
}
}