修改问题详情/回答详情UI(15.16) https://gitlab.ghzs.com/pm/halo-app-issues/issues/650#note_30101
This commit is contained in:
@ -866,8 +866,8 @@ public class DialogUtils {
|
||||
TextView negativeTv = contentView.findViewById(R.id.negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.positive);
|
||||
TextView content = contentView.findViewById(R.id.content);
|
||||
positiveTv.setBackground(DrawableView.getOvalDrawable(R.color.text_f5f5f5));
|
||||
negativeTv.setBackground(DrawableView.getOvalDrawable(R.color.theme));
|
||||
positiveTv.setBackground(DrawableView.getOvalDrawable(R.color.text_f5f5f5, 999));
|
||||
negativeTv.setBackground(DrawableView.getOvalDrawable(R.color.theme, 999));
|
||||
content.setText(Html.fromHtml(context.getString(R.string.video_upload_draft_dialog_content)));
|
||||
|
||||
negativeTv.setOnClickListener(view -> {
|
||||
|
||||
@ -326,6 +326,10 @@ fun Int.toColor(): Int {
|
||||
return HaloApp.getInstance().application.resources.getColor(this)
|
||||
}
|
||||
|
||||
fun Int.toResString(): String {
|
||||
return HaloApp.getInstance().application.resources.getString(this)
|
||||
}
|
||||
|
||||
fun Int.toSimpleCount(): String {
|
||||
return NumberUtils.transSimpleCount(this)
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@ import androidx.core.content.ContextCompat
|
||||
import com.gh.common.util.DisplayUtils
|
||||
import com.halo.assistant.HaloApp
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.gh.common.util.dip2px
|
||||
|
||||
object DrawableView {
|
||||
@ -18,7 +20,6 @@ object DrawableView {
|
||||
return getServerDrawable(ContextCompat.getColor(HaloApp.getInstance().application, colorId))
|
||||
}
|
||||
|
||||
|
||||
@JvmStatic
|
||||
fun getServerDrawable(colorCode: String): Drawable {
|
||||
return getServerDrawable(Color.parseColor(colorCode))
|
||||
@ -33,10 +34,10 @@ object DrawableView {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getOvalDrawable(@ColorRes colorId: Int): Drawable {
|
||||
fun getOvalDrawable(@ColorRes colorId: Int, radius: Float = 999F): Drawable {
|
||||
val drawable = GradientDrawable()
|
||||
drawable.setColor(ContextCompat.getColor(HaloApp.getInstance().application, colorId))
|
||||
drawable.cornerRadius = DisplayUtils.dip2px(999F).toFloat()
|
||||
drawable.cornerRadius = DisplayUtils.dip2px(radius).toFloat()
|
||||
return drawable
|
||||
}
|
||||
|
||||
@ -66,4 +67,16 @@ object DrawableView {
|
||||
drawable.cornerRadius = radius
|
||||
return drawable
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setTextDrawable(textView: TextView, @DrawableRes drawableId: Int?, text: String? = null) {
|
||||
val drawable = if (drawableId != null){
|
||||
ContextCompat.getDrawable(HaloApp.getInstance().application, drawableId)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
|
||||
textView.setCompoundDrawables(drawable, null, null, null)
|
||||
if (text != null) textView.text = text
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,6 @@ import androidx.core.content.ContextCompat;
|
||||
public class ExpendTextView extends AppCompatTextView {
|
||||
|
||||
private CharSequence mSnapshotText;
|
||||
private CharSequence mCloseText;
|
||||
|
||||
private String mExpendText = "...全文";
|
||||
|
||||
@ -48,7 +47,6 @@ public class ExpendTextView extends AppCompatTextView {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
if (mInitLayout && !mOpenLayout && getLineCount() > mMaxLines) {
|
||||
mSnapshotText = getText();
|
||||
mCloseText = getText();
|
||||
mInitLayout = false;
|
||||
showExpendButton();
|
||||
}
|
||||
@ -81,7 +79,7 @@ public class ExpendTextView extends AppCompatTextView {
|
||||
float expendTextWidth = paint.measureText(mExpendText);
|
||||
CharSequence content = mSnapshotText.subSequence(start, lastLineEnd);
|
||||
if (viewWidth - lastLineRight > expendTextWidth) {
|
||||
content = content.toString().trim() + mExpendText;
|
||||
content = content.toString().trim() + mExpendText ;
|
||||
} else {
|
||||
CharSequence lastText = mSnapshotText.subSequence(lastLineStart, lastLineEnd);
|
||||
for (int i = lastText.length() - 1; i > 0; i--) {
|
||||
@ -93,7 +91,7 @@ public class ExpendTextView extends AppCompatTextView {
|
||||
}
|
||||
}
|
||||
}
|
||||
SpannableStringBuilder msp = new SpannableStringBuilder(mCloseText);
|
||||
SpannableStringBuilder msp = new SpannableStringBuilder(mSnapshotText);
|
||||
int length = msp.length();
|
||||
int startPosition = content.length() - mExpendText.length();
|
||||
startPosition = startPosition < 0 ? 0 : startPosition;
|
||||
|
||||
@ -32,6 +32,7 @@ import com.gh.common.AppExecutor
|
||||
import com.gh.common.TimeElapsedHelper
|
||||
import com.gh.common.history.HistoryHelper
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.common.view.RichEditor
|
||||
import com.gh.gamecenter.*
|
||||
import com.gh.gamecenter.databinding.FragmentAnswerDetailBinding
|
||||
@ -414,34 +415,37 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
// 是否已回答
|
||||
when (mAnswerStatus) {
|
||||
ANSWERED_MY_ANSWER -> {
|
||||
mBinding.statusTv.text = "编辑回答"
|
||||
mBinding.statusTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.title))
|
||||
mBinding.statusIv.setImageResource(R.drawable.questionsdetail_myanswer_icon)
|
||||
mBinding.statusTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
mBinding.statusTv,
|
||||
R.drawable.question_detail_answer_icon,
|
||||
"编辑回答")
|
||||
}
|
||||
ANSWERED_NOT_MY_ANSWER -> {
|
||||
mBinding.statusTv.text = "我的回答"
|
||||
mBinding.statusTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme))
|
||||
mBinding.statusIv.setImageResource(R.drawable.ic_answer_detail_edit_full)
|
||||
mBinding.statusTv.setTextColor(R.color.text_999999.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
mBinding.statusTv,
|
||||
R.drawable.question_detail_myanswer_icon,
|
||||
"我的回答")
|
||||
}
|
||||
NOT_ANSWERED_BUT_HAVE_DRAFT -> {
|
||||
mBinding.statusTv.text = "继续回答"
|
||||
mBinding.statusTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.title))
|
||||
mBinding.statusIv.setImageResource(R.drawable.questionsdetail_answer_icon)
|
||||
mBinding.statusTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
mBinding.statusTv,
|
||||
R.drawable.question_detail_answer_icon,
|
||||
"继续回答")
|
||||
}
|
||||
NOT_ANSWERED_YET -> {
|
||||
mBinding.statusTv.text = "我来回答"
|
||||
mBinding.statusTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme))
|
||||
mBinding.statusIv.setImageResource(R.drawable.ic_answer_detail_edit_empty)
|
||||
mBinding.statusTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
mBinding.statusTv,
|
||||
R.drawable.question_detail_answer_icon,
|
||||
"我来回答")
|
||||
}
|
||||
}
|
||||
|
||||
if (me.isAnswerOwn) {
|
||||
mBinding.followTv.isEnabled = false
|
||||
mBinding.followTv.setText(R.string.myself)
|
||||
mBinding.followTv.visibility = View.VISIBLE
|
||||
mBinding.followTv.alpha = 1f
|
||||
mBinding.followTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.button_gray))
|
||||
mBinding.followTv.setBackgroundResource(R.drawable.button_border_gray)
|
||||
mBinding.followTv.visibility = View.GONE
|
||||
} else {
|
||||
mBinding.followTv.isEnabled = true
|
||||
if (!me.isFollower) {
|
||||
@ -697,7 +701,6 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
R.id.tv_share,
|
||||
R.id.container_dislike,
|
||||
R.id.reuse_no_connection,
|
||||
R.id.status_iv,
|
||||
R.id.status_tv,
|
||||
R.id.answer_count_container,
|
||||
R.id.container_like,
|
||||
@ -769,7 +772,7 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
R.id.status_tv, R.id.status_iv -> {
|
||||
R.id.status_tv -> {
|
||||
mViewModel.answerDetail?.let {
|
||||
when (mAnswerStatus) {
|
||||
ANSWERED_MY_ANSWER -> editAnswer(it)
|
||||
@ -999,10 +1002,8 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
private fun updateFollowBtn(isFollowed: Boolean) {
|
||||
if (isFollowed) {
|
||||
if (mBinding.followTv.visibility == View.GONE) return
|
||||
|
||||
mBinding.followTv.text = "已关注"
|
||||
mBinding.followTv.background = null
|
||||
mBinding.followTv.setTextColor(ContextCompat.getColor(context!!, R.color.theme))
|
||||
DrawableView.setTextDrawable(mBinding.followTv, null, "已关注")
|
||||
mBinding.followTv.setTextColor(R.color.text_999999.toColor())
|
||||
mBinding.followTv.postDelayed({
|
||||
if (context == null) return@postDelayed
|
||||
mBinding.followTv.animate()
|
||||
@ -1013,10 +1014,13 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
.start()
|
||||
}, 2000L)
|
||||
} else {
|
||||
mBinding.followTv.setText(R.string.concern)
|
||||
mBinding.followTv.visibility = View.VISIBLE
|
||||
mBinding.followTv.background = ContextCompat.getDrawable(context!!, R.drawable.button_normal_style)
|
||||
mBinding.followTv.setTextColor(ContextCompat.getColor(context!!, R.color.all_white))
|
||||
mBinding.followTv.background = DrawableView.getOvalDrawable(R.color.background, 2F)
|
||||
mBinding.followTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
mBinding.followTv,
|
||||
R.drawable.answer_detail_follow_icon,
|
||||
R.string.concern.toResString())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1122,7 +1126,7 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
|
||||
@JavascriptInterface
|
||||
fun onVideoClick(content: String) {
|
||||
toast("video click:" + content)
|
||||
toast("video click:" + content)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,10 @@ import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -19,6 +17,7 @@ import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.base.OnListClickListener
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.ReuseViewHolder
|
||||
@ -222,29 +221,47 @@ class QuestionsDetailAdapter(
|
||||
|
||||
// "我来回答"
|
||||
if (!TextUtils.isEmpty(mQuestionEntity!!.me.myAnswerId)) {
|
||||
updateAnswerTv(holder.answerTv, R.string.question_detail_myanswer)
|
||||
holder.answerTv.setTextColor(R.color.text_999999.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
holder.answerTv,
|
||||
R.drawable.question_detail_myanswer_icon,
|
||||
R.string.question_detail_myanswer.toResString())
|
||||
} else if (mQuestionEntity!!.isExistDrafts) {
|
||||
updateAnswerTv(holder.answerTv, R.string.question_detail_resume_answer)
|
||||
holder.answerTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
holder.answerTv,
|
||||
R.drawable.question_detail_answer_icon,
|
||||
R.string.question_detail_resume_answer.toResString())
|
||||
} else {
|
||||
updateAnswerTv(holder.answerTv, R.string.question_detail_answer)
|
||||
holder.answerTv.setTextColor(R.color.theme.toColor())
|
||||
DrawableView.setTextDrawable(
|
||||
holder.answerTv,
|
||||
R.drawable.question_detail_answer_icon,
|
||||
R.string.question_detail_answer.toResString())
|
||||
}
|
||||
|
||||
// "关注问题"
|
||||
when {
|
||||
mQuestionEntity!!.me.isQuestionOwn -> {
|
||||
holder.concern.setBackgroundResource(R.drawable.questions_detail_tag_bg)
|
||||
holder.concern.setTextColor(ContextCompat.getColor(mContext, R.color.hint))
|
||||
holder.concern.text = "编辑问题"
|
||||
holder.concern.setTextColor(ContextCompat.getColor(mContext, R.color.text_666666))
|
||||
DrawableView.setTextDrawable(holder.concern, null, "编辑问题")
|
||||
}
|
||||
mQuestionEntity!!.me.isQuestionFollowed -> {
|
||||
holder.concern.setBackgroundResource(R.drawable.questions_detail_tag_bg)
|
||||
holder.concern.setTextColor(ContextCompat.getColor(mContext, R.color.hint))
|
||||
holder.concern.text = "已关注"
|
||||
holder.concern.setTextColor(ContextCompat.getColor(mContext, R.color.text_666666))
|
||||
DrawableView.setTextDrawable(
|
||||
holder.concern,
|
||||
R.drawable.question_detail_concerned_icon,
|
||||
"已关注")
|
||||
}
|
||||
else -> {
|
||||
holder.concern.setBackgroundResource(R.drawable.button_normal_style)
|
||||
holder.concern.setTextColor(Color.WHITE)
|
||||
holder.concern.text = "关注问题"
|
||||
DrawableView.setTextDrawable(
|
||||
holder.concern,
|
||||
R.drawable.question_detail_concern_icon,
|
||||
"关注问题")
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,19 +289,24 @@ class QuestionsDetailAdapter(
|
||||
}
|
||||
|
||||
private fun addTag(mTagRl: FlexboxLayout, tag: String, isLastTag: Boolean) {
|
||||
val view = LayoutInflater.from(mContext).inflate(R.layout.questionsdedit_tag_item, null)
|
||||
val tagTv = view as TextView
|
||||
tagTv.text = tag
|
||||
tagTv.setBackgroundResource(R.drawable.button_normal_style)
|
||||
tagTv.setTextColor(Color.WHITE)
|
||||
val params = FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
params.setMargins(0, DisplayUtils.dip2px(mContext, 5f), if (!isLastTag) DisplayUtils.dip2px(mContext, 8f) else 0,
|
||||
DisplayUtils.dip2px(mContext, 5f))
|
||||
tagTv.layoutParams = params
|
||||
mTagRl.addView(view)
|
||||
val tagTv = TextView(mContext)
|
||||
mTagRl.addView(tagTv)
|
||||
|
||||
view.setOnClickListener {
|
||||
tagTv.text = tag
|
||||
tagTv.gravity = Gravity.CENTER
|
||||
tagTv.textSize = 12F
|
||||
tagTv.background = DrawableView.getOvalDrawable(R.color.text_EEF5FB, 2F)
|
||||
tagTv.setTextColor(R.color.theme.toColor())
|
||||
tagTv.setPadding(8F.dip2px(), 0, 8F.dip2px(), 0)
|
||||
|
||||
val params = FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 24F.dip2px())
|
||||
params.setMargins(0,
|
||||
DisplayUtils.dip2px(mContext, 10f),
|
||||
if (!isLastTag) DisplayUtils.dip2px(mContext, 12f) else 0,
|
||||
DisplayUtils.dip2px(mContext, 10f))
|
||||
tagTv.layoutParams = params
|
||||
|
||||
tagTv.setOnClickListener {
|
||||
DataUtils.onMtaEvent(mContext, "问题标签", mQuestionEntity!!.community.name, mQuestionEntity!!.title + "-" + tag)
|
||||
mContext.startActivity(AskColumnDetailActivity.getIntentByTag(mContext, tag,
|
||||
CommunityEntity(mQuestionEntity!!.community.id,
|
||||
@ -292,18 +314,6 @@ class QuestionsDetailAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAnswerTv(answerTv: TextView, @StringRes stringId: Int) {
|
||||
answerTv.text = mContext.getString(stringId)
|
||||
|
||||
val drawable = if (R.string.question_detail_myanswer == stringId) {
|
||||
ContextCompat.getDrawable(mContext, R.drawable.questionsdetail_myanswer_icon)
|
||||
} else {
|
||||
ContextCompat.getDrawable(mContext, R.drawable.questionsdetail_answer_icon)
|
||||
}
|
||||
drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
|
||||
answerTv.setCompoundDrawables(drawable, null, null, null)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
if (mQuestionEntity == null) {
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user