Skip to content

Commit

Permalink
WIP bubbles, notification only shows as normal, trying to debug
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Oct 19, 2023
1 parent 6e3dd95 commit a30d5cb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
<activity
android:name=".activities.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:allowEmbedded="true"
android:resizeableActivity="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down Expand Up @@ -222,7 +224,9 @@

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

<activity
android:name=".openconversations.ListOpenConversationsActivity"
Expand Down
39 changes: 38 additions & 1 deletion app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ import android.text.TextUtils
import android.util.Base64
import android.util.Log
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.BubbleMetadata
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.Person
import androidx.core.app.RemoteInput
import androidx.core.content.ContextCompat
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.emoji2.text.EmojiCompat
import androidx.work.Data
Expand Down Expand Up @@ -495,6 +499,9 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId)
addReplyAction(notificationBuilder, systemNotificationId)
addMarkAsReadAction(notificationBuilder, systemNotificationId)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
setBubble(notificationBuilder)
}
}

if (TYPE_RECORDING == pushMessage.type && ncNotification != null) {
Expand Down Expand Up @@ -572,7 +579,9 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
}
person.setIcon(loadAvatarSync(avatarUrl, context!!))
}
notificationBuilder.setStyle(getStyle(person.build(), style))
val personBuilt = person.build()
notificationBuilder.setStyle(getStyle(personBuilt, style))
notificationBuilder.addPerson(personBuilt)
}

private fun buildIntentForAction(cls: Class<*>, systemNotificationId: Int, messageId: Int): PendingIntent {
Expand Down Expand Up @@ -619,6 +628,34 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
}
}

@RequiresApi(Build.VERSION_CODES.R)
private fun setBubble(notificationBuilder: NotificationCompat.Builder) {
val intent = getIntentToOpenConversation()

val shortcutId = "1_2_3"
val shortcut =
ShortcutInfoCompat.Builder(context!!, shortcutId)
.setCategories(setOf(Notification.CATEGORY_CALL)) // this function is only called for messages
.setIntent(Intent(Intent.ACTION_DEFAULT))
.setLongLived(true)
.setShortLabel("testing Bubble")
.build()

val bubbleData = intent?.let {
BubbleMetadata.Builder(it, IconCompat.createWithResource(context!!, R.drawable.ic_logo))
.setDesiredHeight(600)
.setIntent(intent)
.setAutoExpandBubble(true)
.setSuppressNotification(true)
.build() // eventually change the icon to the avatar of the conversation
// also this will eventually need to be set up to only show for important conversations
}
notificationBuilder
.setBubbleMetadata(bubbleData)
.setShortcutId(shortcutId)
.setShortcutInfo(shortcut)
}

private fun addReplyAction(notificationBuilder: NotificationCompat.Builder, systemNotificationId: Int) {
val replyLabel = context!!.resources.getString(R.string.nc_reply)
val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY)
Expand Down

0 comments on commit a30d5cb

Please sign in to comment.