3408: Only support iconics (get rid of "discouraged api") (#3476)
* 3408: Only support iconics (get rid of "discouraged api") * 3408: Remove unused import
This commit is contained in:
parent
7f7afb3e46
commit
8c519af611
|
@ -1,7 +1,6 @@
|
|||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableStringBuilder
|
||||
|
@ -11,7 +10,6 @@ import android.text.style.DynamicDrawableSpan
|
|||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.ImageSpan
|
||||
import android.text.style.URLSpan
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
|
||||
import java.util.regex.Pattern
|
||||
|
@ -97,34 +95,24 @@ fun highlightSpans(text: Spannable, colour: Int) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces text of the form [drawabale name] or [iconics name] with their spanned counterparts (ImageSpan).
|
||||
* Replaces text of the form [iconics name] with their spanned counterparts (ImageSpan).
|
||||
*/
|
||||
fun addDrawables(text: CharSequence, color: Int, size: Int, context: Context): Spannable {
|
||||
val alignment = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) DynamicDrawableSpan.ALIGN_CENTER else DynamicDrawableSpan.ALIGN_BASELINE
|
||||
|
||||
val builder = SpannableStringBuilder(text)
|
||||
|
||||
val pattern = Pattern.compile("\\[(drawable|iconics) ([0-9a-z_]+)\\]")
|
||||
val pattern = Pattern.compile("\\[iconics ([0-9a-z_]+)\\]")
|
||||
val matcher = pattern.matcher(builder)
|
||||
while (matcher.find()) {
|
||||
val resourceType = matcher.group(1)
|
||||
val resourceName = matcher.group(2)
|
||||
val resourceName = matcher.group(1)
|
||||
?: continue
|
||||
|
||||
val drawable: Drawable? = when (resourceType) {
|
||||
"iconics" -> IconicsDrawable(context, GoogleMaterial.getIcon(resourceName))
|
||||
else -> {
|
||||
val drawableResourceId = context.resources.getIdentifier(resourceName, "drawable", context.packageName)
|
||||
if (drawableResourceId != 0) AppCompatResources.getDrawable(context, drawableResourceId) else null
|
||||
}
|
||||
}
|
||||
val drawable = IconicsDrawable(context, GoogleMaterial.getIcon(resourceName))
|
||||
drawable.setBounds(0, 0, size, size)
|
||||
drawable.setTint(color)
|
||||
|
||||
if (drawable != null) {
|
||||
drawable.setBounds(0, 0, size, size)
|
||||
drawable.setTint(color)
|
||||
|
||||
builder.setSpan(ImageSpan(drawable, alignment), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
builder.setSpan(ImageSpan(drawable, alignment), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
|
||||
return builder
|
||||
|
|
|
@ -662,7 +662,7 @@
|
|||
<string name="status_filtered_show_anyway">Trotzdem anzeigen</string>
|
||||
<string name="help_empty_home">Dies ist deine <b>Startseite</b>. Sie zeigt die neuesten Beiträge der Accounts,
|
||||
denen du folgst.\n\nUm andere Accounts zu finden, kannst du entweder andere Timelines lesen.
|
||||
Zum Beispiel die Lokale Timeline deiner Instanz [drawable ic_local_24dp]. Oder du kannst nach ihrem Namen suchen
|
||||
Zum Beispiel die Lokale Timeline deiner Instanz [iconics gmd_group]. Oder du kannst nach ihrem Namen suchen
|
||||
[iconics gmd_search]; suche z. B. nach Tusky, um unseren Mastodon-Account zu finden.</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -805,6 +805,6 @@
|
|||
|
||||
<string name="help_empty_home">This is your <b>home timeline</b>. It shows the recent posts of the accounts
|
||||
you follow.\n\nTo explore accounts you can either discover them in one of the other timelines.
|
||||
For example the local timeline of your instance [drawable ic_local_24dp]. Or you can search them
|
||||
For example the local timeline of your instance [iconics gmd_group]. Or you can search them
|
||||
by name [iconics gmd_search]; for example search for Tusky to find our Mastodon account.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue