Merge branch 'master' of gitlab.navinfo.com:vivo/navinfovivo
Conflicts: app/src/main/java/com/navinfo/volvo/MainActivity.kt app/src/main/res/menu/bottom_nav_menu.xml app/src/main/res/navigation/mobile_navigation.xml
This commit is contained in:
@@ -29,9 +29,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// menu should be considered as top level destinations.
|
||||
val appBarConfiguration = AppBarConfiguration(
|
||||
setOf(
|
||||
R.id.navigation_home,
|
||||
R.id.navigation_dashboard,
|
||||
R.id.navigation_notifications
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications, R.id.navigation_obtain_message
|
||||
)
|
||||
)
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.room.RoomDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper;
|
||||
|
||||
import com.navinfo.volvo.db.dao.entity.Message;
|
||||
import com.navinfo.volvo.db.dao.entity.Attachment;
|
||||
import com.navinfo.volvo.db.dao.entity.Message;
|
||||
import com.navinfo.volvo.db.dao.entity.User;
|
||||
|
||||
@@ -9,9 +9,15 @@ import com.navinfo.volvo.tools.GsonUtil
|
||||
@Entity(tableName = "Attachment")
|
||||
data class Attachment(
|
||||
@PrimaryKey()
|
||||
var id: String
|
||||
var id: String,
|
||||
var pathUrl: String,
|
||||
var attachmentType: AttachmentType
|
||||
)
|
||||
|
||||
enum class AttachmentType {
|
||||
PIC, AUDIO
|
||||
}
|
||||
|
||||
class AttachmentConverters() {
|
||||
@TypeConverter
|
||||
fun stringToAttachment(value: String): Attachment {
|
||||
|
||||
@@ -43,4 +43,4 @@ data class Message @JvmOverloads constructor(
|
||||
* 附件列表
|
||||
*/
|
||||
var attachment: MutableList<Attachment> = mutableListOf()
|
||||
)
|
||||
)
|
||||
|
||||
13
app/src/main/java/com/navinfo/volvo/ui/ViewExtend.kt
Normal file
13
app/src/main/java/com/navinfo/volvo/ui/ViewExtend.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.navinfo.volvo.ui
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.text.color
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
|
||||
fun TextInputLayout.markRequiredInRed() {
|
||||
hint = buildSpannedString {
|
||||
append(hint)// Mind the space prefix.
|
||||
color(Color.RED) { append(" *") }
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.databinding.FragmentHomeBinding
|
||||
import com.navinfo.volvo.tools.DisplayUtil
|
||||
import com.navinfo.volvo.ui.adapter.MessageAdapter
|
||||
import com.navinfo.volvo.ui.message.ObtainMessageViewModel
|
||||
import com.yanzhenjie.recyclerview.*
|
||||
import com.yanzhenjie.recyclerview.SwipeRecyclerView.LoadMoreListener
|
||||
|
||||
@@ -32,10 +33,21 @@ class HomeFragment : Fragment(), OnItemClickListener, OnItemMenuClickListener {
|
||||
): View {
|
||||
val homeViewModel =
|
||||
ViewModelProvider(this).get(HomeViewModel::class.java)
|
||||
val obtainMessageViewModel = ViewModelProvider(requireActivity()).get(ObtainMessageViewModel::class.java)
|
||||
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
// val textView: TextView = binding.tvNewMessage
|
||||
// textView.setOnClickListener {
|
||||
// val message = Message(1, "新建标题", "", "", "", 0, "1", "2", mutableListOf())
|
||||
// obtainMessageViewModel.setCurrentMessage(message)
|
||||
// // 跳转到新建Message的Fragment
|
||||
// Navigation.findNavController(it).navigate(R.id.home_2_obtain_message)
|
||||
// }
|
||||
// homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
//
|
||||
// }
|
||||
val recyclerview: SwipeRecyclerView = binding.homeMessageRecyclerview
|
||||
recyclerview.adapter = null //先设置null,否则会报错
|
||||
//创建菜单选项
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.navinfo.volvo.ui.message
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.gredicer.datetimepicker.DateTimePickerFragment
|
||||
import com.navinfo.volvo.databinding.FragmentObtainMessageBinding
|
||||
import com.navinfo.volvo.ui.markRequiredInRed
|
||||
|
||||
class ObtainMessageFragment: Fragment() {
|
||||
private var _binding: FragmentObtainMessageBinding? = null
|
||||
private val obtainMessageViewModel by lazy {
|
||||
ViewModelProvider(requireActivity()).get(ObtainMessageViewModel::class.java)
|
||||
}
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentObtainMessageBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
obtainMessageViewModel?.getMessageLiveData()?.observe(
|
||||
viewLifecycleOwner, Observer {
|
||||
// 初始化界面显示内容
|
||||
if(it.title!=null)
|
||||
binding.tvMessageTitle?.setText(it.title)
|
||||
if (it.sendDate!=null) {
|
||||
binding.btnSendTime.setText(it.sendDate)
|
||||
}
|
||||
}
|
||||
)
|
||||
initView()
|
||||
return root
|
||||
}
|
||||
|
||||
fun initView() {
|
||||
// 设置问候信息提示的红色星号
|
||||
binding.tiLayoutTitle.markRequiredInRed()
|
||||
// 设置点击按钮选择发送时间
|
||||
binding.btnSendTime.setOnClickListener {
|
||||
val dialog = DateTimePickerFragment.newInstance().mode(0)
|
||||
dialog.listener = object : DateTimePickerFragment.OnClickListener {
|
||||
override fun onClickListener(selectTime: String) {
|
||||
obtainMessageViewModel.updateMessageSendTime(selectTime)
|
||||
}
|
||||
|
||||
}
|
||||
dialog.show(parentFragmentManager, "SelectSendTime")
|
||||
}
|
||||
|
||||
// 点击按钮选择拍照
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.navinfo.volvo.ui.message
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.db.dao.entity.AttachmentType
|
||||
|
||||
class ObtainMessageViewModel: ViewModel() {
|
||||
private val msgLiveData: MutableLiveData<Message> by lazy {
|
||||
MutableLiveData<Message>()
|
||||
}
|
||||
|
||||
fun setCurrentMessage(msg: Message) {
|
||||
msgLiveData.postValue(msg)
|
||||
}
|
||||
|
||||
fun getMessageLiveData(): MutableLiveData<Message> {
|
||||
return msgLiveData
|
||||
}
|
||||
|
||||
// 更新消息标题
|
||||
fun updateMessageTitle(title: String) {
|
||||
this.msgLiveData.value?.title = title
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新消息附件中的照片文件
|
||||
fun updateMessagePic(picUrl: String) {
|
||||
for (attachment in this.msgLiveData.value!!.attachment) {
|
||||
if (attachment.attachmentType == AttachmentType.PIC) {
|
||||
attachment.pathUrl = picUrl
|
||||
}
|
||||
}
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新消息附件中的录音文件
|
||||
fun updateMessageAudio(audioUrl: String) {
|
||||
for (attachment in this.msgLiveData.value!!.attachment) {
|
||||
if (attachment.attachmentType == AttachmentType.AUDIO) {
|
||||
attachment.pathUrl = audioUrl
|
||||
}
|
||||
}
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新发送人
|
||||
fun updateMessageSendFrom(sendFrom: String) {
|
||||
this.msgLiveData.value?.fromId = sendFrom
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新接收人
|
||||
fun updateMessageSendTo(sendTo: String) {
|
||||
this.msgLiveData.value?.toId = sendTo
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新发件时间
|
||||
fun updateMessageSendTime(sendTime: String) {
|
||||
this.msgLiveData.value?.sendDate = sendTime
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user