From 64972c3c881ceb9f5387a781b4f4d72c757cc69c Mon Sep 17 00:00:00 2001 From: squallzhjch <zhangjingchao@navinfo.com> Date: Fri, 6 Jan 2023 16:04:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AB=96=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../volvo/database/dao/GreetingMessageDao.kt | 2 +- .../java/com/navinfo/volvo/model/LoginUser.kt | 9 ++ .../volvo/ui/fragments/login/LoginFragment.kt | 26 ++-- .../ui/fragments/login/LoginViewModel.kt | 8 +- .../message/ObtainMessageFragment.kt | 11 +- app/src/main/res/layout/fragment_login.xml | 138 ++++++++++-------- .../main/res/navigation/mobile_navigation.xml | 13 +- 8 files changed, 116 insertions(+), 92 deletions(-) create mode 100644 app/src/main/java/com/navinfo/volvo/model/LoginUser.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e62f29e..d539e1e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,7 @@ android:name=".ui.message.MessageActivity" android:exported="false" android:label="@string/title_activity_second" + android:screenOrientation="portrait" android:theme="@style/Theme.NavinfoVolvo.NoActionBar"> <meta-data android:name="android.app.lib_name" diff --git a/app/src/main/java/com/navinfo/volvo/database/dao/GreetingMessageDao.kt b/app/src/main/java/com/navinfo/volvo/database/dao/GreetingMessageDao.kt index 981cea3..3da19ab 100644 --- a/app/src/main/java/com/navinfo/volvo/database/dao/GreetingMessageDao.kt +++ b/app/src/main/java/com/navinfo/volvo/database/dao/GreetingMessageDao.kt @@ -21,7 +21,7 @@ interface GreetingMessageDao { /** * 分页查询 */ - @Query("SELECT * FROM GreetingMessage") + @Query("SELECT * FROM GreetingMessage order by sendDate DESC") fun findAllByDataSource(): PagingSource<Int, GreetingMessage> /** diff --git a/app/src/main/java/com/navinfo/volvo/model/LoginUser.kt b/app/src/main/java/com/navinfo/volvo/model/LoginUser.kt new file mode 100644 index 0000000..1c55d05 --- /dev/null +++ b/app/src/main/java/com/navinfo/volvo/model/LoginUser.kt @@ -0,0 +1,9 @@ +package com.navinfo.volvo.model + +/** + * 登录用户信息 + */ +data class LoginUser( + var name: String, + var password: String +) \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginFragment.kt b/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginFragment.kt index a605eb0..e921ce5 100644 --- a/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginFragment.kt +++ b/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.databinding.DataBindingUtil import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.navinfo.volvo.R @@ -16,11 +17,8 @@ import dagger.hilt.android.AndroidEntryPoint class LoginFragment : BaseFragment() { // private var loginViewModel:LoginViewModel by viewModel(get()) - private var viewBinding: FragmentLoginBinding? = null + private lateinit var viewBinding: FragmentLoginBinding - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = viewBinding!! private val viewModel by viewModels<LoginViewModel> { viewModelFactoryProvider } @@ -29,19 +27,21 @@ class LoginFragment : BaseFragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View { - viewBinding = FragmentLoginBinding.inflate(inflater, container, false) - val root: View = binding.root - binding.loginFragmentRegisterButton.setOnClickListener { + viewBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_login, container, false) + viewBinding.lifecycleOwner = this + initView() + return viewBinding.root + } + + private fun initView() { + viewBinding.loginFragmentRegisterButton.setOnClickListener { + } - binding.loginFragmentLoginButton.setOnClickListener { + viewBinding.loginFragmentLoginButton.setOnClickListener { +// viewModel.login(viewBinding.loginFragmentUserLayout) findNavController().navigate(R.id.action_login_to_home) } - return root } - override fun onDestroyView() { - viewBinding = null - super.onDestroyView() - } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginViewModel.kt b/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginViewModel.kt index ef6d19a..8f47282 100644 --- a/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginViewModel.kt +++ b/app/src/main/java/com/navinfo/volvo/ui/fragments/login/LoginViewModel.kt @@ -6,14 +6,12 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.navinfo.volvo.database.AppDatabase import com.navinfo.volvo.database.entity.User +import com.navinfo.volvo.util.SharedPreferenceHelper import javax.inject.Inject -class LoginViewModel @Inject constructor(private val dataBase: AppDatabase) : ViewModel() { +class LoginViewModel @Inject constructor(private val sharedPreferenceHelper: SharedPreferenceHelper) : ViewModel() { - private val _user = MutableLiveData<User>().apply { - - } - val user: LiveData<User> = _user +// val user: LiveData<User> = _user fun liveDataOnclick(view: View) { diff --git a/app/src/main/java/com/navinfo/volvo/ui/fragments/message/ObtainMessageFragment.kt b/app/src/main/java/com/navinfo/volvo/ui/fragments/message/ObtainMessageFragment.kt index 90dfee1..dc94c35 100644 --- a/app/src/main/java/com/navinfo/volvo/ui/fragments/message/ObtainMessageFragment.kt +++ b/app/src/main/java/com/navinfo/volvo/ui/fragments/message/ObtainMessageFragment.kt @@ -2,7 +2,6 @@ package com.navinfo.volvo.ui.fragments.message import android.content.DialogInterface import android.graphics.Paint -import android.net.Uri import android.os.Bundle import android.text.TextUtils import android.view.LayoutInflater @@ -16,18 +15,13 @@ import android.widget.ArrayAdapter import android.widget.Toast import androidx.core.widget.addTextChangedListener import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.navigation.Navigation import androidx.navigation.fragment.findNavController -import com.bumptech.glide.Glide -import com.bumptech.glide.load.engine.DiskCacheStrategy import com.easytools.tools.DateUtils -import com.easytools.tools.DeviceUtils import com.easytools.tools.DisplayUtils import com.easytools.tools.FileIOUtils -import com.easytools.tools.FileUtils import com.easytools.tools.ResourceUtils import com.easytools.tools.ToastUtils import com.elvishew.xlog.XLog @@ -54,7 +48,6 @@ import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File import java.io.FileInputStream -import java.io.FileOutputStream import java.util.* @@ -177,7 +170,7 @@ class ObtainMessageFragment: Fragment() { obtainMessageViewModel.updateMessageAudio("") } - val sendToArray = mutableListOf<String>("绑定车辆1(LYVXFEFEXNL754427)") + val sendToArray = mutableListOf<String>("LYVXFEFEXNL754427") binding.edtSendTo.adapter = ArrayAdapter<String>(context!!, android.R.layout.simple_dropdown_item_1line, android.R.id.text1, sendToArray) binding.edtSendTo.onItemSelectedListener = object: OnItemSelectedListener { @@ -535,7 +528,7 @@ class ObtainMessageFragment: Fragment() { val confirmCallback = object: ObtainMessageViewModel.MyConfirmCallback { override fun onSucess() { - findNavController().navigate(R.id.navi) + findNavController().navigate(R.id.navigation_home) } } diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml index 6a7d09f..6829329 100644 --- a/app/src/main/res/layout/fragment_login.xml +++ b/app/src/main/res/layout/fragment_login.xml @@ -1,78 +1,90 @@ <?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<layout 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="com.navinfo.volvo.ui.fragments.login.LoginFragment"> + xmlns:tools="http://schemas.android.com/tools"> + <data> + <variable + name="loginUser" + type="com.navinfo.volvo.model.LoginUser" /> + </data> - <androidx.constraintlayout.utils.widget.ImageFilterView - android:id="@+id/login_fragment_logo" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:src="@mipmap/volvo_logo_small" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.2" - app:roundPercent="0.2" /> - - <com.google.android.material.textfield.TextInputLayout - android:id="@+id/login_fragment_user_layout" + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginLeft="20dp" - android:layout_marginRight="20dp" - android:scrollbarAlwaysDrawHorizontalTrack="true" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.4"> + android:layout_height="match_parent" + tools:context="com.navinfo.volvo.ui.fragments.login.LoginFragment"> - <com.google.android.material.textfield.TextInputEditText + + <androidx.constraintlayout.utils.widget.ImageFilterView + android:id="@+id/login_fragment_logo" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@mipmap/volvo_logo_small" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.2" + app:roundPercent="0.2" /> + + <com.google.android.material.textfield.TextInputLayout + android:id="@+id/login_fragment_user_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="用户名" /> - </com.google.android.material.textfield.TextInputLayout> + android:layout_marginLeft="20dp" + android:layout_marginRight="20dp" + android:scrollbarAlwaysDrawHorizontalTrack="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.4"> - <com.google.android.material.textfield.TextInputLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginLeft="20dp" - android:layout_marginRight="20dp" - app:layout_constraintTop_toBottomOf="@id/login_fragment_user_layout"> + <com.google.android.material.textfield.TextInputEditText + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@{loginUser.name}" + android:hint="请输入用户名" /> + </com.google.android.material.textfield.TextInputLayout> - <com.google.android.material.textfield.TextInputEditText + <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="密码" /> - </com.google.android.material.textfield.TextInputLayout> + android:layout_marginLeft="20dp" + android:layout_marginRight="20dp" + app:layout_constraintTop_toBottomOf="@id/login_fragment_user_layout"> - <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton - android:id="@+id/login_fragment_register_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:text="注册" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintHorizontal_chainStyle="spread" - app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintRight_toLeftOf="@id/login_fragment_login_button" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.7" /> + <com.google.android.material.textfield.TextInputEditText + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textPassword" + android:text="@{loginUser.password}" + android:hint="请输入密码" /> + </com.google.android.material.textfield.TextInputLayout> - <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton - android:id="@+id/login_fragment_login_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:text="登录" - app:layout_constraintBaseline_toBaselineOf="@id/login_fragment_register_button" - app:layout_constraintLeft_toRightOf="@id/login_fragment_register_button" - app:layout_constraintRight_toRightOf="parent" /> + <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton + android:id="@+id/login_fragment_register_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:text="注册" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintHorizontal_chainStyle="spread" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@id/login_fragment_login_button" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.7" /> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file + <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton + android:id="@+id/login_fragment_login_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:text="登录" + app:layout_constraintBaseline_toBaselineOf="@id/login_fragment_register_button" + app:layout_constraintLeft_toRightOf="@id/login_fragment_register_button" + app:layout_constraintRight_toRightOf="parent" /> + + </androidx.constraintlayout.widget.ConstraintLayout> +</layout> \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index cece6d9..83fe244 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -48,5 +48,16 @@ android:id="@+id/navigation_obtain_message" android:name="com.navinfo.volvo.ui.fragments.message.ObtainMessageFragment" android:label="问候编辑" - tools:layout="@layout/fragment_obtain_message" /> + tools:layout="@layout/fragment_obtain_message" > + <action + android:id="@+id/action_login_to_home" + app:destination="@id/navigation_home" + app:enterAnim="@anim/from_left" + app:exitAnim="@anim/to_right" + app:popEnterAnim="@anim/from_right" + app:popExitAnim="@anim/to_left" + app:popUpTo="@id/navigation_obtain_message" + app:popUpToInclusive="true" /> + </fragment> + </navigation> \ No newline at end of file