Address PR review comments.
- use util startNotificationSettingsIntent. - add documentation. - use remember with userPushStoreFactory for recomposition.
This commit is contained in:
parent
5e8cb958f8
commit
004abd16dc
7 changed files with 22 additions and 11 deletions
|
|
@ -49,7 +49,7 @@ class NotificationSettingsNode @AssistedInject constructor(
|
|||
val state = presenter.present()
|
||||
NotificationSettingsView(
|
||||
state = state,
|
||||
onOpenEditDefault = { openEditDefault(it) },
|
||||
onOpenEditDefault = { openEditDefault(isOneToOne = it) },
|
||||
onBackPressed = ::navigateUp,
|
||||
modifier = modifier,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class NotificationSettingsPresenter @Inject constructor(
|
|||
) : Presenter<NotificationSettingsState> {
|
||||
@Composable
|
||||
override fun present(): NotificationSettingsState {
|
||||
val userPushStore = userPushStoreFactory.create(matrixClient.sessionId)
|
||||
val userPushStore = remember { userPushStoreFactory.create(matrixClient.sessionId) }
|
||||
val systemNotificationsEnabled: MutableState<Boolean> = remember {
|
||||
mutableStateOf(systemNotificationsEnabledProvider.notificationsEnabled())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import io.element.android.libraries.androidutils.system.startNotificationSettingsIntent
|
||||
import io.element.android.libraries.designsystem.components.dialogs.ErrorDialog
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceCategory
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceSwitch
|
||||
|
|
@ -55,10 +56,13 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
|||
import io.element.android.libraries.theme.ElementTheme
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
/**
|
||||
* A view that allows a user edit their global notification settings.
|
||||
*/
|
||||
@Composable
|
||||
fun NotificationSettingsView(
|
||||
state: NotificationSettingsState,
|
||||
onOpenEditDefault: (Boolean) -> Unit,
|
||||
onOpenEditDefault: (isOneToOne: Boolean) -> Unit,
|
||||
onBackPressed: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
|
|
@ -113,11 +117,7 @@ private fun NotificationSettingsContentView(
|
|||
subtitle = stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required,
|
||||
stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required_content_link)),
|
||||
onClick = {
|
||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
val uri: Uri = Uri.fromParts("package", context.packageName, null)
|
||||
intent.data = uri
|
||||
context.startActivity(intent)
|
||||
context.startNotificationSettingsIntent()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ fun DefaultNotificationSettingOption(
|
|||
}
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
internal fun DefaultNotificationSettingOptionLightPreview() = ElementPreview { ContentToPreview() }
|
||||
internal fun DefaultNotificationSettingOptionPreview() = ElementPreview { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ class EditDefaultNotificationSettingPresenter @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun CoroutineScope.setDefaultNotificationMode(mode: RoomNotificationMode) = launch {
|
||||
// On modern clients, we don't have different settings for encrypted and non-encrypted rooms (Legacy clients did).
|
||||
notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = true, mode = mode, isOneToOne = isOneToOne)
|
||||
notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = false, mode = mode, isOneToOne = isOneToOne)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ import io.element.android.libraries.designsystem.components.preferences.Preferen
|
|||
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
/**
|
||||
* A view that allows a user to edit the default notification setting for rooms. This can be set separately
|
||||
* for one-to-one and group rooms, indicated by [EditDefaultNotificationSettingState.isOneToOne].
|
||||
*/
|
||||
@Composable
|
||||
fun EditDefaultNotificationSettingView(
|
||||
state: EditDefaultNotificationSettingState,
|
||||
|
|
@ -44,6 +48,7 @@ fun EditDefaultNotificationSettingView(
|
|||
title = stringResource(id = title)
|
||||
) {
|
||||
|
||||
// Only ALL_MESSAGES and MENTIONS_AND_KEYWORDS_ONLY are valid global defaults.
|
||||
val validModes = listOf(RoomNotificationMode.ALL_MESSAGES, RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY)
|
||||
|
||||
val categoryTitle = if(state.isOneToOne) {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ fun Context.copyToClipboard(
|
|||
* Shows notification settings for the current app.
|
||||
* In android O will directly opens the notification settings, in lower version it will show the App settings
|
||||
*/
|
||||
fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResultLauncher<Intent>? = null) {
|
||||
val intent = Intent()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
|
|
@ -132,7 +132,12 @@ fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResu
|
|||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.data = Uri.fromParts("package", packageName, null)
|
||||
}
|
||||
activityResultLauncher.launch(intent)
|
||||
|
||||
if (activityResultLauncher != null) {
|
||||
activityResultLauncher.launch(intent)
|
||||
} else {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.openAppSettingsPage(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue