feat(Scout): add proper icons for suggestion entries
This commit is contained in:
parent
7b0c3bfd12
commit
d8772204e0
8 changed files with 101 additions and 22 deletions
|
|
@ -1,2 +1,2 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="youImportedTheWrongR" />
|
||||
<manifest package="moe.lava.awoocord.scout" />
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package moe.lava.awoocord.scout
|
|||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.aliucord.Utils
|
||||
import com.aliucord.annotations.AliucordPlugin
|
||||
import com.aliucord.entities.Plugin
|
||||
|
|
@ -11,6 +11,7 @@ import com.aliucord.patcher.after
|
|||
import com.aliucord.patcher.before
|
||||
import com.aliucord.patcher.instead
|
||||
import com.discord.BuildConfig
|
||||
import com.discord.databinding.WidgetSearchSuggestionsItemHasBinding
|
||||
import com.discord.restapi.RequiredHeadersInterceptor
|
||||
import com.discord.restapi.RequiredHeadersInterceptor.HeadersProvider
|
||||
import com.discord.restapi.RestAPIBuilder
|
||||
|
|
@ -19,6 +20,8 @@ import com.discord.simpleast.core.parser.Parser
|
|||
import com.discord.simpleast.core.parser.Rule
|
||||
import com.discord.stores.StoreSearch
|
||||
import com.discord.stores.StoreSearchInput
|
||||
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload
|
||||
import com.discord.utilities.mg_recycler.SingleTypePayload
|
||||
import com.discord.utilities.rest.RestAPI.AppHeadersProvider
|
||||
import com.discord.utilities.search.network.`SearchFetcher$getRestObservable$3`
|
||||
import com.discord.utilities.search.network.SearchQuery
|
||||
|
|
@ -39,6 +42,7 @@ import com.discord.widgets.search.suggestions.WidgetSearchSuggestionsAdapter
|
|||
import com.franmontiel.persistentcookiejar.PersistentCookieJar
|
||||
import com.franmontiel.persistentcookiejar.cache.SetCookieCache
|
||||
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor
|
||||
import com.lytefast.flexinput.R
|
||||
import moe.lava.awoocord.scout.api.SearchAPIInterface
|
||||
import moe.lava.awoocord.scout.parsing.DateNode
|
||||
import moe.lava.awoocord.scout.parsing.SimpleParserRule
|
||||
|
|
@ -52,10 +56,16 @@ import java.util.regex.Pattern
|
|||
@AliucordPlugin(requiresRestart = false)
|
||||
@Suppress("unused", "unchecked_cast")
|
||||
class Scout : Plugin() {
|
||||
lateinit var scoutRes: ScoutResource
|
||||
lateinit var ssProvider: ScoutSearchStringProvider
|
||||
lateinit var searchApi: SearchAPIInterface
|
||||
|
||||
init {
|
||||
needsResources = true
|
||||
}
|
||||
|
||||
override fun load(context: Context) {
|
||||
scoutRes = ScoutResource(resources)
|
||||
ssProvider = ScoutSearchStringProvider(context)
|
||||
searchApi = buildSearchApi(context)
|
||||
}
|
||||
|
|
@ -213,15 +223,34 @@ class Scout : Plugin() {
|
|||
}
|
||||
|
||||
// Patch to set icons
|
||||
patcher.before<WidgetSearchSuggestionsAdapter.HasViewHolder.Companion>(
|
||||
"getIconRes",
|
||||
HasAnswerOption::class.java
|
||||
patcher.before<WidgetSearchSuggestionsAdapter.HasViewHolder>(
|
||||
"onConfigure",
|
||||
Int::class.java,
|
||||
MGRecyclerDataPayload::class.java,
|
||||
) { param ->
|
||||
val type = param.args[0] as HasAnswerOption
|
||||
if (type == HasAnswerOptionExtension.POLL)
|
||||
param.result = 0x7f08032e
|
||||
else if (type == HasAnswerOptionExtension.SNAPSHOT)
|
||||
param.result = 0x7f08032e
|
||||
val suggestion = (param.args[1] as SingleTypePayload<HasSuggestion>).data
|
||||
val option = suggestion.hasAnswerOption
|
||||
|
||||
val resID = when (option) {
|
||||
HasAnswerOptionExtension.POLL -> "baseline_poll_24"
|
||||
HasAnswerOptionExtension.SNAPSHOT -> "baseline_forward_to_inbox_24"
|
||||
else -> null
|
||||
}
|
||||
|
||||
resID?.let {
|
||||
val bindingField = this::class.java.getDeclaredField("binding")
|
||||
bindingField.isAccessible = true
|
||||
val binding = bindingField.get(this) as WidgetSearchSuggestionsItemHasBinding
|
||||
|
||||
binding.d.text = option.getLocalizedInputText(null)
|
||||
binding.b.setOnClickListener {
|
||||
WidgetSearchSuggestionsAdapter.HasViewHolder.`access$getAdapter$p`(this).onHasClicked.invoke(option)
|
||||
}
|
||||
|
||||
binding.c.setImageDrawable(scoutRes.getDrawable(it))
|
||||
|
||||
param.result = null
|
||||
}
|
||||
}
|
||||
|
||||
patcher.instead<SearchSuggestionEngine>(
|
||||
|
|
@ -466,12 +495,19 @@ class Scout : Plugin() {
|
|||
FilterType::class.java
|
||||
) { param ->
|
||||
val type = param.args[1] as FilterType
|
||||
if (type in FilterTypeExtension.dates)
|
||||
param.result = ContextCompat.getDrawable(context, ScoutResource.DRAWABLE_IC_CLOCK)
|
||||
if (type == FilterTypeExtension.SORT)
|
||||
param.result = ContextCompat.getDrawable(context, ScoutResource.DRAWABLE_IC_SORT_WHITE)
|
||||
if (type == FilterTypeExtension.EXCLUDE)
|
||||
param.result = ContextCompat.getDrawable(context, ScoutResource.DRAWABLE_IC_SORT_WHITE)
|
||||
val (isDiscord, resID) = when (type) {
|
||||
FilterTypeExtension.BEFORE -> true to R.e.ic_history_white_24dp
|
||||
FilterTypeExtension.DURING -> false to scoutRes.getDrawableId("baseline_clock_24")
|
||||
FilterTypeExtension.AFTER -> false to scoutRes.getDrawableId("baseline_update_24")
|
||||
FilterTypeExtension.SORT -> true to R.e.ic_sort_white_24dp
|
||||
FilterTypeExtension.EXCLUDE -> false to scoutRes.getDrawableId("baseline_do_disturb_on_24")
|
||||
else -> false to null
|
||||
}
|
||||
|
||||
resID?.let {
|
||||
val res = if (isDiscord) context.resources else resources
|
||||
param.result = ResourcesCompat.getDrawable(res, it, null)
|
||||
}
|
||||
}
|
||||
|
||||
// Patch for retrieving sample filter answer/placeholder
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
package moe.lava.awoocord.scout.ui
|
||||
|
||||
object ScoutResource {
|
||||
const val SORT_FILTER = 0xfffffff0.toInt()
|
||||
const val SORT_ANSWER = 0xfffffff1.toInt()
|
||||
const val EXCLUDE_FILTER = 0xfffffff2.toInt()
|
||||
const val DRAWABLE_IC_CLOCK = 0x7f0803bb
|
||||
const val DRAWABLE_IC_SORT_WHITE =0x7f080586
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
|
||||
class ScoutResource(private val resources: Resources) {
|
||||
companion object {
|
||||
const val SORT_FILTER = 0xfffffff0.toInt()
|
||||
const val SORT_ANSWER = 0xfffffff1.toInt()
|
||||
const val EXCLUDE_FILTER = 0xfffffff2.toInt()
|
||||
}
|
||||
|
||||
fun getId(name: String, type: String) =
|
||||
resources.getIdentifier(name, type, "moe.lava.awoocord.scout")
|
||||
|
||||
@DrawableRes fun getDrawableId(name: String) =
|
||||
getId(name, "drawable")
|
||||
|
||||
fun getDrawable(@DrawableRes id: Int) =
|
||||
ResourcesCompat.getDrawable(resources, id, null)
|
||||
|
||||
fun getDrawable(name: String) =
|
||||
getDrawable(getDrawableId(name))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
|
||||
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM17,13H7v-2h10V13z"/>
|
||||
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20,4H4C2.9,4 2,4.9 2,6v12c0,1.1 0.9,2 2,2h9v-2H4V8l8,5l8,-5v5h2V6C22,4.9 21.1,4 20,4zM12,11L4,6h16L12,11zM19,15l4,4l-4,4v-3h-4v-2h4V15z"/>
|
||||
|
||||
</vector>
|
||||
5
plugins/Scout/src/main/res/drawable/baseline_poll_24.xml
Normal file
5
plugins/Scout/src/main/res/drawable/baseline_poll_24.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM9,17L7,17v-7h2v7zM13,17h-2L11,7h2v10zM17,17h-2v-4h2v4z"/>
|
||||
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M21,10.12h-6.78l2.74,-2.82c-2.73,-2.7 -7.15,-2.8 -9.88,-0.1c-2.73,2.71 -2.73,7.08 0,9.79s7.15,2.71 9.88,0C18.32,15.65 19,14.08 19,12.1h2c0,1.98 -0.88,4.55 -2.64,6.29c-3.51,3.48 -9.21,3.48 -12.72,0c-3.5,-3.47 -3.53,-9.11 -0.02,-12.58s9.14,-3.47 12.65,0L21,3V10.12zM12.5,8v4.25l3.5,2.08l-0.72,1.21L11,13V8H12.5z"/>
|
||||
|
||||
</vector>
|
||||
Loading…
Add table
Add a link
Reference in a new issue