Hide blocked users list when there are no blocked users (#2504)

This commit is contained in:
Jorge Martin Espinosa 2024-03-07 17:14:44 +01:00 committed by GitHub
parent 148e7c2241
commit b07ec3e681
5 changed files with 20 additions and 5 deletions

1
changelog.d/2198.bugfix Normal file
View file

@ -0,0 +1 @@
Hide blocked users list when there are no blocked users.

View file

@ -22,6 +22,7 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import io.element.android.features.logout.api.direct.DirectLogoutPresenter import io.element.android.features.logout.api.direct.DirectLogoutPresenter
@ -39,6 +40,8 @@ import io.element.android.libraries.matrix.api.user.getCurrentUser
import io.element.android.libraries.matrix.api.verification.SessionVerificationService import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import io.element.android.services.analytics.api.AnalyticsService import io.element.android.services.analytics.api.AnalyticsService
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@ -86,6 +89,12 @@ class PreferencesRootPresenter @Inject constructor(
mutableStateOf(null) mutableStateOf(null)
} }
val showBlockedUsersItem by produceState(initialValue = false) {
matrixClient.ignoredUsersFlow
.onEach { value = it.isNotEmpty() }
.launchIn(this)
}
val directLogoutState = directLogoutPresenter.present() val directLogoutState = directLogoutPresenter.present()
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
@ -106,6 +115,7 @@ class PreferencesRootPresenter @Inject constructor(
showDeveloperSettings = showDeveloperSettings, showDeveloperSettings = showDeveloperSettings,
showNotificationSettings = showNotificationSettings.value, showNotificationSettings = showNotificationSettings.value,
showLockScreenSettings = showLockScreenSettings.value, showLockScreenSettings = showLockScreenSettings.value,
showBlockedUsersItem = showBlockedUsersItem,
directLogoutState = directLogoutState, directLogoutState = directLogoutState,
snackbarMessage = snackbarMessage, snackbarMessage = snackbarMessage,
) )

View file

@ -33,6 +33,7 @@ data class PreferencesRootState(
val showDeveloperSettings: Boolean, val showDeveloperSettings: Boolean,
val showLockScreenSettings: Boolean, val showLockScreenSettings: Boolean,
val showNotificationSettings: Boolean, val showNotificationSettings: Boolean,
val showBlockedUsersItem: Boolean,
val directLogoutState: DirectLogoutState, val directLogoutState: DirectLogoutState,
val snackbarMessage: SnackbarMessage?, val snackbarMessage: SnackbarMessage?,
) )

View file

@ -33,6 +33,7 @@ fun aPreferencesRootState() = PreferencesRootState(
showDeveloperSettings = true, showDeveloperSettings = true,
showNotificationSettings = true, showNotificationSettings = true,
showLockScreenSettings = true, showLockScreenSettings = true,
showBlockedUsersItem = true,
snackbarMessage = SnackbarMessage(CommonStrings.common_verification_complete), snackbarMessage = SnackbarMessage(CommonStrings.common_verification_complete),
directLogoutState = aDirectLogoutState(), directLogoutState = aDirectLogoutState(),
) )

View file

@ -122,11 +122,13 @@ fun PreferencesRootView(
onClick = onOpenNotificationSettings, onClick = onOpenNotificationSettings,
) )
} }
ListItem( if (state.showBlockedUsersItem) {
headlineContent = { Text(stringResource(id = CommonStrings.common_blocked_users)) }, ListItem(
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())), headlineContent = { Text(stringResource(id = CommonStrings.common_blocked_users)) },
onClick = onOpenBlockedUsers, leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())),
) onClick = onOpenBlockedUsers,
)
}
ListItem( ListItem(
headlineContent = { Text(stringResource(id = CommonStrings.common_report_a_problem)) }, headlineContent = { Text(stringResource(id = CommonStrings.common_report_a_problem)) },
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.ChatProblem())), leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.ChatProblem())),