mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Add StoriesRepository to ProfileFragmentViewModel constructor
This commit is contained in:
parent
3d69148d9b
commit
02cb1f5db5
@ -347,6 +347,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory(
|
viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory(
|
||||||
UserRepository.Companion.getInstance(),
|
UserRepository.Companion.getInstance(),
|
||||||
FriendshipRepository.Companion.getInstance(),
|
FriendshipRepository.Companion.getInstance(),
|
||||||
|
StoriesRepository.Companion.getInstance(),
|
||||||
this,
|
this,
|
||||||
getArguments()
|
getArguments()
|
||||||
)).get(ProfileFragmentViewModel.class);
|
)).get(ProfileFragmentViewModel.class);
|
||||||
|
@ -7,12 +7,14 @@ import androidx.savedstate.SavedStateRegistryOwner
|
|||||||
import awais.instagrabber.repositories.responses.User
|
import awais.instagrabber.repositories.responses.User
|
||||||
import awais.instagrabber.utils.extensions.TAG
|
import awais.instagrabber.utils.extensions.TAG
|
||||||
import awais.instagrabber.webservices.FriendshipRepository
|
import awais.instagrabber.webservices.FriendshipRepository
|
||||||
|
import awais.instagrabber.webservices.StoriesRepository
|
||||||
import awais.instagrabber.webservices.UserRepository
|
import awais.instagrabber.webservices.UserRepository
|
||||||
|
|
||||||
class ProfileFragmentViewModel(
|
class ProfileFragmentViewModel(
|
||||||
state: SavedStateHandle,
|
state: SavedStateHandle,
|
||||||
userRepository: UserRepository,
|
userRepository: UserRepository,
|
||||||
friendshipRepository: FriendshipRepository,
|
friendshipRepository: FriendshipRepository,
|
||||||
|
storiesRepository: StoriesRepository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val _profile = MutableLiveData<User?>()
|
private val _profile = MutableLiveData<User?>()
|
||||||
val profile: LiveData<User?> = _profile
|
val profile: LiveData<User?> = _profile
|
||||||
@ -24,7 +26,7 @@ class ProfileFragmentViewModel(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository")
|
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository $storiesRepository")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ class ProfileFragmentViewModel(
|
|||||||
class ProfileFragmentViewModelFactory(
|
class ProfileFragmentViewModelFactory(
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
private val friendshipRepository: FriendshipRepository,
|
private val friendshipRepository: FriendshipRepository,
|
||||||
|
private val storiesRepository: StoriesRepository,
|
||||||
owner: SavedStateRegistryOwner,
|
owner: SavedStateRegistryOwner,
|
||||||
defaultArgs: Bundle? = null,
|
defaultArgs: Bundle? = null,
|
||||||
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
|
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
|
||||||
@ -40,6 +43,11 @@ class ProfileFragmentViewModelFactory(
|
|||||||
modelClass: Class<T>,
|
modelClass: Class<T>,
|
||||||
handle: SavedStateHandle,
|
handle: SavedStateHandle,
|
||||||
): T {
|
): T {
|
||||||
return ProfileFragmentViewModel(handle, userRepository, friendshipRepository) as T
|
return ProfileFragmentViewModel(
|
||||||
|
handle,
|
||||||
|
userRepository,
|
||||||
|
friendshipRepository,
|
||||||
|
storiesRepository
|
||||||
|
) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@ package awais.instagrabber.viewmodels
|
|||||||
import androidx.lifecycle.SavedStateHandle
|
import androidx.lifecycle.SavedStateHandle
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import awais.instagrabber.repositories.FriendshipService
|
import awais.instagrabber.repositories.FriendshipService
|
||||||
|
import awais.instagrabber.repositories.StoriesService
|
||||||
import awais.instagrabber.repositories.UserService
|
import awais.instagrabber.repositories.UserService
|
||||||
import awais.instagrabber.repositories.responses.*
|
import awais.instagrabber.repositories.responses.*
|
||||||
import awais.instagrabber.webservices.FriendshipRepository
|
import awais.instagrabber.webservices.FriendshipRepository
|
||||||
|
import awais.instagrabber.webservices.StoriesRepository
|
||||||
import awais.instagrabber.webservices.UserRepository
|
import awais.instagrabber.webservices.UserRepository
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
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
|
@Test
|
||||||
fun testNoUsernameNoCurrentUser() {
|
fun testNoUsernameNoCurrentUser() {
|
||||||
val state = SavedStateHandle(
|
val state = SavedStateHandle(
|
||||||
@ -57,6 +89,7 @@ internal class ProfileFragmentViewModelTest {
|
|||||||
)
|
)
|
||||||
val userRepository = UserRepository(userService)
|
val userRepository = UserRepository(userService)
|
||||||
val friendshipRepository = FriendshipRepository(friendshipService)
|
val friendshipRepository = FriendshipRepository(friendshipService)
|
||||||
val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository)
|
val storiesRepository = StoriesRepository(storiesService)
|
||||||
|
val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository, storiesRepository)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user