Open clock/calendar app again when clicking on clock widget
This commit is contained in:
parent
6c0c6bd6f8
commit
fbcd5ed327
@ -3,6 +3,7 @@ package de.mm20.launcher2.ui.component
|
||||
import android.text.format.DateFormat
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
@ -14,6 +15,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.center
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.PointMode
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
@ -35,14 +37,14 @@ fun DigitalClock(time: Long) {
|
||||
Locale.getDefault()
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
modifier = Modifier.offset(y = 16.dp),
|
||||
text = format.format(time),
|
||||
style = MaterialTheme.typography.displayLarge.copy(
|
||||
fontSize = 100.sp,
|
||||
fontWeight = FontWeight.Black,
|
||||
textAlign = TextAlign.Center,
|
||||
lineHeight = 0.8.em,
|
||||
letterSpacing = -0.1.em
|
||||
letterSpacing = -0.1.em,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@ -4,14 +4,16 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.provider.AlarmClock
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -21,7 +23,6 @@ import de.mm20.launcher2.preferences.dataStore
|
||||
import de.mm20.launcher2.ui.component.AnalogClock
|
||||
import de.mm20.launcher2.ui.component.BinaryClock
|
||||
import de.mm20.launcher2.ui.component.DigitalClock
|
||||
import de.mm20.launcher2.ui.ktx.toDp
|
||||
import de.mm20.launcher2.ui.locals.LocalWindowSize
|
||||
import de.mm20.launcher2.ui.widget.parts.DatePart
|
||||
import kotlinx.coroutines.flow.map
|
||||
@ -81,15 +82,26 @@ fun Clock(transparentBackground: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
when (clockStyle) {
|
||||
ClockStyle.Analog -> {
|
||||
AnalogClock(time = time)
|
||||
Box(
|
||||
modifier = Modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
context.startActivity(Intent(AlarmClock.ACTION_SHOW_ALARMS).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
})
|
||||
}
|
||||
ClockStyle.Binary -> {
|
||||
BinaryClock(time = time)
|
||||
}
|
||||
else -> {
|
||||
DigitalClock(time = time)
|
||||
) {
|
||||
when (clockStyle) {
|
||||
ClockStyle.Analog -> {
|
||||
AnalogClock(time = time)
|
||||
}
|
||||
ClockStyle.Binary -> {
|
||||
BinaryClock(time = time)
|
||||
}
|
||||
else -> {
|
||||
DigitalClock(time = time)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,36 @@
|
||||
package de.mm20.launcher2.ui.widget.parts
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.Intent
|
||||
import android.provider.CalendarContract
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import de.mm20.launcher2.calendar.CalendarViewModel
|
||||
import de.mm20.launcher2.ui.component.TextClock
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@Composable
|
||||
fun DatePart() {
|
||||
TextClock(
|
||||
formatFlags = DateUtils.FORMAT_SHOW_WEEKDAY or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
val context = LocalContext.current
|
||||
TextButton(onClick = {
|
||||
val startMillis = System.currentTimeMillis()
|
||||
val builder = CalendarContract.CONTENT_URI.buildUpon()
|
||||
builder.appendPath("time")
|
||||
ContentUris.appendId(builder, startMillis)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(builder.build())
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
|
||||
context.startActivity(intent)
|
||||
}) {
|
||||
TextClock(
|
||||
formatFlags = DateUtils.FORMAT_SHOW_WEEKDAY or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user