Skip to content

Commit

Permalink
Merge pull request #985 from yschimke/previews
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Jan 11, 2024
2 parents 5267aab + 9da38d2 commit 30f7cdc
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 205 deletions.
3 changes: 3 additions & 0 deletions WearTilesKotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@ dependencies {

implementation libs.androidx.wear.tooling.preview
implementation libs.compose.ui.tooling.preview

debugImplementation libs.androidx.ui.tooling
debugImplementation libs.androidx.tiles.tooling.preview
debugImplementation libs.androidx.tiles.tooling
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,107 +16,97 @@
package com.example.wear.tiles.golden

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.wear.protolayout.ResourceBuilders
import androidx.wear.tiles.RequestBuilders
import androidx.wear.tiles.tooling.preview.Preview
import androidx.wear.tiles.tooling.preview.TilePreviewData
import androidx.wear.tiles.tooling.preview.TilePreviewHelper.singleTimelineEntryTileBuilder
import androidx.wear.tooling.preview.devices.WearDevices
import com.example.wear.tiles.R
import com.example.wear.tiles.tools.WearLargeRoundDevicePreview
import com.example.wear.tiles.tools.WearSmallRoundDevicePreview
import com.example.wear.tiles.tools.emptyClickable
import com.google.android.horologist.compose.tools.LayoutRootPreview
import com.google.android.horologist.compose.tools.buildDeviceParameters
import com.google.android.horologist.tiles.images.drawableResToImageResource

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun Goal() {
val context = LocalContext.current
LayoutRootPreview(
Goal.layout(context, context.deviceParams(), steps = 5168, goal = 8000)
)
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun Goal(context: Context) = TilePreviewData {
singleTimelineEntryTileBuilder(
Goal.layout(
context, it.deviceConfiguration, steps = 5168, goal = 8000
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun WorkoutButtons() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun WorkoutButtons(context: Context) = TilePreviewData(onTileResourceRequest = resources {
addIdToImageMapping(
Workout.BUTTON_1_ICON_ID, drawableResToImageResource(R.drawable.ic_run_24)
)
addIdToImageMapping(
Workout.BUTTON_2_ICON_ID, drawableResToImageResource(R.drawable.ic_yoga_24)
)
addIdToImageMapping(
Workout.BUTTON_3_ICON_ID, drawableResToImageResource(R.drawable.ic_cycling_24)
)
}) {
singleTimelineEntryTileBuilder(
Workout.buttonsLayout(
context,
context.deviceParams(),
it.deviceConfiguration,
weekSummary = "1 run this week",
button1Clickable = emptyClickable,
button2Clickable = emptyClickable,
button3Clickable = emptyClickable,
chipClickable = emptyClickable
)
) {
addIdToImageMapping(
Workout.BUTTON_1_ICON_ID,
drawableResToImageResource(R.drawable.ic_run_24)
)
addIdToImageMapping(
Workout.BUTTON_2_ICON_ID,
drawableResToImageResource(R.drawable.ic_yoga_24)
)
addIdToImageMapping(
Workout.BUTTON_3_ICON_ID,
drawableResToImageResource(R.drawable.ic_cycling_24)
)
}
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun WorkoutLargeChip() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun WorkoutLargeChip(context: Context) = TilePreviewData {
singleTimelineEntryTileBuilder(
Workout.largeChipLayout(
context,
context.deviceParams(),
it.deviceConfiguration,
clickable = emptyClickable,
lastWorkoutSummary = "Last session 45m"
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun Run() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun Run(context: Context) = TilePreviewData {
singleTimelineEntryTileBuilder(
Run.layout(
context,
context.deviceParams(),
it.deviceConfiguration,
lastRunText = "2 days ago",
startRunClickable = emptyClickable,
moreChipClickable = emptyClickable
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun Ski() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun Ski(context: Context) = TilePreviewData {
singleTimelineEntryTileBuilder(
Ski.layout(
context,
stat1 = Ski.Stat("Max Spd", "46.5", "mph"),
stat2 = Ski.Stat("Distance", "21.8", "mile")
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun SleepTracker() {
//@Preview
fun SleepTracker(context: Context) {
// TODO: This tile doesn't use standard components; we can achieve it by drawing on a Canvas (Compose's DrawScope) then converting it to a bitmap using Horologist
}

private fun Context.deviceParams() = buildDeviceParameters(resources)
internal fun resources(fn: ResourceBuilders.Resources.Builder.() -> Unit): (RequestBuilders.ResourcesRequest) -> ResourceBuilders.Resources =
{
ResourceBuilders.Resources.Builder().setVersion(it.version).apply(fn).build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,51 @@
package com.example.wear.tiles.golden

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.wear.tiles.tooling.preview.Preview
import androidx.wear.tiles.tooling.preview.TilePreviewData
import androidx.wear.tiles.tooling.preview.TilePreviewHelper
import androidx.wear.tooling.preview.devices.WearDevices
import com.example.wear.tiles.R
import com.example.wear.tiles.tools.WearLargeRoundDevicePreview
import com.example.wear.tiles.tools.WearSmallRoundDevicePreview
import com.example.wear.tiles.tools.emptyClickable
import com.google.android.horologist.compose.tools.LayoutRootPreview
import com.google.android.horologist.compose.tools.buildDeviceParameters
import com.google.android.horologist.tiles.images.drawableResToImageResource

/**
* b/238548541 (internal bug - the spacing doesn't match Figma)
*/
@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun HeartRateSimple() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun HeartRateSimple(context: Context) = TilePreviewData {
TilePreviewHelper.singleTimelineEntryTileBuilder(
HeartRate.simpleLayout(
context,
context.deviceParams(),
it.deviceConfiguration,
heartRateBpm = 86,
clickable = emptyClickable
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun HeartRateGraph() {
// TODO: not trivial, ataul has dibs though please!
//@Preview
fun HeartRateGraph(context: Context) {
TODO()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun MeditationChips() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun MeditationChips(context: Context) = TilePreviewData(resources {
addIdToImageMapping(
Meditation.CHIP_1_ICON_ID,
drawableResToImageResource(R.drawable.ic_breathe_24)
)
addIdToImageMapping(
Meditation.CHIP_2_ICON_ID,
drawableResToImageResource(R.drawable.ic_mindfulness_24)
)
}) {
TilePreviewHelper.singleTimelineEntryTileBuilder(
Meditation.chipsLayout(
context,
context.deviceParams(),
it.deviceConfiguration,
session1 = Meditation.Session(
label = "Breathe",
iconId = Meditation.CHIP_1_ICON_ID,
Expand All @@ -72,69 +73,52 @@ fun MeditationChips() {
),
browseClickable = emptyClickable
)
) {
addIdToImageMapping(
Meditation.CHIP_1_ICON_ID,
drawableResToImageResource(R.drawable.ic_breathe_24)
)
addIdToImageMapping(
Meditation.CHIP_2_ICON_ID,
drawableResToImageResource(R.drawable.ic_mindfulness_24)
)
}
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun MeditationButtons() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun MeditationButtons(context: Context) = TilePreviewData {
TilePreviewHelper.singleTimelineEntryTileBuilder(
Meditation.buttonsLayout(
context,
context.deviceParams(),
it.deviceConfiguration,
timer1 = Meditation.Timer(minutes = 5, clickable = emptyClickable),
timer2 = Meditation.Timer(minutes = 10, clickable = emptyClickable),
timer3 = Meditation.Timer(minutes = 15, clickable = emptyClickable),
clickable = emptyClickable
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun Timer() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun Timer(context: Context) = TilePreviewData {
TilePreviewHelper.singleTimelineEntryTileBuilder(
Timer.layout(
context,
context.deviceParams(),
it.deviceConfiguration,
timer1 = Timer.Timer(minutes = "05", clickable = emptyClickable),
timer2 = Timer.Timer(minutes = "10", clickable = emptyClickable),
timer3 = Timer.Timer(minutes = "15", clickable = emptyClickable),
timer4 = Timer.Timer(minutes = "20", clickable = emptyClickable),
timer5 = Timer.Timer(minutes = "30", clickable = emptyClickable),
clickable = emptyClickable
)
)
).build()
}

@WearSmallRoundDevicePreview
@WearLargeRoundDevicePreview
@Composable
fun Alarm() {
val context = LocalContext.current
LayoutRootPreview(
@Preview(device = WearDevices.SMALL_ROUND)
@Preview(device = WearDevices.LARGE_ROUND)
fun Alarm(context: Context) = TilePreviewData {
TilePreviewHelper.singleTimelineEntryTileBuilder(
Alarm.layout(
context,
context.deviceParams(),
it.deviceConfiguration,
timeUntilAlarm = "Less than 1 min",
alarmTime = "14:58",
alarmDays = "Mon, Tue, Wed",
clickable = emptyClickable
)
)
).build()
}

private fun Context.deviceParams() = buildDeviceParameters(resources)
Loading

0 comments on commit 30f7cdc

Please sign in to comment.