fix: 数据异常时闪退

This commit is contained in:
HuanCheng65 2024-02-02 14:16:48 +08:00
parent 26d85c7577
commit dd151775d1
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
3 changed files with 16 additions and 15 deletions

View File

@ -44,7 +44,9 @@ abstract class BaseComposeActivityWithData<DATA> : BaseComposeActivity() {
@Composable
final override fun Content() {
Content(data!!)
data?.let { data ->
Content(data)
}
}
@Composable

View File

@ -540,14 +540,11 @@ private fun getDescText(
time: Long?,
ipAddress: String?
): String {
val texts = mutableListOf<String>()
if (time != null) texts.add(DateTimeUtils.getRelativeTimeString(App.INSTANCE, time))
if (!ipAddress.isNullOrEmpty()) texts.add(
App.INSTANCE.getString(
R.string.text_ip_location,
"$ipAddress"
)
val texts = listOfNotNull(
time?.let { DateTimeUtils.getRelativeTimeString(App.INSTANCE, it) },
ipAddress?.let { App.INSTANCE.getString(R.string.text_ip_location, it) }
)
if (texts.isEmpty()) return ""
return texts.joinToString(" ")
}

View File

@ -187,16 +187,18 @@ private fun getDescText(
floor: Int,
ipAddress: String?
): String {
val texts = mutableListOf<String>()
if (time != null) texts.add(getRelativeTimeString(App.INSTANCE, time))
if (floor > 1) texts.add(App.INSTANCE.getString(R.string.tip_post_floor, floor))
if (!ipAddress.isNullOrEmpty()) texts.add(
App.INSTANCE.getString(
val texts = listOfNotNull(
time?.let { getRelativeTimeString(App.INSTANCE, it) },
if (floor > 1) App.INSTANCE.getString(R.string.tip_post_floor, floor) else null,
if (ipAddress.isNullOrEmpty()) null else App.INSTANCE.getString(
R.string.text_ip_location,
"$ipAddress"
ipAddress
)
)
return texts.joinToString(" ")
if (texts.isEmpty()) {
return ""
}
return texts.joinToString(" · ")
}
@Composable