fix: 详情界面新增
This commit is contained in:
34
app/src/main/java/com/navinfo/volvo/MainActivity.kt
Normal file
34
app/src/main/java/com/navinfo/volvo/MainActivity.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.navinfo.volvo
|
||||
|
||||
import android.os.Bundle
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.navinfo.volvo.databinding.ActivityMainBinding
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val navView: BottomNavigationView = binding.navView
|
||||
|
||||
val navController = findNavController(R.id.nav_host_fragment_activity_main)
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
val appBarConfiguration = AppBarConfiguration(
|
||||
setOf(
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
|
||||
)
|
||||
)
|
||||
// setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
}
|
||||
}
|
||||
185
app/src/main/java/com/navinfo/volvo/db/dao/MapLifeDataBase.java
Normal file
185
app/src/main/java/com/navinfo/volvo/db/dao/MapLifeDataBase.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package com.navinfo.volvo.db.dao;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper;
|
||||
|
||||
import com.navinfo.volvo.db.dao.entity.Message;
|
||||
import com.tencent.wcdb.database.SQLiteCipherSpec;
|
||||
import com.tencent.wcdb.database.SQLiteDatabase;
|
||||
|
||||
import com.tencent.wcdb.room.db.WCDBOpenHelperFactory;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.wcdb.repair.BackupKit;
|
||||
import com.tencent.wcdb.repair.RecoverKit;
|
||||
import com.tencent.wcdb.room.db.WCDBDatabase;
|
||||
|
||||
@Database(entities = {Message.class}, version = 1, exportSchema = false)
|
||||
public abstract class MapLifeDataBase extends RoomDatabase {
|
||||
// marking the instance as volatile to ensure atomic access to the variable
|
||||
/**
|
||||
* 数据库单例对象
|
||||
*/
|
||||
private static volatile MapLifeDataBase INSTANCE;
|
||||
|
||||
/**
|
||||
* 要素数据库类
|
||||
*/
|
||||
public abstract MessageDao getMessageDao();
|
||||
|
||||
/**
|
||||
* 数据库秘钥
|
||||
*/
|
||||
private final static String DB_PASSWORD = "123456";
|
||||
|
||||
public static MapLifeDataBase getDatabase(final Context context, final String name) {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (MapLifeDataBase.class) {
|
||||
if (INSTANCE == null) {
|
||||
// [WCDB] To use Room library with WCDB, pass a WCDBOpenHelper factory object
|
||||
// to the database builder with .openHelperFactory(...). In the factory object,
|
||||
// you can specify passphrase and cipher options to open or create encrypted
|
||||
// database, as well as optimization options like asynchronous checkpoint.
|
||||
SQLiteCipherSpec cipherSpec = new SQLiteCipherSpec()
|
||||
.setPageSize(1024)
|
||||
.setSQLCipherVersion(3);
|
||||
WCDBOpenHelperFactory factory = new WCDBOpenHelperFactory()
|
||||
.passphrase(DB_PASSWORD.getBytes()) // passphrase to the database, remove this line for plain-text
|
||||
.cipherSpec(cipherSpec) // cipher to use, remove for default settings
|
||||
.writeAheadLoggingEnabled(true) // enable WAL mode, remove if not needed
|
||||
.asyncCheckpointEnabled(true); // enable asynchronous checkpoint, remove if not needed
|
||||
|
||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), MapLifeDataBase.class, name)
|
||||
|
||||
// [WCDB] Specify open helper to use WCDB database implementation instead
|
||||
// of the Android framework.
|
||||
.openHelperFactory((SupportSQLiteOpenHelper.Factory) factory)
|
||||
|
||||
// Wipes and rebuilds instead of migrating if no Migration object.
|
||||
// Migration is not part of this codelab.
|
||||
.fallbackToDestructiveMigration().addCallback(sRoomDatabaseCallback).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the onOpen method to populate the database.
|
||||
* For this sample, we clear the database every time it is created or opened.
|
||||
* <p>
|
||||
* If you want to populate the database only when the database is created for the 1st time,
|
||||
* override RoomDatabase.Callback()#onCreate
|
||||
*/
|
||||
private static Callback sRoomDatabaseCallback = new Callback() {
|
||||
|
||||
@Override
|
||||
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
||||
super.onOpen(db);
|
||||
// If you want to keep the data through app restarts,
|
||||
// comment out the following line.
|
||||
new PopulateDbAsync(INSTANCE).execute();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Populate the database in the background.
|
||||
* If you want to start with more words, just add them.
|
||||
*/
|
||||
private static class PopulateDbAsync extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private final MessageDao messageDao;
|
||||
|
||||
PopulateDbAsync(MapLifeDataBase db) {
|
||||
messageDao = db.getMessageDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(final Void... params) {
|
||||
// Start the app with a clean database every time.
|
||||
// Not needed if you only populate on creation.
|
||||
//mDao.deleteAll();
|
||||
Log.e("qj", "doInBackground");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据恢复
|
||||
*/
|
||||
protected boolean recoverData() {
|
||||
if (INSTANCE != null) {
|
||||
SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase();
|
||||
RecoverKit recover = new RecoverKit(sqlite, // 要恢复到的目标 DB
|
||||
sqlite.getPath() + "-backup", // 备份文件
|
||||
DB_PASSWORD.getBytes() // 加密备份文件的密钥,非 DB 密钥
|
||||
);
|
||||
int result = recover.run(false); // fatal 参数传 false 表示遇到错误忽略并继续,
|
||||
// 若传 true 遇到错误则中止并返回 FAILED
|
||||
switch (result) {
|
||||
case RecoverKit.RESULT_OK:
|
||||
/* 成功 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==RecoverKit成功");
|
||||
return true;
|
||||
case RecoverKit.RESULT_CANCELED: /* 取消操作 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==RecoverKit取消操作");
|
||||
break;
|
||||
case RecoverKit.RESULT_FAILED: /* 失败 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==RecoverKit失败");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
recover.release();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据
|
||||
*/
|
||||
protected boolean backup() {
|
||||
Log.e("qj", "sRoomDatabaseCallback===backup==start");
|
||||
if (INSTANCE != null) {
|
||||
//备份文件
|
||||
SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase();
|
||||
BackupKit backup = new BackupKit(sqlite, // 要备份的 DB
|
||||
sqlite.getPath() + "-backup", // 备份文件
|
||||
"123456".getBytes(), // 加密备份文件的密钥,非 DB 密钥
|
||||
0, null);
|
||||
int result = backup.run();
|
||||
switch (result) {
|
||||
case BackupKit.RESULT_OK:
|
||||
/* 成功 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==成功");
|
||||
return true;
|
||||
case BackupKit.RESULT_CANCELED:
|
||||
/* 取消操作 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==取消操作");
|
||||
break;
|
||||
case BackupKit.RESULT_FAILED:
|
||||
/* 失败 */
|
||||
Log.e("qj", "sRoomDatabaseCallback==失败");
|
||||
break;
|
||||
}
|
||||
|
||||
backup.release();
|
||||
}
|
||||
Log.e("qj", "sRoomDatabaseCallback===backup==end");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void release() {
|
||||
INSTANCE = null;
|
||||
}
|
||||
}
|
||||
19
app/src/main/java/com/navinfo/volvo/db/dao/MessageDao.kt
Normal file
19
app/src/main/java/com/navinfo/volvo/db/dao/MessageDao.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.navinfo.volvo.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
|
||||
@Dao
|
||||
interface MessageDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg check: Message)
|
||||
|
||||
@Query("SELECT * FROM Message where id =:id")
|
||||
fun findCheckManagerById(id: Long): Message?
|
||||
|
||||
@Query("SELECT * FROM Message")
|
||||
fun findList(): List<Message>
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.navinfo.volvo.db.dao.entity
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class Attachment {
|
||||
lateinit var path:String
|
||||
lateinit var attachmentType: attachmentType
|
||||
}
|
||||
|
||||
enum class attachmentType {
|
||||
PIC, AUDIO
|
||||
}
|
||||
|
||||
class AttachmentConvert {
|
||||
private val gson = Gson()
|
||||
|
||||
@TypeConverter
|
||||
fun objectToString(list: List<Attachment>): String {
|
||||
return gson.toJson(list)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun stringToObject(json: String?): List<Attachment> {
|
||||
val listType: Type = object : TypeToken<List<Attachment>>() {}.type
|
||||
return gson.fromJson(json, listType)
|
||||
}
|
||||
}
|
||||
46
app/src/main/java/com/navinfo/volvo/db/dao/entity/Message.kt
Normal file
46
app/src/main/java/com/navinfo/volvo/db/dao/entity/Message.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.navinfo.volvo.db.dao.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
|
||||
@TypeConverters(AttachmentConvert::class)
|
||||
@Entity(tableName = "message")
|
||||
class Message(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
/**
|
||||
*标题
|
||||
*/
|
||||
var title: String,
|
||||
/**
|
||||
* 信息内容
|
||||
*/
|
||||
var message: String,
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
var optionDate: String,
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
var sendDate: String,
|
||||
/**
|
||||
* 信息状态
|
||||
*/
|
||||
var status: Int,
|
||||
/**
|
||||
* 发送者ID
|
||||
*/
|
||||
var fromId: String,
|
||||
/**
|
||||
* 接收者ID
|
||||
*/
|
||||
var toId: String,
|
||||
/**
|
||||
* 附件列表
|
||||
*/
|
||||
var attachment: MutableList<Attachment>
|
||||
) {
|
||||
|
||||
}
|
||||
12
app/src/main/java/com/navinfo/volvo/db/dao/entity/User.kt
Normal file
12
app/src/main/java/com/navinfo/volvo/db/dao/entity/User.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.navinfo.volvo.db.dao.entity
|
||||
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
class User(
|
||||
@PrimaryKey()
|
||||
val id:String,
|
||||
var name:String,
|
||||
var nickname:String,
|
||||
|
||||
) {
|
||||
}
|
||||
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(" *") }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.navinfo.volvo.ui.dashboard
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.navinfo.volvo.databinding.FragmentDashboardBinding
|
||||
|
||||
class DashboardFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentDashboardBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val dashboardViewModel =
|
||||
ViewModelProvider(this).get(DashboardViewModel::class.java)
|
||||
|
||||
_binding = FragmentDashboardBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textDashboard
|
||||
dashboardViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.navinfo.volvo.ui.dashboard
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class DashboardViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is dashboard Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
53
app/src/main/java/com/navinfo/volvo/ui/home/HomeFragment.kt
Normal file
53
app/src/main/java/com/navinfo/volvo/ui/home/HomeFragment.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.navinfo.volvo.ui.home
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.Navigation
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.databinding.FragmentHomeBinding
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.ui.message.ObtainMessageViewModel
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): 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) {
|
||||
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/com/navinfo/volvo/ui/home/HomeViewModel.kt
Normal file
13
app/src/main/java/com/navinfo/volvo/ui/home/HomeViewModel.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.navinfo.volvo.ui.home
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is home Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
@@ -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.path = picUrl
|
||||
}
|
||||
}
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新消息附件中的录音文件
|
||||
fun updateMessageAudio(audioUrl: String) {
|
||||
for (attachment in this.msgLiveData.value!!.attachment) {
|
||||
if (attachment.attachmentType == attachmentType.AUDIO) {
|
||||
attachment.path = 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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.navinfo.volvo.ui.notifications
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.navinfo.volvo.databinding.FragmentNotificationsBinding
|
||||
|
||||
class NotificationsFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentNotificationsBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val notificationsViewModel =
|
||||
ViewModelProvider(this).get(NotificationsViewModel::class.java)
|
||||
|
||||
_binding = FragmentNotificationsBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textNotifications
|
||||
notificationsViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.navinfo.volvo.ui.notifications
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class NotificationsViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is notifications Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
Reference in New Issue
Block a user