Skip to content

Commit 3e25a68

Browse files
committed
fix to enable system bubble when they are disabled but "create bubble" is chosen for a conversation
before this commit, only systemAllowsAllConversations was checked. This was not enough but also system wide enabling of bubbles must be checked + minor refactoring
1 parent f69ed77 commit 3e25a68

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,6 +3333,8 @@ open class ChatActivity :
33333333
menu.removeItem(R.id.conversation_voice_call)
33343334
}
33353335

3336+
menu.findItem(R.id.create_conversation_bubble)?.isVisible = NotificationUtils.deviceSupportsBubbles
3337+
33363338
handleThreadNotificationIcon(menu.findItem(R.id.thread_notifications))
33373339
}
33383340
return true
@@ -3402,8 +3404,15 @@ open class ChatActivity :
34023404
}
34033405

34043406
private fun createConversationBubble() {
3407+
if (!NotificationUtils.deviceSupportsBubbles) {
3408+
Log.e(TAG, "createConversationBubble was called but device doesnt support it. It should not be possible " +
3409+
"to get here via UI!")
3410+
return
3411+
}
3412+
34053413
lifecycleScope.launch {
3406-
if (!appPreferences.areBubblesEnabled()) {
3414+
if (!appPreferences.areBubblesEnabled() || !NotificationUtils.areSystemBubblesEnabled(context)) {
3415+
// Do not replace with snackbar as it needs to survive screen change
34073416
Toast.makeText(
34083417
this@ChatActivity,
34093418
getString(R.string.nc_conversation_notification_bubble_disabled),
@@ -3416,6 +3425,7 @@ open class ChatActivity :
34163425
if (!appPreferences.areBubblesForced()) {
34173426
val conversationAllowsBubbles = isConversationBubbleEnabled()
34183427
if (!conversationAllowsBubbles) {
3428+
// Do not replace with snackbar as it needs to survive screen change
34193429
Toast.makeText(
34203430
this@ChatActivity,
34213431
getString(R.string.nc_conversation_notification_bubble_enable_conversation),
@@ -3567,7 +3577,7 @@ open class ChatActivity :
35673577
// Check if notification channel supports bubbles and recreate if needed
35683578
val channel = notificationManager.getNotificationChannel(channelId)
35693579

3570-
if (channel == null || !channel.canBubble()) {
3580+
if (channel == null || NotificationUtils.deviceSupportsBubbles && !channel.canBubble()) {
35713581
NotificationUtils.registerNotificationChannels(
35723582
applicationContext,
35733583
appPreferences!!

app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import android.animation.Animator
1515
import android.animation.AnimatorListenerAdapter
1616
import android.annotation.SuppressLint
1717
import android.app.KeyguardManager
18-
import android.app.NotificationManager
1918
import android.content.ActivityNotFoundException
2019
import android.content.Context
2120
import android.content.DialogInterface
@@ -442,19 +441,20 @@ class SettingsActivity :
442441
binding.settingsBubbles.visibility = View.VISIBLE
443442
binding.settingsBubblesForce.visibility = View.VISIBLE
444443

445-
val systemAllowsAllConversations = isSystemBubblePreferenceAll()
444+
val systemAllowsAllConversations = NotificationUtils.isSystemBubblePreferenceAll(context)
445+
val systemBubblesEnabled = NotificationUtils.areSystemBubblesEnabled(context)
446446
updateBubbleSummary(systemAllowsAllConversations)
447447

448-
var bubblesEnabled = appPreferences.areBubblesEnabled()
449-
if (bubblesEnabled && !systemAllowsAllConversations) {
448+
var appBubblesEnabled = appPreferences.areBubblesEnabled()
449+
if (appBubblesEnabled && (!systemAllowsAllConversations || !systemBubblesEnabled)) {
450450
appPreferences.setBubblesEnabled(false)
451-
bubblesEnabled = false
451+
appBubblesEnabled = false
452452
}
453453

454-
setGlobalBubbleSwitchState(bubblesEnabled)
454+
setGlobalBubbleSwitchState(appBubblesEnabled)
455455
binding.settingsBubblesForceSwitch.isChecked = appPreferences.areBubblesForced()
456456

457-
updateBubbleForceRowState(bubblesEnabled)
457+
updateBubbleForceRowState(appBubblesEnabled)
458458

459459
binding.settingsBubblesSwitch.setOnCheckedChangeListener { _, isChecked ->
460460
if (isUpdatingBubbleSwitchState) {
@@ -494,10 +494,10 @@ class SettingsActivity :
494494
}
495495

496496
private fun handleGlobalBubblePreferenceChange(enabled: Boolean) {
497-
val systemAllowsAllConversations = isSystemBubblePreferenceAll()
497+
val systemAllowsAllConversations = NotificationUtils.isSystemBubblePreferenceAll(context)
498498

499499
if (enabled) {
500-
if (!systemAllowsAllConversations) {
500+
if (!systemAllowsAllConversations || !NotificationUtils.areSystemBubblesEnabled(context)) {
501501
pendingBubbleEnableAfterSystemChange = true
502502
showSystemBubblesDisabledFeedback()
503503
updateBubbleSummary(systemAllowsAllConversations)
@@ -556,15 +556,6 @@ class SettingsActivity :
556556
updateBubbleSummary(true)
557557
}
558558

559-
private fun isSystemBubblePreferenceAll(): Boolean {
560-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
561-
return false
562-
}
563-
564-
val notificationManager = getSystemService(NotificationManager::class.java)
565-
return notificationManager?.bubblePreference == NotificationManager.BUBBLE_PREFERENCE_ALL
566-
}
567-
568559
private fun navigateToSystemBubbleSettings() {
569560
val targetPackage = packageName
570561
val targetUid = applicationInfo?.uid ?: -1

app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable
2323
import android.media.AudioAttributes
2424
import android.net.Uri
2525
import android.os.Build
26+
import android.provider.Settings
2627
import android.service.notification.StatusBarNotification
2728
import android.text.TextUtils
2829
import android.util.Log
@@ -79,6 +80,34 @@ object NotificationUtils {
7980
const val KEY_UPLOAD_GROUP = "com.nextcloud.talk.utils.KEY_UPLOAD_GROUP"
8081
const val GROUP_SUMMARY_NOTIFICATION_ID = -1
8182

83+
val deviceSupportsBubbles = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
84+
85+
fun areSystemBubblesEnabled(context: Context): Boolean {
86+
if (!deviceSupportsBubbles) {
87+
return false
88+
}
89+
90+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
91+
Settings.Secure.getInt(
92+
context.contentResolver,
93+
"notification_bubbles",
94+
1
95+
) == 1
96+
} else {
97+
// Android 10 (Q) — bubbles always enabled
98+
true
99+
}
100+
}
101+
102+
fun isSystemBubblePreferenceAll(context: Context): Boolean {
103+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
104+
return false
105+
}
106+
107+
val notificationManager = context.getSystemService(NotificationManager::class.java)
108+
return notificationManager?.bubblePreference == NotificationManager.BUBBLE_PREFERENCE_ALL
109+
}
110+
82111
private fun createNotificationChannel(
83112
context: Context,
84113
notificationChannel: Channel,
@@ -87,8 +116,7 @@ object NotificationUtils {
87116
) {
88117
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
89118
val isMessagesChannel = notificationChannel.id == NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name
90-
val shouldSupportBubbles =
91-
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && isMessagesChannel
119+
val shouldSupportBubbles = deviceSupportsBubbles && isMessagesChannel
92120

93121
val existingChannel = notificationManager.getNotificationChannel(notificationChannel.id)
94122
val needsRecreation = shouldSupportBubbles && existingChannel != null && !existingChannel.canBubble()

0 commit comments

Comments
 (0)