Skip to content

Commit

Permalink
feat: update the look of the widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Chesire committed Oct 8, 2023
1 parent bdfa137 commit a458d88
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.ui.graphics.Color

internal val DarkColorPalette = darkColorScheme(
val DarkColorPalette = darkColorScheme(
primary = Color(0xFF65d3ff),
onPrimary = Color(0xFF003546),
primaryContainer = Color(0xFF004d64),
Expand All @@ -30,7 +30,7 @@ internal val DarkColorPalette = darkColorScheme(
onSurfaceVariant = Color(0xFFc0c8cd)
)

internal val LightColorPalette = lightColorScheme(
val LightColorPalette = lightColorScheme(
primary = Color(0xFF006783),
onPrimary = Color(0xFFffffff),
primaryContainer = Color(0xFFbde9ff),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ import androidx.glance.GlanceId
import androidx.glance.GlanceModifier
import androidx.glance.LocalContext
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.appWidgetBackground
import androidx.glance.appwidget.background
import androidx.glance.appwidget.cornerRadius
import androidx.glance.appwidget.lazy.LazyColumn
import androidx.glance.appwidget.lazy.items
import androidx.glance.appwidget.provideContent
import androidx.glance.color.ColorProvider
import androidx.glance.layout.Alignment
import androidx.glance.layout.Column
import androidx.glance.layout.Row
import androidx.glance.layout.Spacer
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.fillMaxWidth
import androidx.glance.layout.height
import androidx.glance.layout.padding
import androidx.glance.text.Text
import androidx.glance.text.TextStyle
import com.chesire.nekome.core.compose.theme.DarkColorPalette
import com.chesire.nekome.core.compose.theme.LightColorPalette
import com.chesire.nekome.feature.serieswidget.SeriesWidgetEntryPoint
import dagger.hilt.EntryPoints

Expand All @@ -35,11 +43,11 @@ class SeriesWidget : GlanceAppWidget() {

@Composable
private fun ProvideContent() {
val ctx = LocalContext.current.applicationContext
val context = LocalContext.current.applicationContext

// TODO: Use remember for this?
val viewModel = EntryPoints.get(
ctx,
context,
SeriesWidgetEntryPoint::class.java
).seriesWidgetViewModel()

Expand All @@ -57,20 +65,28 @@ class SeriesWidget : GlanceAppWidget() {
) {
LazyColumn(
modifier = GlanceModifier
.appWidgetBackground()
.background(
day = LightColorPalette.surface,
night = DarkColorPalette.surface
)
.fillMaxSize()
.padding(8.dp)
) {
items(
items = state.series,
itemId = { it.userId.toLong() }
) { item ->
SeriesCard(
id = item.userId,
title = item.title,
progress = item.progress,
isUpdating = item.isUpdating,
updateSeries = updateSeries
)
Column {
SeriesCard(
id = item.userId,
title = item.title,
progress = item.progress,
isUpdating = item.isUpdating,
updateSeries = updateSeries
)
Spacer(modifier = GlanceModifier.height(8.dp).fillMaxWidth())
}
}
}
}
Expand All @@ -81,18 +97,47 @@ class SeriesWidget : GlanceAppWidget() {
title: String,
progress: String,
isUpdating: Boolean,
updateSeries: (Int) -> Unit
updateSeries: (Int) -> Unit,
modifier: GlanceModifier = GlanceModifier
) {
Row(
modifier = GlanceModifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth()
.background(
day = LightColorPalette.primaryContainer,
night = DarkColorPalette.primaryContainer
)
.cornerRadius(8.dp)
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Column {
Text(text = title)
Text(text = progress)
Column(
modifier = GlanceModifier
.defaultWeight()
.padding(end = 8.dp)
) {
Text(
text = title,
style = TextStyle(
color = ColorProvider(
day = LightColorPalette.onPrimaryContainer,
night = DarkColorPalette.onPrimaryContainer
)
)
)
Text(
text = progress,
style = TextStyle(
color = ColorProvider(
day = LightColorPalette.onPrimaryContainer,
night = DarkColorPalette.onPrimaryContainer
)
)
)
}
Spacer(modifier = GlanceModifier.defaultWeight())
Button(text = "+1", onClick = { updateSeries(id) })
Button(
text = "+1",
onClick = { updateSeries(id) }
)
}
}
}

0 comments on commit a458d88

Please sign in to comment.