Skip to content

Commit

Permalink
fix: 编辑群聊后崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
YuS1aN committed Mar 24, 2024
1 parent c397b3c commit e54e75f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
34 changes: 20 additions & 14 deletions app/src/main/java/me/kbai/zhenxunui/tool/Ansi2SpannedHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.text.style.StrikethroughSpan
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import androidx.annotation.RequiresApi
import me.kbai.zhenxunui.extends.logE
import pk.ansi4j.core.DefaultFunctionFinder
import pk.ansi4j.core.DefaultParserFactory
import pk.ansi4j.core.DefaultTextHandler
Expand All @@ -30,7 +31,7 @@ import pk.ansi4j.core.iso6429.IndependentControlFunctionHandler
import java.util.AbstractCollection

class Ansi2SpannedHelper {
private val mFactory: ParserFactory? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
private val mFactory: ParserFactory? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
initFactory()
} else {
null
Expand All @@ -41,22 +42,27 @@ class Ansi2SpannedHelper {
val builder = SpannableStringBuilder()
val parser = (mFactory ?: return SpannedString(text)).createParser(text)

while (true) {
val fragment = parser.parse() ?: break
if (fragment.type == FragmentType.TEXT) {
val start = builder.length
builder.append(fragment.text)
mStyles.forEach {
builder.setSpan(it, start, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
} else if (fragment.type == FragmentType.FUNCTION) {
val functionFragment = fragment as FunctionFragment
if (functionFragment.function == ControlSequenceFunction.SGR_SELECT_GRAPHIC_RENDITION) {
functionFragment.arguments.forEach { parseArgument(it) }
try {
while (true) {
val fragment = parser.parse() ?: break
if (fragment.type == FragmentType.TEXT) {
val start = builder.length
builder.append(fragment.text)
mStyles.forEach {
builder.setSpan(it, start, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
} else if (fragment.type == FragmentType.FUNCTION) {
val functionFragment = fragment as FunctionFragment
if (functionFragment.function == ControlSequenceFunction.SGR_SELECT_GRAPHIC_RENDITION) {
functionFragment.arguments.forEach { parseArgument(it) }
}
}
}
mStyles.clear()
} catch (e: Exception) {
logE(e)
return SpannedString(text)
}
mStyles.clear()
return builder
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/me/kbai/zhenxunui/tool/CrashHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object CrashHandler {
private fun log(context: Context, throwable: Throwable) = logE(
"MODEL: ${Build.MODEL} " +
"SDK: ${Build.VERSION.SDK_INT} " +
"CPU_ABI: ${Build.SUPPORTED_ABIS} " +
"CPU_ABI: ${Build.SUPPORTED_ABIS.contentToString()} " +
"VERSION: ${getPackageVersionName(context)} " +
"\n StackTrace: \n" +
Log.getStackTraceString(throwable),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class BaseEditInfoFragment<VB : ViewBinding> : BaseFragment<VB>() {
.build()
}

protected abstract fun getWebViews(): Array<WebView>
protected abstract fun getWebViews(): Array<out WebView>

protected abstract fun updateInfo(): Any

Expand All @@ -45,8 +45,8 @@ abstract class BaseEditInfoFragment<VB : ViewBinding> : BaseFragment<VB>() {
}

override fun onDestroyView() {
super.onDestroyView()
getWebViews().forEach { it.destroy() }
super.onDestroyView()
}

@SuppressLint("SetJavaScriptEnabled")
Expand Down

0 comments on commit e54e75f

Please sign in to comment.