diff --git a/app/src/firebaseCommon/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt b/app/src/firebaseCommon/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt new file mode 100644 index 0000000000..9fac856304 --- /dev/null +++ b/app/src/firebaseCommon/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt @@ -0,0 +1,12 @@ +package org.thoughtcrime.securesms.onboarding.messagenotifications + +import android.app.Application +import android.content.pm.PackageManager + +internal fun Application.isFastModeAvailable(): Boolean { + return try { + applicationContext.packageManager.getApplicationInfo("com.google.android.gms", 0).enabled + } catch (_: PackageManager.NameNotFoundException) { + false + } +} diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt new file mode 100644 index 0000000000..43d8485bc0 --- /dev/null +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt @@ -0,0 +1,5 @@ +package org.thoughtcrime.securesms.onboarding.messagenotifications + +import android.app.Application + +internal fun Application.isFastModeAvailable(): Boolean = true diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt index 8b3bcd7060..1ca5501104 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt @@ -1,7 +1,5 @@ package org.thoughtcrime.securesms.onboarding.messagenotifications -import android.R.attr.checked -import android.R.attr.onClick import androidx.annotation.StringRes import androidx.compose.foundation.border import androidx.compose.foundation.layout.Box @@ -43,7 +41,7 @@ import org.thoughtcrime.securesms.ui.theme.ThemeColors @Composable internal fun MessageNotificationsScreen( state: UiState = UiState(), - setEnabled: (Boolean) -> Unit = {}, + selectFastMode: (Boolean) -> Unit = {}, onContinue: () -> Unit = {}, quit: () -> Unit = {}, dismissDialog: () -> Unit = {} @@ -95,9 +93,10 @@ internal fun MessageNotificationsScreen( modifier = Modifier .qaTag(R.string.AccessibilityId_notificationsFastMode) .fillMaxWidth(), - tag = R.string.recommended, - checked = state.pushEnabled, - onClick = { setEnabled(true) } + tag = if(state.fastModeAvailable) R.string.recommended else R.string.unavailable, + checked = state.fastModeSelected, + enabled = state.fastModeAvailable, + onClick = { selectFastMode(true) } ) // spacing between buttons is provided by ripple/downstate of NotificationRadioButton @@ -113,8 +112,9 @@ internal fun MessageNotificationsScreen( modifier = Modifier .qaTag(R.string.AccessibilityId_notificationsSlowMode) .fillMaxWidth(), - checked = state.pushDisabled, - onClick = { setEnabled(false) } + checked = state.slowModeSelected, + enabled = true, + onClick = { selectFastMode(false) } ) } } @@ -130,6 +130,7 @@ private fun NotificationRadioButton( modifier: Modifier = Modifier, @StringRes tag: Int? = null, checked: Boolean = false, + enabled: Boolean = false, onClick: () -> Unit = {} ) { // Pass-through from this string ID version to the version that takes strings @@ -139,6 +140,7 @@ private fun NotificationRadioButton( modifier = modifier, tag = tag, checked = checked, + enabled = enabled, onClick = onClick ) } @@ -150,12 +152,14 @@ private fun NotificationRadioButton( modifier: Modifier = Modifier, @StringRes tag: Int? = null, checked: Boolean = false, + enabled: Boolean = false, onClick: () -> Unit = {} ) { RadioButton( onClick = onClick, modifier = modifier, selected = checked, + enabled = enabled, contentPadding = PaddingValues( vertical = 7.dp ) @@ -190,7 +194,7 @@ private fun NotificationRadioButton( Text( stringResource(it), modifier = Modifier.padding(top = LocalDimensions.current.xxsSpacing), - color = LocalColors.current.accent, + color = if(enabled) LocalColors.current.accent else LocalColors.current.disabled, style = LocalType.current.h9 ) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt index abab1f68c8..77dc8ff06c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt @@ -68,7 +68,7 @@ class MessageNotificationsActivity : BaseActionBarActivity() { val uiState by viewModel.uiStates.collectAsState() MessageNotificationsScreen( uiState, - setEnabled = viewModel::setEnabled, + selectFastMode = viewModel::selectFastMode, onContinue = viewModel::onContinue, quit = viewModel::quit, dismissDialog = viewModel::dismissDialog diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsViewModel.kt index b78eb69b71..9d91f94327 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsViewModel.kt @@ -26,21 +26,31 @@ internal class MessageNotificationsViewModel( private val createAccountManager: CreateAccountManager, private val clearDataUtils: ClearDataUtils, ): AndroidViewModel(application) { - private val _uiStates = MutableStateFlow(UiState()) + private val _uiStates = MutableStateFlow(createInitialState()) val uiStates = _uiStates.asStateFlow() private val _events = MutableSharedFlow() val events = _events.asSharedFlow() - fun setEnabled(enabled: Boolean) { - _uiStates.update { UiState(pushEnabled = enabled) } + private fun createInitialState(): UiState { + val fastModeAvailable = application.isFastModeAvailable() + return UiState( + fastModeSelected = fastModeAvailable, + fastModeAvailable = fastModeAvailable, + ) + } + + fun selectFastMode(enabled: Boolean) { + _uiStates.update { + it.copy(fastModeSelected = enabled && it.fastModeAvailable) + } } fun onContinue() { viewModelScope.launch { if (state is State.CreateAccount) createAccountManager.createAccount(state.displayName) - prefs[PUSH_ENABLED] = uiStates.value.pushEnabled + prefs[PUSH_ENABLED] = uiStates.value.fastModeSelected _events.emit( when (state) { @@ -78,11 +88,12 @@ internal class MessageNotificationsViewModel( } data class UiState( - val pushEnabled: Boolean = true, + val fastModeSelected: Boolean = true, val showingBackWarningDialogText: Int? = null, - val clearData: Boolean = false + val clearData: Boolean = false, + val fastModeAvailable: Boolean = false, ) { - val pushDisabled get() = !pushEnabled + val slowModeSelected get() = !fastModeSelected } sealed interface State { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/UserProfileUtils.kt b/app/src/main/java/org/thoughtcrime/securesms/util/UserProfileUtils.kt index c4df000fbf..3e43dd196b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/UserProfileUtils.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/UserProfileUtils.kt @@ -112,7 +112,7 @@ class UserProfileUtils @AssistedInject constructor( return UserProfileModalData( name = if (recipient.isLocalNumber) context.getString(R.string.you) else recipient.displayName(), - subtitle = (recipient.data as? RecipientData.Contact)?.nickname?.takeIf { it.isNotBlank() }?.let { "($it)" }, + subtitle = (recipient.data as? RecipientData.Contact)?.nickname?.takeIf { it.isNotBlank() }?.let { "(${recipient.data.name})" }, avatarUIData = avatarUtils.getUIDataFromRecipient(recipient), showProBadge = recipient.shouldShowProBadge, currentUserPro = recipientRepository.getSelf().isPro, diff --git a/app/src/website/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt b/app/src/website/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt new file mode 100644 index 0000000000..43d8485bc0 --- /dev/null +++ b/app/src/website/kotlin/org/thoughtcrime/securesms/onboarding/messagenotifications/FastModeAvailability.kt @@ -0,0 +1,5 @@ +package org.thoughtcrime.securesms.onboarding.messagenotifications + +import android.app.Application + +internal fun Application.isFastModeAvailable(): Boolean = true