feat: 吧务标记

This commit is contained in:
HuanCheng65 2022-06-23 22:18:20 +08:00
parent 7e4babed2a
commit 7807cddca8
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
3 changed files with 49 additions and 6 deletions

View File

@ -2,6 +2,8 @@ package com.huanchengfly.tieba.post.adapters
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils import android.text.TextUtils
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -18,9 +20,11 @@ import com.huanchengfly.tieba.post.activities.ForumActivity.Companion.launch
import com.huanchengfly.tieba.post.activities.ReplyActivity import com.huanchengfly.tieba.post.activities.ReplyActivity
import com.huanchengfly.tieba.post.api.models.ThreadContentBean import com.huanchengfly.tieba.post.api.models.ThreadContentBean
import com.huanchengfly.tieba.post.components.MyViewHolder import com.huanchengfly.tieba.post.components.MyViewHolder
import com.huanchengfly.tieba.post.components.spans.RoundBackgroundColorSpan
import com.huanchengfly.tieba.post.fragments.MenuDialogFragment import com.huanchengfly.tieba.post.fragments.MenuDialogFragment
import com.huanchengfly.tieba.post.models.ReplyInfoBean import com.huanchengfly.tieba.post.models.ReplyInfoBean
import com.huanchengfly.tieba.post.plugins.PluginManager import com.huanchengfly.tieba.post.plugins.PluginManager
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
import com.huanchengfly.tieba.post.utils.* import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.utils.TiebaUtil.reportPost import com.huanchengfly.tieba.post.utils.TiebaUtil.reportPost
import com.huanchengfly.tieba.post.widgets.MyLinearLayout import com.huanchengfly.tieba.post.widgets.MyLinearLayout
@ -154,10 +158,26 @@ 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)
if (user.isBawu == "1") {
val bawuType = if (user.bawuType == "manager") "吧主" else "小吧主"
username = SpannableStringBuilder(username).apply {
append(" ")
append(
bawuType, RoundBackgroundColorSpan(
context,
Util.alphaColor(ThemeUtils.getColorByAttr(context, R.attr.colorAccent), 30),
ThemeUtils.getColorByAttr(context, R.attr.colorAccent),
DisplayUtil.dp2px(context, 10f).toFloat()
), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
holder.setText( holder.setText(
R.id.thread_list_item_user_name, R.id.thread_list_item_user_name,
StringUtil.getUsernameString(context, user.name, user.nameShow) username
) )
val levelId = val levelId =
if (user.levelId == null || TextUtils.isEmpty(user.levelId)) "?" else user.levelId if (user.levelId == null || TextUtils.isEmpty(user.levelId)) "?" else user.levelId
ThemeUtil.setChipThemeByLevel( ThemeUtil.setChipThemeByLevel(

View File

@ -560,13 +560,30 @@ class ThreadReplyAdapter(context: Context) :
showMenu(item, position) showMenu(item, position)
true true
} }
viewHolder.setText(
R.id.thread_list_item_user_name, 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") {
val bawuType = if (userInfoBean.bawuType == "manager") "吧主" else "小吧主"
username = SpannableStringBuilder(username).apply {
append(" ")
append(
bawuType, RoundBackgroundColorSpan(
context,
Util.alphaColor(ThemeUtils.getColorByAttr(context, R.attr.colorAccent), 30),
ThemeUtils.getColorByAttr(context, R.attr.colorAccent),
DisplayUtil.dp2px(context, 10f).toFloat()
), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
viewHolder.setText(
R.id.thread_list_item_user_name,
username
) )
if (userInfoBean != null) { if (userInfoBean != null) {
val levelId = val levelId =

View File

@ -4,12 +4,16 @@ import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView; import android.widget.TextView;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.components.spans.EmotionSpanV2; import com.huanchengfly.tieba.post.components.spans.EmotionSpanV2;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -54,12 +58,14 @@ public class StringUtil {
} }
} }
public static String getUsernameString(Context context, String username, String nickname) { public static CharSequence getUsernameString(Context context, String username, String nickname) {
boolean showBoth = SharedPreferencesUtil.get(context, SharedPreferencesUtil.SP_SETTINGS).getBoolean("show_both_username_and_nickname", false); boolean showBoth = SharedPreferencesUtil.get(context, SharedPreferencesUtil.SP_SETTINGS).getBoolean("show_both_username_and_nickname", false);
if (TextUtils.isEmpty(nickname)) { if (TextUtils.isEmpty(nickname)) {
return TextUtils.isEmpty(username) ? "" : username; return TextUtils.isEmpty(username) ? "" : username;
} else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals(username, nickname)) { } else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals(username, nickname)) {
return context.getString(R.string.username_both, nickname, username); 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 nickname; return nickname;
} }