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 @@ -221,6 +221,6 @@ private fun MmsSupportPreview() {
// renders the no-SIMs state. That state is worth pinning: it is what a
// device with no SIMs shows, and it is easy to break the branch on.
Stage {
MmsSupportScreen(onBack = {})
MmsSupportScreen(onBack = {}, mmsEnabled = true, onMmsEnabledChange = {})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.anindra.messages.ui.previews

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Switch
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import com.anindra.messages.ui.GroupedRowList
import com.anindra.messages.ui.MmsCardRow
import com.anindra.messages.ui.theme.MessagesTheme

@PreviewLightDark
@Composable
private fun MmsCardRowPreview() {
MessagesTheme(mode = "system") {
Column(Modifier.padding(16.dp)) {
GroupedRowList {
MmsCardRow(
title = "MMS",
subtitle = "Pictures, voice notes and contacts are sent over MMS",
trailing = { Switch(checked = true, onCheckedChange = {}) },
showDivider = true
)
MmsCardRow(
title = "Android",
subtitle = "Off on this carrier · +1 · US · +15555215556",
showDivider = false
)
}
}
}
}
50 changes: 48 additions & 2 deletions app/src/main/java/com/anindra/messages/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ class AppViewModel(app: Application) : AndroidViewModel(app) {
// recipients never see a group and their replies come back private
// (#448); this is the same rule AOSP, QKSMS and Fossify follow. Where the
// carrier forbids a group MMS, the per-person SMS below is the fallback.
if (recipients.size > 1 && SmsSender.groupMmsEnabled(getApplication(), subId)) {
if (recipients.size > 1 && settings.mmsEnabled &&
SmsSender.groupMmsEnabled(getApplication(), subId)
) {
val stored = repo.sendTextAsMms(conversationId, body, subId) ?: return
if (settings.soundsEnabled) NotificationHelper.playSentSound(getApplication())
val handedOff = SmsSender.sendMms(
Expand Down Expand Up @@ -735,6 +737,16 @@ class AppViewModel(app: Application) : AndroidViewModel(app) {
onStored(0)
return
}
// Every attachment — picture, clip, voice note, contact card — travels as
// an MMS part, so the setting stops the path rather than the picker: the
// share sheet and a retry reach this function directly.
if (!settings.mmsEnabled) {
Toast.makeText(
getApplication(), R.string.chat_mms_disabled, Toast.LENGTH_SHORT
).show()
onStored(0)
return
}
scope.launch {
val convo = repo.conversationByIdSuspend(conversationId)
?: return@launch onStored(0)
Expand Down Expand Up @@ -857,6 +869,14 @@ class AppViewModel(app: Application) : AndroidViewModel(app) {
val msg = repo.messageByIdSuspend(messageId) ?: return@launch
val convo = repo.conversationByIdSuspend(msg.conversationId) ?: return@launch
if (!isPhoneNumber(convo.address)) return@launch
if (!settings.mmsEnabled && msg.mediaUri.isNotBlank()) {
withContext(Dispatchers.Main) {
Toast.makeText(
getApplication(), R.string.chat_mms_disabled, Toast.LENGTH_SHORT
).show()
}
return@launch
}
repo.markMessageStatusSuspend(messageId, "sending")
val recipients = repo.conversationRecipients(msg.conversationId)
.filter { isPhoneNumber(it) }
Expand Down Expand Up @@ -1603,6 +1623,7 @@ open class MainActivity : FragmentActivity() {
}

applyAppLockProbe(intent, bootVm)
applyMmsProbe(intent, bootVm)
appLockEnabled = bootVm.settings.appLockEnabled

// Script hooks: --es set_theme dark|light|system|amoled|dynamic, --ez open_settings true, --ez privacy_mode true|false
Expand Down Expand Up @@ -2209,7 +2230,16 @@ onOpenAccessibility = { navRoute = "accessibility" },
}
)
"mms-check" -> MmsSupportScreen(
onBack = { navRoute = "advanced" }
onBack = { navRoute = "advanced" },
mmsEnabled = vm.settings.mmsEnabled,
onMmsEnabledChange = { on ->
vm.settings.mmsEnabled = on
// The plus took the emoji button's
// place while MMS was on; turning
// MMS off hands that slot back, so
// the setting has to say so.
if (!on) vm.settings.emojiButtonEnabled = true
}
)
"notif-settings" -> NotificationSettingsScreen(
vm = vm,
Expand Down Expand Up @@ -2602,6 +2632,22 @@ onOpenAccessibility = { navRoute = "accessibility" },
* app-lock session, so a script can assert its lifetime without a real
* biometric prompt (an emulator has no enrolled fingerprint).
*/
/**
* Debug builds only: `--es mms_probe off|on` flips the MMS switch, so a
* regression script can drive the composer without walking the settings
* tree. It writes the same setting the switch writes.
*/
private fun applyMmsProbe(intent: Intent, vm: AppViewModel) {
val debuggable =
(applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0
if (!debuggable) return
// if/else rather than a `when`: the navigation test reads string-keyed
// branches as screens, and a probe is not one.
val probe = intent.getStringExtra("mms_probe")
if (probe == "off") vm.settings.mmsEnabled = false
if (probe == "on") vm.settings.mmsEnabled = true
}

private fun applyLockSessionProbe(intent: Intent) {
val debuggable =
(applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/anindra/messages/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SettingsStore(context: Context) {
const val KEY_SUGGESTED_REPLIES = "suggested_replies_enabled"
const val KEY_SHOW_SIM_INDICATOR = "show_sim_indicator"
const val KEY_EMOJI_BUTTON = "emoji_button_enabled"
const val KEY_MMS_ENABLED = "mms_enabled"
const val KEY_PERMANENT_DELETE = "permanent_delete_enabled"
const val KEY_PERMANENT_DELETE_WARN = "permanent_delete_warn"
const val KEY_REVERSE_SWIPE = "reverse_swipe_enabled"
Expand Down Expand Up @@ -453,6 +454,19 @@ class SettingsStore(context: Context) {
get() = prefs.getBoolean(KEY_EMOJI_BUTTON, DEFAULTS_EMOJI_BUTTON)
set(v) { prefs.edit().putBoolean(KEY_EMOJI_BUTTON, v).apply(); _revision.value++ }

/**
* Whether the app will send MMS at all.
*
* Turning it off leaves text messaging untouched: the composer loses its
* attach button, its tray and the microphone (a voice note is an MMS
* attachment), and the emoji button takes the slot the plus had. Incoming
* MMS is still received — a picture someone sends is not something the
* setting should throw away.
*/
var mmsEnabled: Boolean
get() = prefs.getBoolean(KEY_MMS_ENABLED, true)
set(v) { prefs.edit().putBoolean(KEY_MMS_ENABLED, v).apply(); _revision.value++ }

var permanentDeleteEnabled: Boolean
get() = prefs.getBoolean(KEY_PERMANENT_DELETE, false)
set(v) { prefs.edit().putBoolean(KEY_PERMANENT_DELETE, v).apply(); _revision.value++ }
Expand Down
93 changes: 76 additions & 17 deletions app/src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Switch
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand Down Expand Up @@ -412,7 +415,11 @@ fun LinkSettingsScreen(vm: AppViewModel, onBack: () -> Unit) {
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MmsSupportScreen(onBack: () -> Unit) {
fun MmsSupportScreen(
onBack: () -> Unit,
mmsEnabled: Boolean,
onMmsEnabledChange: (Boolean) -> Unit
) {
BackHandler(onBack = onBack)
val context = LocalContext.current
val checks = remember { SimMmsProbe.run(context) }
Expand All @@ -421,29 +428,36 @@ fun MmsSupportScreen(onBack: () -> Unit) {
title = stringResource(R.string.mms_check_title),
onBack = onBack
) {
if (checks.isEmpty()) {
SettingsGroup {
SettingsRow(
position = RowPosition.SINGLE,
title = stringResource(R.string.mms_check_no_sims)
// One card, not a run of them: the switch and the per-SIM verdicts
// answer the same question, and two cards read as two unrelated things.
GroupedRowList(Modifier.padding(horizontal = SettingsLayout.SCREEN_PADDING)) {
MmsCardRow(
title = stringResource(R.string.settings_mms_enabled),
subtitle = stringResource(R.string.settings_mms_enabled_summary),
trailing = {
Switch(checked = mmsEnabled, onCheckedChange = onMmsEnabledChange)
},
onClick = { onMmsEnabledChange(!mmsEnabled) },
showDivider = true
)
if (checks.isEmpty()) {
MmsCardRow(
title = stringResource(R.string.mms_check_no_sims),
showDivider = false
)
}
} else {
SettingsGroup {
} else {
checks.forEachIndexed { index, check ->
SettingsRow(
position = when {
checks.size == 1 -> RowPosition.SINGLE
index == 0 -> RowPosition.FIRST
index == checks.lastIndex -> RowPosition.LAST
else -> RowPosition.MIDDLE
},
MmsCardRow(
title = check.carrierName?.takeIf { it.isNotBlank() }
?: stringResource(R.string.settings_sim_unknown),
subtitle = mmsCheckSubtitle(check)
subtitle = mmsCheckSubtitle(check),
showDivider = index != checks.lastIndex
)
}
}
}

if (checks.isNotEmpty()) {
SettingsFooter(
stringResource(
R.string.mms_check_summary,
Expand All @@ -457,6 +471,51 @@ fun MmsSupportScreen(onBack: () -> Unit) {
}
}

/**
* One line of the MMS card: a title, its explanation, and a control or a
* verdict. Split by hairlines inside a single [GroupedRowList] rather than each
* drawn as its own card, so the switch and the carriers read as one block.
*/
@Composable
internal fun MmsCardRow(
title: String,
subtitle: String? = null,
trailing: @Composable (() -> Unit)? = null,
onClick: (() -> Unit)? = null,
showDivider: Boolean = true
) {
Column(Modifier.fillMaxWidth()) {
Row(
modifier = Modifier
.fillMaxWidth()
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
.padding(horizontal = SettingsLayout.ROW_CONTENT_PADDING, vertical = 14.dp),
verticalAlignment = Alignment.CenterVertically
) {
Column(Modifier.weight(1f)) {
Text(title, style = MaterialTheme.typography.bodyLarge)
if (subtitle != null) {
Text(
subtitle,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
if (trailing != null) {
Spacer(Modifier.width(12.dp))
trailing()
}
}
if (showDivider) {
HorizontalDivider(
color = MaterialTheme.colorScheme.outlineVariant,
modifier = Modifier.padding(start = SettingsLayout.ROW_CONTENT_PADDING)
)
}
}
}

@Composable
private fun mmsCheckSubtitle(check: SimMmsCheck): String {
val verdict = stringResource(
Expand Down
30 changes: 26 additions & 4 deletions app/src/main/java/com/anindra/messages/ui/ChatScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1999,8 +1999,13 @@ fun ChatScreen(
// must not reserve an inset as well, or the tray lands on
// top of it.
composerBottomInset = composerInset,
showEmojiButton = vm.settings.emojiButtonEnabled,
voiceEnabled = hasMicrophone,
// With MMS off the plus has nothing to open: the emoji
// button takes its place, and the microphone goes with
// the tray because a voice note is an MMS attachment.
showEmojiButton = vm.settings.emojiButtonEnabled ||
!vm.settings.mmsEnabled,
attachEnabled = vm.settings.mmsEnabled,
voiceEnabled = hasMicrophone && vm.settings.mmsEnabled,
voiceMaxSeconds = voiceMaxSeconds,
onVoiceStart = { startVoiceNote() },
onVoiceFinish = {
Expand Down Expand Up @@ -3872,6 +3877,8 @@ internal fun InputBar(
schedulingEnabled: Boolean = true,
onEmojiToggle: () -> Unit,
onAttach: () -> Unit,
/** False when the app does not send MMS: no plus, and no tray behind it. */
attachEnabled: Boolean = true,
/** The tray is open under the bar, so the attach button offers to close it. */
attachOpen: Boolean = false,
/** Lets the caller hand focus back when the tray closes. */
Expand Down Expand Up @@ -4012,7 +4019,22 @@ internal fun InputBar(
verticalAlignment = Alignment.CenterVertically
) {
Box(Modifier.size(48.dp), contentAlignment = Alignment.Center) {
IconButton(onClick = onAttach) {
if (!attachEnabled) {
// The plus has nothing to open, so the slot it
// held carries the emoji button instead.
if (showEmojiButton) {
IconButton(
onClick = onEmojiToggle,
modifier = Modifier.size(40.dp)
) {
Icon(
Icons.Rounded.EmojiEmotions,
stringResource(R.string.icon_emoji),
tint = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
} else IconButton(onClick = onAttach) {
// One ring, one animation: the plus turns 45° into the
// cross that closes the tray, so closing it is the same
// control it was opened with.
Expand Down Expand Up @@ -4120,7 +4142,7 @@ internal fun InputBar(
)
}
}
if (showEmojiButton) {
if (showEmojiButton && attachEnabled) {
IconButton(onClick = onEmojiToggle, modifier = Modifier.size(40.dp)) {
Icon(
Icons.Rounded.EmojiEmotions, stringResource(R.string.icon_emoji),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ar/strings_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<string name="settings_font_title">الخط</string>
<string name="settings_advanced_emoji_button">زر الرموز التعبيرية</string>
<string name="settings_advanced_emoji_button_desc">إظهار زر الرموز التعبيرية في حقل الرسالة</string>
<string name="settings_mms_enabled">MMS</string>
<string name="settings_mms_enabled_summary">تُرسل الصور والرسائل الصوتية وجهات الاتصال عبر MMS</string>
<string name="settings_choose_font">اختيار الخط</string>
<string name="font_dm_sans">DM Sans</string>
<string name="font_inter">Inter</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<string name="chat_add_to_contacts">إضافة إلى جهات الاتصال</string>
<string name="chat_contact_saved">تم حفظ جهة الاتصال في Downloads/Messages</string>
<string name="chat_contact_save_failed">تعذّر حفظ جهة الاتصال</string>
<string name="chat_mms_disabled">MMS متوقف — لا يمكن إرسال الصور أو الرسائل الصوتية</string>

<string name="chat_voice_slide_cancel">اسحب للإلغاء</string>
<string name="chat_voice_release_cancel">اترك للإلغاء</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<string name="settings_font_title">Schriftart</string>
<string name="settings_advanced_emoji_button">Emoji-Schaltfläche</string>
<string name="settings_advanced_emoji_button_desc">Emoji-Schaltfläche im Nachrichtenfeld anzeigen</string>
<string name="settings_mms_enabled">MMS</string>
<string name="settings_mms_enabled_summary">Bilder, Sprachnachrichten und Kontakte werden über MMS gesendet</string>
<string name="settings_choose_font">Schriftart wählen</string>
<string name="font_dm_sans">DM Sans</string>
<string name="font_inter">Inter</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="chat_add_to_contacts">Zu Kontakten hinzufügen</string>
<string name="chat_contact_saved">Kontakt unter Downloads/Messages gespeichert</string>
<string name="chat_contact_save_failed">Kontakt konnte nicht gespeichert werden</string>
<string name="chat_mms_disabled">MMS ist aus — Bilder und Sprachnachrichten können nicht gesendet werden</string>
<!-- Voice messages -->
<string name="chat_voice_slide_cancel">Wischen zum Abbrechen</string>
<string name="chat_voice_release_cancel">Loslassen zum Abbrechen</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<string name="settings_font_title">Fuente</string>
<string name="settings_advanced_emoji_button">Botón de emoji</string>
<string name="settings_advanced_emoji_button_desc">Mostrar el botón de emoji en el campo de mensaje</string>
<string name="settings_mms_enabled">MMS</string>
<string name="settings_mms_enabled_summary">Las fotos, notas de voz y contactos se envían por MMS</string>
<string name="settings_choose_font">Elegir fuente</string>
<string name="font_dm_sans">DM Sans</string>
<string name="font_inter">Inter</string>
Expand Down
Loading