Fix flow listening in SettingsController

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-06-22 10:44:35 +02:00 committed by Andy Scherzinger
parent b9d2ca2517
commit f7786e1b93
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
2 changed files with 96 additions and 90 deletions

View File

@ -101,7 +101,9 @@ import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
@ -147,16 +149,13 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
get() =
resources!!.getString(R.string.nc_settings)
private fun getCurrentUser() {
scope.launch {
currentUserProvider.currentUser.collect {
Log.e(TAG, "User: $it")
this@SettingsController.currentUser = it
this@SettingsController.credentials =
private suspend fun getCurrentUser() {
val user = currentUserProvider.currentUser.first()
Log.e(TAG, "User: $user")
currentUser = user
credentials =
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token)
}
}
}
override fun onViewBound(view: View) {
super.onViewBound(view)
@ -164,6 +163,8 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
sharedApplication!!.componentApplication.inject(this)
ViewCompat.setTransitionName((binding.avatarImage), "userAvatar.transitionTag")
runBlocking {
getCurrentUser()
if (saveStateHandler == null) {
@ -202,6 +203,7 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
setupClientCertView()
}
}
private fun setupPhoneBookIntegration() {
scope.launch {
@ -484,6 +486,9 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
super.onAttach(view)
actionBar?.show()
dispose(null)
runBlocking {
getCurrentUser()
binding.settingsVersion.setOnClickListener {
@ -548,6 +553,7 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
)
}
}
}
private fun setupProxyTypeSettings() {
if (("No proxy" == appPreferences!!.proxyType) || appPreferences!!.proxyType == null) {

View File

@ -38,8 +38,8 @@ class PushConfigurationConverter {
}
@TypeConverter
fun fromStringToPushConfiguration(value: String): PushConfigurationState? {
if (value.isBlank()) {
fun fromStringToPushConfiguration(value: String?): PushConfigurationState? {
if (value.isNullOrBlank()) {
return null
}