fix: 修复一些 Bug
This commit is contained in:
parent
eb37aaf74d
commit
a071fd1f5d
|
|
@ -66,6 +66,7 @@ import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
|||
import com.huanchengfly.tieba.post.utils.*
|
||||
import com.huanchengfly.tieba.post.utils.ColorUtils.getDarkerColor
|
||||
import com.huanchengfly.tieba.post.utils.ColorUtils.greifyColor
|
||||
import com.huanchengfly.tieba.post.utils.StringUtil.getShortNumString
|
||||
import com.huanchengfly.tieba.post.utils.anim.animSet
|
||||
import com.huanchengfly.tieba.post.utils.preload.PreloadUtil
|
||||
import com.huanchengfly.tieba.post.widgets.MyViewPager
|
||||
|
|
@ -618,21 +619,6 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
|||
}
|
||||
}
|
||||
|
||||
private fun getNumStr(num: String): String {
|
||||
val long = num.toLong()
|
||||
if (long > 9999) {
|
||||
val longW = long * 10 / 10000L / 10F
|
||||
if (longW > 999) {
|
||||
val longKW = longW.toLong() / 1000L
|
||||
return "${longKW}KW"
|
||||
} else {
|
||||
return "${longW}W"
|
||||
}
|
||||
} else {
|
||||
return num
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshHeaderView() {
|
||||
if (mDataBean != null && mDataBean!!.forum != null) {
|
||||
headerView.visibility = View.VISIBLE
|
||||
|
|
@ -688,9 +674,9 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
|||
it.typeface = Typeface.createFromAsset(assets, "bebas.ttf")
|
||||
}
|
||||
//statTitleTextView.typeface = Typeface.createFromAsset(assets, "TiebaStatFont.ttf")
|
||||
statMembersTextView.text = getNumStr(mDataBean!!.forum!!.memberNum!!)
|
||||
statPostsTextView.text = getNumStr(mDataBean!!.forum!!.postNum!!)
|
||||
statThreadsTextView.text = getNumStr(mDataBean!!.forum!!.threadNum!!)
|
||||
statMembersTextView.text = mDataBean!!.forum!!.memberNum!!.getShortNumString()
|
||||
statPostsTextView.text = mDataBean!!.forum!!.postNum!!.getShortNumString()
|
||||
statThreadsTextView.text = mDataBean!!.forum!!.threadNum!!.getShortNumString()
|
||||
if (mDataBean!!.forum!!.slogan.isNullOrEmpty()) {
|
||||
(headerSloganTextView.parent as View).visibility = View.GONE
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class MessageListAdapter(
|
|||
}
|
||||
viewHolder.setText(
|
||||
R.id.message_list_item_user_name,
|
||||
StringUtil.getUsernameString(context, item.replyer.name, item.replyer.nameShow)
|
||||
StringUtil.getUsernameString(context, item.replyer.name ?: "", item.replyer.nameShow)
|
||||
)
|
||||
viewHolder.setText(
|
||||
R.id.message_list_item_user_time,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class SearchUserAdapter(
|
|||
override fun convert(viewHolder: MyViewHolder, item: SearchUserBean.UserBean, position: Int) {
|
||||
viewHolder.setText(
|
||||
R.id.item_search_user_title,
|
||||
StringUtil.getUsernameString(context, item.name, item.userNickname)
|
||||
StringUtil.getUsernameString(context, item.name ?: "", item.userNickname)
|
||||
)
|
||||
ImageUtil.load(
|
||||
viewHolder.getView(R.id.item_search_user_avatar),
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ class ThreadMainPostAdapter(
|
|||
true
|
||||
}
|
||||
holder.setVisibility(R.id.thread_list_item_user_lz_tip, true)
|
||||
var username: CharSequence = StringUtil.getUsernameString(context, user.name, user.nameShow)
|
||||
var username: CharSequence =
|
||||
StringUtil.getUsernameString(context, user.name ?: "", user.nameShow)
|
||||
if (user.isBawu == "1") {
|
||||
val bawuType = if (user.bawuType == "manager") "吧主" else "小吧主"
|
||||
username = SpannableStringBuilder(username).apply {
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ class ThreadReplyAdapter(context: Context) :
|
|||
var username: CharSequence =
|
||||
if (userInfoBean == null) item.authorId ?: "" else StringUtil.getUsernameString(
|
||||
context,
|
||||
userInfoBean.name,
|
||||
userInfoBean.name ?: "",
|
||||
userInfoBean.nameShow
|
||||
)
|
||||
if (userInfoBean != null && userInfoBean.isBawu == "1") {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.huanchengfly.tieba.post.interfaces.Refreshable
|
|||
import com.huanchengfly.tieba.post.interfaces.ScrollTopable
|
||||
import com.huanchengfly.tieba.post.utils.AnimUtil.alphaIn
|
||||
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||
import com.huanchengfly.tieba.post.utils.StringUtil.getShortNumString
|
||||
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||
import com.huanchengfly.tieba.post.utils.Util
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
|
|
@ -143,21 +144,6 @@ class ForumInfoFragment : BaseFragment(), Refreshable, ScrollTopable {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getNumStr(num: String): String {
|
||||
val long = num.toLong()
|
||||
if (long > 9999) {
|
||||
val longW = long * 10 / 10000L / 10F
|
||||
if (longW > 999) {
|
||||
val longKW = longW.toLong() / 1000L
|
||||
return "${longKW}KW"
|
||||
} else {
|
||||
return "${longW}W"
|
||||
}
|
||||
} else {
|
||||
return num
|
||||
}
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
mRefreshLayout.isRefreshing = true
|
||||
launch(IO + job) {
|
||||
|
|
@ -174,9 +160,9 @@ class ForumInfoFragment : BaseFragment(), Refreshable, ScrollTopable {
|
|||
ImageUtil.load(avatar, ImageUtil.LOAD_TYPE_AVATAR, data.forum!!.avatar)
|
||||
title.text = attachContext.getString(R.string.title_forum, data.forum!!.name)
|
||||
slogan.text = data.forum!!.slogan
|
||||
statMembersTextView.text = getNumStr(mDataBean!!.forum!!.memberNum!!)
|
||||
statPostsTextView.text = getNumStr(mDataBean!!.forum!!.postNum!!)
|
||||
statThreadsTextView.text = getNumStr(mDataBean!!.forum!!.threadNum!!)
|
||||
statMembersTextView.text = mDataBean!!.forum!!.memberNum!!.getShortNumString()
|
||||
statPostsTextView.text = mDataBean!!.forum!!.postNum!!.getShortNumString()
|
||||
statThreadsTextView.text = mDataBean!!.forum!!.threadNum!!.getShortNumString()
|
||||
if (data.forum!!.zyqDefine != null && data.forum!!.zyqDefine!!.isNotEmpty()) {
|
||||
mFriendLinksView.visibility = View.VISIBLE
|
||||
zyqTitle.text = data.forum!!.zyqTitle
|
||||
|
|
|
|||
|
|
@ -111,15 +111,16 @@ object EmotionManager {
|
|||
}
|
||||
|
||||
private fun updateCache() {
|
||||
val emotionDataCacheFile = File(getEmotionCacheDir(), "emotion_data_cache")
|
||||
if (!emotionDataCacheFile.exists()) {
|
||||
emotionDataCacheFile.createNewFile()
|
||||
runCatching {
|
||||
val emotionDataCacheFile = File(getEmotionCacheDir(), "emotion_data_cache")
|
||||
if (emotionDataCacheFile.exists() || emotionDataCacheFile.createNewFile()) {
|
||||
FileUtil.writeFile(
|
||||
emotionDataCacheFile,
|
||||
EmotionCache(emotionIds, emotionMapping).toJson(),
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
FileUtil.writeFile(
|
||||
emotionDataCacheFile,
|
||||
EmotionCache(emotionIds, emotionMapping).toJson(),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
private fun getContext(): Context {
|
||||
|
|
|
|||
|
|
@ -1,82 +1,108 @@
|
|||
package com.huanchengfly.tieba.post.utils;
|
||||
package com.huanchengfly.tieba.post.utils
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.widget.TextView;
|
||||
import android.content.Context
|
||||
import android.text.*
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.widget.TextView
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.components.spans.EmotionSpanV2
|
||||
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
||||
import com.huanchengfly.tieba.post.utils.EmotionManager.getEmotionDrawable
|
||||
import com.huanchengfly.tieba.post.utils.EmotionManager.getEmotionIdByName
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
import com.huanchengfly.tieba.post.R;
|
||||
import com.huanchengfly.tieba.post.components.spans.EmotionSpanV2;
|
||||
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class StringUtil {
|
||||
public static SpannableString getEmotionContent(int emotion_map_type, final TextView tv, CharSequence source) {
|
||||
try {
|
||||
object StringUtil {
|
||||
@JvmStatic
|
||||
fun getEmotionContent(
|
||||
emotion_map_type: Int,
|
||||
tv: TextView,
|
||||
source: CharSequence?
|
||||
): SpannableString {
|
||||
return try {
|
||||
if (source == null) {
|
||||
return new SpannableString("");
|
||||
return SpannableString("")
|
||||
}
|
||||
SpannableString spannableString;
|
||||
if (source instanceof SpannableString) {
|
||||
spannableString = (SpannableString) source;
|
||||
val spannableString: SpannableString = if (source is SpannableString) {
|
||||
source
|
||||
} else {
|
||||
spannableString = new SpannableString(source);
|
||||
SpannableString(source)
|
||||
}
|
||||
String regexEmotion = EmotionUtil.getRegex(emotion_map_type);
|
||||
Pattern patternEmotion = Pattern.compile(regexEmotion);
|
||||
Matcher matcherEmotion = patternEmotion.matcher(spannableString);
|
||||
val regexEmotion = EmotionUtil.getRegex(emotion_map_type)
|
||||
val patternEmotion = Pattern.compile(regexEmotion)
|
||||
val matcherEmotion = patternEmotion.matcher(spannableString)
|
||||
while (matcherEmotion.find()) {
|
||||
String key = matcherEmotion.group();
|
||||
int start = matcherEmotion.start();
|
||||
String group1 = matcherEmotion.group(1);
|
||||
Drawable emotionDrawable = EmotionManager.INSTANCE.getEmotionDrawable(tv.getContext(), EmotionManager.INSTANCE.getEmotionIdByName(group1));
|
||||
val key = matcherEmotion.group()
|
||||
val start = matcherEmotion.start()
|
||||
val group1 = matcherEmotion.group(1) ?: ""
|
||||
val emotionDrawable = getEmotionDrawable(tv.context, getEmotionIdByName(group1))
|
||||
if (emotionDrawable != null) {
|
||||
TextPaint paint = tv.getPaint();
|
||||
int size = Math.round(-paint.ascent() + paint.descent());
|
||||
EmotionSpanV2 span = new EmotionSpanV2(emotionDrawable, size);
|
||||
spannableString.setSpan(span, start, start + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
val paint = tv.paint
|
||||
val size = (-paint.ascent() + paint.descent()).roundToInt()
|
||||
val span = EmotionSpanV2(emotionDrawable, size)
|
||||
spannableString.setSpan(
|
||||
span,
|
||||
start,
|
||||
start + key.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
}
|
||||
return spannableString;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SpannableString spannableString;
|
||||
if (source instanceof SpannableString) {
|
||||
spannableString = (SpannableString) source;
|
||||
spannableString
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
val spannableString: SpannableString = if (source is SpannableString) {
|
||||
source
|
||||
} else {
|
||||
spannableString = new SpannableString(source);
|
||||
SpannableString(source)
|
||||
}
|
||||
return spannableString;
|
||||
spannableString
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSequence getUsernameString(Context context, String username, String nickname) {
|
||||
boolean showBoth = AppPreferencesUtilsKt.getAppPreferences(context).getShowBothUsernameAndNickname();
|
||||
@JvmStatic
|
||||
fun getUsernameString(context: Context, username: String, nickname: String?): CharSequence {
|
||||
val showBoth = context.appPreferences.showBothUsernameAndNickname
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
return TextUtils.isEmpty(username) ? "" : username;
|
||||
} else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals(username, nickname)) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(nickname);
|
||||
builder.append("(" + username + ")", new ForegroundColorSpan(ThemeUtils.getColorByAttr(context, R.attr.color_text_disabled)), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return builder;
|
||||
return if (TextUtils.isEmpty(username)) "" else username
|
||||
} else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals(
|
||||
username,
|
||||
nickname
|
||||
)
|
||||
) {
|
||||
val builder = SpannableStringBuilder(nickname)
|
||||
builder.append(
|
||||
"($username)",
|
||||
ForegroundColorSpan(ThemeUtils.getColorByAttr(context, R.attr.color_text_disabled)),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
return builder
|
||||
}
|
||||
return nickname;
|
||||
return nickname ?: ""
|
||||
}
|
||||
|
||||
public static String getAvatarUrl(String portrait) {
|
||||
if (TextUtils.isEmpty(portrait)) {
|
||||
return "";
|
||||
@JvmStatic
|
||||
fun getAvatarUrl(portrait: String?): String {
|
||||
if (portrait.isNullOrEmpty()) {
|
||||
return ""
|
||||
}
|
||||
if (portrait.startsWith("http://") || portrait.startsWith("https://")) {
|
||||
return portrait;
|
||||
}
|
||||
return "http://tb.himg.baidu.com/sys/portrait/item/" + portrait;
|
||||
return if (portrait.startsWith("http://") || portrait.startsWith("https://")) {
|
||||
portrait
|
||||
} else "http://tb.himg.baidu.com/sys/portrait/item/$portrait"
|
||||
}
|
||||
}
|
||||
|
||||
fun String.getShortNumString(): String {
|
||||
val long = toLongOrNull() ?: return ""
|
||||
return if (long > 9999) {
|
||||
val longW = long * 10 / 10000L / 10F
|
||||
if (longW > 999) {
|
||||
val longKW = longW.toLong() / 1000L
|
||||
"${longKW}KW"
|
||||
} else {
|
||||
"${longW}W"
|
||||
}
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,9 @@
|
|||
android:layout_below="@id/item_search_forum_title"
|
||||
android:layout_alignBottom="@id/item_search_forum_avatar"
|
||||
android:layout_toEndOf="@id/item_search_forum_avatar"
|
||||
android:ellipsize="end"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="1"
|
||||
android:textSize="13sp"
|
||||
app:tint="@color/default_color_text_secondary"
|
||||
tools:text="Sub Title" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue