Removed deprecated hasTextContent and getTextContent functions + hide auto start service notification when Core has started
This commit is contained in:
parent
351ce7c9e5
commit
318ae8ee20
4 changed files with 26 additions and 16 deletions
|
@ -196,7 +196,7 @@ class ChatMessagesListAdapter(
|
|||
if (chatMessage.state != ChatMessage.State.NotDelivered) {
|
||||
popup.menu.removeItem(R.id.chat_message_menu_resend)
|
||||
}
|
||||
if (!chatMessage.hasTextContent()) {
|
||||
if (chatMessage.contents.find { content -> content.isText } == null) {
|
||||
popup.menu.removeItem(R.id.chat_message_menu_copy_text)
|
||||
}
|
||||
if (chatMessageViewModel.contact.value != null) {
|
||||
|
@ -250,10 +250,14 @@ class ChatMessagesListAdapter(
|
|||
|
||||
private fun copyTextToClipboard() {
|
||||
val chatMessage = binding.viewModel?.chatMessage
|
||||
if (chatMessage != null && chatMessage.hasTextContent()) {
|
||||
val clipboard: ClipboardManager = coreContext.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("Message", chatMessage.textContent)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
if (chatMessage != null) {
|
||||
val content = chatMessage.contents.find { content -> content.isText }
|
||||
if (content != null) {
|
||||
val clipboard: ClipboardManager =
|
||||
coreContext.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("Message", content.utf8Text)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
Log.i("[Context] Global state changed [$state]")
|
||||
if (state == GlobalState.On) {
|
||||
contactsManager.fetchContactsAsync()
|
||||
notificationsManager.stopForegroundNotificationIfPossible()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class CoreService : CoreService() {
|
|||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (intent?.extras?.get("StartForeground") == true) {
|
||||
Log.i("[Service] Starting as foreground")
|
||||
Log.i("[Service] Starting as foreground due to device boot or app update")
|
||||
coreContext.notificationsManager.startForeground(this, true)
|
||||
} else if (corePreferences.keepServiceAlive) {
|
||||
Log.i("[Service] Starting as foreground to keep app alive in background")
|
||||
|
@ -60,7 +60,7 @@ class CoreService : CoreService() {
|
|||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
if (!corePreferences.keepServiceAlive) {
|
||||
if (coreContext.core.isInBackground()) {
|
||||
if (coreContext.core.isInBackground) {
|
||||
Log.i("[Service] Task removed, stopping Core")
|
||||
coreContext.stop()
|
||||
} else {
|
||||
|
|
|
@ -146,7 +146,9 @@ class NotificationsManager(private val context: Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if (!message.hasTextContent() && message.fileTransferInformation == null) {
|
||||
if (message.contents.find { content ->
|
||||
content.isFile or content.isFileTransfer or content.isText
|
||||
} == null) {
|
||||
Log.w("[Notifications Manager] Received message with neither text or attachment, do not notify")
|
||||
return
|
||||
}
|
||||
|
@ -290,7 +292,7 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
|
||||
fun startForeground(coreService: CoreService, useAutoStartDescription: Boolean = true) {
|
||||
Log.i("[Notifications Manager] Starting Service as foreground")
|
||||
Log.i("[Notifications Manager] Starting service as foreground")
|
||||
if (serviceNotification == null) {
|
||||
createServiceNotification(useAutoStartDescription)
|
||||
}
|
||||
|
@ -301,7 +303,7 @@ class NotificationsManager(private val context: Context) {
|
|||
|
||||
private fun startForeground(notificationId: Int, callNotification: Notification) {
|
||||
if (currentForegroundServiceNotificationId == 0 && service != null) {
|
||||
Log.i("[Notifications Manager] Starting Service as foreground using call notification")
|
||||
Log.i("[Notifications Manager] Starting service as foreground using call notification")
|
||||
currentForegroundServiceNotificationId = notificationId
|
||||
service?.startForeground(currentForegroundServiceNotificationId, callNotification)
|
||||
}
|
||||
|
@ -309,7 +311,7 @@ class NotificationsManager(private val context: Context) {
|
|||
|
||||
private fun stopForegroundNotification() {
|
||||
if (service != null) {
|
||||
Log.i("[Notifications Manager] Stopping Service as foreground")
|
||||
Log.i("[Notifications Manager] Stopping service as foreground")
|
||||
service?.stopForeground(true)
|
||||
currentForegroundServiceNotificationId = 0
|
||||
}
|
||||
|
@ -317,12 +319,14 @@ class NotificationsManager(private val context: Context) {
|
|||
|
||||
fun stopForegroundNotificationIfPossible() {
|
||||
if (service != null && currentForegroundServiceNotificationId == SERVICE_NOTIF_ID && !corePreferences.keepServiceAlive) {
|
||||
Log.i("[Notifications Manager] Stopping auto-started service notification")
|
||||
stopForegroundNotification()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopCallForeground() {
|
||||
if (service != null && currentForegroundServiceNotificationId != SERVICE_NOTIF_ID && !corePreferences.keepServiceAlive) {
|
||||
Log.i("[Notifications Manager] Stopping call notification used as foreground service")
|
||||
stopForegroundNotification()
|
||||
}
|
||||
}
|
||||
|
@ -582,14 +586,14 @@ class NotificationsManager(private val context: Context) {
|
|||
val roundPicture = ImageUtils.getRoundBitmapFromUri(context, pictureUri)
|
||||
val displayName = contact?.fullName ?: LinphoneUtils.getDisplayName(message.fromAddress)
|
||||
|
||||
val notifiable = getNotifiableForRoom(room)
|
||||
var text = ""
|
||||
if (message.hasTextContent()) text = message.textContent.orEmpty()
|
||||
else {
|
||||
var text: String = message.contents.find { content -> content.isText }?.utf8Text ?: ""
|
||||
if (text.isEmpty()) {
|
||||
for (content in message.contents) {
|
||||
text += content.name
|
||||
}
|
||||
}
|
||||
|
||||
val notifiable = getNotifiableForRoom(room)
|
||||
val notifiableMessage = NotifiableMessage(text, contact, displayName, message.time, senderAvatar = roundPicture, isOutgoing = message.isOutgoing)
|
||||
notifiable.messages.add(notifiableMessage)
|
||||
|
||||
|
@ -639,8 +643,9 @@ class NotificationsManager(private val context: Context) {
|
|||
private fun displayReplyMessageNotification(message: ChatMessage, notifiable: Notifiable) {
|
||||
Log.i("[Notifications Manager] Updating message notification with reply for notification ${notifiable.notificationId}")
|
||||
|
||||
val text = message.contents.find { content -> content.isText }?.utf8Text ?: ""
|
||||
val reply = NotifiableMessage(
|
||||
message.textContent.orEmpty(),
|
||||
text,
|
||||
null,
|
||||
notifiable.myself ?: LinphoneUtils.getDisplayName(message.fromAddress),
|
||||
System.currentTimeMillis(),
|
||||
|
|
Loading…
Reference in a new issue