Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
)

val soundUri = getCallRingtoneUri(applicationContext, appPreferences)
val notificationChannelId = NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_CALLS_V5.name
val notificationChannelId = NotificationUtils.getCallsNotificationChannelId(applicationContext)
val uri = user.baseUrl!!.toUri()
val baseUrl = uri.host

Expand Down Expand Up @@ -771,7 +771,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
TYPE_ADMIN_NOTIFICATIONS,
TYPE_REMOTE_TALK_SHARE -> {
notificationBuilder.setChannelId(
NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name
NotificationUtils.getMessagesNotificationChannelId(applicationContext)
)
}
}
Expand Down Expand Up @@ -1231,8 +1231,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
if (isOngoingCallNotificationVisible) {
val notificationBuilder = NotificationCompat.Builder(
context!!,
NotificationUtils.NotificationChannels
.NOTIFICATION_CHANNEL_MESSAGES_V4.name
NotificationUtils.getMessagesNotificationChannelId(context!!)
)

val intent = createContentIntent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ class DeviceStateReader @Inject constructor(
ringtoneUri == null -> RingtoneState.Silent
ringtoneUri.toString() == NotificationUtils.DEFAULT_CALL_RINGTONE_URI ||
ringtoneUri.toString() == NotificationUtils.DEFAULT_MESSAGE_RINGTONE_URI -> RingtoneState.Default
else -> RingtoneManager.getRingtone(context, ringtoneUri)?.getTitle(context)
?.let { RingtoneState.Custom(it) }
?: RingtoneState.Default
else -> RingtoneState.Custom(
title = RingtoneManager.getRingtone(context, ringtoneUri)?.getTitle(context)
?: ringtoneUri.lastPathSegment
?: ringtoneUri.toString(),
uri = ringtoneUri.toString()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.settings

import android.content.Context
import androidx.annotation.WorkerThread
import androidx.core.net.toUri
import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import javax.inject.Inject

/** Changes the sound of a notification channel, which recreates the channel. */
class NotificationSoundUpdater @Inject constructor(
private val context: Context,
private val appPreferences: AppPreferences
) {
/**
* @param uri null for no sound
* @return false if the sound could not be set
*/
@WorkerThread
fun update(sound: NotificationSound, uri: String?): Boolean =
when (sound) {
NotificationSound.CALL -> NotificationUtils.updateCallRingtone(context, appPreferences, uri?.toUri())
NotificationSound.MESSAGE -> NotificationUtils.updateMessageRingtone(context, appPreferences, uri?.toUri())
}
}
56 changes: 56 additions & 0 deletions app/src/main/java/com/nextcloud/talk/settings/PickSoundContract.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.settings

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContract
import androidx.core.content.IntentCompat
import androidx.core.net.toUri

/** Opens the system ringtone picker. */
class PickSoundContract : ActivityResultContract<PickSoundContract.Request, PickSoundContract.Result?>() {

/**
* @param existingUri the sound selected in the picker, null for no sound
*/
data class Request(val sound: NotificationSound, val title: String, val existingUri: String?)

/** @param uri the picked sound, null for no sound */
data class Result(val uri: String?)

override fun createIntent(context: Context, input: Request): Intent {
val (ringtoneType, systemDefaultUri) = when (input.sound) {
NotificationSound.CALL -> RingtoneManager.TYPE_RINGTONE to Settings.System.DEFAULT_RINGTONE_URI
NotificationSound.MESSAGE -> RingtoneManager.TYPE_NOTIFICATION to Settings.System.DEFAULT_NOTIFICATION_URI
}
return Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, ringtoneType)
.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, input.title)
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, systemDefaultUri)
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, input.existingUri?.toUri())
}

/** @return null if nothing was picked; a missing extra must not be treated as "no sound" */
override fun parseResult(resultCode: Int, intent: Intent?): Result? {
if (resultCode != Activity.RESULT_OK || intent?.hasExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) != true) {
return null
}
val pickedUri = IntentCompat.getParcelableExtra(
intent,
RingtoneManager.EXTRA_RINGTONE_PICKED_URI,
Uri::class.java
)
return Result(pickedUri?.toString())
}
}
36 changes: 30 additions & 6 deletions app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import com.nextcloud.talk.settings.ui.ProxyCallbacks
import com.nextcloud.talk.settings.ui.SettingsScreen
import com.nextcloud.talk.settings.ui.SettingsScreenCallbacks
import com.nextcloud.talk.settings.ui.SystemSettingsScreen
import com.nextcloud.talk.settings.ui.systemSettingsScreen
import com.nextcloud.talk.settings.ui.titleRes
import com.nextcloud.talk.utils.LoggingUtils.sendMailWithAttachment
import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.UnifiedPushUtils
Expand Down Expand Up @@ -101,6 +103,10 @@ class SettingsActivity : BaseActivity() {
}
}

private val callSoundPickerLauncher = registerSoundPicker(NotificationSound.CALL)

private val messageSoundPickerLauncher = registerSoundPicker(NotificationSound.MESSAGE)

private val contactsPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { results ->
if (results.isNotEmpty() && results.values.all { it }) {
Expand Down Expand Up @@ -157,6 +163,8 @@ class SettingsActivity : BaseActivity() {
},
onOpenSystemSettings = ::openSystemSettings,
onOpenDiagnosis = { startActivity(intentForAccount(DiagnosisActivity::class.java)) },
onPickNotificationSound = ::pickNotificationSound,
onNotificationSoundChange = viewModel::setNotificationSound,
onShowNotificationWarningChange = viewModel::setShowNotificationWarning,
onScreenLockChange = viewModel::setScreenLock,
onScreenLockTimeoutChange = viewModel::setScreenLockTimeout,
Expand Down Expand Up @@ -267,11 +275,9 @@ class SettingsActivity : BaseActivity() {
Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT, "package:$packageName".toUri())
}
SystemSettingsScreen.CALL_NOTIFICATIONS ->
notificationChannelSettingsIntent(NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_CALLS_V5)
notificationChannelSettingsIntent(NotificationUtils.getCallsNotificationChannelId(this))
SystemSettingsScreen.MESSAGE_NOTIFICATIONS ->
notificationChannelSettingsIntent(
NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4
)
notificationChannelSettingsIntent(NotificationUtils.getMessagesNotificationChannelId(this))
}
openSystemSettings(intent)
}
Expand All @@ -284,10 +290,28 @@ class SettingsActivity : BaseActivity() {
}
}

private fun notificationChannelSettingsIntent(channel: NotificationUtils.NotificationChannels): Intent =
private fun notificationChannelSettingsIntent(channelId: String): Intent =
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID)
.putExtra(Settings.EXTRA_CHANNEL_ID, channel.name)
.putExtra(Settings.EXTRA_CHANNEL_ID, channelId)

private fun registerSoundPicker(sound: NotificationSound) =
registerForActivityResult(PickSoundContract()) { result ->
result?.let { viewModel.setNotificationSound(sound, it.uri) }
}

private fun pickNotificationSound(sound: NotificationSound, current: RingtoneState) {
val launcher = when (sound) {
NotificationSound.CALL -> callSoundPickerLauncher
NotificationSound.MESSAGE -> messageSoundPickerLauncher
}
try {
launcher.launch(PickSoundContract.Request(sound, getString(sound.titleRes), sound.uriOf(current)))
} catch (e: ActivityNotFoundException) {
Log.w(TAG, "No ringtone picker available, opening the notification channel settings instead", e)
openSystemSettings(sound.systemSettingsScreen)
}
}

private fun openLogs() {
startActivity(Intent(this, LogsActivity::class.java))
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/com/nextcloud/talk/settings/SettingsUiState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.nextcloud.talk.settings

import androidx.compose.runtime.Immutable
import com.nextcloud.talk.utils.NotificationUtils

@Immutable
data class SettingsUiState(
Expand Down Expand Up @@ -91,8 +92,24 @@ sealed interface RingtoneState {
/** The notification channel is turned off. */
data object Disabled : RingtoneState
data object Silent : RingtoneState

/** The sound bundled with the app, which the system ringtone picker doesn't list. */
data object Default : RingtoneState
data class Custom(val title: String) : RingtoneState
data class Custom(val title: String, val uri: String) : RingtoneState
}

/** The notification sounds that can be chosen on the settings screen. */
enum class NotificationSound(private val bundledUri: String, val audioUsage: Int) {
CALL(NotificationUtils.DEFAULT_CALL_RINGTONE_URI, NotificationUtils.CALLS_AUDIO_USAGE),
MESSAGE(NotificationUtils.DEFAULT_MESSAGE_RINGTONE_URI, NotificationUtils.MESSAGES_AUDIO_USAGE);

/** The uri of the sound that [ringtone] stands for, null for no sound. */
fun uriOf(ringtone: RingtoneState): String? =
when (ringtone) {
RingtoneState.Default -> bundledUri
is RingtoneState.Custom -> ringtone.uri
RingtoneState.Silent, RingtoneState.Disabled -> null
}
}

@Immutable
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/nextcloud/talk/settings/SettingsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SettingsViewModel @AssistedInject constructor(
private val settingsRepository: SettingsRepository,
private val logsRepository: LogsRepository,
private val deviceStateReader: DeviceStateReader,
private val notificationSoundUpdater: NotificationSoundUpdater,
private val accountRemover: AccountRemover,
private val workManager: WorkManager,
private val logger: Logger,
Expand Down Expand Up @@ -207,6 +208,17 @@ class SettingsViewModel @AssistedInject constructor(
}
}

/** @param uri null for no sound */
fun setNotificationSound(sound: NotificationSound, uri: String?) {
viewModelScope.launch {
val updated = withContext(preferenceWriter) { notificationSoundUpdater.update(sound, uri) }
if (!updated) {
_events.send(SettingsEvent.ShowMessage(R.string.nc_common_error_sorry))
}
refreshDeviceState()
}
}

fun setShowNotificationWarning(show: Boolean) {
_uiState.update { it.copy(notifications = it.notifications.copy(showNotificationWarning = show)) }
persist { prefs ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ internal fun MediaQualityDialog(reducedQuality: Boolean, onSelect: (Boolean) ->
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(bottom = 8.dp)
)
MediaQualityOption(
RadioOption(
label = stringResource(R.string.nc_media_quality_original),
selected = !reducedQuality,
onClick = { onSelect(false) }
)
MediaQualityOption(
RadioOption(
label = stringResource(R.string.nc_media_quality_reduced),
selected = reducedQuality,
onClick = { onSelect(true) }
Expand All @@ -134,7 +134,7 @@ internal fun MediaQualityDialog(reducedQuality: Boolean, onSelect: (Boolean) ->
}

@Composable
private fun MediaQualityOption(label: String, selected: Boolean, onClick: () -> Unit) {
internal fun RadioOption(label: String, selected: Boolean, onClick: () -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.nextcloud.talk.settings.ui

import android.content.res.Configuration
import androidx.annotation.StringRes
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
Expand All @@ -23,6 +24,7 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.nextcloud.talk.R
import com.nextcloud.talk.settings.NotificationSound
import com.nextcloud.talk.settings.NotificationsUiState
import com.nextcloud.talk.settings.PushAvailability
import com.nextcloud.talk.settings.RingtoneState
Expand Down Expand Up @@ -203,22 +205,53 @@ private fun TroubleshootingDialog(onOpenDiagnosis: () -> Unit, onDismiss: () ->

@Composable
private fun RingtoneItems(state: NotificationsUiState, highlightIssues: Boolean, callbacks: SettingsScreenCallbacks) {
RingtoneItem(
title = stringResource(R.string.nc_settings_call_ringtone),
ringtone = state.callRingtone,
enabled = state.ringtoneSettingsEnabled,
highlight = highlightIssues,
onClick = { callbacks.onOpenSystemSettings(SystemSettingsScreen.CALL_NOTIFICATIONS) }
)
RingtoneItem(
title = stringResource(R.string.nc_settings_other_notifications_ringtone),
ringtone = state.messageRingtone,
enabled = state.ringtoneSettingsEnabled,
highlight = highlightIssues,
onClick = { callbacks.onOpenSystemSettings(SystemSettingsScreen.MESSAGE_NOTIFICATIONS) }
)
var soundDialog by rememberSaveable { mutableStateOf<NotificationSound?>(null) }

NotificationSound.entries.forEach { sound ->
val ringtone = state.ringtone(sound)
RingtoneItem(
title = stringResource(sound.titleRes),
ringtone = ringtone,
enabled = state.ringtoneSettingsEnabled,
highlight = highlightIssues,
onClick = {
if (ringtone == RingtoneState.Disabled) {
callbacks.onOpenSystemSettings(sound.systemSettingsScreen)
} else {
soundDialog = sound
}
}
)
}

soundDialog?.let { sound ->
SoundDialog(
sound = sound,
current = state.ringtone(sound),
callbacks = callbacks,
onDismiss = { soundDialog = null }
)
}
}

private fun NotificationsUiState.ringtone(sound: NotificationSound): RingtoneState =
when (sound) {
NotificationSound.CALL -> callRingtone
NotificationSound.MESSAGE -> messageRingtone
}

internal val NotificationSound.systemSettingsScreen: SystemSettingsScreen
get() = when (this) {
NotificationSound.CALL -> SystemSettingsScreen.CALL_NOTIFICATIONS
NotificationSound.MESSAGE -> SystemSettingsScreen.MESSAGE_NOTIFICATIONS
}

internal val NotificationSound.titleRes: Int
@StringRes get() = when (this) {
NotificationSound.CALL -> R.string.nc_settings_call_ringtone
NotificationSound.MESSAGE -> R.string.nc_settings_other_notifications_ringtone
}

@Composable
private fun RingtoneItem(
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.nextcloud.talk.components.ColoredStatusBar
import com.nextcloud.talk.components.IncognitoKeyboard
import com.nextcloud.talk.components.StandardAppBar
import com.nextcloud.talk.settings.AccountUiState
import com.nextcloud.talk.settings.NotificationSound
import com.nextcloud.talk.settings.NotificationsUiState
import com.nextcloud.talk.settings.PrivacyUiState
import com.nextcloud.talk.settings.ProxyUiState
Expand Down Expand Up @@ -72,6 +73,11 @@ data class SettingsScreenCallbacks(
val onRequestNotificationPermission: () -> Unit = {},
val onOpenSystemSettings: (SystemSettingsScreen) -> Unit = {},
val onOpenDiagnosis: () -> Unit = {},
/** Opens the system ringtone picker, with the current sound selected. */
val onPickNotificationSound: (NotificationSound, RingtoneState) -> Unit = { _, _ -> },

/** Sets the sound by its uri, null for no sound. */
val onNotificationSoundChange: (NotificationSound, String?) -> Unit = { _, _ -> },
val onShowNotificationWarningChange: (Boolean) -> Unit = {},
val onScreenLockChange: (Boolean) -> Unit = {},
val onScreenLockTimeoutChange: (String) -> Unit = {},
Expand Down
Loading
Loading