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