Skip to content

Commit e35d72a

Browse files
committed
Fix spotlight widget empty image case
1 parent a954a89 commit e35d72a

8 files changed

Lines changed: 101 additions & 73 deletions

File tree

app/src/main/java/com/capyreader/app/notifications/NotificationHelper.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class NotificationHelper(
138138
const val ARTICLE_ID_KEY = "article_id"
139139
const val FEED_ID_KEY = "feed_id"
140140
const val UNREAD_ONLY_KEY = "unread_only"
141+
const val SHOW_ALL_KEY = "show_all"
141142

142143
private const val ARTICLE_REFRESH_GROUP = "article_refresh"
143144

@@ -157,6 +158,7 @@ class NotificationHelper(
157158

158159
fun openFromIntent(intent: Intent, appPreferences: AppPreferences): String? {
159160
val openFromShowMore = intent.getBooleanExtra(UNREAD_ONLY_KEY, false)
161+
val openShowAll = intent.getBooleanExtra(SHOW_ALL_KEY, false)
160162
val articleID = intent.getStringExtra(ARTICLE_ID_KEY)
161163
val feedID = intent.getStringExtra(FEED_ID_KEY)
162164

@@ -167,6 +169,14 @@ class NotificationHelper(
167169
ArticleFilter.Articles(articleStatus = ArticleStatus.UNREAD)
168170
)
169171

172+
return null
173+
} else if (openShowAll) {
174+
intent.replaceExtras(Bundle())
175+
176+
appPreferences.filter.set(
177+
ArticleFilter.Articles(articleStatus = ArticleStatus.ALL)
178+
)
179+
170180
return null
171181
} else if (articleID != null && feedID != null) {
172182
intent.replaceExtras(Bundle())

app/src/main/java/com/capyreader/app/ui/widget/SpotlightLayout.kt

Lines changed: 86 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import androidx.compose.ui.graphics.Color
1010
import androidx.compose.ui.unit.dp
1111
import androidx.compose.ui.unit.sp
1212
import androidx.core.net.toUri
13+
import androidx.glance.Button
1314
import androidx.glance.ColorFilter
1415
import androidx.glance.GlanceModifier
1516
import androidx.glance.GlanceTheme
1617
import androidx.glance.Image
1718
import androidx.glance.ImageProvider
1819
import androidx.glance.LocalContext
19-
import androidx.glance.LocalSize
2020
import androidx.glance.action.Action
2121
import androidx.glance.action.clickable
2222
import androidx.glance.appwidget.action.actionRunCallback
@@ -46,20 +46,20 @@ import com.capyreader.app.OpenArticleInBrowserActivity.Companion.ARTICLE_URL_KEY
4646
import com.capyreader.app.R
4747
import com.capyreader.app.notifications.NotificationHelper.Companion.ARTICLE_ID_KEY
4848
import com.capyreader.app.notifications.NotificationHelper.Companion.FEED_ID_KEY
49+
import com.capyreader.app.notifications.NotificationHelper.Companion.SHOW_ALL_KEY
4950

5051
@Composable
5152
fun SpotlightLayout(
5253
entry: SpotlightEntry?,
5354
imageBitmap: Bitmap?,
5455
) {
5556
val context = LocalContext.current
56-
val size = LocalSize.current
57-
val isCompact = size.width < 220.dp
57+
val textColor = ColorProvider(Color.White, Color.White)
5858

5959
Box(
6060
modifier = GlanceModifier
6161
.fillMaxSize()
62-
.background(GlanceTheme.colors.widgetBackground)
62+
.background(GlanceTheme.colors.primaryContainer)
6363
.cornerRadius(16.dp)
6464
) {
6565
if (entry == null) {
@@ -79,70 +79,59 @@ fun SpotlightLayout(
7979
}
8080

8181
Box(
82+
modifier = GlanceModifier
83+
.fillMaxSize()
84+
.background(ImageProvider(R.drawable.spotlight_scrim))
85+
) {}
86+
87+
Box(
88+
contentAlignment = Alignment.BottomStart,
8289
modifier = GlanceModifier
8390
.fillMaxSize()
8491
.clickable(openAction)
85-
.background(ImageProvider(R.drawable.spotlight_gradient))
92+
.padding(start = 16.dp, end = 16.dp, top = 48.dp, bottom = 16.dp)
8693
) {
87-
Box(
88-
contentAlignment = Alignment.TopStart,
89-
modifier = GlanceModifier.fillMaxSize()
90-
) {
91-
Image(
92-
provider = ImageProvider(R.drawable.capy_icon_small),
93-
contentDescription = null,
94-
colorFilter = ColorFilter.tint(ColorProvider(Color.White, Color.White)),
95-
modifier = GlanceModifier
96-
.padding(12.dp)
97-
.size(48.dp)
94+
Column(modifier = GlanceModifier.fillMaxWidth()) {
95+
Text(
96+
entry.feedName,
97+
maxLines = 1,
98+
style = TextStyle(
99+
fontSize = 14.sp,
100+
fontWeight = FontWeight.Medium,
101+
color = textColor,
102+
),
103+
)
104+
Text(
105+
entry.title,
106+
maxLines = 3,
107+
style = TextStyle(
108+
fontSize = 22.sp,
109+
fontWeight = FontWeight.Bold,
110+
color = textColor,
111+
),
98112
)
99113
}
114+
}
100115

101-
Box(
102-
contentAlignment = Alignment.BottomStart,
103-
modifier = GlanceModifier.fillMaxSize()
104-
) {
105-
Row(
106-
verticalAlignment = Alignment.Bottom,
107-
modifier = GlanceModifier
108-
.fillMaxWidth()
109-
.padding(start = 16.dp, end = 8.dp, bottom = 12.dp, top = 32.dp)
110-
) {
111-
Column(modifier = GlanceModifier.defaultWeight()) {
112-
Text(
113-
entry.feedName,
114-
maxLines = 1,
115-
style = TextStyle(
116-
fontSize = 12.sp,
117-
fontWeight = FontWeight.Medium,
118-
color = ColorProvider(Color.White, Color.White),
119-
),
120-
)
121-
Text(
122-
entry.title,
123-
maxLines = 2,
124-
style = TextStyle(
125-
fontSize = 16.sp,
126-
fontWeight = FontWeight.Bold,
127-
color = ColorProvider(Color.White, Color.White),
128-
),
129-
)
130-
}
131-
132-
if (!isCompact) {
133-
NavButtons(modifier = GlanceModifier.padding(start = 8.dp))
134-
}
135-
}
136-
}
116+
Box(
117+
contentAlignment = Alignment.TopStart,
118+
modifier = GlanceModifier.fillMaxSize()
119+
) {
120+
Image(
121+
provider = ImageProvider(R.drawable.capy_icon_small),
122+
contentDescription = null,
123+
colorFilter = ColorFilter.tint(textColor),
124+
modifier = GlanceModifier
125+
.padding(12.dp)
126+
.size(48.dp)
127+
)
137128
}
138129

139-
if (isCompact) {
140-
Box(
141-
contentAlignment = Alignment.TopEnd,
142-
modifier = GlanceModifier.fillMaxSize()
143-
) {
144-
NavButtons(modifier = GlanceModifier.padding(8.dp))
145-
}
130+
Box(
131+
contentAlignment = Alignment.TopEnd,
132+
modifier = GlanceModifier.fillMaxSize()
133+
) {
134+
NavButtons(modifier = GlanceModifier.padding(8.dp))
146135
}
147136
}
148137
}
@@ -188,8 +177,9 @@ private fun NavButtons(modifier: GlanceModifier = GlanceModifier) {
188177

189178
@Composable
190179
private fun EmptyState(context: Context) {
191-
Box(
192-
contentAlignment = Alignment.Center,
180+
Column(
181+
verticalAlignment = Alignment.CenterVertically,
182+
horizontalAlignment = Alignment.CenterHorizontally,
193183
modifier = GlanceModifier.fillMaxSize()
194184
) {
195185
Text(
@@ -198,9 +188,22 @@ private fun EmptyState(context: Context) {
198188
color = GlanceTheme.colors.onSurface
199189
)
200190
)
191+
Spacer(GlanceModifier.size(8.dp))
192+
Button(
193+
text = context.getString(R.string.widget_spotlight_see_all),
194+
onClick = context.openAll(),
195+
)
201196
}
202197
}
203198

199+
private fun Context.openAll() =
200+
actionStartActivity(
201+
Intent(this, MainActivity::class.java).apply {
202+
putExtra(SHOW_ALL_KEY, true)
203+
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
204+
}
205+
)
206+
204207
private fun Context.openArticle(entry: SpotlightEntry): Action {
205208
return if (entry.openInBrowser && entry.articleURL != null) {
206209
actionStartActivity(
@@ -226,7 +229,7 @@ private fun Context.openArticle(entry: SpotlightEntry): Action {
226229
@Composable
227230
fun SpotlightLayoutPreview() {
228231
val previewBitmap =
229-
BitmapFactory.decodeResource(LocalContext.current.resources, R.drawable.spotlight_widget_preview)
232+
BitmapFactory.decodeResource(LocalContext.current.resources, R.drawable.hello_world)
230233

231234
GlanceTheme {
232235
SpotlightLayout(
@@ -245,7 +248,27 @@ fun SpotlightLayoutPreview() {
245248
}
246249

247250
@OptIn(ExperimentalGlancePreviewApi::class)
248-
@Preview
251+
@Preview(widthDp = 320, heightDp = 180)
252+
@Composable
253+
fun SpotlightLayoutTextOnlyPreview() {
254+
GlanceTheme {
255+
SpotlightLayout(
256+
entry = SpotlightEntry(
257+
id = "1",
258+
feedID = "nasa",
259+
feedName = "NASA Image of the Day",
260+
title = "Circular Star Trails Over the Austrian Alps",
261+
imageURL = null,
262+
articleURL = "https://www.nasa.gov/image-article/hello-world/",
263+
openInBrowser = false,
264+
),
265+
imageBitmap = null,
266+
)
267+
}
268+
}
269+
270+
@OptIn(ExperimentalGlancePreviewApi::class)
271+
@Preview(widthDp = 320, heightDp = 180)
249272
@Composable
250273
fun SpotlightLayoutDarkPreview() {
251274
GlanceTheme(

app/src/main/java/com/capyreader/app/ui/widget/SpotlightWidget.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SpotlightWidget : GlanceAppWidget() {
6363
}
6464

6565
override suspend fun providePreview(context: Context, widgetCategory: Int) {
66-
val previewBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.spotlight_widget_preview)
66+
val previewBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.hello_world)
6767

6868
provideContent {
6969
GlanceTheme {
64.5 KB
Loading

app/src/main/res/drawable/spotlight_gradient.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
2+
<solid android:color="#99000000" />
3+
</shape>
-156 KB
Loading

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
<string name="widget_headlines_account_error">Add an account first</string>
325325
<string name="widget_receiver_spotlight_title">Spotlight</string>
326326
<string name="widget_spotlight_empty">No unread articles</string>
327+
<string name="widget_spotlight_see_all">See all</string>
327328
<string name="widget_spotlight_previous">Previous</string>
328329
<string name="widget_spotlight_next">Next</string>
329330
<string name="settings_gestures_improve_talkback_title">Improve TalkBack</string>

0 commit comments

Comments
 (0)