Show current user in the settings and extract code in CurrentUserProvider.
This commit is contained in:
parent
b4a5128a05
commit
e1b528e861
12 changed files with 226 additions and 69 deletions
|
|
@ -17,23 +17,38 @@
|
|||
package io.element.android.features.preferences.impl.root
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import io.element.android.features.analytics.api.preferences.AnalyticsPreferencesPresenter
|
||||
import io.element.android.features.logout.api.LogoutPreferencePresenter
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesPresenter
|
||||
import io.element.android.libraries.architecture.Async
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.matrix.api.user.CurrentUserProvider
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
class PreferencesRootPresenter @Inject constructor(
|
||||
private val logoutPresenter: LogoutPreferencePresenter,
|
||||
private val rageshakePresenter: RageshakePreferencesPresenter,
|
||||
private val analyticsPresenter: AnalyticsPreferencesPresenter,
|
||||
private val currentUserProvider: CurrentUserProvider,
|
||||
private val buildType: BuildType,
|
||||
) : Presenter<PreferencesRootState> {
|
||||
|
||||
@Composable
|
||||
override fun present(): PreferencesRootState {
|
||||
val matrixUser: MutableState<MatrixUser?> = rememberSaveable {
|
||||
mutableStateOf(null)
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
initialLoad(matrixUser)
|
||||
}
|
||||
|
||||
val logoutState = logoutPresenter.present()
|
||||
val rageshakeState = rageshakePresenter.present()
|
||||
val analyticsState = analyticsPresenter.present()
|
||||
|
|
@ -42,8 +57,12 @@ class PreferencesRootPresenter @Inject constructor(
|
|||
logoutState = logoutState,
|
||||
rageshakeState = rageshakeState,
|
||||
analyticsState = analyticsState,
|
||||
myUser = Async.Uninitialized,
|
||||
myUser = matrixUser.value,
|
||||
showDeveloperSettings = showDeveloperSettings
|
||||
)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.initialLoad(matrixUser: MutableState<MatrixUser?>) = launch {
|
||||
matrixUser.value = currentUserProvider.provide()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,12 @@ package io.element.android.features.preferences.impl.root
|
|||
import io.element.android.features.analytics.api.preferences.AnalyticsPreferencesState
|
||||
import io.element.android.features.logout.api.LogoutPreferenceState
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesState
|
||||
import io.element.android.libraries.architecture.Async
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
|
||||
data class PreferencesRootState(
|
||||
val logoutState: LogoutPreferenceState,
|
||||
val rageshakeState: RageshakePreferencesState,
|
||||
val analyticsState: AnalyticsPreferencesState,
|
||||
val myUser: Async<MatrixUser>,
|
||||
val myUser: MatrixUser?,
|
||||
val showDeveloperSettings: Boolean
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,12 +19,11 @@ package io.element.android.features.preferences.impl.root
|
|||
import io.element.android.features.analytics.api.preferences.aAnalyticsPreferencesState
|
||||
import io.element.android.features.logout.api.aLogoutPreferenceState
|
||||
import io.element.android.features.rageshake.api.preferences.aRageshakePreferencesState
|
||||
import io.element.android.libraries.architecture.Async
|
||||
|
||||
fun aPreferencesRootState() = PreferencesRootState(
|
||||
logoutState = aLogoutPreferenceState(),
|
||||
rageshakeState = aRageshakePreferencesState(),
|
||||
analyticsState = aAnalyticsPreferencesState(),
|
||||
myUser = Async.Uninitialized,
|
||||
myUser = null,
|
||||
showDeveloperSettings = true
|
||||
)
|
||||
|
|
|
|||
|
|
@ -92,5 +92,5 @@ fun PreferencesRootViewDarkPreview(@PreviewParameter(MatrixUserProvider::class)
|
|||
|
||||
@Composable
|
||||
private fun ContentToPreview(matrixUser: MatrixUser) {
|
||||
PreferencesRootView(aPreferencesRootState().copy(myUser = Async.Success(matrixUser)))
|
||||
PreferencesRootView(aPreferencesRootState().copy(myUser = matrixUser))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,10 @@
|
|||
|
||||
package io.element.android.features.preferences.impl.user
|
||||
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.architecture.Async
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
|
|
@ -32,16 +28,13 @@ import io.element.android.libraries.matrix.ui.components.MatrixUserWithNullProvi
|
|||
|
||||
@Composable
|
||||
fun UserPreferences(
|
||||
user: Async<MatrixUser>,
|
||||
user: MatrixUser?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
when (val userData = user.dataOrNull()) {
|
||||
null -> Spacer(modifier = modifier.height(1.dp))
|
||||
else -> MatrixUserHeader(
|
||||
modifier = modifier,
|
||||
matrixUser = userData
|
||||
)
|
||||
}
|
||||
MatrixUserHeader(
|
||||
modifier = modifier,
|
||||
matrixUser = user
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
|
|
@ -56,9 +49,5 @@ internal fun UserPreferencesDarkPreview(@PreviewParameter(MatrixUserWithNullProv
|
|||
|
||||
@Composable
|
||||
private fun ContentToPreview(matrixUser: MatrixUser?) {
|
||||
if (matrixUser == null) {
|
||||
UserPreferences(Async.Uninitialized)
|
||||
} else {
|
||||
UserPreferences(Async.Success(matrixUser))
|
||||
}
|
||||
UserPreferences(matrixUser)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue