From dd151775d1a4a4489d2be20d250b65fc490998df Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:16:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=95=B0=E6=8D=AE=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=97=B6=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/arch/BaseComposeActivity.kt | 4 +++- .../tieba/post/ui/page/subposts/SubPostsPage.kt | 11 ++++------- .../tieba/post/ui/page/thread/ThreadPage.kt | 16 +++++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/arch/BaseComposeActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/arch/BaseComposeActivity.kt index 15792837..f9071908 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/arch/BaseComposeActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/arch/BaseComposeActivity.kt @@ -44,7 +44,9 @@ abstract class BaseComposeActivityWithData : BaseComposeActivity() { @Composable final override fun Content() { - Content(data!!) + data?.let { data -> + Content(data) + } } @Composable diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt index 4ebf4708..4b1e4883 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt @@ -540,14 +540,11 @@ private fun getDescText( time: Long?, ipAddress: String? ): String { - val texts = mutableListOf() - 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(" ") } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt index 5f50d9bf..0c1aac65 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt @@ -187,16 +187,18 @@ private fun getDescText( floor: Int, ipAddress: String? ): String { - val texts = mutableListOf() - 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