This file contains 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
//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 | |
} | |
} |
This file contains 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
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) |
This file contains 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
@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), |
This file contains 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 HomeAnalyticsInteractor( | |
private val analyticsSender: AnalyticsSender | |
) { | |
private var startTime: Long = 0 | |
fun startTracking() { | |
startTime = System.currentTimeMillis() | |
} | |
fun sendEvent() { |
This file contains 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 HomeViewModel( | |
private val analyticsInteractor: HomeAnalyticsInteractor | |
) : ViewModel() { | |
fun onFragmentCreated(){ | |
analyticsInteractor.startTracking() | |
} | |
fun sendData() { | |
analyticsInteractor.sendEvent() |
This file contains 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 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)) { |
This file contains 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 NotificationProperty( | |
state: Boolean | |
) : AnalyticsProperty(AnalyticsConstants.UserProperties.NOTIFICATION_STATE, state) |
This file contains 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 AnalyticsProperty( | |
val propertyName: String, | |
val parameter: Any, | |
val providers: List<AnalyticsProvider> = listOf( | |
AnalyticsProvider.ANALYTICS_FIREBASE, | |
AnalyticsProvider.ANALYTICS_AMPLITUDE | |
) | |
) |
This file contains 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 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()) |
This file contains 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 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 | |
) | |
) |