add new event button (widget + FAB), fix widget event row height
This commit is contained in:
parent
ca67729f43
commit
296051efb5
2 changed files with 36 additions and 2 deletions
|
|
@ -16,20 +16,27 @@ import androidx.compose.foundation.layout.width
|
|||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeTopAppBar
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import android.content.Intent
|
||||
import android.provider.CalendarContract
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import space.darkest.nova.android.data.AgendaDay
|
||||
|
|
@ -43,6 +50,7 @@ import java.util.Locale
|
|||
@Composable
|
||||
fun AgendaScreen(agenda: List<AgendaDay>) {
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
val context = LocalContext.current
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
|
|
@ -51,6 +59,17 @@ fun AgendaScreen(agenda: List<AgendaDay>) {
|
|||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(
|
||||
onClick = {
|
||||
context.startActivity(Intent(Intent.ACTION_INSERT).apply {
|
||||
data = CalendarContract.Events.CONTENT_URI
|
||||
})
|
||||
},
|
||||
) {
|
||||
Icon(Icons.Default.Add, contentDescription = "New event")
|
||||
}
|
||||
},
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
) { innerPadding ->
|
||||
if (agenda.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package space.darkest.nova.android.widget
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.CalendarContract
|
||||
import androidx.glance.appwidget.components.CircleIconButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
|
@ -67,6 +68,15 @@ class AgendaWidget : GlanceAppWidget() {
|
|||
startIcon = ImageProvider(android.R.drawable.ic_menu_my_calendar),
|
||||
title = "Agenda",
|
||||
textColor = GlanceTheme.colors.onSurface,
|
||||
actions = {
|
||||
CircleIconButton(
|
||||
imageProvider = ImageProvider(android.R.drawable.ic_input_add),
|
||||
contentDescription = "New event",
|
||||
contentColor = GlanceTheme.colors.onSurfaceVariant,
|
||||
backgroundColor = null,
|
||||
onClick = actionStartActivityIntent(newEventIntent()),
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
backgroundColor = GlanceTheme.colors.widgetBackground,
|
||||
|
|
@ -207,10 +217,10 @@ class AgendaWidget : GlanceAppWidget() {
|
|||
|
||||
Spacer(GlanceModifier.width(8.dp))
|
||||
|
||||
// color indicator
|
||||
// color indicator - height adapts to content via the row
|
||||
Box(
|
||||
modifier = GlanceModifier
|
||||
.size(width = 3.dp, height = 36.dp)
|
||||
.width(3.dp)
|
||||
.cornerRadius(2.dp)
|
||||
.background(GlanceTheme.colors.primary),
|
||||
) {}
|
||||
|
|
@ -244,6 +254,11 @@ class AgendaWidget : GlanceAppWidget() {
|
|||
|
||||
companion object {
|
||||
private val timeFormatter = DateTimeFormatter.ofPattern("HH:mm")
|
||||
|
||||
private fun newEventIntent() = Intent(Intent.ACTION_INSERT).apply {
|
||||
data = CalendarContract.Events.CONTENT_URI
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue