Compare commits

...

1 Commits

View File

@ -30,6 +30,7 @@ import io.reactivex.schedulers.Schedulers
import okhttp3.ResponseBody
import org.json.JSONObject
import retrofit2.HttpException
import java.util.regex.Pattern
class DescViewModel(
application: Application,
@ -48,6 +49,10 @@ class DescViewModel(
private var mGameInfo: GameInfo? = null
private val mIdMaps = hashMapOf<String, String>()
private var mSubjectPage = 1
private var mUnderlineReplacement = "<u>\$1</u>"
private val mUnderlinePattern by lazy { Pattern.compile("<span style=\"text-decoration: underline;\">(.*?)</span>") }
var list = MutableLiveData<ArrayList<DetailEntity>>()
var changeColumnGameLiveData = MutableLiveData<Boolean>()
var gameId = game?.id
@ -373,8 +378,19 @@ class DescViewModel(
rawItem.customColumn?.desBrief = rawItem.customColumn?.desBrief?.replaceUnsupportedHtmlTag()
}
rawItem.customColumn?.des = rawItem.customColumn?.desFull
?: rawItem.customColumn?.des
// 将下划线改成 Android TextView 能够解析的样式
rawItem.customColumn?.desFull?.let {
rawItem.customColumn?.desFull = replaceUnSupportedUnderlineStylewithSupportedStyle(it)
}
rawItem.customColumn?.desBrief?.let {
rawItem.customColumn?.desBrief = replaceUnSupportedUnderlineStylewithSupportedStyle(it)
}
rawItem.customColumn?.des?.let {
rawItem.customColumn?.des = replaceUnSupportedUnderlineStylewithSupportedStyle(it)
}
// 优先使用 desFull 作为最终的 des
rawItem.customColumn?.des = rawItem.customColumn?.desFull ?: rawItem.customColumn?.des
}
}
@ -396,6 +412,13 @@ class DescViewModel(
return detailEntityList
}
/**
* 将 TextView 不支持的下划线样式改成支持的样式
*/
private fun replaceUnSupportedUnderlineStylewithSupportedStyle(originString: String): String {
return mUnderlinePattern.matcher(originString).replaceAll(mUnderlineReplacement)
}
fun getServerIndexPosition() = mServerPosition
fun getLibaoIndexPosition() = mLibaoPosition