|
@ -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 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |