Skip to content

Commit cb5db3d

Browse files
committed
feat: widget label & descriptions & style tweak
1 parent f77fc3a commit cb5db3d

File tree

9 files changed

+27
-17
lines changed

9 files changed

+27
-17
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122

123123
<receiver
124124
android:name=".ui.widget.ArticleListWidgetReceiver"
125+
android:label="@string/list_widget_label"
125126
android:exported="true">
126127
<intent-filter>
127128
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@@ -133,6 +134,7 @@
133134
</receiver>
134135
<receiver
135136
android:name=".ui.widget.ArticleCardWidgetReceiver"
137+
android:label="@string/card_widget_label"
136138
android:exported="true">
137139
<intent-filter>
138140
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

app/src/main/java/me/ash/reader/ui/widget/ArticleCardWidget.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ fun ArticleCard(article: Article?, bitmap: Bitmap?, modifier: GlanceModifier = G
200200
fontSize = 16.sp,
201201
fontWeight = FontWeight.Bold,
202202
),
203+
maxLines = 6
203204
)
204205
}
205206
}

app/src/main/java/me/ash/reader/ui/widget/ArticleListWidget.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ fun Header(text: String, theme: Theme, modifier: GlanceModifier = GlanceModifier
161161
18.sp
162162
}
163163

164+
val topPadding = if (isLargeVariant) 28.dp else 24.dp
165+
164166
val bottomPadding = if (isLargeVariant) 10.dp else 8.dp
165167

166-
Column(modifier = modifier.padding(bottom = bottomPadding).padding(horizontal = 12.dp)) {
168+
Column(
169+
modifier =
170+
modifier.padding(top = topPadding, bottom = bottomPadding).padding(horizontal = 12.dp)
171+
) {
167172
Text(
168173
text = text,
169174
style =
@@ -192,7 +197,6 @@ fun ArticleList(
192197
val context = LocalContext.current
193198
if (items.isEmpty()) {
194199
Column(modifier = modifier.fillMaxSize().clickable(actionStartActivity<MainActivity>())) {
195-
Spacer(modifier = GlanceModifier.height(24.dp))
196200
Header(title, theme)
197201
Text(
198202
text = context.getString(R.string.no_unread_articles),
@@ -209,7 +213,6 @@ fun ArticleList(
209213
}
210214
} else {
211215
Column(modifier = modifier) {
212-
Spacer(modifier = GlanceModifier.height(24.dp))
213216
Header(title, theme)
214217

215218
LazyColumn() {

app/src/main/java/me/ash/reader/ui/widget/FeedWidgetConfig.kt renamed to app/src/main/java/me/ash/reader/ui/widget/WidgetConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package me.ash.reader.ui.widget
33
import kotlinx.serialization.Serializable
44

55
@Serializable
6-
data class FeedWidgetConfig(val theme: Theme, val dataSource: DataSource) {
6+
data class WidgetConfig(val theme: Theme, val dataSource: DataSource) {
77
companion object {
88
fun default(accountId: Int) =
9-
FeedWidgetConfig(theme = Theme.SansSerif, dataSource = DataSource.Account(accountId))
9+
WidgetConfig(theme = Theme.SansSerif, dataSource = DataSource.Account(accountId))
1010
}
1111
}
1212

app/src/main/java/me/ash/reader/ui/widget/WidgetConfigActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class WidgetConfigActivity : ComponentActivity() {
9898
setContent {
9999
settingsProvider.ProvidesSettings {
100100
AppTheme(useDarkTheme = LocalDarkTheme.current.isDarkTheme()) {
101-
var config: FeedWidgetConfig by remember { mutableStateOf(config) }
101+
var config: WidgetConfig by remember { mutableStateOf(config) }
102102

103103
val dataSources =
104104
repository.getCurrentDataSources().collectAsStateValue(emptyList())
@@ -187,7 +187,7 @@ class WidgetConfigActivity : ComponentActivity() {
187187
}
188188

189189
fun updateWidget(
190-
config: FeedWidgetConfig,
190+
config: WidgetConfig,
191191
glanceId: GlanceId,
192192
appWidgetId: Int,
193193
isCard: Boolean,
@@ -289,7 +289,7 @@ fun SingleChoiceItem(
289289
.padding(vertical = 16.dp, horizontal = 24.dp),
290290
verticalAlignment = Alignment.CenterVertically,
291291
) {
292-
Column {
292+
Column(modifier = Modifier.weight(1f)) {
293293
Text(
294294
title,
295295
style = MaterialTheme.typography.bodyLargeEmphasized,
@@ -302,7 +302,6 @@ fun SingleChoiceItem(
302302
color = MaterialTheme.colorScheme.onSurfaceVariant,
303303
)
304304
}
305-
Spacer(modifier = Modifier.weight(1f))
306305
RadioButton(selected = selected, onClick = null, interactionSource = interactionSource)
307306
}
308307
}

app/src/main/java/me/ash/reader/ui/widget/WidgetRepository.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ constructor(
5050

5151
private fun Context.getConfigFlow(
5252
widgetId: Int,
53-
default: FeedWidgetConfig = FeedWidgetConfig.default(accountService.getCurrentAccountId()),
54-
): Flow<FeedWidgetConfig> =
53+
default: WidgetConfig = WidgetConfig.default(accountService.getCurrentAccountId()),
54+
): Flow<WidgetConfig> =
5555
widgetDataStore.data.map {
5656
val string = it[stringPreferencesKey(widgetId.toString())]
5757
if (string == null) default
5858
else
59-
runCatching { json.decodeFromString<FeedWidgetConfig>(string) }
59+
runCatching { json.decodeFromString<WidgetConfig>(string) }
6060
.getOrDefault(default)
6161
}
6262

63-
private suspend fun Context.writeConfig(widgetId: Int, config: FeedWidgetConfig) =
63+
private suspend fun Context.writeConfig(widgetId: Int, config: WidgetConfig) =
6464
withContext(Dispatchers.IO) {
6565
widgetDataStore.edit { preferences ->
6666
val configString =
@@ -85,14 +85,14 @@ constructor(
8585
}
8686
}
8787

88-
fun getDefaultConfig() = FeedWidgetConfig.default(accountService.getCurrentAccountId())
88+
fun getDefaultConfig() = WidgetConfig.default(accountService.getCurrentAccountId())
8989

90-
suspend fun writeConfig(widgetId: Int, config: FeedWidgetConfig) =
90+
suspend fun writeConfig(widgetId: Int, config: WidgetConfig) =
9191
context.writeConfig(widgetId, config)
9292

93-
suspend fun getConfig(widgetId: Int): FeedWidgetConfig = getConfigFlow(widgetId).first()
93+
suspend fun getConfig(widgetId: Int): WidgetConfig = getConfigFlow(widgetId).first()
9494

95-
fun getConfigFlow(widgetId: Int): Flow<FeedWidgetConfig> = context.getConfigFlow(widgetId)
95+
fun getConfigFlow(widgetId: Int): Flow<WidgetConfig> = context.getConfigFlow(widgetId)
9696

9797
fun clearConfig(widgetIds: IntArray) =
9898
coroutineScope.launch(Dispatchers.IO) {

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,7 @@
372372
<string name="done">Done</string>
373373
<string name="last_updated">Last updated</string>
374374
<string name="no_unread_articles">No unread articles</string>
375+
<string name="list_widget_label">List view</string>
376+
<string name="card_widget_label">Card view</string>"
377+
<string name="widget_description">View latest unread articles from selected sources</string>
375378
</resources>

app/src/main/res/xml/article_card_widget_info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
22
android:configure="me.ash.reader.ui.widget.WidgetConfigActivity"
3+
android:description="@string/widget_description"
34
android:initialLayout="@layout/glance_default_loading_layout"
45
android:maxResizeWidth="180dp"
56
android:maxResizeHeight="150dp"

app/src/main/res/xml/article_list_widget_info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
22
android:configure="me.ash.reader.ui.widget.WidgetConfigActivity"
3+
android:description="@string/widget_description"
34
android:initialLayout="@layout/glance_default_loading_layout"
45
android:maxResizeWidth="480dp"
56
android:maxResizeHeight="800dp"

0 commit comments

Comments
 (0)