pref: 表情显示性能
This commit is contained in:
parent
67d4af51aa
commit
91893bb3b7
|
|
@ -346,9 +346,9 @@ class ReplyActivity : BaseActivity(), View.OnClickListener,
|
||||||
editText.mgr.disable()
|
editText.mgr.disable()
|
||||||
editText.setText(
|
editText.setText(
|
||||||
StringUtil.getEmoticonContent(
|
StringUtil.getEmoticonContent(
|
||||||
EmoticonUtil.EMOTICON_ALL_WEB_TYPE,
|
|
||||||
editText,
|
editText,
|
||||||
content
|
content,
|
||||||
|
EmoticonUtil.EMOTICON_ALL_WEB_TYPE
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
editText.mgr.enable()
|
editText.mgr.enable()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,12 @@ import com.huanchengfly.tieba.post.api.models.MessageListBean
|
||||||
import com.huanchengfly.tieba.post.api.models.MessageListBean.MessageInfoBean
|
import com.huanchengfly.tieba.post.api.models.MessageListBean.MessageInfoBean
|
||||||
import com.huanchengfly.tieba.post.components.MyViewHolder
|
import com.huanchengfly.tieba.post.components.MyViewHolder
|
||||||
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.DateTimeUtils
|
||||||
|
import com.huanchengfly.tieba.post.utils.EmoticonUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.NavigationHelper
|
||||||
|
import com.huanchengfly.tieba.post.utils.StringUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.getItemBackgroundDrawable
|
||||||
|
|
||||||
class MessageListAdapter(
|
class MessageListAdapter(
|
||||||
context: Context, private val type: Int
|
context: Context, private val type: Int
|
||||||
|
|
@ -73,13 +78,12 @@ class MessageListAdapter(
|
||||||
)
|
)
|
||||||
val contentTextView = viewHolder.getView<TextView>(R.id.message_list_item_content)
|
val contentTextView = viewHolder.getView<TextView>(R.id.message_list_item_content)
|
||||||
contentTextView.text = StringUtil.getEmoticonContent(
|
contentTextView.text = StringUtil.getEmoticonContent(
|
||||||
EmoticonUtil.EMOTICON_ALL_TYPE,
|
|
||||||
contentTextView,
|
contentTextView,
|
||||||
item.content
|
item.content,
|
||||||
|
EmoticonUtil.EMOTICON_ALL_TYPE
|
||||||
)
|
)
|
||||||
val textView = viewHolder.getView<TextView>(R.id.message_list_item_quote)
|
val textView = viewHolder.getView<TextView>(R.id.message_list_item_quote)
|
||||||
textView.text = StringUtil.getEmoticonContent(
|
textView.text = StringUtil.getEmoticonContent(
|
||||||
EmoticonUtil.EMOTICON_ALL_TYPE,
|
|
||||||
textView,
|
textView,
|
||||||
if (type == MessageFragment.TYPE_REPLY_ME) {
|
if (type == MessageFragment.TYPE_REPLY_ME) {
|
||||||
if ("1" == item.isFloor) {
|
if ("1" == item.isFloor) {
|
||||||
|
|
@ -89,7 +93,8 @@ class MessageListAdapter(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.title
|
item.title
|
||||||
}
|
},
|
||||||
|
EmoticonUtil.EMOTICON_ALL_TYPE
|
||||||
)
|
)
|
||||||
textView.setOnClickListener {
|
textView.setOnClickListener {
|
||||||
if ("1" == item.isFloor && item.quotePid != null) {
|
if ("1" == item.isFloor && item.quotePid != null) {
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ public class RecyclerFloorAdapter extends BaseSingleTypeAdapter<SubFloorListBean
|
||||||
|
|
||||||
private void setText(TextView textView, CharSequence content) {
|
private void setText(TextView textView, CharSequence content) {
|
||||||
content = BilibiliUtil.replaceVideoNumberSpan(getContext(), content);
|
content = BilibiliUtil.replaceVideoNumberSpan(getContext(), content);
|
||||||
content = StringUtil.getEmoticonContent(EmoticonUtil.EMOTICON_ALL_TYPE, textView, content);
|
content = StringUtil.getEmoticonContent(textView, content, EmoticonUtil.EMOTICON_ALL_TYPE);
|
||||||
textView.setText(content);
|
textView.setText(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ class ThreadReplyAdapter(context: Context) :
|
||||||
}
|
}
|
||||||
textView.text = replaceVideoNumberSpan(
|
textView.text = replaceVideoNumberSpan(
|
||||||
context,
|
context,
|
||||||
StringUtil.getEmoticonContent(EmoticonUtil.EMOTICON_ALL_TYPE, textView, builder)
|
StringUtil.getEmoticonContent(textView, builder, EmoticonUtil.EMOTICON_ALL_TYPE)
|
||||||
)
|
)
|
||||||
textView.setPadding(
|
textView.setPadding(
|
||||||
DisplayUtil.dp2px(context, 8f),
|
DisplayUtil.dp2px(context, 8f),
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.text.InlineTextContent
|
import androidx.compose.foundation.text.InlineTextContent
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
|
|
@ -21,6 +22,9 @@ import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.rememberTextMeasurer
|
import androidx.compose.ui.text.rememberTextMeasurer
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.github.panpf.sketch.compose.AsyncImage
|
||||||
|
import com.github.panpf.sketch.fetch.newFileUri
|
||||||
|
import com.github.panpf.sketch.fetch.newResourceUri
|
||||||
import com.github.panpf.sketch.request.LoadRequest
|
import com.github.panpf.sketch.request.LoadRequest
|
||||||
import com.github.panpf.sketch.request.LoadResult
|
import com.github.panpf.sketch.request.LoadResult
|
||||||
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||||
|
|
@ -48,6 +52,11 @@ fun getEmoticonHeightPx(style: TextStyle): Int {
|
||||||
return textLayoutResult.size.height
|
return textLayoutResult.size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class Emoticon(
|
||||||
|
val id: String,
|
||||||
|
val name: String
|
||||||
|
)
|
||||||
|
|
||||||
object EmoticonManager {
|
object EmoticonManager {
|
||||||
private val DEFAULT_EMOTICON_MAPPING: Map<String, String> = mapOf(
|
private val DEFAULT_EMOTICON_MAPPING: Map<String, String> = mapOf(
|
||||||
"呵呵" to "image_emoticon1",
|
"呵呵" to "image_emoticon1",
|
||||||
|
|
@ -128,13 +137,8 @@ object EmoticonManager {
|
||||||
PlaceholderVerticalAlign.TextCenter
|
PlaceholderVerticalAlign.TextCenter
|
||||||
),
|
),
|
||||||
children = {
|
children = {
|
||||||
Image(
|
AsyncImage(
|
||||||
painter = rememberDrawablePainter(
|
imageUri = rememberEmoticonUri(id = id),
|
||||||
drawable = getEmoticonDrawable(
|
|
||||||
LocalContext.current,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
),
|
|
||||||
contentDescription = stringResource(
|
contentDescription = stringResource(
|
||||||
id = R.string.emoticon,
|
id = R.string.emoticon,
|
||||||
getEmoticonNameById(id) ?: ""
|
getEmoticonNameById(id) ?: ""
|
||||||
|
|
@ -212,6 +216,15 @@ object EmoticonManager {
|
||||||
return File(getEmoticonCacheDir(), "$id.png")
|
return File(getEmoticonCacheDir(), "$id.png")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAllEmoticon(): List<Emoticon> {
|
||||||
|
return emoticonIds.map { id ->
|
||||||
|
Emoticon(
|
||||||
|
id = id,
|
||||||
|
name = getEmoticonNameById(id) ?: ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getEmoticonIdByName(name: String): String? {
|
fun getEmoticonIdByName(name: String): String? {
|
||||||
return emoticonMapping[name]
|
return emoticonMapping[name]
|
||||||
}
|
}
|
||||||
|
|
@ -252,6 +265,32 @@ object EmoticonManager {
|
||||||
).also { drawableCache[id] = it }
|
).also { drawableCache[id] = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getEmoticonUri(context: Context, id: String?): String {
|
||||||
|
id ?: return ""
|
||||||
|
val resId = getEmoticonResId(context, id)
|
||||||
|
if (resId != 0) {
|
||||||
|
return newResourceUri(resId)
|
||||||
|
}
|
||||||
|
val emoticonFile = getEmoticonFile(id)
|
||||||
|
if (!emoticonFile.exists()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return newFileUri(emoticonFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun rememberEmoticonPainter(id: String): Painter {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val drawable = remember(id) { getEmoticonDrawable(context, id) }
|
||||||
|
return rememberDrawablePainter(drawable = drawable)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun rememberEmoticonUri(id: String): String {
|
||||||
|
val context = LocalContext.current
|
||||||
|
return remember(id) { getEmoticonUri(context, id) }
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun fetchEmoticons(context: Context) {
|
private suspend fun fetchEmoticons(context: Context) {
|
||||||
emoticonIds.forEach {
|
emoticonIds.forEach {
|
||||||
val resId = getEmoticonResId(context, it)
|
val resId = getEmoticonResId(context, it)
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,8 @@ object EmoticonUtil {
|
||||||
// 特殊文字处理,将表情等转换一下
|
// 特殊文字处理,将表情等转换一下
|
||||||
mEditText!!.setText(
|
mEditText!!.setText(
|
||||||
getEmoticonContent(
|
getEmoticonContent(
|
||||||
emoticon_map_type,
|
mEditText!!,
|
||||||
mEditText!!, sb
|
sb, emoticon_map_type
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class PostListAdapterHelper(
|
||||||
private fun setText(textView: TextView, content: CharSequence?) {
|
private fun setText(textView: TextView, content: CharSequence?) {
|
||||||
var text = content
|
var text = content
|
||||||
text = replaceVideoNumberSpan(context, text)
|
text = replaceVideoNumberSpan(context, text)
|
||||||
text = StringUtil.getEmoticonContent(EmoticonUtil.EMOTICON_ALL_TYPE, textView, text)
|
text = StringUtil.getEmoticonContent(textView, text, EmoticonUtil.EMOTICON_ALL_TYPE)
|
||||||
textView.text = text
|
textView.text = text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ import kotlin.math.roundToInt
|
||||||
object StringUtil {
|
object StringUtil {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getEmoticonContent(
|
fun getEmoticonContent(
|
||||||
emoticon_map_type: Int,
|
|
||||||
tv: TextView,
|
tv: TextView,
|
||||||
source: CharSequence?
|
source: CharSequence?,
|
||||||
|
emoticonType: Int = EmoticonUtil.EMOTICON_ALL_TYPE
|
||||||
): SpannableString {
|
): SpannableString {
|
||||||
return try {
|
return try {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
|
|
@ -38,7 +38,7 @@ object StringUtil {
|
||||||
} else {
|
} else {
|
||||||
SpannableString(source)
|
SpannableString(source)
|
||||||
}
|
}
|
||||||
val regexEmoticon = EmoticonUtil.getRegex(emoticon_map_type)
|
val regexEmoticon = EmoticonUtil.getRegex(emoticonType)
|
||||||
val patternEmoticon = Pattern.compile(regexEmoticon)
|
val patternEmoticon = Pattern.compile(regexEmoticon)
|
||||||
val matcherEmoticon = patternEmoticon.matcher(spannableString)
|
val matcherEmoticon = patternEmoticon.matcher(spannableString)
|
||||||
while (matcherEmoticon.find()) {
|
while (matcherEmoticon.find()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue