Skip to content
Open
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
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@
android:name=".chat.ChatActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".chat.BubbleActivity"
android:theme="@style/AppTheme"
android:allowEmbedded="true"
android:resizeableActivity="true"
android:documentLaunchMode="always" />

<activity
android:name=".activities.CallActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
Expand Down
96 changes: 96 additions & 0 deletions app/src/main/java/com/nextcloud/talk/chat/BubbleActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2025 Alexandre Wery <nextcloud-talk-android@alwy.be>
* 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(this@BubbleActivity.intent)
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
}
}
}
120 changes: 105 additions & 15 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2025 Alexandre Wery <nextcloud-talk-android@alwy.be>
* SPDX-FileCopyrightText: 2024 Christian Reiner <foss@christian-reiner.info>
* SPDX-FileCopyrightText: 2024 Parneet Singh <gurayaparneet@gmail.com>
* SPDX-FileCopyrightText: 2024 Giacomo Pacini <giacomo@paciosoft.com>
Expand Down Expand Up @@ -157,6 +158,7 @@ import com.nextcloud.talk.events.UserMentionClickEvent
import com.nextcloud.talk.events.WebSocketCommunicationEvent
import com.nextcloud.talk.jobs.DeleteConversationWorker
import com.nextcloud.talk.jobs.DownloadFileToCacheWorker
import com.nextcloud.talk.jobs.NotificationWorker.Companion.BUBBLE_SWITCH_KEY
import com.nextcloud.talk.jobs.ShareOperationWorker
import com.nextcloud.talk.jobs.UploadAndShareFilesWorker
import com.nextcloud.talk.location.LocationPickerActivity
Expand All @@ -172,6 +174,7 @@ import com.nextcloud.talk.models.json.threads.ThreadInfo
import com.nextcloud.talk.polls.ui.PollCreateDialogFragment
import com.nextcloud.talk.polls.ui.PollMainDialogFragment
import com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity
import com.nextcloud.talk.settings.SettingsActivity
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
import com.nextcloud.talk.signaling.SignalingMessageReceiver
import com.nextcloud.talk.signaling.SignalingMessageSender
Expand Down Expand Up @@ -224,6 +227,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWIT
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_THREAD_ID
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
import com.nextcloud.talk.utils.preferences.preferencestorage.DatabaseStorageModule
import com.nextcloud.talk.utils.rx.DisposableSet
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper
Expand Down Expand Up @@ -264,7 +268,7 @@ import kotlin.math.roundToInt

@Suppress("TooManyFunctions", "LargeClass", "LongMethod")
@AutoInjector(NextcloudTalkApplication::class)
class ChatActivity :
open class ChatActivity :
BaseActivity(),
CallStartedMessageInterface {

Expand Down Expand Up @@ -1146,8 +1150,8 @@ class ChatActivity :

pendingTargetMessageId = extras?.getString(BundleKeys.KEY_MESSAGE_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(BundleKeys.KEY_MESSAGE_ID)?.takeIf { it > 0L }
pendingTargetThreadId = extras?.getString(BundleKeys.KEY_THREAD_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(BundleKeys.KEY_THREAD_ID)?.takeIf { it > 0L }
pendingTargetThreadId = extras?.getString(KEY_THREAD_ID)?.toLongOrNull()?.takeIf { it > 0L }
?: extras?.getLong(KEY_THREAD_ID)?.takeIf { it > 0L }
pendingTargetSearchQuery = extras?.getString(BundleKeys.KEY_SEARCH_QUERY)
}

Expand Down Expand Up @@ -2845,11 +2849,14 @@ 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 upcomingEvent =
(chatViewModel.upcomingEventViewState.value as? ChatViewModel.UpcomingEventUIState.Success)?.event
Expand All @@ -2862,15 +2869,22 @@ class ChatActivity :
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,
Expand Down Expand Up @@ -3199,7 +3213,7 @@ class ChatActivity :
val nextSearchItem = menu.findItem(R.id.conversation_search_next)

if (inSearchMode) {
val searchState = chatViewModel.searchUiState.value
chatViewModel.searchUiState.value
conversationVoiceCallMenuItem?.isVisible = false
conversationVideoMenuItem?.isVisible = false
menu.findItem(R.id.shared_items)?.isVisible = false
Expand Down Expand Up @@ -3247,10 +3261,11 @@ class ChatActivity :
showThreadsItem.isVisible = !isChatThread() &&
hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.THREADS)

if (CapabilitiesUtil.isAbleToCall(spreedCapabilities) &&
!isChatThread() &&
!ConversationUtils.isNoteToSelfConversation(currentConversation)
) {
val createBubbleItem = menu.findItem(R.id.create_conversation_bubble)
createBubbleItem.isVisible = Build.VERSION.SDK_INT >= 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)

Expand Down Expand Up @@ -3282,6 +3297,8 @@ class ChatActivity :
menu.removeItem(R.id.conversation_voice_call)
}

menu.findItem(R.id.create_conversation_bubble)?.isVisible = NotificationUtils.deviceSupportsBubbles

Comment on lines 3299 to +3301
handleThreadNotificationIcon(menu.findItem(R.id.thread_notifications))
}
return true
Expand Down Expand Up @@ -3362,6 +3379,11 @@ class ChatActivity :
true
}

R.id.create_conversation_bubble -> {
createConversationBubble()
true
}

else -> super.onOptionsItemSelected(item)
}

Expand Down Expand Up @@ -3442,6 +3464,73 @@ class ChatActivity :
)
}

@Suppress("ReturnCount")
private fun createConversationBubble() {
if (!NotificationUtils.deviceSupportsBubbles) {
Log.e(
TAG,
"createConversationBubble was called but device doesn't support it. It should not be possible " +
"to get here via UI!"
)
return
}

if (!appPreferences.areBubblesEnabled() || !NotificationUtils.areSystemBubblesEnabled(context)) {
// Do not replace with snackbar as it needs to survive screen change
Toast.makeText(
context,
getString(R.string.nc_conversation_notification_bubble_disabled),
Toast.LENGTH_SHORT
).show()
openBubbleSettings()
return
}

if (!appPreferences.areBubblesForced() && !isConversationBubbleEnabled()) {
// Do not replace with snackbar as it needs to survive screen change
Toast.makeText(
context,
getString(R.string.nc_conversation_notification_bubble_enable_conversation),
Toast.LENGTH_SHORT
).show()
showConversationInfoScreen(focusBubbleSwitch = true)
return
}

val conversationName = currentConversation?.displayName ?: getString(R.string.nc_app_name)
currentConversation?.let {
val bubbleInfo = NotificationUtils.BubbleInfo(
roomToken = roomToken,
conversationRemoteId = it.name,
conversationName = conversationName,
conversationUser = conversationUser,
isOneToOneConversation = isOneToOneConversation(),
credentials = credentials
)

NotificationUtils.createConversationBubble(
context = context,
bubbleInfo = bubbleInfo,
appPreferences = appPreferences,
lifecycleScope
)
}
}

private fun isConversationBubbleEnabled(): Boolean =
runCatching {
DatabaseStorageModule(conversationUser, roomToken).getBoolean(BUBBLE_SWITCH_KEY, false)
}.onFailure { e ->
when (e) {
is IOException -> Log.e(TAG, "Failed to read conversation bubble preference: IO error", e)
is IllegalStateException -> Log.e(
TAG,
"Failed to read conversation bubble preference: Invalid state",
e
)
}
}.getOrDefault(false)

@Suppress("Detekt.LongMethod")
private fun showThreadNotificationMenu() {
fun setThreadNotificationLevel(level: Int) {
Expand Down Expand Up @@ -3724,7 +3813,7 @@ class ChatActivity :
viewThemeUtils.talk.themeSearchView(actionView)
actionView.requestFocus()
window.decorView.post {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
val imm = getSystemService(INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.showSoftInput(actionView.findFocus(), InputMethodManager.SHOW_IMPLICIT)
}

Expand All @@ -3744,7 +3833,7 @@ class ChatActivity :
chatViewModel.onSearchQueryChanged(query.orEmpty())
chatViewModel.jumpToSearchSelection()
actionView.clearFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
val imm = getSystemService(INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(actionView.windowToken, 0)
return true
}
Expand Down Expand Up @@ -4206,8 +4295,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(),
Expand Down Expand Up @@ -4540,6 +4629,7 @@ 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 INVITE_LENGTH = 6
private const val ACTOR_LENGTH = 6
private const val CHUNK_SIZE: Int = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ConversationInfoActivity : BaseActivity() {
intent.getStringExtra(KEY_ROOM_TOKEN)
) { "Missing room token" }

val shouldFocus = intent.getBooleanExtra(BundleKeys.KEY_FOCUS_CONVERSATION_BUBBLE, false)

val upcomingEvent = intent.getParcelableExtraProvider<UpcomingEvent>(BundleKeys.KEY_UPCOMING_EVENT)
val upcomingEventSummary = upcomingEvent?.summary
val upcomingEventTime = upcomingEvent?.start?.let { start ->
Expand All @@ -186,6 +188,7 @@ class ConversationInfoActivity : BaseActivity() {
if (upcomingEventSummary != null || upcomingEventTime != null) {
viewModel.setUpcomingEvent(upcomingEventSummary, upcomingEventTime)
}
viewModel.setFocusBubble(shouldFocus)
}
.onFailure {
Log.e(TAG, "Failed to get current user")
Expand Down Expand Up @@ -325,7 +328,10 @@ class ConversationInfoActivity : BaseActivity() {
onArchiveClick = { conversationUser?.let { viewModel.toggleArchive(it, conversationToken) } },
onLeaveConversationClick = { leaveConversation() },
onClearHistoryClick = { showClearHistoryDialog() },
onDeleteConversationClick = { showDeleteConversationDialog() }
onDeleteConversationClick = { showDeleteConversationDialog() },
onBubbleClick = {
viewModel.toggleBubble(this, this.lifecycleScope)
}
)

private fun showSharedItems() {
Expand Down
Loading
Loading