@@ -10,13 +10,13 @@ import androidx.compose.ui.graphics.Color
1010import androidx.compose.ui.unit.dp
1111import androidx.compose.ui.unit.sp
1212import androidx.core.net.toUri
13+ import androidx.glance.Button
1314import androidx.glance.ColorFilter
1415import androidx.glance.GlanceModifier
1516import androidx.glance.GlanceTheme
1617import androidx.glance.Image
1718import androidx.glance.ImageProvider
1819import androidx.glance.LocalContext
19- import androidx.glance.LocalSize
2020import androidx.glance.action.Action
2121import androidx.glance.action.clickable
2222import androidx.glance.appwidget.action.actionRunCallback
@@ -46,20 +46,20 @@ import com.capyreader.app.OpenArticleInBrowserActivity.Companion.ARTICLE_URL_KEY
4646import com.capyreader.app.R
4747import com.capyreader.app.notifications.NotificationHelper.Companion.ARTICLE_ID_KEY
4848import com.capyreader.app.notifications.NotificationHelper.Companion.FEED_ID_KEY
49+ import com.capyreader.app.notifications.NotificationHelper.Companion.SHOW_ALL_KEY
4950
5051@Composable
5152fun 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
190179private 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+
204207private 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
227230fun 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
250273fun SpotlightLayoutDarkPreview () {
251274 GlanceTheme (
0 commit comments