@@ -21,14 +21,13 @@ import android.util.LruCache
21
21
import androidx.annotation.RequiresApi
22
22
import androidx.core.content.getSystemService
23
23
import 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
27
25
import java.lang.reflect.Method
28
26
29
27
@RequiresApi(N_MR1 ) class AgentShortcuts (private val context : Context ) {
30
28
31
29
companion object {
30
+ private const val FLAG_ALLOW_EMBEDDED = - 0x80000000
32
31
fun buildShortcutId (key : String ) = " C:$key "
33
32
}
34
33
@@ -62,13 +61,15 @@ import java.lang.reflect.Method
62
61
}
63
62
64
63
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.
66
65
.setIntent(intent.apply { if (action == null ) action = Intent .ACTION_MAIN })
67
66
.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 ) {
70
69
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()
72
73
Log .i(TAG , " Updating shortcut \" ${shortcut.id} \" ${if (BuildConfig .DEBUG ) " : " + shortcut.intent.toString() else " " } " )
73
74
return if (sm.addDynamicShortcuts(listOf (shortcut))) true .also { Log .i(TAG , " Shortcut updated: $id " ) }
74
75
else false .also { Log .e(TAG , " Unexpected rate limit." ) }
@@ -82,12 +83,12 @@ import java.lang.reflect.Method
82
83
catch (e: RuntimeException ) { null .also { Log .e(TAG , " Error creating context for agent in user ${profile.hashCode()} " , e) }}
83
84
84
85
/* * @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
87
88
val agentContext = mAgentContextByProfile[profile] ? : return false
88
89
if (mDynamicShortcutContacts.get(id) != null ) return true
89
90
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
91
92
catch (e: RuntimeException ) { Log .e(TAG , " Error publishing shortcut: $id " , e) }
92
93
return false
93
94
}
@@ -126,5 +127,3 @@ import java.lang.reflect.Method
126
127
mAgentContextByProfile.clear()
127
128
}
128
129
}
129
-
130
- const val FLAG_ALLOW_EMBEDDED = - 0x80000000
0 commit comments