Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev

This commit is contained in:
kehaoyuan
2020-06-12 18:30:12 +08:00
6 changed files with 55 additions and 36 deletions

View File

@ -540,7 +540,9 @@ inline fun Context.doOnMainProcessOnly(f: () -> Unit) {
if (processName == null || BuildConfig.APPLICATION_ID == processName) {
f.invoke()
} else {
Utils.log("Block one useless sub process method call.")
tryWithDefaultCatch {
Utils.log("Block one useless sub process method call from ${Thread.currentThread().stackTrace[3].methodName} -> ${Thread.currentThread().stackTrace[2].methodName}.")
}
}
}

View File

@ -50,18 +50,18 @@ object GameSubstituteRepositoryHelper {
@JvmStatic
@SuppressLint("CheckResult")
fun updateSubstitutableGames() {
val single = if (UserManager.getInstance().isLoggedIn) {
Utils.log("获取登录后的可替换游戏")
mApi.getIdListOfPlayedGames(UserManager.getInstance().userId, Utils.getTime(mApplicationContext))
} else {
Utils.log("获取未登录 ${HaloApp.getInstance().gid} 时的可替换游戏")
mApi.getIdListOfDownloadedGames(HaloApp.getInstance().gid, Utils.getTime(mApplicationContext))
}
single.subscribeOn(Schedulers.io()).subscribe(object : BiResponse<List<String>>() {
override fun onSuccess(data: List<String>) {
mSubstitutableGameIdSet = data.toHashSet()
mApplicationContext.doOnMainProcessOnly {
val single = if (UserManager.getInstance().isLoggedIn) {
mApi.getIdListOfPlayedGames(UserManager.getInstance().userId, Utils.getTime(mApplicationContext))
} else {
mApi.getIdListOfDownloadedGames(HaloApp.getInstance().gid, Utils.getTime(mApplicationContext))
}
})
single.subscribeOn(Schedulers.io()).subscribe(object : BiResponse<List<String>>() {
override fun onSuccess(data: List<String>) {
mSubstitutableGameIdSet = data.toHashSet()
}
})
}
}
/**
@ -75,7 +75,6 @@ object GameSubstituteRepositoryHelper {
}
private fun updateGameRepository(subjects: List<SubjectEntity>?) {
if (subjects == null) return
SPUtils.setString(KEY_GAME_REPOSITORY, subjects.toJson())

View File

@ -25,7 +25,7 @@ public class ExpandTextView extends AppCompatTextView {
private String mEndText = "...";
private String mExpandText = mEndText + "全文";
private boolean mUseGradientAlphaEndText = false;
private boolean mShrinkOnAnchor = false;
private boolean mShrinkOnAnchor = false; // 以锚点所在的位置进行收起 (即 maxLines = 锚点所在的行)
private int mMaxLines = 3; // 由于sdk版本限制(getMaxLines) 这里设置默认值
@ -33,6 +33,7 @@ public class ExpandTextView extends AppCompatTextView {
private boolean mIsExpanded = false; // 位于 recyclerView 时需要自行在外层管理是否已展开
private ExpandCallback mExpandCallback;
private SelfCalculateMaxLinesCallback mMaxLinesCalculatedCallback;
private Rect mLastVisibleLineRect;
private Rect mLastActualLineRect;
@ -65,25 +66,23 @@ public class ExpandTextView extends AppCompatTextView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (mShrinkOnAnchor) {
if (mShrinkOnAnchor && getText().toString().contains(SHRINK_ANCHOR)) {
updateMaxLinesByShrinkAnchor();
}
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() - getExtraBottomPadding());
}
private void updateMaxLinesByShrinkAnchor() {
int count = getLineCount();
for (int line = 0; line < count; line++) {
int start = getLayout().getLineStart(line);
int end = getLayout().getLineEnd(line);
CharSequence substring = getText().subSequence(start, end);
int lineCount = getLineCount();
for (int line = 0; line < lineCount; line++) {
CharSequence substring = getText().subSequence(getLayout().getLineStart(line), getLayout().getLineEnd(line));
if (substring.toString().contains(SHRINK_ANCHOR)) {
if (mMaxLines != line + 1) {
setExpandMaxLines(line + 1);
int anchorIndex = getText().toString().indexOf(SHRINK_ANCHOR);
SpannableStringBuilder sb = new SpannableStringBuilder(getText());
sb.delete(anchorIndex, anchorIndex + 1);
setText(sb);
if (!mIsExpanded) {
setExpandMaxLines(line + 1);
mMaxLinesCalculatedCallback.onMaxLinesCalculated(line + 1);
}
setText(findAndDeleteAnchor(getText()));
break;
}
}
@ -94,13 +93,13 @@ public class ExpandTextView extends AppCompatTextView {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (mInitLayout && !mIsExpanded && getLineCount() > mMaxLines) {
mSnapshotText = getText();
mSnapshotText = findAndDeleteAnchor(getText());
mInitLayout = false;
showExpandButton();
}
}
public void setExpendText(String text) {
public void setExpandText(String text) {
this.mExpandText = text;
}
@ -241,6 +240,18 @@ public class ExpandTextView extends AppCompatTextView {
return result;
}
// 去掉锚点
private CharSequence findAndDeleteAnchor(CharSequence charSequence) {
int anchorIndex = charSequence.toString().indexOf(SHRINK_ANCHOR);
if (anchorIndex >= 0) {
SpannableStringBuilder sb = new SpannableStringBuilder(getText());
sb.delete(anchorIndex, anchorIndex + 1);
return sb;
} else {
return charSequence;
}
}
/**
* 此方法仅更改标记,不做实际展开的操作
*/
@ -253,8 +264,16 @@ public class ExpandTextView extends AppCompatTextView {
setMaxLines(maxLines);
}
public void setSelfCalculateMaxLinesCallback(SelfCalculateMaxLinesCallback callback) {
mMaxLinesCalculatedCallback = callback;
}
public interface ExpandCallback {
void onExpand();
}
public interface SelfCalculateMaxLinesCallback {
void onMaxLinesCalculated(int maxLines);
}
}

View File

@ -3,6 +3,7 @@ package com.gh.gamecenter.gamedetail.desc
import android.content.Context
import android.text.TextUtils
import android.util.SparseBooleanArray
import android.util.SparseIntArray
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
@ -57,6 +58,7 @@ class DescAdapter(context: Context,
private var mExpandableTextExpandStatusSparseBooleanArray = SparseBooleanArray()
private var mCustomColumnTagsExpandStatusSparseBooleanArray = SparseBooleanArray()
private var mExpandableTextViewMaxLinesSparseIntArray = SparseIntArray()
fun updateDescItemList(descItemList: ArrayList<DetailEntity>) {
this.descItemList = descItemList
@ -616,7 +618,7 @@ class DescAdapter(context: Context,
} else {
when {
customColumn.showDesType == "all" || customColumn.showDesRowNum == 0 -> Int.MAX_VALUE
else -> customColumn.showDesRowNum!!
else -> mExpandableTextViewMaxLinesSparseIntArray.get(position)
}
}
val layoutManager = if (customColumn.showInfoTagDesType == "expand" || mCustomColumnTagsExpandStatusSparseBooleanArray.get(position)) {
@ -630,11 +632,12 @@ class DescAdapter(context: Context,
GridLayoutManager(mContext, 3)
}
// TODO 记录 ExpandTextView 具体测量要展开行数以后的 maxLines
titleHintTv.paint?.isUnderlineText = true
contentTv.setExpandMaxLines(Int.MAX_VALUE)
contentTv.setExpandMaxLines(maxDesLines)
contentTv.setIsExpanded(Int.MAX_VALUE == maxDesLines)
contentTv.setTextWithInterceptingInternalUrl(customColumn.des?.fromHtml() ?: "", handleDefaultHighlighter = true, copyHighlighterOnClick = true)
contentTv.setTextWithInterceptingInternalUrl(text = customColumn.des?.fromHtml()
?: "", handleDefaultHighlighter = true, copyHighlighterOnClick = true)
contentTv.setSelfCalculateMaxLinesCallback { mExpandableTextViewMaxLinesSparseIntArray.put(position, it) }
recyclerView.isNestedScrollingEnabled = false
recyclerView.layoutManager = layoutManager
recyclerView.setOnClickListener {

View File

@ -193,7 +193,6 @@ class DescViewModel(application: Application,
ToastUtils.showToast("感谢您的反馈信息,我们将尽快处理~")
}
})
}
// 装饰列表数据
@ -269,8 +268,6 @@ class DescViewModel(application: Application,
hasShownCustomColumnTagsExpandHint = true
}
// rawItem.customColumn?.desFull = "This paragraph contains some <u>mispelled</u> text<b>Bold Text Here</b><em>Italicized Text Here</em>This paragraph contains some <u>mispelled</u> text.<b>Bold Text Here</b><em>Italicized Text Here</em> ||||| This paragraph contains some <u>mispelled</u> text.<b>Bold Text Here</b><em>Italicized Text Here</em> <a href=\"ghzhushou://game/5e11b9d7871aba0016590f1d?position=1\">game</a> <a href=\"https://cn.bing.com\">bing</a> ###click me###"
// rawItem.customColumn?.desBrief = "This paragraph contains some <u>mispelled</u> text<b>Bold Text Here</b><em>Italicized Text Here</em>This paragraph contains some <u>mispelled</u> text.<b>Bold Text Here</b><em>Italicized Text Here</em>"
// 手动为自定义栏目的说明添加展开分隔符
if (!TextUtils.isEmpty(rawItem.customColumn?.desBrief)) {
val index = rawItem.customColumn?.desBrief?.length ?: 0

View File

@ -9,7 +9,6 @@ import android.view.ViewGroup
import android.widget.EditText
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import com.gh.base.OnViewClickListener
import com.gh.base.ToolBarActivity
import com.gh.base.adapter.FragmentAdapter
import com.gh.base.fragment.BaseFragment_TabLayout
@ -80,7 +79,7 @@ class AskColumnDetailActivity : ToolBarActivity() {
}
mBinding = ActivityAskColumnDetailBinding.bind(mContentView)
mBinding.columnDetailDes?.setExpendText("...更多")
mBinding.columnDetailDes?.setExpandText("...更多")
mBinding.entity = mColumnEntity
mNoConn.setOnClickListener {
loadColumn()