diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt index eeb241ec4..43d9b3d8f 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt @@ -85,6 +85,19 @@ abstract class BaseController : ButterKnifeController(), ComponentCallbacks { return floatingActionButton } + protected val appBar: AppBarLayout? + get() { + var appBarLayout: AppBarLayout? = null + activity?.let { + if (it is MainActivity) { + appBarLayout = it.appBar + } + } + + return appBarLayout + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { diff --git a/app/src/main/java/com/nextcloud/talk/newarch/data/repository/online/NextcloudTalkRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/newarch/data/repository/online/NextcloudTalkRepositoryImpl.kt index 1d5d64e37..1964ac9c0 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/data/repository/online/NextcloudTalkRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/data/repository/online/NextcloudTalkRepositoryImpl.kt @@ -98,7 +98,7 @@ class NextcloudTalkRepositoryImpl(private val apiService: ApiService) : Nextclou } override suspend fun registerPushWithProxyForUser(user: UserNgEntity, options: Map): Any { - return apiService.unregisterForPushWithProxy(ApiUtils.getUrlPushProxy(), options) + return apiService.registerForPushWithProxy(ApiUtils.getUrlPushProxy(), options) } override suspend fun unregisterPushWithProxyForUser(user: UserNgEntity, options: Map): Any { diff --git a/app/src/main/java/com/nextcloud/talk/newarch/data/source/remote/ApiService.kt b/app/src/main/java/com/nextcloud/talk/newarch/data/source/remote/ApiService.kt index eda04c26a..a93ecb2d0 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/data/source/remote/ApiService.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/data/source/remote/ApiService.kt @@ -27,7 +27,6 @@ import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.push.PushRegistrationOverall import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall import com.nextcloud.talk.models.json.userprofile.UserProfileOverall -import io.reactivex.Observable import retrofit2.http.* interface ApiService { diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryView.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryView.kt index acb88aa03..e1d52d1e1 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryView.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/account/loginentry/LoginEntryView.kt @@ -65,10 +65,12 @@ class LoginEntryView(val bundle: Bundle) : BaseView() { @SuppressLint("SetJavaScriptEnabled") override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { - actionBar?.hide() viewModel = viewModelProvider(factory).get(LoginEntryViewModel::class.java) val view = super.onCreateView(inflater, container) + appBar?.isVisible = false + actionBar?.hide() + assembledPrefix = resources?.getString(R.string.nc_talk_login_scheme) + protocolSuffix + "login/" viewModel.state.observe(this@LoginEntryView, Observer { 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 357a9803b..fa38f823f 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 @@ -19,7 +19,9 @@ import com.nextcloud.talk.newarch.domain.usecases.base.UseCaseResponse import com.nextcloud.talk.newarch.local.models.UserNgEntity import com.nextcloud.talk.utils.PushUtils import com.nextcloud.talk.utils.preferences.AppPreferences +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.koin.core.parameter.parametersOf import java.net.URLDecoder @@ -107,7 +109,7 @@ class LoginEntryViewModel constructor( } } - private fun getProfile(loginData: LoginData) { + private suspend fun getProfile(loginData: LoginData) { user.username = loginData.username!! user.baseUrl = loginData.serverUrl!! user.token = loginData.token @@ -128,7 +130,7 @@ class LoginEntryViewModel constructor( }) } - private fun getCapabilities() { + private suspend fun getCapabilities() { getCapabilitiesUseCase.invoke(viewModelScope, parametersOf(user.baseUrl), object : UseCaseResponse { override suspend fun onSuccess(result: CapabilitiesOverall) { user.capabilities = result.ocs.data.capabilities @@ -141,15 +143,18 @@ class LoginEntryViewModel constructor( }) } - private fun getSignalingSettings() { + private suspend fun getSignalingSettings() { getSignalingSettingsUseCase.invoke(viewModelScope, parametersOf(user), object : UseCaseResponse { override suspend fun onSuccess(result: SignalingSettingsOverall) { - user.signalingSettings = result.ocs.signalingSettings - val pushConfiguration = PushConfiguration() - val pushConfigurationStateWrapper = PushConfigurationStateWrapper(PushConfigurationState.PENDING, 0) - pushConfiguration.pushConfigurationStateWrapper = pushConfigurationStateWrapper - usersRepository.insertUser(user) - registerForPush() + 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() + } } override suspend fun onError(errorModel: ErrorModel?) { @@ -161,31 +166,37 @@ class LoginEntryViewModel constructor( private suspend fun registerForPush() { val token = appPreferences.pushToken if (!token.isNullOrBlank()) { - user.pushConfiguration?.pushToken = token - usersRepository.updateUser(user) - registerForPushWithServer(token) + withContext(Dispatchers.IO) { + user.pushConfiguration?.pushToken = token + usersRepository.updateUser(user) + registerForPushWithServer(token) + } } else { state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_MISSING_TOKEN)) } } - private fun registerForPushWithServer(token: String) { + private suspend fun registerForPushWithServer(token: String) { val options = PushUtils(usersRepository).getMapForPushRegistrationWithServer(context, token) registerPushWithServerUseCase.invoke(viewModelScope, parametersOf(user, options), object : UseCaseResponse { override suspend fun onSuccess(result: PushRegistrationOverall) { - 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() + 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() + } } override suspend fun onError(errorModel: ErrorModel?) { - 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)) + 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)) + } } }) } @@ -196,22 +207,29 @@ class LoginEntryViewModel constructor( if (options != null) { registerPushWithProxyUseCase.invoke(viewModelScope, parametersOf(user, options), object : UseCaseResponse { override suspend fun onSuccess(result: Any) { - 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)) + 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)) + } } override suspend fun onError(errorModel: ErrorModel?) { - user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_PROXY_REGISTRATION - user.pushConfiguration?.pushConfigurationStateWrapper?.reason = errorModel?.code - usersRepository.updateUser(user) - state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_PUSH_PROXY_FAILED)) + withContext(Dispatchers.IO) { + user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_PROXY_REGISTRATION + user.pushConfiguration?.pushConfigurationStateWrapper?.reason = errorModel?.code + usersRepository.updateUser(user) + setAdjustedUserAsActive() + state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_PUSH_PROXY_FAILED)) + } } }) } else { - user.pushConfiguration?.pushConfigurationStateWrapper?.pushConfigurationState = PushConfigurationState.FAILED_WITH_PROXY_REGISTRATION - usersRepository.updateUser(user) - state.postValue(LoginEntryStateWrapper(LoginEntryState.OK, LoginEntryStateClarification.PUSH_REGISTRATION_WITH_PUSH_PROXY_FAILED)) + 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)) + } } } diff --git a/app/src/main/java/com/nextcloud/talk/newarch/features/account/serverentry/ServerEntryView.kt b/app/src/main/java/com/nextcloud/talk/newarch/features/account/serverentry/ServerEntryView.kt index 4cf59cc9e..a515e6e2c 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/features/account/serverentry/ServerEntryView.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/features/account/serverentry/ServerEntryView.kt @@ -48,10 +48,12 @@ class ServerEntryView : BaseView() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { - actionBar?.hide() viewModel = viewModelProvider(factory).get(ServerEntryViewModel::class.java) val view = super.onCreateView(inflater, container) + appBar?.isVisible = false + actionBar?.hide() + view.serverEntryTextInputEditText.setCompoundDrawablesWithIntrinsicBounds(null, null, resources?.getDrawable(R.drawable.ic_arrow_forward_white_24px), null) view.serverEntryTextInputEditText.compoundDrawables[2].alpha = 99 diff --git a/app/src/main/java/com/nextcloud/talk/newarch/local/converters/PushConfigurationConverter.kt b/app/src/main/java/com/nextcloud/talk/newarch/local/converters/PushConfigurationConverter.kt index e8d91b009..021c6acfa 100644 --- a/app/src/main/java/com/nextcloud/talk/newarch/local/converters/PushConfigurationConverter.kt +++ b/app/src/main/java/com/nextcloud/talk/newarch/local/converters/PushConfigurationConverter.kt @@ -41,6 +41,10 @@ class PushConfigurationConverter { @TypeConverter fun fromStringToPushConfiguration(value: String): PushConfiguration? { + if (value.isNullOrBlank()) { + return null + } + return json.parse(PushConfiguration.serializer(), value) } }