Skip to content

Commit

Permalink
feat(widget): built better UI
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Info committed Oct 25, 2023
1 parent c2315c3 commit 410107b
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 98 deletions.
57 changes: 49 additions & 8 deletions app/src/main/kotlin/com/zjutjh/ijh/ui/component/ClassSchedule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,33 @@ import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material3.Badge
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
Expand All @@ -29,7 +52,26 @@ import androidx.core.os.LocaleListCompat
import com.zjutjh.ijh.data.repository.mock.CourseRepositoryMock
import com.zjutjh.ijh.model.Course
import com.zjutjh.ijh.model.Section
import com.zjutjh.ijh.ui.theme.*
import com.zjutjh.ijh.ui.theme.Blue0
import com.zjutjh.ijh.ui.theme.Blue5
import com.zjutjh.ijh.ui.theme.Cyan0
import com.zjutjh.ijh.ui.theme.Desert
import com.zjutjh.ijh.ui.theme.Green0
import com.zjutjh.ijh.ui.theme.IJhTheme
import com.zjutjh.ijh.ui.theme.Orange0
import com.zjutjh.ijh.ui.theme.Purple3
import com.zjutjh.ijh.ui.theme.RainbowChampagne
import com.zjutjh.ijh.ui.theme.RainbowCoral
import com.zjutjh.ijh.ui.theme.RainbowLavender
import com.zjutjh.ijh.ui.theme.RainbowLightBlue
import com.zjutjh.ijh.ui.theme.RainbowLightGreen
import com.zjutjh.ijh.ui.theme.RainbowLime
import com.zjutjh.ijh.ui.theme.RainbowOrange
import com.zjutjh.ijh.ui.theme.RainbowPeach
import com.zjutjh.ijh.ui.theme.RainbowPink
import com.zjutjh.ijh.ui.theme.RainbowViolet
import com.zjutjh.ijh.ui.theme.Red0
import com.zjutjh.ijh.ui.theme.Red2
import com.zjutjh.ijh.util.CourseStack
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
Expand All @@ -40,7 +82,6 @@ import java.time.DayOfWeek
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.TextStyle
import java.util.*
import kotlin.math.roundToInt
import kotlin.time.toKotlinDuration

Expand Down Expand Up @@ -80,8 +121,8 @@ fun ClassSchedule(
) {
val today = dateTime.dayOfWeek

DayOfWeek.values().forEachIndexed { index, dayOfWeek ->
val dayCourses = remember (courses) {
DayOfWeek.entries.forEachIndexed { index, dayOfWeek ->
val dayCourses = remember(courses) {
courses.filter { it.dayOfWeek == dayOfWeek }.toImmutableList()
}
ClassScheduleRowItem(
Expand Down Expand Up @@ -259,7 +300,7 @@ private fun ClassScheduleRowItem(
}

// Enforce group recompose
key (elements) {
key(elements) {
ClassScheduleColumn(courses = elements) {
elements.forEachIndexed { index, courseStack ->
ClassScheduleColumnItem(
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/zjutjh/ijh/widget/Actions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zjutjh.ijh.widget

import android.content.Context
import androidx.glance.GlanceId
import androidx.glance.action.ActionParameters
import androidx.glance.appwidget.action.ActionCallback
import com.zjutjh.ijh.work.ScheduleWidgetUpdater

class UpdateAction : ActionCallback {
override suspend fun onAction(
context: Context,
glanceId: GlanceId,
parameters: ActionParameters
) {
ScheduleWidgetUpdater.enqueue(context)
}
}
43 changes: 42 additions & 1 deletion app/src/main/kotlin/com/zjutjh/ijh/widget/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
*/
package com.zjutjh.ijh.widget

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.glance.ColorFilter
import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
import androidx.glance.action.Action
import androidx.glance.action.clickable
import androidx.glance.appwidget.cornerRadius
import androidx.glance.background
import androidx.glance.layout.Box
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.height
import androidx.glance.layout.width
import androidx.glance.text.FontWeight
import androidx.glance.text.Text
import androidx.glance.text.TextAlign
import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider

Expand All @@ -17,10 +33,35 @@ import androidx.glance.unit.ColorProvider
fun GText(
text: String,
color: ColorProvider = GlanceTheme.colors.onSurface,
size: TextUnit = MaterialTheme.typography.bodySmall.fontSize,
weight: FontWeight = FontWeight.Normal,
textAlign: TextAlign? = null,
modifier: GlanceModifier = GlanceModifier
) = Text(
text = text,
modifier = modifier,
style = TextStyle(color),
style = TextStyle(color = color, fontSize = size, fontWeight = weight, textAlign = textAlign),
maxLines = 1,
)

@Composable
fun IconButton(
provider: ImageProvider,
onClick: Action
) {
Box(
modifier = GlanceModifier
.background(GlanceTheme.colors.primary)
.height(30.dp)
.width(30.dp)
.cornerRadius(10.dp)
.clickable(onClick)
) {
Image(
provider = provider,
contentDescription = "Image in button",
modifier = GlanceModifier.fillMaxSize(),
colorFilter = ColorFilter.tint(GlanceTheme.colors.onPrimary)
)
}
}
Loading

0 comments on commit 410107b

Please sign in to comment.