Skip to content

Instantly share code, notes, and snippets.

View thesiamak's full-sized avatar

Siamak thesiamak

View GitHub Profile
class DisplayTimer (context: Context) : LinearLayout(context)
, LifecycleObserver {
private var timer:Timer? =null
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun igniteTimer(){
timer = Timer("ring the bell").apply{
schedule(object : TimerTask() {
override fun run() {
class MyFragment:Fragment(){
val displayTimer = DisplayTimer(requireContext())
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// assign the observability to timer view.
viewLifecycleOwner.lifecycle.addObserver(displayTimer)
}
class DisplayTimer (context: Context) : LinearLayout(context)
, LifecycleObserver { //LifecycleObserver is implemented here.
// Code removed for brevity
}
class DisplayTimer (context: Context) : LinearLayout(context) {
fun igniteTimer(){
Timer("ring the bell")
.schedule(object : TimerTask() {
override fun run() {
Tick()
}