mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-14 10:47:30 +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);
|
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||||
viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory(
|
viewModel = new ViewModelProvider(this, new ProfileFragmentViewModelFactory(
|
||||||
UserRepository.Companion.getInstance(),
|
UserRepository.Companion.getInstance(),
|
||||||
|
FriendshipRepository.Companion.getInstance(),
|
||||||
this,
|
this,
|
||||||
getArguments()
|
getArguments()
|
||||||
)).get(ProfileFragmentViewModel.class);
|
)).get(ProfileFragmentViewModel.class);
|
||||||
|
@ -6,11 +6,13 @@ import androidx.lifecycle.*
|
|||||||
import androidx.savedstate.SavedStateRegistryOwner
|
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.UserRepository
|
import awais.instagrabber.webservices.UserRepository
|
||||||
|
|
||||||
class ProfileFragmentViewModel(
|
class ProfileFragmentViewModel(
|
||||||
state: SavedStateHandle,
|
state: SavedStateHandle,
|
||||||
userRepository: UserRepository,
|
userRepository: UserRepository,
|
||||||
|
friendshipRepository: FriendshipRepository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val _profile = MutableLiveData<User?>()
|
private val _profile = MutableLiveData<User?>()
|
||||||
val profile: LiveData<User?> = _profile
|
val profile: LiveData<User?> = _profile
|
||||||
@ -22,13 +24,14 @@ class ProfileFragmentViewModel(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d(TAG, "${state.keys()} $userRepository")
|
Log.d(TAG, "${state.keys()} $userRepository $friendshipRepository")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
class ProfileFragmentViewModelFactory(
|
class ProfileFragmentViewModelFactory(
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
|
private val friendshipRepository: FriendshipRepository,
|
||||||
owner: SavedStateRegistryOwner,
|
owner: SavedStateRegistryOwner,
|
||||||
defaultArgs: Bundle? = null,
|
defaultArgs: Bundle? = null,
|
||||||
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
|
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
|
||||||
@ -37,6 +40,6 @@ class ProfileFragmentViewModelFactory(
|
|||||||
modelClass: Class<T>,
|
modelClass: Class<T>,
|
||||||
handle: SavedStateHandle,
|
handle: SavedStateHandle,
|
||||||
): T {
|
): 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.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.UserService
|
import awais.instagrabber.repositories.UserService
|
||||||
import awais.instagrabber.repositories.responses.FriendshipStatus
|
import awais.instagrabber.repositories.responses.*
|
||||||
import awais.instagrabber.repositories.responses.UserSearchResponse
|
import awais.instagrabber.webservices.FriendshipRepository
|
||||||
import awais.instagrabber.repositories.responses.WrappedUser
|
|
||||||
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
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
internal class ProfileFragmentViewModelTest {
|
internal class ProfileFragmentViewModelTest {
|
||||||
private val userService = object: UserService {
|
private val userService = object : UserService {
|
||||||
override suspend fun getUserInfo(uid: Long): WrappedUser {
|
override suspend fun getUserInfo(uid: Long): WrappedUser {
|
||||||
TODO("Not yet implemented")
|
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
|
@Test
|
||||||
fun testNoUsernameNoCurrentUser() {
|
fun testNoUsernameNoCurrentUser() {
|
||||||
val state = SavedStateHandle(mutableMapOf<String, Any>(
|
val state = SavedStateHandle(
|
||||||
|
mutableMapOf<String, Any>(
|
||||||
"username" to ""
|
"username" to ""
|
||||||
))
|
)
|
||||||
|
)
|
||||||
val userRepository = UserRepository(userService)
|
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