Shorcuts creation improvements
This commit is contained in:
parent
f71811f65a
commit
898d3d0aa4
4 changed files with 33 additions and 19 deletions
|
@ -25,7 +25,6 @@ import android.app.*
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Icon
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
|
@ -118,7 +117,7 @@ class Api31Compatibility {
|
|||
} else {
|
||||
Person.Builder()
|
||||
.setName(conferenceInfo.subject)
|
||||
.setIcon(Icon.createWithResource(context, R.drawable.voip_multiple_contacts_avatar_alt))
|
||||
.setIcon(coreContext.contactsManager.groupAvatar.toIcon(context))
|
||||
.setImportant(false)
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -68,6 +68,9 @@ class ContactsManager(private val context: Context) {
|
|||
|
||||
var contactIdToWatchFor: String = ""
|
||||
|
||||
val contactAvatar: IconCompat
|
||||
val groupAvatar: IconCompat
|
||||
|
||||
private val localFriends = arrayListOf<Friend>()
|
||||
|
||||
private val contactsUpdatedListeners = ArrayList<ContactsUpdatedListener>()
|
||||
|
@ -79,13 +82,18 @@ class ContactsManager(private val context: Context) {
|
|||
for (friend in friends) {
|
||||
refreshContactOnPresenceReceived(friend)
|
||||
}
|
||||
Log.i("[Contacts Manager] Contacts refreshed due to presence received")
|
||||
notifyListeners()
|
||||
Log.i("[Contacts Manager] Presence notified to all listeners")
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
initSyncAccount()
|
||||
|
||||
contactAvatar = IconCompat.createWithResource(context, R.drawable.voip_single_contact_avatar_alt)
|
||||
groupAvatar = IconCompat.createWithResource(context, R.drawable.voip_multiple_contacts_avatar_alt)
|
||||
|
||||
val core = coreContext.core
|
||||
for (list in core.friendsLists) {
|
||||
list.addListener(friendListListener)
|
||||
|
@ -260,6 +268,7 @@ class ContactsManager(private val context: Context) {
|
|||
Log.d("[Contacts Manager] Received presence information for contact $friend")
|
||||
if (corePreferences.storePresenceInNativeContact && PermissionHelper.get().hasWriteContactsPermission()) {
|
||||
if (friend.refKey != null) {
|
||||
Log.i("[Contacts Manager] Storing presence in native contact ${friend.refKey}")
|
||||
storePresenceInNativeContact(friend)
|
||||
}
|
||||
}
|
||||
|
@ -383,17 +392,17 @@ fun Friend.getPerson(): Person {
|
|||
val bm: Bitmap? =
|
||||
ImageUtils.getRoundBitmapFromUri(
|
||||
coreContext.context,
|
||||
getPictureUri()
|
||||
getThumbnailUri()
|
||||
)
|
||||
val icon =
|
||||
if (bm == null) IconCompat.createWithResource(
|
||||
coreContext.context,
|
||||
R.drawable.voip_single_contact_avatar_alt
|
||||
) else IconCompat.createWithAdaptiveBitmap(bm)
|
||||
if (bm == null) {
|
||||
coreContext.contactsManager.contactAvatar
|
||||
} else IconCompat.createWithAdaptiveBitmap(bm)
|
||||
if (icon != null) {
|
||||
personBuilder.setIcon(icon)
|
||||
}
|
||||
|
||||
personBuilder.setUri(nativeUri)
|
||||
personBuilder.setImportant(starred)
|
||||
return personBuilder.build()
|
||||
}
|
||||
|
|
|
@ -431,7 +431,7 @@ class NotificationsManager(private val context: Context) {
|
|||
if (picture != null) {
|
||||
IconCompat.createWithAdaptiveBitmap(picture)
|
||||
} else {
|
||||
IconCompat.createWithResource(context, R.drawable.voip_single_contact_avatar_alt)
|
||||
coreContext.contactsManager.contactAvatar
|
||||
}
|
||||
if (userIcon != null) builder.setIcon(userIcon)
|
||||
builder.build()
|
||||
|
@ -791,7 +791,7 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
style.isGroupConversation = notifiable.isGroup
|
||||
|
||||
val icon = lastPerson?.icon ?: IconCompat.createWithResource(context, R.drawable.voip_single_contact_avatar_alt)
|
||||
val icon = lastPerson?.icon ?: coreContext.contactsManager.contactAvatar
|
||||
val bubble = NotificationCompat.BubbleMetadata.Builder(bubbleIntent, icon)
|
||||
.setDesiredHeightResId(R.dimen.chat_message_bubble_desired_height)
|
||||
.build()
|
||||
|
|
|
@ -30,8 +30,8 @@ import androidx.core.app.Person
|
|||
import androidx.core.content.LocusIdCompat
|
||||
import androidx.core.content.pm.ShortcutInfoCompat
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import kotlin.math.min
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.main.MainActivity
|
||||
import org.linphone.contact.getPerson
|
||||
import org.linphone.core.Address
|
||||
|
@ -132,7 +132,8 @@ class ShortcutsHelper(val context: Context) {
|
|||
return
|
||||
}
|
||||
|
||||
val maxShortcuts = shortcutManager.maxShortcutCountPerActivity
|
||||
Log.i("[Shortcut Helper] Creating launcher shortcuts for chat rooms")
|
||||
val maxShortcuts = min(shortcutManager.maxShortcutCountPerActivity, 5)
|
||||
var count = 0
|
||||
for (room in coreContext.core.chatRooms) {
|
||||
// Android can usually only have around 4-5 shortcuts at a time
|
||||
|
@ -143,12 +144,13 @@ class ShortcutsHelper(val context: Context) {
|
|||
|
||||
val shortcut: ShortcutInfo? = createChatRoomShortcut(context, room)
|
||||
if (shortcut != null) {
|
||||
Log.i("[Shortcut Helper] Creating launcher shortcut for ${shortcut.shortLabel}")
|
||||
Log.i("[Shortcut Helper] Created launcher shortcut for ${shortcut.shortLabel}")
|
||||
shortcuts.add(shortcut)
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
shortcutManager.dynamicShortcuts = shortcuts
|
||||
Log.i("[Shortcut Helper] Created $count launcher shortcuts")
|
||||
}
|
||||
|
||||
private fun createChatRoomShortcut(context: Context, chatRoom: ChatRoom): ShortcutInfo? {
|
||||
|
@ -166,20 +168,24 @@ class ShortcutsHelper(val context: Context) {
|
|||
if (chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())) {
|
||||
val contact =
|
||||
coreContext.contactsManager.findContactByAddress(chatRoom.peerAddress)
|
||||
if (contact != null) {
|
||||
personsList.add(contact.getPerson())
|
||||
val person = contact?.getPerson()
|
||||
if (person != null) {
|
||||
personsList.add(person)
|
||||
}
|
||||
|
||||
icon = person?.icon ?: coreContext.contactsManager.contactAvatar
|
||||
subject = contact?.name ?: LinphoneUtils.getDisplayName(chatRoom.peerAddress)
|
||||
icon = contact?.getPerson()?.icon ?: IconCompat.createWithResource(context, R.drawable.voip_single_contact_avatar_alt)
|
||||
} else if (chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) && chatRoom.participants.isNotEmpty()) {
|
||||
val address = chatRoom.participants.first().address
|
||||
val contact =
|
||||
coreContext.contactsManager.findContactByAddress(address)
|
||||
if (contact != null) {
|
||||
personsList.add(contact.getPerson())
|
||||
val person = contact?.getPerson()
|
||||
if (person != null) {
|
||||
personsList.add(person)
|
||||
}
|
||||
|
||||
subject = contact?.name ?: LinphoneUtils.getDisplayName(address)
|
||||
icon = contact?.getPerson()?.icon ?: IconCompat.createWithResource(context, R.drawable.voip_single_contact_avatar_alt)
|
||||
icon = person?.icon ?: coreContext.contactsManager.contactAvatar
|
||||
} else {
|
||||
for (participant in chatRoom.participants) {
|
||||
val contact =
|
||||
|
@ -189,7 +195,7 @@ class ShortcutsHelper(val context: Context) {
|
|||
}
|
||||
}
|
||||
subject = chatRoom.subject.orEmpty()
|
||||
icon = IconCompat.createWithResource(context, R.drawable.voip_multiple_contacts_avatar_alt)
|
||||
icon = coreContext.contactsManager.groupAvatar
|
||||
}
|
||||
|
||||
val persons = arrayOfNulls<Person>(personsList.size)
|
||||
|
|
Loading…
Reference in a new issue