mirror of
https://github.com/KitsunePie/AppErrorsTracking.git
synced 2025-09-01 08:45:16 +08:00
Refactor code style
This commit is contained in:
@@ -62,10 +62,9 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
private var stackTrace = ""
|
private var stackTrace = ""
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
if (!parseIntent(intent)) return
|
if (intent.parseAppErrorsInfo().not()) return
|
||||||
|
|
||||||
binding.titleBackIcon.setOnClickListener { onBackPressed() }
|
binding.titleBackIcon.setOnClickListener { onBackPressed() }
|
||||||
|
|
||||||
binding.disableAutoWrapErrorStackTraceSwitch.bind(ConfigData.DISABLE_AUTO_WRAP_ERROR_STACK_TRACE) {
|
binding.disableAutoWrapErrorStackTraceSwitch.bind(ConfigData.DISABLE_AUTO_WRAP_ERROR_STACK_TRACE) {
|
||||||
onInitialize {
|
onInitialize {
|
||||||
binding.errorStackTraceScrollView.isVisible = it
|
binding.errorStackTraceScrollView.isVisible = it
|
||||||
@@ -76,14 +75,19 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
resetScrollView()
|
resetScrollView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.detailTitleText.setOnClickListener { binding.appPanelScrollView.smoothScrollTo(0, 0) }
|
binding.detailTitleText.setOnClickListener { binding.appPanelScrollView.smoothScrollTo(0, 0) }
|
||||||
|
|
||||||
resetScrollView()
|
resetScrollView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseIntent(intent: Intent?): Boolean {
|
/**
|
||||||
val appErrorsInfo = runCatching { intent?.getSerializableExtraCompat<AppErrorsInfoBean>(EXTRA_APP_ERRORS_INFO) }.getOrNull()
|
* 从 [Intent] 中解析 [AppErrorsInfoBean] 并加载至界面
|
||||||
|
*
|
||||||
|
* @receiver [Intent] 待解析的 [Intent] 实例
|
||||||
|
*
|
||||||
|
* @return [Boolean] 是否解析成功:true为成功;false为失败,可能是 [Intent] 为空或者 [AppErrorsInfoBean] 为空
|
||||||
|
*/
|
||||||
|
private fun Intent?.parseAppErrorsInfo(): Boolean {
|
||||||
|
val appErrorsInfo = runCatching { this?.getSerializableExtraCompat<AppErrorsInfoBean>(EXTRA_APP_ERRORS_INFO) }.getOrNull()
|
||||||
if (appErrorsInfo == null) {
|
if (appErrorsInfo == null) {
|
||||||
toastAndFinish(name = "AppErrorsInfo")
|
toastAndFinish(name = "AppErrorsInfo")
|
||||||
return false
|
return false
|
||||||
@@ -146,7 +150,7 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
binding.errorStackTraceMovableText.text = appErrorsInfo.stackTrace
|
binding.errorStackTraceMovableText.text = appErrorsInfo.stackTrace
|
||||||
binding.errorStackTraceFixedText.text = appErrorsInfo.stackTrace
|
binding.errorStackTraceFixedText.text = appErrorsInfo.stackTrace
|
||||||
binding.appPanelScrollView.setOnScrollChangeListener { _, _, y, _, _ ->
|
binding.appPanelScrollView.setOnScrollChangeListener { _, _, y, _, _ ->
|
||||||
binding.detailTitleText.text = if (y >= 30.dp(context = this))
|
binding.detailTitleText.text = if (y >= 30.dp(context = this@AppErrorsDetailActivity))
|
||||||
appNameOf(appErrorsInfo.packageName).ifBlank { appErrorsInfo.packageName }
|
appNameOf(appErrorsInfo.packageName).ifBlank { appErrorsInfo.packageName }
|
||||||
else LocaleString.appName
|
else LocaleString.appName
|
||||||
}
|
}
|
||||||
@@ -177,9 +181,7 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
}
|
}
|
||||||
override fun onNewIntent(intent: Intent?) {
|
override fun onNewIntent(intent: Intent?) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
if (parseIntent(intent)) {
|
if (intent.parseAppErrorsInfo()) binding.appPanelScrollView.scrollTo(0, 0)
|
||||||
binding.appPanelScrollView.scrollTo(0, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user