1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

Add MediaRepository to ProfileFragmentViewModel constructor

This commit is contained in:
Ammar Githam 2021-06-12 10:07:31 +09:00
parent 58e0863de5
commit 2a0295e325
3 changed files with 52 additions and 4 deletions

View File

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

View File

@ -7,6 +7,7 @@ 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
@ -15,6 +16,7 @@ class ProfileFragmentViewModel(
userRepository: UserRepository,
friendshipRepository: FriendshipRepository,
storiesRepository: StoriesRepository,
mediaRepository: MediaRepository,
) : ViewModel() {
private val _profile = MutableLiveData<User?>()
val profile: LiveData<User?> = _profile
@ -26,7 +28,7 @@ class ProfileFragmentViewModel(
private set
init {
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository")
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository $mediaRepository")
}
}
@ -35,6 +37,7 @@ class ProfileFragmentViewModelFactory(
private val userRepository: UserRepository,
private val friendshipRepository: FriendshipRepository,
private val storiesRepository: StoriesRepository,
private val mediaRepository: MediaRepository,
owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null,
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@ -47,7 +50,8 @@ class ProfileFragmentViewModelFactory(
handle,
userRepository,
friendshipRepository,
storiesRepository
storiesRepository,
mediaRepository,
) as T
}
}

View File

@ -3,10 +3,12 @@ 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.responses.*
import awais.instagrabber.webservices.FriendshipRepository
import awais.instagrabber.webservices.MediaRepository
import awais.instagrabber.webservices.StoriesRepository
import awais.instagrabber.webservices.UserRepository
import org.junit.Test
@ -50,7 +52,7 @@ internal class ProfileFragmentViewModelTest {
}
}
private val storiesService = object: StoriesService {
private val storiesService = object : StoriesService {
override suspend fun fetch(mediaId: Long): String {
TODO("Not yet implemented")
}
@ -80,6 +82,40 @@ internal class ProfileFragmentViewModelTest {
}
}
private val mediaService = object : MediaService {
override suspend fun fetch(mediaId: Long): MediaInfoResponse {
TODO("Not yet implemented")
}
override suspend fun fetchLikes(mediaId: String, action: String): LikersResponse {
TODO("Not yet implemented")
}
override suspend fun action(action: String, mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun editCaption(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun translate(form: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun uploadFinish(retryContext: String, queryParams: Map<String, String>, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun delete(mediaId: String, mediaType: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
override suspend fun archive(mediaId: String, signedForm: Map<String, String>): String {
TODO("Not yet implemented")
}
}
@Test
fun testNoUsernameNoCurrentUser() {
val state = SavedStateHandle(
@ -90,6 +126,13 @@ internal class ProfileFragmentViewModelTest {
val userRepository = UserRepository(userService)
val friendshipRepository = FriendshipRepository(friendshipService)
val storiesRepository = StoriesRepository(storiesService)
val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository, storiesRepository)
val mediaRepository = MediaRepository(mediaService)
val viewModel = ProfileFragmentViewModel(
state,
userRepository,
friendshipRepository,
storiesRepository,
mediaRepository
)
}
}