@@ -21,14 +21,13 @@ import android.util.LruCache
2121import androidx.annotation.RequiresApi
2222import androidx.core.content.getSystemService
2323import com.oasisfeng.nevo.decorators.wechat.ConversationManager.Conversation
24- import com.oasisfeng.nevo.decorators.wechat.WeChatDecorator.AGENT_PACKAGE
25- import com.oasisfeng.nevo.decorators.wechat.WeChatDecorator.TAG
26- import com.oasisfeng.nevo.decorators.wechat.WeChatDecorator.WECHAT_PACKAGE
24+ import com.oasisfeng.nevo.decorators.wechat.IconHelper.toLocalAdaptiveIcon
2725import java.lang.reflect.Method
2826
2927@RequiresApi(N_MR1 ) class AgentShortcuts (private val context : Context ) {
3028
3129 companion object {
30+ private const val FLAG_ALLOW_EMBEDDED = - 0x80000000
3231 fun buildShortcutId (key : String ) = " C:$key "
3332 }
3433
@@ -62,13 +61,15 @@ import java.lang.reflect.Method
6261 }
6362
6463 val shortcut = ShortcutInfo .Builder (agentContext, id).setActivity(ComponentName (AGENT_PACKAGE , activity))
65- .setShortLabel(conversation.title).setRank(if (conversation.isGroupChat) 1 else 0 ) // Always keep last direct message conversation on top.
64+ .setShortLabel(conversation.title!! ).setRank(if (conversation.isGroupChat() ) 1 else 0 ) // Always keep last direct message conversation on top.
6665 .setIntent(intent.apply { if (action == null ) action = Intent .ACTION_MAIN })
6766 .setCategories(setOf (ShortcutInfo .SHORTCUT_CATEGORY_CONVERSATION )).apply {
68- if ( conversation.icon != null ) setIcon(conversation.icon. toLocalAdaptiveIcon(context, sm))
69- if (SDK_INT >= Q ) @SuppressLint( " RestrictedApi " ) {
67+ conversation.icon?. run { setIcon(toLocalAdaptiveIcon(context, sm)) }
68+ if (SDK_INT >= Q ) {
7069 setLongLived(true ).setLocusId(LocusId (id))
71- if (! conversation.isGroupChat) setPerson(conversation.sender().build().toAndroidPerson()) }}.build()
70+ if (! conversation.isGroupChat()) setPerson(conversation.sender().build().toNative())
71+ }
72+ }.build()
7273 Log .i(TAG , " Updating shortcut \" ${shortcut.id} \" ${if (BuildConfig .DEBUG ) " : " + shortcut.intent.toString() else " " } " )
7374 return if (sm.addDynamicShortcuts(listOf (shortcut))) true .also { Log .i(TAG , " Shortcut updated: $id " ) }
7475 else false .also { Log .e(TAG , " Unexpected rate limit." ) }
@@ -82,12 +83,12 @@ import java.lang.reflect.Method
8283 catch (e: RuntimeException ) { null .also { Log .e(TAG , " Error creating context for agent in user ${profile.hashCode()} " , e) }}
8384
8485 /* * @return whether shortcut is ready */
85- @RequiresApi( N_MR1 ) fun updateShortcutIfNeeded (id : String , conversation : Conversation , profile : UserHandle ): Boolean {
86- if (! conversation.isChat || conversation.isBotMessage) return false
86+ fun updateShortcutIfNeeded (id : String , conversation : Conversation , profile : UserHandle ): Boolean {
87+ if (! conversation.isChat() || conversation.isBotMessage() ) return false
8788 val agentContext = mAgentContextByProfile[profile] ? : return false
8889 if (mDynamicShortcutContacts.get(id) != null ) return true
8990 try { if (updateShortcut(id, conversation, agentContext))
90- return true .also { if (conversation.icon.type != TYPE_RESOURCE ) mDynamicShortcutContacts.put(id, Unit ) }} // If no large icon, wait for the next update
91+ return true .also { if (conversation.icon? .type != TYPE_RESOURCE ) mDynamicShortcutContacts.put(id, Unit ) }} // If no large icon, wait for the next update
9192 catch (e: RuntimeException ) { Log .e(TAG , " Error publishing shortcut: $id " , e) }
9293 return false
9394 }
@@ -126,5 +127,3 @@ import java.lang.reflect.Method
126127 mAgentContextByProfile.clear()
127128 }
128129}
129-
130- const val FLAG_ALLOW_EMBEDDED = - 0x80000000
0 commit comments