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

Add GraphQLRepository to ProfileFragmentViewModel constructor

This commit is contained in:
Ammar Githam 2021-06-12 12:43:15 +09:00
parent 205e21b07c
commit dad2260ea2
3 changed files with 32 additions and 13 deletions

View File

@ -349,6 +349,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
FriendshipRepository.Companion.getInstance(),
StoriesRepository.Companion.getInstance(),
MediaRepository.Companion.getInstance(),
GraphQLRepository.Companion.getInstance(),
this,
getArguments()
)).get(ProfileFragmentViewModel.class);

View File

@ -6,10 +6,7 @@ import androidx.lifecycle.*
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.MediaRepository
import awais.instagrabber.webservices.StoriesRepository
import awais.instagrabber.webservices.UserRepository
import awais.instagrabber.webservices.*
class ProfileFragmentViewModel(
state: SavedStateHandle,
@ -17,6 +14,7 @@ class ProfileFragmentViewModel(
friendshipRepository: FriendshipRepository,
storiesRepository: StoriesRepository,
mediaRepository: MediaRepository,
graphQLRepository: GraphQLRepository,
) : ViewModel() {
private val _profile = MutableLiveData<User?>()
val profile: LiveData<User?> = _profile
@ -38,6 +36,7 @@ class ProfileFragmentViewModelFactory(
private val friendshipRepository: FriendshipRepository,
private val storiesRepository: StoriesRepository,
private val mediaRepository: MediaRepository,
private val graphQLRepository: GraphQLRepository,
owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null,
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@ -52,6 +51,7 @@ class ProfileFragmentViewModelFactory(
friendshipRepository,
storiesRepository,
mediaRepository,
graphQLRepository,
) as T
}
}

View File

@ -2,15 +2,9 @@ package awais.instagrabber.viewmodels
import androidx.lifecycle.SavedStateHandle
import androidx.test.ext.junit.runners.AndroidJUnit4
import awais.instagrabber.repositories.FriendshipService
import awais.instagrabber.repositories.MediaService
import awais.instagrabber.repositories.StoriesService
import awais.instagrabber.repositories.UserService
import awais.instagrabber.repositories.*
import awais.instagrabber.repositories.responses.*
import awais.instagrabber.webservices.FriendshipRepository
import awais.instagrabber.webservices.MediaRepository
import awais.instagrabber.webservices.StoriesRepository
import awais.instagrabber.webservices.UserRepository
import awais.instagrabber.webservices.*
import org.junit.Test
import org.junit.runner.RunWith
@ -116,6 +110,28 @@ internal class ProfileFragmentViewModelTest {
}
}
private val graphQLService = object : GraphQLService {
override suspend fun fetch(queryParams: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun getUser(username: String): String {
TODO("Not yet implemented")
}
override suspend fun getPost(shortcode: String): String {
TODO("Not yet implemented")
}
override suspend fun getTag(tag: String): String {
TODO("Not yet implemented")
}
override suspend fun getLocation(locationId: Long): String {
TODO("Not yet implemented")
}
}
@Test
fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle(
@ -127,12 +143,14 @@ internal class ProfileFragmentViewModelTest {
val friendshipRepository = FriendshipRepository(friendshipService)
val storiesRepository = StoriesRepository(storiesService)
val mediaRepository = MediaRepository(mediaService)
val graphQLRepository = GraphQLRepository(graphQLService)
val viewModel = ProfileFragmentViewModel(
state,
userRepository,
friendshipRepository,
storiesRepository,
mediaRepository
mediaRepository,
graphQLRepository,
)
}
}