-
-
Notifications
You must be signed in to change notification settings - Fork 293
Adding bubbles support #5554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arlexTech
wants to merge
22
commits into
nextcloud:master
Choose a base branch
from
arlexTech:feature/bubble-conversations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding bubbles support #5554
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
18a7a2f
Adding bubbles support
arlexTech 57c2d7f
fix ktlintCheck detekt testGplayDebugUnitTest
arlexTech 0053b5b
remove deprecated onBackPressed and extracted code in function
arlexTech 734a700
prevent second app instance and adding talk icon button in bubble mode
arlexTech 3cc598e
fix potential issue with room token
arlexTech eaf4731
fix getLargeIcon preventing bubble notification
arlexTech 63f0818
bubbles off by default and lead to android bubble settings if needed …
arlexTech 7c463cb
codacy warnings
arlexTech 4e23c56
systemNotificationId fix
arlexTech d11c761
Fix 2 bubbles
arlexTech 0578f62
Merge branch 'master' into feature/bubble-conversations
arlexTech 605af97
fix user provider usage
mahibi 6a5a728
change logic to not delete bubbles
mahibi 0341869
fix to enable system bubble when they are disabled but "create bubble…
mahibi 39bb469
Merge branch 'nextcloud:master' into feature/bubble-conversations
arlexTech 43f442f
Merge branch 'nextcloud:master' into feature/bubble-conversations
arlexTech 304da57
Remove outdated comment
arlexTech a255e19
Merge branch 'nextcloud:master' into feature/bubble-conversations
arlexTech 374c378
Fix build
arlexTech 8ab2945
Extracted bubble logic
arlexTech 658d629
Fix codacy
arlexTech 93f31f2
Fix codacy fix
arlexTech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/nextcloud/talk/chat/BubbleActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Nextcloud Talk - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2025 Alexandre Wery <[email protected]> | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package com.nextcloud.talk.chat | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import androidx.activity.OnBackPressedCallback | ||
| import com.nextcloud.talk.R | ||
| import com.nextcloud.talk.activities.MainActivity | ||
| import com.nextcloud.talk.utils.bundle.BundleKeys | ||
|
|
||
| class BubbleActivity : ChatActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
| supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_talk) | ||
| supportActionBar?.setDisplayShowHomeEnabled(true) | ||
| findViewById<androidx.appcompat.widget.Toolbar>(R.id.chat_toolbar)?.setNavigationOnClickListener { | ||
| openConversationList() | ||
| } | ||
|
|
||
| onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { | ||
| override fun handleOnBackPressed() { | ||
| moveTaskToBack(false) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| override fun onPrepareOptionsMenu(menu: android.view.Menu): Boolean { | ||
| super.onPrepareOptionsMenu(menu) | ||
|
|
||
| menu.findItem(R.id.create_conversation_bubble)?.isVisible = false | ||
| menu.findItem(R.id.open_conversation_in_app)?.isVisible = true | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun onOptionsItemSelected(item: android.view.MenuItem): Boolean = | ||
| when (item.itemId) { | ||
| R.id.open_conversation_in_app -> { | ||
| openInMainApp() | ||
| true | ||
| } | ||
| android.R.id.home -> { | ||
| openConversationList() | ||
| true | ||
| } | ||
| else -> super.onOptionsItemSelected(item) | ||
| } | ||
|
|
||
| private fun openInMainApp() { | ||
| val intent = Intent(this, MainActivity::class.java).apply { | ||
| action = Intent.ACTION_MAIN | ||
| addCategory(Intent.CATEGORY_LAUNCHER) | ||
| putExtras([email protected]) | ||
| conversationUser?.id?.let { putExtra(BundleKeys.KEY_INTERNAL_USER_ID, it) } | ||
| flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP | ||
| } | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| private fun openConversationList() { | ||
| val intent = Intent(this, MainActivity::class.java).apply { | ||
| action = Intent.ACTION_MAIN | ||
| addCategory(Intent.CATEGORY_LAUNCHER) | ||
| flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP | ||
| } | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| @Deprecated("Deprecated in Java") | ||
| override fun onSupportNavigateUp(): Boolean { | ||
| openInMainApp() | ||
| return true | ||
| } | ||
|
|
||
| companion object { | ||
| fun newIntent(context: Context, roomToken: String, conversationName: String?): Intent = | ||
| Intent(context, BubbleActivity::class.java).apply { | ||
| putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken) | ||
| conversationName?.let { putExtra(BundleKeys.KEY_CONVERSATION_NAME, it) } | ||
| action = Intent.ACTION_VIEW | ||
| flags = Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_MULTIPLE_TASK | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /* | ||
| * Nextcloud Talk - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2025 Alexandre Wery <[email protected]> | ||
| * SPDX-FileCopyrightText: 2024 Christian Reiner <[email protected]> | ||
| * SPDX-FileCopyrightText: 2024 Parneet Singh <[email protected]> | ||
| * SPDX-FileCopyrightText: 2024 Giacomo Pacini <[email protected]> | ||
|
|
@@ -163,6 +164,7 @@ import com.nextcloud.talk.models.json.threads.ThreadInfo | |
| import com.nextcloud.talk.polls.ui.PollCreateDialogFragment | ||
| import com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity | ||
| import com.nextcloud.talk.shareditems.activities.SharedItemsActivity | ||
| import com.nextcloud.talk.settings.SettingsActivity | ||
| import com.nextcloud.talk.signaling.SignalingMessageReceiver | ||
| import com.nextcloud.talk.signaling.SignalingMessageSender | ||
| import com.nextcloud.talk.threadsoverview.ThreadsOverviewActivity | ||
|
|
@@ -214,6 +216,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_THREAD_ID | |
| import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil | ||
| import com.nextcloud.talk.utils.rx.DisposableSet | ||
| import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder | ||
| import com.nextcloud.talk.utils.preferences.preferencestorage.DatabaseStorageModule | ||
| import com.nextcloud.talk.webrtc.WebSocketConnectionHelper | ||
| import com.nextcloud.talk.webrtc.WebSocketInstance | ||
| import com.otaliastudios.autocomplete.Autocomplete | ||
|
|
@@ -252,7 +255,7 @@ import kotlin.math.roundToInt | |
|
|
||
| @Suppress("TooManyFunctions") | ||
| @AutoInjector(NextcloudTalkApplication::class) | ||
| class ChatActivity : | ||
| open class ChatActivity : | ||
| BaseActivity(), | ||
| MessagesListAdapter.OnLoadMoreListener, | ||
| MessagesListAdapter.Formatter<Date>, | ||
|
|
@@ -2678,26 +2681,36 @@ class ChatActivity : | |
| ) | ||
| } | ||
|
|
||
| private fun showConversationInfoScreen() { | ||
| private fun showConversationInfoScreen(focusBubbleSwitch: Boolean = false) { | ||
| val bundle = Bundle() | ||
|
|
||
| bundle.putString(KEY_ROOM_TOKEN, roomToken) | ||
| bundle.putBoolean(BundleKeys.KEY_ROOM_ONE_TO_ONE, isOneToOneConversation()) | ||
| if (focusBubbleSwitch) { | ||
| bundle.putBoolean(BundleKeys.KEY_FOCUS_CONVERSATION_BUBBLE, true) | ||
| } | ||
|
|
||
| val intent = Intent(this, ConversationInfoActivity::class.java) | ||
| intent.putExtras(bundle) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| private fun openBubbleSettings() { | ||
| val intent = Intent(this, SettingsActivity::class.java) | ||
| intent.putExtra(BundleKeys.KEY_FOCUS_BUBBLE_SETTINGS, true) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| private fun validSessionId(): Boolean = | ||
| currentConversation != null && | ||
| sessionIdAfterRoomJoined?.isNotEmpty() == true && | ||
| sessionIdAfterRoomJoined != "0" | ||
|
|
||
| @Suppress("Detekt.TooGenericExceptionCaught") | ||
| private fun cancelNotificationsForCurrentConversation() { | ||
| protected open fun cancelNotificationsForCurrentConversation() { | ||
| val isBubbleMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && isLaunchedFromBubble | ||
| if (conversationUser != null) { | ||
| if (!TextUtils.isEmpty(roomToken)) { | ||
| if (!TextUtils.isEmpty(roomToken) && !isBubbleMode) { | ||
| try { | ||
| NotificationUtils.cancelExistingNotificationsForRoom( | ||
| applicationContext, | ||
|
|
@@ -3284,6 +3297,10 @@ class ChatActivity : | |
| showThreadsItem.isVisible = !isChatThread() && | ||
| hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.THREADS) | ||
|
|
||
| val createBubbleItem = menu.findItem(R.id.create_conversation_bubble) | ||
| createBubbleItem.isVisible = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && | ||
| !isChatThread() | ||
|
|
||
| if (CapabilitiesUtil.isAbleToCall(spreedCapabilities) && !isChatThread()) { | ||
| conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call) | ||
| conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call) | ||
|
|
@@ -3316,6 +3333,8 @@ class ChatActivity : | |
| menu.removeItem(R.id.conversation_voice_call) | ||
| } | ||
|
|
||
| menu.findItem(R.id.create_conversation_bubble)?.isVisible = NotificationUtils.deviceSupportsBubbles | ||
|
|
||
| handleThreadNotificationIcon(menu.findItem(R.id.thread_notifications)) | ||
| } | ||
| return true | ||
|
|
@@ -3326,8 +3345,8 @@ class ChatActivity : | |
| hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.THREADS) | ||
|
|
||
| val threadNotificationIcon = when (conversationThreadInfo?.attendee?.notificationLevel) { | ||
| 1 -> R.drawable.outline_notifications_active_24 | ||
| 3 -> R.drawable.ic_baseline_notifications_off_24 | ||
| NOTIFICATION_LEVEL_DEFAULT -> R.drawable.outline_notifications_active_24 | ||
| NOTIFICATION_LEVEL_NEVER -> R.drawable.ic_baseline_notifications_off_24 | ||
| else -> R.drawable.baseline_notifications_24 | ||
| } | ||
| threadNotificationItem.icon = ContextCompat.getDrawable(context, threadNotificationIcon) | ||
|
|
@@ -3376,9 +3395,79 @@ class ChatActivity : | |
| true | ||
| } | ||
|
|
||
| R.id.create_conversation_bubble -> { | ||
| createConversationBubble() | ||
| true | ||
| } | ||
|
|
||
| else -> super.onOptionsItemSelected(item) | ||
| } | ||
|
|
||
| private fun createConversationBubble() { | ||
| if (!NotificationUtils.deviceSupportsBubbles) { | ||
| Log.e(TAG, "createConversationBubble was called but device doesnt support it. It should not be possible " + | ||
| "to get here via UI!") | ||
| return | ||
| } | ||
|
|
||
| lifecycleScope.launch { | ||
| if (!appPreferences.areBubblesEnabled() || !NotificationUtils.areSystemBubblesEnabled(context)) { | ||
| // Do not replace with snackbar as it needs to survive screen change | ||
| Toast.makeText( | ||
| this@ChatActivity, | ||
| getString(R.string.nc_conversation_notification_bubble_disabled), | ||
| Toast.LENGTH_SHORT | ||
| ).show() | ||
| openBubbleSettings() | ||
| return@launch | ||
| } | ||
|
|
||
| if (!appPreferences.areBubblesForced()) { | ||
| val conversationAllowsBubbles = isConversationBubbleEnabled() | ||
| if (!conversationAllowsBubbles) { | ||
| // Do not replace with snackbar as it needs to survive screen change | ||
| Toast.makeText( | ||
| this@ChatActivity, | ||
| getString(R.string.nc_conversation_notification_bubble_enable_conversation), | ||
| Toast.LENGTH_SHORT | ||
| ).show() | ||
| showConversationInfoScreen(focusBubbleSwitch = true) | ||
| return@launch | ||
| } | ||
| } | ||
|
|
||
| val conversationName = currentConversation?.displayName ?: getString(R.string.nc_app_name) | ||
|
|
||
| NotificationUtils.createConversationBubble( | ||
| context = this@ChatActivity, | ||
| bubbleInfo = NotificationUtils.BubbleInfo( | ||
| roomToken = roomToken, | ||
| conversationRemoteId = currentConversation!!.name, | ||
| conversationName = conversationName, | ||
| conversationUser = conversationUser!!, | ||
| isOneToOneConversation = isOneToOneConversation(), | ||
| credentials = credentials | ||
| ), | ||
| appPreferences = appPreferences!! | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private suspend fun isConversationBubbleEnabled(): Boolean { | ||
| val user = conversationUser ?: return false | ||
| return withContext(Dispatchers.IO) { | ||
| try { | ||
| DatabaseStorageModule(user, roomToken).getBoolean(BUBBLE_SWITCH_KEY, false) | ||
| } catch (e: IOException) { | ||
| Log.e(TAG, "Failed to read conversation bubble preference: IO error", e) | ||
| false | ||
| } catch (e: IllegalStateException) { | ||
| Log.e(TAG, "Failed to read conversation bubble preference: Invalid state", e) | ||
| false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Suppress("Detekt.LongMethod") | ||
| private fun showThreadNotificationMenu() { | ||
| fun setThreadNotificationLevel(level: Int) { | ||
|
|
@@ -3433,7 +3522,7 @@ class ChatActivity : | |
| subtitle = null, | ||
| icon = R.drawable.ic_baseline_notifications_off_24, | ||
| onClick = { | ||
| setThreadNotificationLevel(3) | ||
| setThreadNotificationLevel(NOTIFICATION_LEVEL_NEVER) | ||
| } | ||
| ) | ||
| ) | ||
|
|
@@ -4106,8 +4195,8 @@ class ChatActivity : | |
| displayName = currentConversation?.displayName ?: "" | ||
| ) | ||
| showSnackBar(roomToken) | ||
| } catch (e: Exception) { | ||
| Log.w(TAG, "File corresponding to the uri does not exist $shareUri", e) | ||
| } catch (e: IOException) { | ||
| Log.w(TAG, "File corresponding to the uri does not exist: IO error $shareUri", e) | ||
| downloadFileToCache(message, false) { | ||
| uploadFile( | ||
| fileUri = shareUri.toString(), | ||
|
|
@@ -4593,6 +4682,8 @@ class ChatActivity : | |
| private const val HTTP_FORBIDDEN = 403 | ||
| private const val HTTP_NOT_FOUND = 404 | ||
| private const val MESSAGE_PULL_LIMIT = 100 | ||
| private const val NOTIFICATION_LEVEL_DEFAULT = 1 | ||
| private const val NOTIFICATION_LEVEL_NEVER = 3 | ||
| private const val INVITE_LENGTH = 6 | ||
| private const val ACTOR_LENGTH = 6 | ||
| private const val CHUNK_SIZE: Int = 10 | ||
|
|
@@ -4608,6 +4699,7 @@ class ChatActivity : | |
| private const val CURRENT_AUDIO_POSITION_KEY = "CURRENT_AUDIO_POSITION" | ||
| private const val CURRENT_AUDIO_WAS_PLAYING_KEY = "CURRENT_AUDIO_PLAYING" | ||
| private const val RESUME_AUDIO_TAG = "RESUME_AUDIO_TAG" | ||
| private const val BUBBLE_SWITCH_KEY = "bubble_switch" | ||
| private const val FIVE_MINUTES_IN_SECONDS: Long = 300 | ||
| private const val ROOM_TYPE_ONE_TO_ONE = "1" | ||
| private const val ACTOR_TYPE = "users" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.