From cc24c81b0d49ccfa6e6d1135b252732760d987e5 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 16 Jan 2020 20:13:57 +0100 Subject: [PATCH] Adjust account creation Signed-off-by: Mario Danic --- .../account/loginentry/LoginEntryViewModel.kt | 76 ++++++++----------- .../features/contactsflow/ContactsView.kt | 9 +++ .../contactsflow/ContactsViewModel.kt | 5 ++ .../contactsflow/ContactsViewModelFactory.kt | 5 ++ .../talk/newarch/mvvm/BaseViewModel.kt | 6 +- 5 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsView.kt create mode 100644 app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModel.kt create mode 100644 app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModelFactory.kt diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryViewModel.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryViewModel.kt index fa38f823f..4773ca95e 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryViewModel.kt @@ -41,7 +41,7 @@ class LoginEntryViewModel constructor( private var updatingUser = false fun parseData(prefix: String, separator: String, data: String?) { - viewModelScope.launch { + ioScope.launch { if (data?.startsWith(prefix) == false) { state.postValue(LoginEntryStateWrapper(LoginEntryState.FAILED, LoginEntryStateClarification.INVALID_PARSED_DATA)) return@launch @@ -113,7 +113,7 @@ class LoginEntryViewModel constructor( user.username = loginData.username!! user.baseUrl = loginData.serverUrl!! user.token = loginData.token - getProfileUseCase.invoke(viewModelScope, parametersOf(user), object : UseCaseResponse { + getProfileUseCase.invoke(ioScope, parametersOf(user), object : UseCaseResponse { override suspend fun onSuccess(result: UserProfileOverall) { result.ocs.data.userId?.let { userId -> user.displayName = result.ocs.data.displayName @@ -131,7 +131,7 @@ class LoginEntryViewModel constructor( } private suspend fun getCapabilities() { - getCapabilitiesUseCase.invoke(viewModelScope, parametersOf(user.baseUrl), object : UseCaseResponse { + getCapabilitiesUseCase.invoke(ioScope, parametersOf(user.baseUrl), object : UseCaseResponse { override suspend fun onSuccess(result: CapabilitiesOverall) { user.capabilities = result.ocs.data.capabilities getSignalingSettings() @@ -144,17 +144,15 @@ class LoginEntryViewModel constructor( } private suspend fun getSignalingSettings() { - getSignalingSettingsUseCase.invoke(viewModelScope, parametersOf(user), object : UseCaseResponse { + getSignalingSettingsUseCase.invoke(ioScope, parametersOf(user), object : UseCaseResponse { override suspend fun onSuccess(result: SignalingSettingsOverall) { - withContext(Dispatchers.IO) { - user.signalingSettings = result.ocs.signalingSettings - val pushConfiguration = PushConfiguration() - val pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PENDING, 0) - pushConfiguration.pushConfigurationStateWrapper = pushConfigurationStateWrapper - usersRepository.insertUser(user) - setAdjustedUserAsActive() - registerForPush() - } + user.signalingSettings = result.ocs.signalingSettings + val pushConfiguration = PushConfiguration() + val pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PENDING, 0) + pushConfiguration.pushConfigurationStateWrapper = pushConfigurationStateWrapper + usersRepository.insertUser(user) + setAdjustedUserAsActive() + registerForPush() } override suspend fun onError(errorModel: ErrorModel?) { @@ -166,11 +164,9 @@ class LoginEntryViewModel constructor( private suspend fun registerForPush() { val token = appPreferences.pushToken if (!token.isNullOrBlank()) { - withContext(Dispatchers.IO) { - user.pushConfiguration?.pushToken = token - usersRepository.updateUser(user) - registerForPushWithServer(token) - } + user.pushConfiguration?.pushToken = token + usersRepository.updateUser(user) + registerForPushWithServer(token) } else { state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_MISSING_TOKEN)) } @@ -178,25 +174,21 @@ class LoginEntryViewModel constructor( private suspend fun registerForPushWithServer(token: String) { val options = PushUtils(usersRepository).getMapForPushRegistrationWithServer(context, token) - registerPushWithServerUseCase.invoke(viewModelScope, parametersOf(user, options), object : UseCaseResponse { + registerPushWithServerUseCase.invoke(ioScope, parametersOf(user, options), object : UseCaseResponse { override suspend fun onSuccess(result: PushRegistrationOverall) { - withContext(Dispatchers.IO) { - user.pushConfiguration?.deviceIdentifier = result.ocs.data.deviceIdentifier - user.pushConfiguration?.deviceIdentifierSignature = result.ocs.data.signature - user.pushConfiguration?.userPublicKey = result.ocs.data.publicKey - user.pushConfiguration?.pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.SERVER_REGISTRATION_DONE, null) - usersRepository.updateUser(user) - registerForPushWithProxy() - } + user.pushConfiguration?.deviceIdentifier = result.ocs.data.deviceIdentifier + user.pushConfiguration?.deviceIdentifierSignature = result.ocs.data.signature + user.pushConfiguration?.userPublicKey = result.ocs.data.publicKey + user.pushConfiguration?.pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.SERVER_REGISTRATION_DONE, null) + usersRepository.updateUser(user) + registerForPushWithProxy() } override suspend fun onError(errorModel: ErrorModel?) { - withContext(Dispatchers.IO) { - user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_SERVER_REGISTRATION - user.pushConfiguration?.pushConfigurationStateWrapper?.reason = errorModel?.code - usersRepository.updateUser(user) - state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_SERVER_FAILED)) - } + user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_SERVER_REGISTRATION + user.pushConfiguration?.pushConfigurationStateWrapper?.reason = errorModel?.code + usersRepository.updateUser(user) + state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_SERVER_FAILED)) } }) } @@ -205,13 +197,11 @@ class LoginEntryViewModel constructor( val options = PushUtils(usersRepository).getMapForPushRegistrationWithServer(user) if (options != null) { - registerPushWithProxyUseCase.invoke(viewModelScope, parametersOf(user, options), object : UseCaseResponse { + registerPushWithProxyUseCase.invoke(ioScope, parametersOf(user, options), object : UseCaseResponse { override suspend fun onSuccess(result: Any) { - withContext(Dispatchers.IO) { - user.pushConfiguration?.pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PROXY_REGISTRATION_DONE, null) - usersRepository.updateUser(user) - state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, if (!updatingUser) LoginEntryStateClarification.ACCOUNT_CREATED else LoginEntryStateClarification.ACCOUNT_UPDATED)) - } + user.pushConfiguration?.pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PROXY_REGISTRATION_DONE, null) + usersRepository.updateUser(user) + state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, if (!updatingUser) LoginEntryStateClarification.ACCOUNT_CREATED else LoginEntryStateClarification.ACCOUNT_UPDATED)) } override suspend fun onError(errorModel: ErrorModel?) { @@ -225,11 +215,9 @@ class LoginEntryViewModel constructor( } }) } else { - withContext(Dispatchers.IO) { - user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_PROXY_REGISTRATION - usersRepository.updateUser(user) - state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_PUSH_PROXY_FAILED)) - } + user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_PROXY_REGISTRATION + usersRepository.updateUser(user) + state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_PUSH_PROXY_FAILED)) } } diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsView.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsView.kt new file mode 100644 index 000000000..4979b50c8 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsView.kt @@ -0,0 +1,9 @@ +package com.nextcloud.talk.newarch.features.contactsflow + +import com.nextcloud.talk.newarch.conversationsList.mvp.BaseView + +class ContactsView : BaseView() { + override fun getLayoutId(): Int { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModel.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModel.kt new file mode 100644 index 000000000..71a9e6e27 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModel.kt @@ -0,0 +1,5 @@ +package com.nextcloud.talk.newarch.features.contactsflow + +class ContactsViewModel { + +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModelFactory.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModelFactory.kt new file mode 100644 index 000000000..f931f8b64 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/contactsflow/ContactsViewModelFactory.kt @@ -0,0 +1,5 @@ +package com.nextcloud.talk.newarch.features.contactsflow + +class ContactsViewModelFactory { + +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/newarch/mvvm/BaseViewModel.kt b/app/src/main/java/com/nextcloud/talk/newarch/mvvm/BaseViewModel.kt index 724f40f86..d7c701b43 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/mvvm/BaseViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/mvvm/BaseViewModel.kt @@ -40,14 +40,14 @@ abstract class BaseViewModel(application: Application) : AndroidVi Job() + Dispatchers.Main ) - val backgroundScope = CoroutineScope( - Job() + val ioScope = CoroutineScope( + Job() + Dispatchers.IO ) override fun onCleared() { super.onCleared() disposables.clear() uiScope.cancel() - backgroundScope.cancel() + ioScope.cancel() } } \ No newline at end of file