Skip to content

Instantly share code, notes, and snippets.

//Function which calculates the length of the clock hand
private fun calculateClockHandLength(maxHeight: Float, currentHour: Int): Float {
val stepHeight = maxHeight / 12
// Height decreases first 360 deg, then increases again
return stepHeight * if (currentHour < 12) {
12 - 1 - currentHour
} else {
currentHour - 12
}
}
var strokeWidth by remember { mutableStateOf(0f) }
Spacer(modifier = Modifier
.fillMaxSize()
// Set strokeWidth based on the size of the viewport
.onGloballyPositioned {
strokeWidth = (it.size.width / 24).toFloat()
}
.drawBehind {
val center = Offset(size.width / 2, size.height / 2)
@Composable
fun ClockAnimation(duration: Int) {
val infiniteTransition = rememberInfiniteTransition()
// Creates a child animation of float type as a part of the [InfiniteTransition].
val clockAnimation by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 720f,
animationSpec = infiniteRepeatable(
animation = tween(duration, easing = LinearEasing),
class HomeAnalyticsInteractor(
private val analyticsSender: AnalyticsSender
) {
private var startTime: Long = 0
fun startTracking() {
startTime = System.currentTimeMillis()
}
fun sendEvent() {
class HomeViewModel(
private val analyticsInteractor: HomeAnalyticsInteractor
) : ViewModel() {
fun onFragmentCreated(){
analyticsInteractor.startTracking()
}
fun sendData() {
analyticsInteractor.sendEvent()
class AnalyticsSender(
private val analyticsFirebase: AnalyticsFirebaseDummy,
private val analyticsAmplitude: AnalyticsAmplitudeDummy
) {
...
fun setUserProperty(property: AnalyticsProperty) {
if (property.providers.contains(AnalyticsProvider.ANALYTICS_FIREBASE)) {
analyticsFirebase.setUserProperty(property.propertyName, property.toString())
}
if (property.providers.contains(AnalyticsProvider.ANALYTICS_AMPLITUDE)) {
@Kpeved
Kpeved / gist:85242d3d0473bf8860a54a47a5cf53b8
Created May 18, 2020 15:27
NotificationPropertyPart1.kt
class NotificationProperty(
state: Boolean
) : AnalyticsProperty(AnalyticsConstants.UserProperties.NOTIFICATION_STATE, state)
abstract class AnalyticsProperty(
val propertyName: String,
val parameter: Any,
val providers: List<AnalyticsProvider> = listOf(
AnalyticsProvider.ANALYTICS_FIREBASE,
AnalyticsProvider.ANALYTICS_AMPLITUDE
)
)
class AnalyticsSender(
private val analyticsFirebase: AnalyticsFirebaseDummy,
private val analyticsAmplitude: AnalyticsAmplitudeDummy
) {
fun sendEvent(event: AnalyticsEvent) {
if (event.providers.contains(AnalyticsProvider.ANALYTICS_FIREBASE)) {
analyticsFirebase.logEvent(event.eventName, event.params.toBundle())
}
if (event.providers.contains(AnalyticsProvider.ANALYTICS_AMPLITUDE)) {
analyticsAmplitude.trackEvent(event.eventName, event.params.toJson())
class SendClicked(
timeBetweenClicks: Long
) : AnalyticsEvent(
AnalyticsConstants.Events.SendClicked.EVENT,
mapOf( // create a map of properties where key is taken from constants, and value from function properties
AnalyticsConstants.Events.SendClicked.Params.TIME_BETWEEN_CLICKS to timeBetweenClicks
)
)