mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
Add FriendshipRepository to ProfileFragmentViewModel constructor
This commit is contained in:
parent
e1532eb4b8
commit
8f218b9515
@ -346,6 +346,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||
viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory(
|
||||
UserRepository.Companion.getInstance(),
|
||||
FriendshipRepository.Companion.getInstance(),
|
||||
this,
|
||||
getArguments()
|
||||
)).get(ProfileFragmentViewModel.class);
|
||||
|
@ -6,11 +6,13 @@ 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.UserRepository
|
||||
|
||||
class ProfileFragmentViewModel(
|
||||
state: SavedStateHandle,
|
||||
userRepository: UserRepository,
|
||||
friendshipRepository: FriendshipRepository,
|
||||
) : ViewModel() {
|
||||
private val _profile = MutableLiveData<User?>()
|
||||
val profile: LiveData<User?> = _profile
|
||||
@ -22,13 +24,14 @@ class ProfileFragmentViewModel(
|
||||
private set
|
||||
|
||||
init {
|
||||
Log.d(TAG, "${state.keys()} $userRepository")
|
||||
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class ProfileFragmentViewModelFactory(
|
||||
private val userRepository: UserRepository,
|
||||
private val friendshipRepository: FriendshipRepository,
|
||||
owner: SavedStateRegistryOwner,
|
||||
defaultArgs: Bundle? = null,
|
||||
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
|
||||
@ -37,6 +40,6 @@ class ProfileFragmentViewModelFactory(
|
||||
modelClass: Class<T>,
|
||||
handle: SavedStateHandle,
|
||||
): T {
|
||||
return ProfileFragmentViewModel(handle, userRepository) as T
|
||||
return ProfileFragmentViewModel(handle, userRepository, friendshipRepository) as T
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,17 @@ package awais.instagrabber.viewmodels
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import awais.instagrabber.repositories.FriendshipService
|
||||
import awais.instagrabber.repositories.UserService
|
||||
import awais.instagrabber.repositories.responses.FriendshipStatus
|
||||
import awais.instagrabber.repositories.responses.UserSearchResponse
|
||||
import awais.instagrabber.repositories.responses.WrappedUser
|
||||
import awais.instagrabber.repositories.responses.*
|
||||
import awais.instagrabber.webservices.FriendshipRepository
|
||||
import awais.instagrabber.webservices.UserRepository
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
internal class ProfileFragmentViewModelTest {
|
||||
private val userService = object: UserService {
|
||||
private val userService = object : UserService {
|
||||
override suspend fun getUserInfo(uid: Long): WrappedUser {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
@ -30,12 +30,33 @@ internal class ProfileFragmentViewModelTest {
|
||||
}
|
||||
}
|
||||
|
||||
private val friendshipService = object : FriendshipService {
|
||||
override suspend fun change(action: String, id: Long, form: Map<String, String>): FriendshipChangeResponse {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun toggleRestrict(action: String, form: Map<String, String>): FriendshipRestrictResponse {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getList(userId: Long, type: String, queryParams: Map<String, String>): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun changeMute(action: String, form: Map<String, String>): FriendshipChangeResponse {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoUsernameNoCurrentUser() {
|
||||
val state = SavedStateHandle(mutableMapOf<String, Any>(
|
||||
"username" to ""
|
||||
))
|
||||
val state = SavedStateHandle(
|
||||
mutableMapOf<String, Any>(
|
||||
"username" to ""
|
||||
)
|
||||
)
|
||||
val userRepository = UserRepository(userService)
|
||||
val viewModel = ProfileFragmentViewModel(state, userRepository)
|
||||
val friendshipRepository = FriendshipRepository(friendshipService)
|
||||
val viewModel = ProfileFragmentViewModel(state, userRepository, friendshipRepository)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user