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
@@ -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
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nonPlayCommon applies to fdroid build too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I've changed the setup to handle the cases better, using firebaseCommon

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.thoughtcrime.securesms.onboarding.messagenotifications

import android.app.Application

internal fun Application.isFastModeAvailable(): Boolean = true
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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) }
)
}
}
Expand All @@ -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
Expand All @@ -139,6 +140,7 @@ private fun NotificationRadioButton(
modifier = modifier,
tag = tag,
checked = checked,
enabled = enabled,
onClick = onClick
)
}
Expand All @@ -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
)
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event>()
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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.thoughtcrime.securesms.onboarding.messagenotifications

import android.app.Application

internal fun Application.isFastModeAvailable(): Boolean = true