This repository has been archived on 2020-11-15. You can view files and clone it, but cannot push or open issues or pull requests.
hashTagItNow/app/src/main/java/com/eleith/hashtagit/SplashFragment.kt

43 lines
1.2 KiB
Kotlin

package com.eleith.hashtagit
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import kotlinx.coroutines.*
class SplashFragment: Fragment() {
private val job = Job()
private val uiScope = CoroutineScope(Dispatchers.Main + job)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_splash, container, false)
}
override fun onStart() {
super.onStart()
(activity as? HashTagItActivity)?.showToolbar(false)
uiScope.launch {
withContext(Dispatchers.IO) {
delay(2000)
findNavController().navigate(SplashFragmentDirections.actionSplashFragmentToInputFragment())
}
}
}
override fun onStop() {
super.onStop()
(activity as? HashTagItActivity)?.showToolbar(true)
}
override fun onPause() {
super.onPause()
// make sure if user leaves screen to early before delay, we have killed the couroutine
job.cancel()
}
}