Skip to content

Commit

Permalink
WIP Icon Is User Avatar
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Oct 23, 2023
1 parent 4516b33 commit 89f4cee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
android:windowSoftInputMode="adjustResize"
android:allowEmbedded="true"
android:resizeableActivity="true"
android:documentLaunchMode="always">
android:documentLaunchMode="always"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down Expand Up @@ -226,6 +227,9 @@
<activity
android:name=".chat.ChatActivity"
android:theme="@style/AppTheme"
android:allowEmbedded="true"
android:resizeableActivity="true"
android:documentLaunchMode="always"
/>

<activity
Expand Down
73 changes: 44 additions & 29 deletions app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
val notificationBuilder = NotificationCompat.Builder(context!!, "4")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(category)
.setLargeIcon(getLargeIcon())
// .setLargeIcon(getLargeIcon())
.setSmallIcon(R.drawable.ic_logo)
.setContentTitle(contentTitle)
.setContentText(contentText)
Expand Down Expand Up @@ -568,20 +568,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
.setImportant(true)
.setBot(true)
notificationBuilder.setOnlyAlertOnce(true)

if ("user" == userType || "guest" == userType) {
val baseUrl = signatureVerification.user!!.baseUrl
val avatarUrl = if ("user" == userType) {
ApiUtils.getUrlForAvatar(
baseUrl,
notificationUser.id,
false
)
} else {
ApiUtils.getUrlForGuestAvatar(baseUrl, notificationUser.name, false)
}
person.setIcon(loadAvatarSync(avatarUrl, context!!))
}
person.setIcon(getAvatarIcon())
val personBuilt = person.build()
notificationBuilder.setStyle(getStyle(personBuilt, style))
notificationBuilder.addPerson(personBuilt)
Expand Down Expand Up @@ -633,31 +620,59 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor

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

val shortcutId = System.currentTimeMillis().toString()
val intent = getIntentToOpenConversation()!!

val shortCutInfo = ShortcutInfoCompat.Builder(context!!, shortcutId)
.setCategories(setOf(Notification.CATEGORY_MESSAGE))
.setIntent(Intent(Intent.ACTION_DEFAULT))
.setLongLived(true)
.setShortLabel("testing Bubble")
.build()
val shortcutId = pushMessage.notificationUser!!.id!!
val shortcuts = ShortcutManagerCompat.getDynamicShortcuts(context!!)
val index = shortcuts.firstOrNull {
it.id == shortcutId
}

ShortcutManagerCompat.pushDynamicShortcut(context!!, shortCutInfo)
if (index == null) {
val shortCutInfo = ShortcutInfoCompat.Builder(context!!, shortcutId)
.setCategories(setOf(Notification.CATEGORY_MESSAGE))
.setIntent(Intent(Intent.ACTION_DEFAULT))
.setLongLived(true)
.setShortLabel(pushMessage.notificationUser!!.name!!)
.build()
ShortcutManagerCompat.pushDynamicShortcut(context!!, shortCutInfo)
}

val bubbleData =
BubbleMetadata.Builder(intent!!, IconCompat.createWithBitmap(getLargeIcon()))
BubbleMetadata.Builder(intent, getAvatarIcon())
.setDesiredHeight(DESIRED_SIZE)
.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
.setIntent(intent)

bubbleData.setIcon(getAvatarIcon())
// TODO also this will eventually need to be set up to only show for important conversations

notificationBuilder
.setBubbleMetadata(bubbleData)
.setBubbleMetadata(bubbleData.build())
.setShortcutId(shortcutId)
.setLocusId(LocusIdCompat(shortcutId))
}

private fun getAvatarIcon(): IconCompat {
val notificationUser = pushMessage.notificationUser
val userType = notificationUser!!.type
var result: IconCompat? = null
if ("user" == userType || "guest" == userType) {
val baseUrl = signatureVerification.user!!.baseUrl
val avatarUrl = if ("user" == userType) {
ApiUtils.getUrlForAvatar(
baseUrl,
notificationUser.type,
false
)
} else {
ApiUtils.getUrlForGuestAvatar(baseUrl, notificationUser.name, false)
}
result = loadAvatarSync(avatarUrl, context!!)
}

return result ?: IconCompat.createWithResource(context!!, R.drawable.account_circle_96dp)
}

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 89f4cee

Please sign in to comment.