|
@ -16,9 +16,12 @@ import awais.instagrabber.repositories.responses.User |
|
|
import awais.instagrabber.repositories.responses.UserProfileContextLink |
|
|
import awais.instagrabber.repositories.responses.UserProfileContextLink |
|
|
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient |
|
|
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient |
|
|
import awais.instagrabber.repositories.responses.stories.Story |
|
|
import awais.instagrabber.repositories.responses.stories.Story |
|
|
|
|
|
import awais.instagrabber.utils.Constants |
|
|
import awais.instagrabber.utils.ControlledRunner |
|
|
import awais.instagrabber.utils.ControlledRunner |
|
|
import awais.instagrabber.utils.Event |
|
|
import awais.instagrabber.utils.Event |
|
|
|
|
|
import awais.instagrabber.utils.getCsrfTokenFromCookie |
|
|
import awais.instagrabber.utils.SingleRunner |
|
|
import awais.instagrabber.utils.SingleRunner |
|
|
|
|
|
import awais.instagrabber.utils.Utils |
|
|
import awais.instagrabber.utils.extensions.TAG |
|
|
import awais.instagrabber.utils.extensions.TAG |
|
|
import awais.instagrabber.utils.extensions.isReallyPrivate |
|
|
import awais.instagrabber.utils.extensions.isReallyPrivate |
|
|
import awais.instagrabber.viewmodels.ProfileFragmentViewModel.ProfileAction.* |
|
|
import awais.instagrabber.viewmodels.ProfileFragmentViewModel.ProfileAction.* |
|
@ -31,18 +34,20 @@ import java.time.LocalDateTime |
|
|
|
|
|
|
|
|
class ProfileFragmentViewModel( |
|
|
class ProfileFragmentViewModel( |
|
|
private val state: SavedStateHandle, |
|
|
private val state: SavedStateHandle, |
|
|
private val csrfToken: String?, |
|
|
|
|
|
private val deviceUuid: String?, |
|
|
|
|
|
private val userRepository: UserRepository, |
|
|
|
|
|
private val friendshipRepository: FriendshipRepository, |
|
|
|
|
|
private val storiesRepository: StoriesRepository, |
|
|
|
|
|
private val mediaRepository: MediaRepository, |
|
|
|
|
|
private val graphQLRepository: GraphQLRepository, |
|
|
|
|
|
private val favoriteRepository: FavoriteRepository, |
|
|
|
|
|
private val directMessagesRepository: DirectMessagesRepository, |
|
|
|
|
|
|
|
|
private val favoriteRepository: FavoriteRepository?, |
|
|
private val messageManager: DirectMessagesManager?, |
|
|
private val messageManager: DirectMessagesManager?, |
|
|
ioDispatcher: CoroutineDispatcher, |
|
|
ioDispatcher: CoroutineDispatcher, |
|
|
) : ViewModel() { |
|
|
) : ViewModel() { |
|
|
|
|
|
private val cookie: String = Utils.settingsHelper.getString(Constants.COOKIE) |
|
|
|
|
|
private val csrfToken: String? = getCsrfTokenFromCookie(cookie) |
|
|
|
|
|
private val deviceUuid: String = Utils.settingsHelper.getString(Constants.DEVICE_UUID) |
|
|
|
|
|
private val userRepository: UserRepository by lazy { UserRepository.getInstance() } |
|
|
|
|
|
private val friendshipRepository: FriendshipRepository by lazy { FriendshipRepository.getInstance() } |
|
|
|
|
|
private val storiesRepository: StoriesRepository by lazy { StoriesRepository.getInstance() } |
|
|
|
|
|
private val mediaRepository: MediaRepository by lazy { MediaRepository.getInstance() } |
|
|
|
|
|
private val graphQLRepository: GraphQLRepository by lazy { GraphQLRepository.getInstance() } |
|
|
|
|
|
private val directMessagesRepository: DirectMessagesRepository by lazy { DirectMessagesRepository.getInstance() } |
|
|
|
|
|
|
|
|
private val _currentUser = MutableLiveData<Resource<User?>>(Resource.loading(null)) |
|
|
private val _currentUser = MutableLiveData<Resource<User?>>(Resource.loading(null)) |
|
|
private val _isFavorite = MutableLiveData(false) |
|
|
private val _isFavorite = MutableLiveData(false) |
|
|
private val profileAction = MutableLiveData(INIT) |
|
|
private val profileAction = MutableLiveData(INIT) |
|
@ -238,7 +243,7 @@ class ProfileFragmentViewModel( |
|
|
|
|
|
|
|
|
private suspend fun checkAndUpdateFavorite(fetchedUser: User) { |
|
|
private suspend fun checkAndUpdateFavorite(fetchedUser: User) { |
|
|
try { |
|
|
try { |
|
|
val favorite = favoriteRepository.getFavorite(fetchedUser.username, FavoriteType.USER) |
|
|
|
|
|
|
|
|
val favorite = favoriteRepository!!.getFavorite(fetchedUser.username, FavoriteType.USER) |
|
|
if (favorite == null) { |
|
|
if (favorite == null) { |
|
|
_isFavorite.postValue(false) |
|
|
_isFavorite.postValue(false) |
|
|
return |
|
|
return |
|
@ -286,7 +291,7 @@ class ProfileFragmentViewModel( |
|
|
viewModelScope.launch(Dispatchers.IO) { |
|
|
viewModelScope.launch(Dispatchers.IO) { |
|
|
toggleFavoriteControlledRunner.afterPrevious { |
|
|
toggleFavoriteControlledRunner.afterPrevious { |
|
|
try { |
|
|
try { |
|
|
val favorite = favoriteRepository.getFavorite(username, FavoriteType.USER) |
|
|
|
|
|
|
|
|
val favorite = favoriteRepository!!.getFavorite(username, FavoriteType.USER) |
|
|
if (favorite == null) { |
|
|
if (favorite == null) { |
|
|
// insert |
|
|
// insert |
|
|
favoriteRepository.insertOrUpdateFavorite( |
|
|
favoriteRepository.insertOrUpdateFavorite( |
|
@ -592,15 +597,7 @@ class ProfileFragmentViewModel( |
|
|
|
|
|
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
@Suppress("UNCHECKED_CAST") |
|
|
class ProfileFragmentViewModelFactory( |
|
|
class ProfileFragmentViewModelFactory( |
|
|
private val csrfToken: String?, |
|
|
|
|
|
private val deviceUuid: String?, |
|
|
|
|
|
private val userRepository: UserRepository, |
|
|
|
|
|
private val friendshipRepository: FriendshipRepository, |
|
|
|
|
|
private val storiesRepository: StoriesRepository, |
|
|
|
|
|
private val mediaRepository: MediaRepository, |
|
|
|
|
|
private val graphQLRepository: GraphQLRepository, |
|
|
|
|
|
private val favoriteRepository: FavoriteRepository, |
|
|
|
|
|
private val directMessagesRepository: DirectMessagesRepository, |
|
|
|
|
|
|
|
|
private val favoriteRepository: FavoriteRepository?, |
|
|
private val messageManager: DirectMessagesManager?, |
|
|
private val messageManager: DirectMessagesManager?, |
|
|
owner: SavedStateRegistryOwner, |
|
|
owner: SavedStateRegistryOwner, |
|
|
defaultArgs: Bundle? = null, |
|
|
defaultArgs: Bundle? = null, |
|
@ -612,15 +609,7 @@ class ProfileFragmentViewModelFactory( |
|
|
): T { |
|
|
): T { |
|
|
return ProfileFragmentViewModel( |
|
|
return ProfileFragmentViewModel( |
|
|
handle, |
|
|
handle, |
|
|
csrfToken, |
|
|
|
|
|
deviceUuid, |
|
|
|
|
|
userRepository, |
|
|
|
|
|
friendshipRepository, |
|
|
|
|
|
storiesRepository, |
|
|
|
|
|
mediaRepository, |
|
|
|
|
|
graphQLRepository, |
|
|
|
|
|
favoriteRepository, |
|
|
favoriteRepository, |
|
|
directMessagesRepository, |
|
|
|
|
|
messageManager, |
|
|
messageManager, |
|
|
Dispatchers.IO, |
|
|
Dispatchers.IO, |
|
|
) as T |
|
|
) as T |
|
|