- Slices official docs g.co/slices
- App Actions docs g.co/appactions
- Slice I/O 18 talk https://www.youtube.com/watch?v=a7IVH5aNwwc
- FitActions Sample https://github.com/actions-on-google/appactions-fitness-kotlin
Created
July 6, 2019 16:43
-
-
Save marcelpinto/a1c533e843718f59de0c507cc39c14c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseSlice(val context: Context, val sliceUri: Uri) { | |
/** | |
* @return the slice implementation to be used by SliceProvider | |
*/ | |
abstract fun buildSlice(): Slice | |
/** | |
* Call refresh to notify the SliceProvider to load again. | |
*/ | |
protected fun refresh() { | |
context.contentResolver.notifyChange(sliceUri, null) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseSlicesProvider : SliceProvider() { | |
private val lastSlices = mutableMapOf<Uri, BaseSlice>() | |
override fun onBindSlice(sliceUri: Uri): Slice { | |
val slice = lastSlices.getOrPut(sliceUri) { | |
createNewSlice(sliceUri) | |
} | |
return slice.buildSlice() | |
} | |
override fun onCreateSliceProvider(): Boolean { | |
// Initialise your code | |
return true | |
} | |
open fun createNewSlice(sliceUri: Uri): BaseSlice | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createOrderSlice(data: Any): Slice { | |
return list(context = context, uri = sliceUri, ttl = ListBuilder.INFINITY) { | |
header { | |
title = "Your Order" | |
subtitle = "Status: ${data.order.status.name}" | |
primaryAction = createSliceAction { | |
appendPath(DeepLink.AwesomeSlices.PATH) | |
appendPath(DeepLink.AwesomeSlices.SHOW_ORDER) | |
} | |
} | |
data.items.forEach { item -> | |
row { | |
title = getItemTitle(data, item) | |
subtitle = "${item.price}$" | |
} | |
} | |
range { | |
title = "Estimated arrival" | |
subtitle = getEta(data) | |
value = getStep(data) | |
max = MAX_STEPS | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment