Skip to content

Commit 70c922f

Browse files
committed
Don't use previews in prod
1 parent aa59449 commit 70c922f

File tree

1 file changed

+43
-46
lines changed
  • app/src/main/java/co/adityarajput/notifilter/views

1 file changed

+43
-46
lines changed

app/src/main/java/co/adityarajput/notifilter/views/Widget.kt

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Widget(val isPreview: Boolean = false) : GlanceAppWidget() {
2828
override suspend fun provideGlance(context: Context, id: GlanceId) {
2929
provideContent {
3030
if (isPreview) {
31-
WidgetPreview()
31+
Content(sampleNotifications)
3232
} else {
3333
Content(
3434
AppContainer(context).repository.log().collectAsState(emptyList()).value,
@@ -39,12 +39,12 @@ class Widget(val isPreview: Boolean = false) : GlanceAppWidget() {
3939
}
4040

4141
override suspend fun providePreview(context: Context, widgetCategory: Int) =
42-
provideContent { WidgetPreview() }
42+
provideContent { Content(sampleNotifications) }
4343
}
4444

4545
@Composable
4646
@GlanceComposable
47-
fun Content(notifications: List<Notification>, allPackages: List<App>) {
47+
private fun Content(notifications: List<Notification>, allPackages: List<App> = emptyList()) {
4848
val context = LocalContext.current
4949

5050
Scaffold(
@@ -135,50 +135,47 @@ fun Content(notifications: List<Notification>, allPackages: List<App>) {
135135
@OptIn(ExperimentalGlancePreviewApi::class)
136136
@Preview
137137
@Composable
138-
fun WidgetPreview() {
139-
Content(
140-
listOf(
141-
Notification(
142-
"Download paused",
143-
"A software update is available.",
144-
"Software update",
145-
System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000,
146-
id = 1,
147-
),
148-
Notification(
149-
"Upcoming alarm",
150-
"Wed 8:30 AM - Wake up",
151-
"Clock",
152-
System.currentTimeMillis() - 28 * 60 * 60 * 1000,
153-
id = 2,
154-
),
155-
Notification(
156-
"Upcoming alarm",
157-
"Wed 11:30 AM - Exercise",
158-
"Clock",
159-
System.currentTimeMillis() - 25 * 60 * 60 * 1000,
160-
id = 3,
161-
),
162-
Notification(
163-
164-
"The week: a microphone, a ropeway, and something very sour.\nHello!\nOver the last few days...",
165-
"Gmail",
166-
System.currentTimeMillis() - 3 * 60 * 60 * 1000,
167-
id = 4,
168-
),
169-
Notification(
170-
"Book Club",
171-
"Bob: Please go for something lighter this time. I'm tired of tomes!",
172-
"WhatsApp",
173-
System.currentTimeMillis() - 37 * 60 * 1000,
174-
id = 5,
175-
),
176-
).reversed(),
177-
emptyList(),
178-
)
179-
}
138+
private fun WidgetPreview() = Content(sampleNotifications)
180139

181140
@OptIn(ExperimentalGlancePreviewApi::class)
182141
@Preview
183142
@Composable
184-
fun WidgetEmptyPreview() = Content(emptyList(), emptyList())
143+
private fun WidgetEmptyPreview() = Content(emptyList())
144+
145+
private val sampleNotifications = listOf(
146+
Notification(
147+
"Book Club",
148+
"Bob: Please go for something lighter this time. I'm tired of tomes!",
149+
"WhatsApp",
150+
System.currentTimeMillis() - 37 * 60 * 1000,
151+
id = 5,
152+
),
153+
Notification(
154+
155+
"The week: a microphone, a ropeway, and something very sour.\nHello!\nOver the last few days...",
156+
"Gmail",
157+
System.currentTimeMillis() - 3 * 60 * 60 * 1000,
158+
id = 4,
159+
),
160+
Notification(
161+
"Upcoming alarm",
162+
"Wed 11:30 AM - Exercise",
163+
"Clock",
164+
System.currentTimeMillis() - 25 * 60 * 60 * 1000,
165+
id = 3,
166+
),
167+
Notification(
168+
"Upcoming alarm",
169+
"Wed 8:30 AM - Wake up",
170+
"Clock",
171+
System.currentTimeMillis() - 28 * 60 * 60 * 1000,
172+
id = 2,
173+
),
174+
Notification(
175+
"Download paused",
176+
"A software update is available.",
177+
"Software update",
178+
System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000,
179+
id = 1,
180+
),
181+
)

0 commit comments

Comments
 (0)