Skip to content

Instantly share code, notes, and snippets.

@ziginsider
Created July 5, 2021 14:46
Show Gist options
  • Save ziginsider/3c848d6b49059906116a8b94e0af9b55 to your computer and use it in GitHub Desktop.
Save ziginsider/3c848d6b49059906116a8b94e0af9b55 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private var current = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.customViewOne.setPeriod(PERIOD)
binding.customViewTwo.setPeriod(PERIOD)
// Never use GlobalScope for real projects !!!
GlobalScope.launch {
while (current < PERIOD * REPEAT) {
current += INTERVAL
binding.customViewOne.setCurrent(current)
binding.customViewTwo.setCurrent(current)
delay(INTERVAL)
}
}
}
private companion object {
private const val INTERVAL = 100L
private const val PERIOD = 1000L * 30 // 30 sec
private const val REPEAT = 10 // 10 times
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment