调整页面

This commit is contained in:
squallzhjch 2023-03-27 10:22:15 +08:00
parent 909db31556
commit 36dccede60
39 changed files with 616 additions and 186 deletions

123
.idea/codeStyles/Project.xml generated Normal file
View File

@ -0,0 +1,123 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -39,6 +39,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- 为Activity设置<nav-graph/>标签 -->
<nav-graph android:value="@navigation/mobile_navigation" />
</activity>
<meta-data

View File

@ -5,7 +5,9 @@ class Constant {
/**
* 服务器地址
*/
const val SERVER_ADDRESS = "http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/"
// const val SERVER_ADDRESS = "http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/"
const val SERVER_ADDRESS = "http://54.223.225.147:8088/"
const val DEBUG = true
const val message_status_late = "预约,待发送"

View File

@ -6,7 +6,10 @@ import retrofit2.converter.gson.GsonConverterFactory
class NavinfoVolvoCall {
companion object {
private val service by lazy {
Retrofit.Builder().baseUrl("http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/")
// val baseUrl = "http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/"
val baseUrl = "http://54.223.225.147:8088/"
Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(NavinfoVolvoService::class.java)

View File

@ -37,8 +37,10 @@ class PreferencesRepositoryImp @Inject constructor(
}
}
override suspend fun getString(key: String): Flow<String?> = context.datastore.data.map {
it[stringPreferencesKey(key)]
override suspend fun getString(key: String): Flow<String?> {
return context.datastore.data.map {
it[stringPreferencesKey(key)]
}
}
override suspend fun saveInt(key: String, content: Int) {
@ -47,11 +49,14 @@ class PreferencesRepositoryImp @Inject constructor(
}
}
override suspend fun getInt(key: String): Flow<Int?> = context.datastore.data.map {
it[intPreferencesKey(key)]
}
override fun loginUser(): Flow<LoginUser?> {
return loginUser.data
val f = loginUser.data
Log.e("jingo", "获取用户信息总接口 ${f.hashCode()}")
return f
}
}

View File

@ -2,20 +2,16 @@ package com.navinfo.volvo.ui
import android.content.DialogInterface
import android.os.Bundle
import android.view.Gravity
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavOptions
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.transition.Slide
import androidx.transition.Transition
import androidx.transition.TransitionManager
import com.easytools.tools.FileUtils
import com.elvishew.xlog.BuildConfig
import com.elvishew.xlog.LogConfiguration
@ -45,14 +41,12 @@ class MainActivity : BaseActivity() {
private lateinit var binding: ActivityMainBinding
private val viewModel by viewModels<MainActivityViewModel>()
private var curId: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
initView()
XXPermissions.with(this)
// 申请单个权限
.permission(Permission.WRITE_EXTERNAL_STORAGE)
@ -83,25 +77,32 @@ class MainActivity : BaseActivity() {
} else {
onSDCardDenied()
showRationaleForSDCard(permissions)
setupNavigation()
}
}
})
}
private fun initView() {
// supportActionBar.setDefaultDisplayHomeAsUpEnabled()
}
/**
* 设置底部导航栏
*/
private fun setupNavigation() {
val navView: BottomNavigationView = binding.navView
val newMessageView = binding.newMessageFab
val navController = findNavController(R.id.nav_host_fragment_activity_main)
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications,
R.id.navigation_setting,
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
// val appBarConfiguration = AppBarConfiguration(
// setOf(
// R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications,
// R.id.navigation_setting,
// )
// )
// setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.getUnreadCount().collect {
@ -114,44 +115,88 @@ class MainActivity : BaseActivity() {
}
}
}
navView.setOnItemSelectedListener {
if (it.itemId != curId) {
val options = NavOptions.Builder().setPopUpTo(
curId,
inclusive = true,
saveState = true
).build()
navController.navigate(it.itemId, null, options)
// when (it.itemId) {
// R.id.navigation_home -> {
//
// }
// R.id.navigation_dashboard -> {
// navController.navigate(it.itemId)
// }
// R.id.navigation_setting -> {
// navController.navigate(it.itemId)
// }
// R.id.navigation_notifications -> {
// navController.navigate(it.itemId)
// }
// }
}
true
}
navView.setOnItemReselectedListener {
when (it.itemId) {
R.id.navigation_home -> Log.e("jingo", "我是 Reselected navigation_home")
R.id.navigation_dashboard -> Log.e("jingo", "我是 Reselected navigation_dashboard")
R.id.navigation_setting -> Log.e("jingo", "我是 Reselected navigation_setting")
R.id.navigation_notifications -> Log.e(
"jingo",
"我是 Reselected navigation_notifications"
)
}
true
}
navController.addOnDestinationChangedListener { _, destination, _ ->
if (supportActionBar != null) {
if (destination.id == R.id.navigation_login) {
supportActionBar!!.hide()
} else if (!supportActionBar!!.isShowing) {
supportActionBar!!.show()
}
}
if (destination.id == R.id.navigation_home || destination.id == R.id.navigation_dashboard || destination.id == R.id.navigation_notifications) {
runOnUiThread {
val transition: Transition = Slide(Gravity.BOTTOM)
transition.duration = 500;
TransitionManager.beginDelayedTransition(binding.root, transition);
// if (supportActionBar != null) {
// if (destination.id == R.id.navigation_login || destination.id == R.id.navigation_splash) {
// supportActionBar!!.hide()
// } else if (!supportActionBar!!.isShowing) {
// supportActionBar!!.show()
// }
// }
curId = destination.id
if (destination.id == R.id.navigation_home
|| destination.id == R.id.navigation_dashboard
|| destination.id == R.id.navigation_notifications
|| destination.id == R.id.navigation_setting
) {
if (navView.visibility != View.VISIBLE) {
// runOnUiThread {
// val transition: Transition = Slide(Gravity.BOTTOM)
// transition.duration = 500;
// TransitionManager.beginDelayedTransition(binding.root, transition);
navView.visibility = View.VISIBLE
newMessageView.visibility = View.VISIBLE
// }
}
} else {
runOnUiThread {
val transition: Transition = Slide(Gravity.BOTTOM)
transition.duration = 500;
TransitionManager.beginDelayedTransition(binding.root, transition);
if (navView.visibility != View.GONE) {
// runOnUiThread {
// val transition: Transition = Slide(Gravity.BOTTOM)
// transition.duration = 500;
// TransitionManager.beginDelayedTransition(binding.root, transition);
navView.visibility = View.GONE
newMessageView.visibility = View.GONE
// }
}
}
}
binding.newMessageFab.setOnClickListener {
// val intent: Intent = Intent(this@MainActivity, MessageActivity::class.java)
// startActivity(intent)
navController.navigate(R.id.navigation_obtain_message)
}
}
override fun onSupportNavigateUp() =
findNavController(R.id.nav_host_fragment_activity_main).navigateUp()
// override fun onSupportNavigateUp() =
// findNavController(R.id.nav_host_fragment_activity_main).navigateUp()
// @NeedsPermission(Manifest.permission.MANAGE_EXTERNAL_STORAGE)
fun createRootFolder() {

View File

@ -1,10 +1,29 @@
package com.navinfo.volvo.ui.fragments
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import javax.inject.Inject
abstract class BaseFragment : Fragment() {
// @Inject
abstract class BaseFragment : Fragment(){//}, Animation.AnimationListener {
// @Inject
// lateinit var viewModelFactoryProvider: ViewModelProvider.Factory
// override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation {
// val anima = AnimationUtils.loadAnimation(requireActivity(), nextAnim)
// anima.setAnimationListener(this)
// return anima
// }
//
// override fun onAnimationRepeat(animation: Animation?) {
//
// }
//
// override fun onAnimationEnd(animation: Animation?) {
//
// }
//
// override fun onAnimationStart(animation: Animation?) {
//
// }
}

View File

@ -8,8 +8,9 @@ import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.navinfo.volvo.databinding.FragmentDashboardBinding
import com.navinfo.volvo.ui.fragments.BaseFragment
class DashboardFragment : Fragment() {
class DashboardFragment : BaseFragment() {
private var _binding: FragmentDashboardBinding? = null

View File

@ -42,15 +42,17 @@ class HomeFragment : BaseFragment(), OnItemClickListener, OnItemMenuClickListene
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
_binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
// _binding = FragmentHomeBinding.inflate(inflater, container, false)
val root: View = _binding.root
_binding.lifecycleOwner = this
headView = HomeAdapterNotingBinding.inflate(inflater, container, false)
initView()
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
}
private fun initView() {
//创建菜单选项
//注意:使用滑动菜单不能开启滑动删除,否则只有滑动删除没有滑动菜单

View File

@ -42,18 +42,19 @@ class HomeViewModel @Inject constructor(
var userName: String = ""
init {
Log.e("jingo","当前的homeviewmodel 是 ${hashCode()}")
Log.e("jingo", "当前的homeviewmodel 是 ${hashCode()}")
viewModelScope.launch {
shard.loginUser().collectLatest {
userName = it!!.username
Log.e("jingo","用户赋值结束 是 ${userName.hashCode()}")
if (it != null) {
userName = it.username
}
Log.e("jingo", "用户赋值结束 是 ${it.hashCode()}")
}
}
}
suspend fun getNetMessageList(): Flow<PagingData<GreetingMessage>> {
Log.e("jingo","用户赋值了吗? $userName ${userName.hashCode()}")
Log.e("jingo", "用户赋值了吗? $userName ${hashCode()}")
val messagePost = NetworkMessageListPost(who = userName)
return netRepository.getMessagePaging(context = application, messagePost)

View File

@ -8,7 +8,6 @@ import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
@ -16,7 +15,6 @@ import com.navinfo.volvo.R
import com.navinfo.volvo.databinding.FragmentLoginBinding
import com.navinfo.volvo.ui.fragments.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
@ -34,24 +32,31 @@ class LoginFragment : BaseFragment() {
viewBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_login, container, false)
viewBinding.lifecycleOwner = this
initView()
return viewBinding.root
}
private fun initView() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
}
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.user.collect {
if (it != null) {
viewBinding.loginUser = it
}
}
}
}
private fun initView() {
// //获取用户信息,设置到用户登录框中
// lifecycleScope.launch {
// repeatOnLifecycle(Lifecycle.State.STARTED) {
// viewModel.userFlow.collect {
// if (it != null) {
// viewBinding.loginUser = it
// }
// }
// }
// }
viewBinding.loginUser = viewModel.loginUser
//注册按钮点击
viewBinding.loginFragmentRegisterButton.setOnClickListener {
}
//登录按钮点击
viewBinding.loginFragmentLoginButton.setOnClickListener {
if (viewBinding.loginUsername.text!!.isEmpty()) {
Toast.makeText(context, "请输入用户名", Toast.LENGTH_SHORT).show()
@ -61,8 +66,8 @@ class LoginFragment : BaseFragment() {
Toast.makeText(context, "请输入密码", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
lifecycleScope.launch{
repeatOnLifecycle(Lifecycle.State.STARTED){
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.onClickLogin(
viewBinding.loginUsername.text.toString(),
viewBinding.loginPassword.text.toString()

View File

@ -1,22 +1,30 @@
package com.navinfo.volvo.ui.fragments.login
import androidx.lifecycle.MutableLiveData
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.volvo.model.proto.LoginUser
import com.navinfo.volvo.repository.preferences.PreferencesRepository
import com.navinfo.volvo.util.asLiveData
//import com.navinfo.volvo.repository.preferences.PreferencesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class LoginViewModel @Inject constructor(private val repository: PreferencesRepository) :
ViewModel() {
var loginUser: LoginUser? = null
init {
Log.e("jingo", "LoginViewModel 是 ${hashCode()}")
viewModelScope.launch {
repository.loginUser().collectLatest {
Log.e("jingo", "用户赋值结束 是 ${it.hashCode()}")
loginUser = it
}
}
}
val user = repository.loginUser()
suspend fun onClickLogin(name: String, password: String) {
repository.saveLoginUser(id = "", name = name, password = password)

View File

@ -46,6 +46,7 @@ import com.navinfo.volvo.database.entity.GreetingMessage
import com.navinfo.volvo.databinding.FragmentObtainMessageBinding
import com.navinfo.volvo.http.DownloadCallback
import com.navinfo.volvo.model.VolvoModel
import com.navinfo.volvo.ui.fragments.BaseFragment
import com.navinfo.volvo.ui.markRequiredInRed
import com.navinfo.volvo.util.PhotoLoader
import com.navinfo.volvo.utils.EasyMediaFile
@ -64,7 +65,7 @@ import kotlin.streams.toList
@AndroidEntryPoint
class ObtainMessageFragment : Fragment() {
class ObtainMessageFragment : BaseFragment() {
private var _binding: FragmentObtainMessageBinding? = null
private val obtainMessageViewModel by viewModels<ObtainMessageViewModel>()
private val photoHelper by lazy {

View File

@ -37,7 +37,7 @@ class ObtainMessageViewModel @Inject constructor(
viewModelScope.launch {
pre.loginUser().collectLatest {
username = it!!.username
Log.e("jingo", "用户赋值结束 是 ${username.hashCode()}")
Log.e("jingo", "用户赋值结束 是 ${it.hashCode()}")
}
}
}

View File

@ -8,8 +8,9 @@ import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.navinfo.volvo.databinding.FragmentNotificationsBinding
import com.navinfo.volvo.ui.fragments.BaseFragment
class NotificationsFragment : Fragment() {
class NotificationsFragment : BaseFragment() {
private var _binding: FragmentNotificationsBinding? = null

View File

@ -6,11 +6,15 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import com.navinfo.volvo.R
import com.navinfo.volvo.databinding.FragmentSettingBinding
import com.navinfo.volvo.ui.fragments.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
@AndroidEntryPoint
class SettingFragment : BaseFragment() {
@ -25,14 +29,23 @@ class SettingFragment : BaseFragment() {
): View {
viewBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_setting, container, false)
viewBinding.lifecycleOwner = this
initView()
return viewBinding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
}
private fun initView() {
//退出登录
viewBinding.loginFragmentLoginButton.setOnClickListener {
findNavController().navigate(R.id.action_setting_to_login)
lifecycleScope.launch{
repeatOnLifecycle(Lifecycle.State.STARTED){
viewModel.clearUser()
findNavController().navigate(R.id.action_setting_to_login)
}
}
}
}
}

View File

@ -1,8 +1,19 @@
package com.navinfo.volvo.ui.fragments.setting
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.volvo.repository.preferences.PreferencesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject
class SettingModel @Inject constructor() : ViewModel() {
@HiltViewModel
class SettingModel @Inject constructor(private val pre: PreferencesRepository) : ViewModel() {
suspend fun clearUser() {
Log.e("jingo", "SettingModel clearUser")
pre.saveLoginUser("", "", "")
}
}

View File

@ -0,0 +1,144 @@
package com.navinfo.volvo.ui.fragments.splash
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.Html
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import com.navinfo.volvo.R
import com.navinfo.volvo.databinding.FragmentSplashBinding
import com.navinfo.volvo.ui.fragments.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.launch
@AndroidEntryPoint
class SplashFragment : BaseFragment() {
private val viewModel by viewModels<SplashViewModel>()
private lateinit var viewBinding: FragmentSplashBinding
// 位置的协程监听器
private var timeDownJob: Job? = null
override fun onStart() {
Log.e("jingo", "onStart")
super.onStart()
}
override fun onCreate(savedInstanceState: Bundle?) {
Log.e("jingo", "onStart")
super.onCreate(savedInstanceState)
}
override fun onPause() {
Log.e("jingo", "onPause")
super.onPause()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Log.e("jingo", "onViewCreated")
super.onViewCreated(view, savedInstanceState)
initView()
}
override fun onAttach(context: Context) {
Log.e("jingo", "onAttach")
super.onAttach(context)
}
override fun onStop() {
Log.e("jingo", "onStop")
super.onStop()
timeDownJob?.apply {
this.cancel()
}
}
override fun onResume() {
Log.e("jingo", "onResume")
super.onResume()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
Log.e("jingo", "onCreateView")
viewBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_splash, container, false)
viewBinding.lifecycleOwner = this
return viewBinding.root
}
private fun initView() {
//倒计时文字按钮
viewBinding.timeDown.setOnClickListener {
navigate()
}
viewBinding.splashGoWeb.setOnClickListener {
//实现跳转网页的主要代码
val intent = Intent();
intent.action = "android.intent.action.VIEW";
val contentUrl = Uri.parse("https://www.volvocars.com.cn/zh-cn");
intent.data = contentUrl;
startActivity(intent);
}
// 由于 repeatOnLifecycle 是一个挂起函数,
// 因此从 lifecycleScope 中创建新的协程
timeDownJob = lifecycleScope.launch {
// 直到 lifecycle 进入 DESTROYED 状态前都将当前协程挂起。
// repeatOnLifecycle 每当生命周期处于 STARTED 或以后的状态时会在新的协程中
// 启动执行代码块,并在生命周期进入 STOPPED 时取消协程。
repeatOnLifecycle(Lifecycle.State.STARTED) {
// 当生命周期处于 STARTED 时安全地从 locations 中获取数据
// 当生命周期进入 STOPPED 时停止收集数据
viewModel.countDown().collect {
Log.e("jingo", "collect $it")
if (it == 0) {
navigate()
} else {
viewBinding.timeDown.text = "跳过:${it}"
}
}
// 注意:运行到此处时,生命周期已经处于 DESTROYED 状态!
}
}
}
private fun navigate() {
if (viewModel.userName == "") {
findNavController().navigate(R.id.action_splash_to_login)
} else {
findNavController().navigate(R.id.action_splash_to_home)
}
}
override fun onDestroy() {
Log.e("jingo", "onDestroy")
super.onDestroy()
}
override fun onDetach() {
Log.e("jingo", "onDetach")
super.onDetach()
}
override fun onDestroyView() {
Log.e("jingo", "onDestroyView")
super.onDestroyView()
}
}

View File

@ -0,0 +1,54 @@
package com.navinfo.volvo.ui.fragments.splash
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.volvo.repository.preferences.PreferencesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class SplashViewModel @Inject constructor(private val pre: PreferencesRepository) : ViewModel() {
var userName: String = ""
init {
Log.e("jingo", "SplashViewModel init ${hashCode()}")
viewModelScope.launch {
pre.loginUser().collectLatest {
if (it != null) {
Log.e("jingo", "SplashViewModel 获取用户${it.username}")
userName = it.username
}
}
}
}
suspend fun countDown(): Flow<Int> {
Log.e("jingo", "viewModel countDown ${hashCode()}")
var time = 3
// 在这个范围内启动的协程会在Lifecycle被销毁的时候自动取消
return flow<Int> {
(time downTo 0).forEach() {
emit(it)
delay(1000)
}
}
// .onStart {
// // 倒计时开始 在这里可以让Button 禁止点击状态
// }.onCompletion {
// // 倒计时结束 在这里可以让Button 恢复点击状态
// }.catch {
// //错误
// }
}
override fun onCleared() {
Log.e("jingo", "viewModel onCleared ${hashCode()}")
super.onCleared()
}
}

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
</vector>

View File

@ -1,5 +0,0 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View File

@ -1,5 +0,0 @@
<vector android:height="8dp" android:tint="#FF0202"
android:viewportHeight="24" android:viewportWidth="24"
android:width="8dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM5,9v6h4l5,5V4L9,9H5z"/>
</vector>

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M7,9v6h4l5,5V4l-5,5H7z"/>
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--设置圆角-->
<!-- 按顺序分别对应:左下角的角度、右下角的角度、左上角的角度、右上角的角度-->
<corners android:radius="4dp" />
<!-- <solid android:color="@color/white" />-->
<stroke
android:width="1dp"
android:color="@color/white" />
</shape>

View File

@ -6,13 +6,13 @@
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:visibility="gone"
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
android:visibility="gone"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
@ -32,12 +32,12 @@
app:navGraph="@navigation/mobile_navigation" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:visibility="gone"
android:id="@+id/new_message_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:src="@drawable/ic_add_24dp"
android:visibility="gone"
app:elevation="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFragment">
<TextView
android:id="@+id/textview_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_first_fragment"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_first" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">
<TextView
android:id="@+id/textview_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_second"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_second" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/volvo_s90">
<TextView
android:id="@+id/time_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textColor="@color/white"
android:autoLink="all"
android:textSize="16sp"
android:layout_marginRight="30dp"
android:layout_marginTop="40dp"
android:text="跳过:"/>
<TextView
android:id="@+id/splash_go_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_white_frame"
android:gravity="center"
android:paddingLeft="40dp"
android:paddingTop="10dp"
android:paddingRight="40dp"
android:paddingBottom="10dp"
android:text="进入官网"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 KiB

View File

@ -3,7 +3,26 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_login">
app:startDestination="@id/navigation_splash">
<fragment
android:id="@+id/navigation_splash"
android:name="com.navinfo.volvo.ui.fragments.splash.SplashFragment"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splash_to_login"
app:destination="@id/navigation_login"
app:popUpTo="@id/navigation_splash"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_splash_to_home"
app:destination="@id/navigation_home"
app:popUpTo="@id/navigation_splash"
app:popUpToInclusive="true" />
<!-- <deepLink-->
<!-- android:id="@+id/deepLink_volvo_web"-->
<!-- app:uri="https://www.volvocars.com.cn/zh-cn" />-->
</fragment>
<fragment
android:id="@+id/navigation_login"
@ -47,19 +66,17 @@
android:id="@+id/navigation_obtain_message"
android:name="com.navinfo.volvo.ui.fragments.message.ObtainMessageFragment"
android:label="问候编辑"
tools:layout="@layout/fragment_setting"></fragment>
tools:layout="@layout/fragment_obtain_message"></fragment>
<fragment
android:id="@+id/navigation_setting"
android:name="com.navinfo.volvo.ui.fragments.setting.SettingFragment"
android:label="@string/setting"
tools:layout="@layout/fragment_obtain_message">
tools:layout="@layout/fragment_setting">
<action
android:id="@+id/action_setting_to_login"
app:destination="@id/navigation_login"
app:popUpTo="@id/navigation_setting"
app:popUpToInclusive="true"/>
app:popUpTo="@id/navigation_home"
app:popUpToInclusive="true" />
</fragment>
</navigation>

View File

@ -1,3 +1,2 @@
<resources>
<dimen name="fab_margin">48dp</dimen>
</resources>

View File

@ -1,3 +1,2 @@
<resources>
<dimen name="fab_margin">200dp</dimen>
</resources>

View File

@ -1,3 +1,2 @@
<resources>
<dimen name="fab_margin">48dp</dimen>
</resources>

View File

@ -9,7 +9,6 @@
<color name="white">#FFFFFFFF</color>
<color name="red">#FA5151</color>
<color name="gray">#5E5E5E</color>
<color name="gray1">#D2CACA</color>
<color name="blue">#1285EC</color>
<color name="yellow">#F99C3E</color>
</resources>

View File

@ -1,9 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="activity_default_padding">12dp</dimen>
<dimen name="default_font_size">18sp</dimen>
<dimen name="default_widget_padding">6dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NavinfoVolvo" parent="Theme.Material3.Light">
<style name="Theme.NavinfoVolvo" parent="Theme.Material3.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>

View File

@ -22,8 +22,8 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.enableJetifier=true
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=10080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=10080
org.gradle.configureondemand=true
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080
org.gradle.configureondemand=true