From 5c0b5bb4f70d4ece8eda5c81f3897d40593661e7 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 16 Mar 2024 18:01:30 +0530 Subject: [PATCH] fix(widget): open comments screen directly for lobsters-native posts Fixes COMPOSE-LOBSTERS-2P --- CHANGELOG.md | 5 +++++ .../dev/msfjarvis/claw/android/glance/WidgetListEntry.kt | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61ed5807..ad69b185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +* Fix crash when trying to open a comments-only post from + the home screen widget + ## [1.42.0] - 2024-03-16 ### Fixed diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/glance/WidgetListEntry.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/glance/WidgetListEntry.kt index 1b08da69..6d6ef02f 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/glance/WidgetListEntry.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/glance/WidgetListEntry.kt @@ -43,9 +43,10 @@ fun WidgetListEntry(post: UIPost, modifier: GlanceModifier = GlanceModifier) { val titleStyle = MaterialTheme.typography.titleMedium val commentsAction = actionStartActivity(actionParametersOf(destinationKey to post.shortId)) + // If the URL starts with a /, it's a relative URL and we should open the comments page directly. val postAction = - if (post.url.isNotEmpty()) actionStartActivity(Intent(Intent.ACTION_VIEW, Uri.parse(post.url))) - else commentsAction + if (post.url.startsWith('/')) commentsAction + else actionStartActivity(Intent(Intent.ACTION_VIEW, Uri.parse(post.url))) Box(modifier.padding(8.dp)) { Row( verticalAlignment = Alignment.CenterVertically,