fix(android): improve widget layout

This commit is contained in:
Harsh Shandilya 2024-01-17 17:32:12 +05:30
parent 949df2c71f
commit de1bda0034
3 changed files with 28 additions and 19 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
* Add HTML bookmarks as an export format * Add HTML bookmarks as an export format
* Rework widget item layout for consistent touch targets
## [1.38.0] - 2023-11-20 ## [1.38.0] - 2023-11-20

View file

@ -1,5 +1,5 @@
/* /*
* Copyright © 2023 Harsh Shandilya. * Copyright © 2023-2024 Harsh Shandilya.
* Use of this source code is governed by an MIT-style * Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at * license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
@ -14,6 +14,8 @@ import androidx.compose.ui.unit.dp
import androidx.glance.GlanceComposable import androidx.glance.GlanceComposable
import androidx.glance.GlanceModifier import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
import androidx.glance.action.ActionParameters.Key import androidx.glance.action.ActionParameters.Key
import androidx.glance.action.actionParametersOf import androidx.glance.action.actionParametersOf
import androidx.glance.action.actionStartActivity import androidx.glance.action.actionStartActivity
@ -26,12 +28,11 @@ import androidx.glance.layout.Box
import androidx.glance.layout.Row import androidx.glance.layout.Row
import androidx.glance.layout.fillMaxWidth import androidx.glance.layout.fillMaxWidth
import androidx.glance.layout.padding import androidx.glance.layout.padding
import androidx.glance.layout.wrapContentWidth
import androidx.glance.text.Text import androidx.glance.text.Text
import androidx.glance.text.TextAlign
import androidx.glance.text.TextStyle import androidx.glance.text.TextStyle
import dev.msfjarvis.claw.android.MainActivity import dev.msfjarvis.claw.android.MainActivity
import dev.msfjarvis.claw.android.MainActivity.Companion.NAVIGATION_KEY import dev.msfjarvis.claw.android.MainActivity.Companion.NAVIGATION_KEY
import dev.msfjarvis.claw.android.R
import dev.msfjarvis.claw.database.local.SavedPost import dev.msfjarvis.claw.database.local.SavedPost
private val destinationKey = Key<String>(NAVIGATION_KEY) private val destinationKey = Key<String>(NAVIGATION_KEY)
@ -43,7 +44,6 @@ fun WidgetListEntry(
modifier: GlanceModifier = GlanceModifier, modifier: GlanceModifier = GlanceModifier,
) { ) {
val titleStyle = MaterialTheme.typography.titleMedium val titleStyle = MaterialTheme.typography.titleMedium
val subtitleStyle = MaterialTheme.typography.labelLarge
val commentsAction = val commentsAction =
actionStartActivity<MainActivity>(actionParametersOf(destinationKey to post.shortId)) actionStartActivity<MainActivity>(actionParametersOf(destinationKey to post.shortId))
val postAction = val postAction =
@ -69,21 +69,11 @@ fun WidgetListEntry(
fontStyle = titleStyle.fontStyle.toGlance(), fontStyle = titleStyle.fontStyle.toGlance(),
) )
) )
post.commentCount?.let { count -> Image(
Text( provider = ImageProvider(R.drawable.ic_comment),
text = "$count comments", contentDescription = "${post.commentCount ?: 0} comments",
modifier = modifier = GlanceModifier.padding(end = 4.dp).clickable(commentsAction)
GlanceModifier.wrapContentWidth().padding(end = 4.dp).clickable(commentsAction),
style =
TextStyle(
color = GlanceTheme.colors.onSurfaceVariant,
fontSize = subtitleStyle.fontSize,
fontWeight = subtitleStyle.fontWeight.toGlance(),
fontStyle = subtitleStyle.fontStyle.toGlance(),
textAlign = TextAlign.End,
) )
)
}
} }
} }
} }

View file

@ -0,0 +1,18 @@
<!--
~ Copyright © 2024 Harsh Shandilya.
~ Use of this source code is governed by an MIT-style
~ license that can be found in the LICENSE file or at
~ https://opensource.org/licenses/MIT.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:colorControlNormal"
android:alpha="0.6"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M21.99,4c0,-1.1 -0.89,-2 -1.99,-2L4,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h14l4,4 -0.01,-18zM20,4v13.17L18.83,16L4,16L4,4h16zM6,12h12v2L6,14zM6,9h12v2L6,11zM6,6h12v2L6,8z"/>
</vector>