mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 10:32:34 +00:00
Address PR review comments.
- use util startNotificationSettingsIntent. - add documentation. - use remember with userPushStoreFactory for recomposition.
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ class NotificationSettingsNode @AssistedInject constructor(
|
|||||||
val state = presenter.present()
|
val state = presenter.present()
|
||||||
NotificationSettingsView(
|
NotificationSettingsView(
|
||||||
state = state,
|
state = state,
|
||||||
onOpenEditDefault = { openEditDefault(it) },
|
onOpenEditDefault = { openEditDefault(isOneToOne = it) },
|
||||||
onBackPressed = ::navigateUp,
|
onBackPressed = ::navigateUp,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ class NotificationSettingsPresenter @Inject constructor(
|
|||||||
) : Presenter<NotificationSettingsState> {
|
) : Presenter<NotificationSettingsState> {
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): NotificationSettingsState {
|
override fun present(): NotificationSettingsState {
|
||||||
val userPushStore = userPushStoreFactory.create(matrixClient.sessionId)
|
val userPushStore = remember { userPushStoreFactory.create(matrixClient.sessionId) }
|
||||||
val systemNotificationsEnabled: MutableState<Boolean> = remember {
|
val systemNotificationsEnabled: MutableState<Boolean> = remember {
|
||||||
mutableStateOf(systemNotificationsEnabledProvider.notificationsEnabled())
|
mutableStateOf(systemNotificationsEnabledProvider.notificationsEnabled())
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -39,6 +39,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.Lifecycle
|
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.dialogs.ErrorDialog
|
||||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceCategory
|
import io.element.android.libraries.designsystem.components.preferences.PreferenceCategory
|
||||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceSwitch
|
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.theme.ElementTheme
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A view that allows a user edit their global notification settings.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun NotificationSettingsView(
|
fun NotificationSettingsView(
|
||||||
state: NotificationSettingsState,
|
state: NotificationSettingsState,
|
||||||
onOpenEditDefault: (Boolean) -> Unit,
|
onOpenEditDefault: (isOneToOne: Boolean) -> Unit,
|
||||||
onBackPressed: () -> Unit,
|
onBackPressed: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
@@ -113,11 +117,7 @@ private fun NotificationSettingsContentView(
|
|||||||
subtitle = stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required,
|
subtitle = stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required,
|
||||||
stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required_content_link)),
|
stringResource(id = CommonStrings.screen_notification_settings_system_notifications_action_required_content_link)),
|
||||||
onClick = {
|
onClick = {
|
||||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
context.startNotificationSettingsIntent()
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
val uri: Uri = Uri.fromParts("package", context.packageName, null)
|
|
||||||
intent.data = uri
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ fun DefaultNotificationSettingOption(
|
|||||||
}
|
}
|
||||||
@DayNightPreviews
|
@DayNightPreviews
|
||||||
@Composable
|
@Composable
|
||||||
internal fun DefaultNotificationSettingOptionLightPreview() = ElementPreview { ContentToPreview() }
|
internal fun DefaultNotificationSettingOptionPreview() = ElementPreview { ContentToPreview() }
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ContentToPreview() {
|
private fun ContentToPreview() {
|
||||||
|
|||||||
+1
@@ -84,6 +84,7 @@ class EditDefaultNotificationSettingPresenter @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun CoroutineScope.setDefaultNotificationMode(mode: RoomNotificationMode) = launch {
|
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 = true, mode = mode, isOneToOne = isOneToOne)
|
||||||
notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = false, mode = mode, isOneToOne = isOneToOne)
|
notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = false, mode = mode, isOneToOne = isOneToOne)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -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.matrix.api.room.RoomNotificationMode
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
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
|
@Composable
|
||||||
fun EditDefaultNotificationSettingView(
|
fun EditDefaultNotificationSettingView(
|
||||||
state: EditDefaultNotificationSettingState,
|
state: EditDefaultNotificationSettingState,
|
||||||
@@ -44,6 +48,7 @@ fun EditDefaultNotificationSettingView(
|
|||||||
title = stringResource(id = title)
|
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 validModes = listOf(RoomNotificationMode.ALL_MESSAGES, RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY)
|
||||||
|
|
||||||
val categoryTitle = if(state.isOneToOne) {
|
val categoryTitle = if(state.isOneToOne) {
|
||||||
|
|||||||
+7
-2
@@ -122,7 +122,7 @@ fun Context.copyToClipboard(
|
|||||||
* Shows notification settings for the current app.
|
* 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
|
* 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()
|
val intent = Intent()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||||
@@ -132,7 +132,12 @@ fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResu
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
intent.data = Uri.fromParts("package", packageName, null)
|
intent.data = Uri.fromParts("package", packageName, null)
|
||||||
}
|
}
|
||||||
activityResultLauncher.launch(intent)
|
|
||||||
|
if (activityResultLauncher != null) {
|
||||||
|
activityResultLauncher.launch(intent)
|
||||||
|
} else {
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.openAppSettingsPage(
|
fun Context.openAppSettingsPage(
|
||||||
|
|||||||
Reference in New Issue
Block a user