Restartable widget

This commit is contained in:
Sad Ellie 2024-01-06 23:48:10 +03:00
parent 3efca2dc95
commit 3638af2e45
3 changed files with 24 additions and 5 deletions

View File

@ -30,7 +30,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.glance.Button
import androidx.glance.ColorFilter import androidx.glance.ColorFilter
import androidx.glance.GlanceId import androidx.glance.GlanceId
import androidx.glance.GlanceModifier import androidx.glance.GlanceModifier
@ -233,10 +232,11 @@ class UnittoCalculatorWidget : GlanceAppWidget() {
.fillMaxSize(), .fillMaxSize(),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Button( GlanceKeyboardButton(
text = LocalContext.current.resources.getString(com.sadellie.unitto.core.base.R.string.loading_label), glanceModifier = GlanceModifier,
onClick = {}, containerColor = GlanceTheme.colors.primary,
style = TextStyle(GlanceTheme.colors.onBackground, fontSize = 36.sp) iconRes = R.drawable.refresh,
onClick = actionRunCallback<RestartWidget>(),
) )
} }
} }

View File

@ -77,6 +77,16 @@ internal class CopyResultAction : ActionCallback {
} }
} }
internal class RestartWidget : ActionCallback {
override suspend fun onAction(
context: Context,
glanceId: GlanceId,
parameters: ActionParameters
) {
UnittoCalculatorWidget().update(context, glanceId)
}
}
private fun calculate( private fun calculate(
input: String, input: String,
precision: Int, precision: Int,

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M480,800Q346,800 253,707Q160,614 160,480Q160,346 253,253Q346,160 480,160Q549,160 612,188.5Q675,217 720,270L720,160L800,160L800,440L520,440L520,360L688,360Q656,304 600.5,272Q545,240 480,240Q380,240 310,310Q240,380 240,480Q240,580 310,650Q380,720 480,720Q557,720 619,676Q681,632 706,560L790,560Q762,666 676,733Q590,800 480,800Z"/>
</vector>