feat(splash): add SplashActivity with 400ms delay
This commit is contained in:
parent
1f2fc8644f
commit
0edcc005bc
45
app/src/main/kotlin/plus/rua/project/SplashActivity.kt
Normal file
45
app/src/main/kotlin/plus/rua/project/SplashActivity.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package plus.rua.project
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import plus.rua.project.shared.R as CoreR
|
||||
import plus.rua.project.ui.SplashScreen
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
private const val SPLASH_DELAY_MS = 400L
|
||||
|
||||
/**
|
||||
* 启动页 Activity。
|
||||
*
|
||||
* 显示品牌启动图 400ms 后跳转到 [MainActivity],并 finish 自身。
|
||||
*/
|
||||
class SplashActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
SplashScreen(
|
||||
backgroundPainter = painterResource(CoreR.drawable.launch_bg),
|
||||
iconPainter = painterResource(R.mipmap.ic_launcher),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
delay(SPLASH_DELAY_MS)
|
||||
navigateToMain()
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToMain() {
|
||||
if (isFinishing) return
|
||||
startActivityWithSlide(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user