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

View File

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