|
|
|
package com.yinuo.safetywatcher
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import com.yinuo.safetywatcher.navi.NavigationUtil
|
|
|
|
import com.yinuo.safetywatcher.navi.NavigationView
|
|
|
|
import com.yinuo.safetywatcher.ui.SplashView
|
|
|
|
import com.yinuo.safetywatcher.ui.theme.EasypusherTheme
|
|
|
|
import org.easydarwin.push.MediaStream
|
|
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
|
var exitTime = 0L
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
startMediaService()
|
|
|
|
setContent {
|
|
|
|
EasypusherTheme {
|
|
|
|
// A surface container using the 'background' color from the theme
|
|
|
|
Surface(
|
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
|
color = MaterialTheme.colorScheme.background
|
|
|
|
) {
|
|
|
|
val viewModel: MainViewModel = viewModel()
|
|
|
|
if (viewModel.isSplash) {
|
|
|
|
SplashView { viewModel.isSplash = false }
|
|
|
|
} else {
|
|
|
|
NavigationUtil.navHostController = rememberNavController()
|
|
|
|
NavigationView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addBackListener()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun startMediaService() {
|
|
|
|
// 启动服务...
|
|
|
|
val intent = Intent(this, MediaStream::class.java)
|
|
|
|
startService(intent)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun addBackListener() {
|
|
|
|
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
//是主页
|
|
|
|
if (System.currentTimeMillis() - exitTime > 2000) {
|
|
|
|
Toast.makeText(this@MainActivity, "再点一次退出!", Toast.LENGTH_SHORT)
|
|
|
|
.show()
|
|
|
|
exitTime = System.currentTimeMillis()
|
|
|
|
} else {
|
|
|
|
finish()
|
|
|
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|