光环助手V4.0.0-问答社区优化汇总(2200226测试)
https://gitlab.ghzs.com/pm/halo-app-issues/issues/768
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.text.Layout;
|
||||
import android.text.SpannableString;
|
||||
@ -28,6 +29,8 @@ import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
/**
|
||||
* 参考: https://github.com/MrTrying/ExpandableText-Example
|
||||
* <p>
|
||||
* todo 辣鸡代码,有时间移除并在 {@link ExpandTextView} 实现该功能
|
||||
*/
|
||||
public class ExpandAndCloseTextView extends AppCompatTextView {
|
||||
|
||||
@ -112,6 +115,7 @@ public class ExpandAndCloseTextView extends AppCompatTextView {
|
||||
mOpenSpannableStr.append("\n");
|
||||
}
|
||||
if (mCloseSuffixSpan != null) {
|
||||
mOpenSpannableStr = new SpannableStringBuilder(autoSplitText(mOpenSpannableStr.toString()));
|
||||
mOpenSpannableStr.append(mCloseSuffixSpan);
|
||||
}
|
||||
//计算原文截取位置
|
||||
@ -155,6 +159,8 @@ public class ExpandAndCloseTextView extends AppCompatTextView {
|
||||
mCLoseHeight = tempLayout.getHeight() + getPaddingTop() + getPaddingBottom();
|
||||
|
||||
mCloseSpannableStr.append(ELLIPSIS_STRING);
|
||||
|
||||
mCloseSpannableStr = new SpannableStringBuilder(autoSplitText(mCloseSpannableStr.toString()));
|
||||
if (mOpenSuffixSpan != null) {
|
||||
mCloseSpannableStr.append(mOpenSuffixSpan);
|
||||
}
|
||||
@ -497,6 +503,43 @@ public class ExpandAndCloseTextView extends AppCompatTextView {
|
||||
}, 1, mCloseSuffixStr.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
private String autoSplitText(final String rawText) {
|
||||
final Paint tvPaint = getPaint(); //paint,包含字体等信息
|
||||
final float tvWidth = initWidth - getPaddingLeft() - getPaddingRight(); //控件可用宽度
|
||||
|
||||
//将原始文本按行拆分
|
||||
String[] rawTextLines = rawText.replaceAll("\r", "").split("\n");
|
||||
StringBuilder sbNewText = new StringBuilder();
|
||||
for (String rawTextLine : rawTextLines) {
|
||||
if (tvPaint.measureText(rawTextLine) <= tvWidth) {
|
||||
//如果整行宽度在控件可用宽度之内,就不处理了
|
||||
sbNewText.append(rawTextLine);
|
||||
} else {
|
||||
//如果整行宽度超过控件可用宽度,则按字符测量,在超过可用宽度的前一个字符处手动换行
|
||||
float lineWidth = 0;
|
||||
for (int cnt = 0; cnt != rawTextLine.length(); ++cnt) {
|
||||
char ch = rawTextLine.charAt(cnt);
|
||||
lineWidth += tvPaint.measureText(String.valueOf(ch));
|
||||
if (lineWidth <= tvWidth) {
|
||||
sbNewText.append(ch);
|
||||
} else {
|
||||
sbNewText.append("\n");
|
||||
lineWidth = 0;
|
||||
--cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
sbNewText.append("\n");
|
||||
}
|
||||
|
||||
//把结尾多余的\n去掉
|
||||
if (!rawText.endsWith("\n")) {
|
||||
sbNewText.deleteCharAt(sbNewText.length() - 1);
|
||||
}
|
||||
|
||||
return sbNewText.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(View.OnClickListener onClickListener) {
|
||||
mOnClickListener = onClickListener;
|
||||
|
||||
@ -34,6 +34,7 @@ import com.gh.common.constant.Constants.GAME_DETAIL_COME_IN
|
||||
import com.gh.common.history.HistoryHelper
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.common.view.ExpandAndCloseTextView
|
||||
import com.gh.common.view.RichEditor
|
||||
import com.gh.gamecenter.NormalActivity
|
||||
import com.gh.gamecenter.R
|
||||
@ -83,7 +84,7 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
@BindView(R.id.questionsdetail_item_picll)
|
||||
lateinit var mImgLl: LinearLayout
|
||||
@BindView(R.id.questionsdetail_item_des)
|
||||
lateinit var mQuestionsDescTv: TextView
|
||||
lateinit var mQuestionsDescTv: ExpandAndCloseTextView
|
||||
@BindView(R.id.questiondetail_item_pic3_mask)
|
||||
lateinit var mPic3Mask: View
|
||||
@BindView(R.id.questiondetail_item_pic3_desc)
|
||||
@ -1077,7 +1078,9 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
mQuestionsDescTv.visibility = if (question.description.isNullOrEmpty()) {
|
||||
View.GONE
|
||||
} else {
|
||||
mQuestionsDescTv.text = question.description
|
||||
mQuestionsDescTv.initWidth(resources.displayMetrics.widthPixels - 40F.dip2px())
|
||||
mQuestionsDescTv.maxLines = 3
|
||||
mQuestionsDescTv.setOriginalText(question.description)
|
||||
View.VISIBLE
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ class QuestionsDetailAdapter(
|
||||
if (index != -1 && holder is CommunityAnswerItemViewHolder) {
|
||||
val answer = mEntityList[index].answer ?: return
|
||||
val intent = AnswerDetailActivity.getIntent(mContext, answer.id, mEntrance, "问题详情-答案列表")
|
||||
holder.bindAnswerItem(answer,true, mEntrance, "问题详情")
|
||||
holder.bindAnswerItem(answer, true, mEntrance, "问题详情")
|
||||
holder.binding.root.setOnClickListener {
|
||||
(mContext as Activity).startActivityForResult(intent, QuestionsDetailFragment.QUESTIONS_DETAIL_ANSWER_REQUEST)
|
||||
}
|
||||
@ -189,7 +189,7 @@ class QuestionsDetailAdapter(
|
||||
val index = position - TOP_ITEM_COUNT
|
||||
if (index != -1) {
|
||||
val viewHolder = holder as CommunityAnswerItemViewHolder
|
||||
val answerEntity = mEntityList[index].similarAnswer?:return
|
||||
val answerEntity = mEntityList[index].similarAnswer ?: return
|
||||
viewHolder.bindAnswerItem(answerEntity, "", "问题推荐")
|
||||
viewHolder.binding.title.setOnClickListener {
|
||||
val questions = answerEntity.questions
|
||||
@ -266,7 +266,9 @@ class QuestionsDetailAdapter(
|
||||
}
|
||||
|
||||
// 问题描述
|
||||
holder.mDes.text = description
|
||||
holder.mDes.initWidth(mContext.resources.displayMetrics.widthPixels - 40F.dip2px())
|
||||
holder.mDes.maxLines = 3
|
||||
holder.mDes.setOriginalText(description)
|
||||
holder.mDes.goneIf(TextUtils.isEmpty(description))
|
||||
|
||||
// "关注问题"
|
||||
|
||||
@ -7,6 +7,7 @@ import android.widget.TextView;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.view.ExpandAndCloseTextView;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.google.android.flexbox.FlexboxLayout;
|
||||
|
||||
@ -23,7 +24,7 @@ public class QuestionsDetailItemViewHolder extends BaseRecyclerViewHolder {
|
||||
@BindView(R.id.questionsdetail_item_title)
|
||||
public TextView mTitle;
|
||||
@BindView(R.id.questionsdetail_item_des)
|
||||
public TextView mDes;
|
||||
public ExpandAndCloseTextView mDes;
|
||||
@BindView(R.id.questionsdetail_item_pic1)
|
||||
public SimpleDraweeView mPic1;
|
||||
@BindView(R.id.questionsdetail_item_pic2)
|
||||
|
||||
Reference in New Issue
Block a user