更新问候消息
This commit is contained in:
parent
9492580b84
commit
cdb057e477
@ -136,7 +136,7 @@ dependencies {
|
||||
// 日志工具 https://github.com/elvishew/xLog/blob/master/README_ZH.md
|
||||
implementation 'com.elvishew:xlog:1.10.1'
|
||||
//加载图片的依赖包
|
||||
implementation ("com.github.bumptech.glide:glide:4.11.0") {
|
||||
implementation("com.github.bumptech.glide:glide:4.11.0") {
|
||||
exclude group: "com.android.support"
|
||||
}
|
||||
}
|
||||
|
@ -53,5 +53,4 @@
|
||||
android:value="" />
|
||||
<meta-data android:name="ScopedStorage" android:value="true" />
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
</manifest>
|
@ -2,19 +2,19 @@ package com.navinfo.volvo.database
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.navinfo.volvo.database.dao.MessageDao
|
||||
import com.navinfo.volvo.database.dao.GreetingMessageDao
|
||||
import com.navinfo.volvo.database.dao.UserDao
|
||||
import com.navinfo.volvo.model.Attachment
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.model.User
|
||||
import com.navinfo.volvo.database.entity.Attachment
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
import com.navinfo.volvo.database.entity.User
|
||||
|
||||
@Database(
|
||||
entities = [Message::class, Attachment::class, User::class],
|
||||
entities = [GreetingMessage::class, Attachment::class, User::class],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun getMessageDao(): MessageDao
|
||||
abstract fun getMessageDao(): GreetingMessageDao
|
||||
|
||||
abstract fun getUserDao(): UserDao
|
||||
}
|
@ -1,191 +1,191 @@
|
||||
package com.navinfo.volvo.database;
|
||||
|
||||
|
||||
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.database.dao.MessageDao;
|
||||
import com.navinfo.volvo.database.dao.UserDao;
|
||||
import com.navinfo.volvo.model.Message;
|
||||
import com.navinfo.volvo.model.Attachment;
|
||||
import com.navinfo.volvo.model.User;
|
||||
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, Attachment.class, User.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();
|
||||
|
||||
public abstract UserDao getUserDao();
|
||||
|
||||
/**
|
||||
* 数据库秘钥
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
//package com.navinfo.volvo.database;
|
||||
//
|
||||
//
|
||||
//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.database.dao.MessageDao;
|
||||
//import com.navinfo.volvo.database.dao.UserDao;
|
||||
//import com.navinfo.volvo.database.entity.Message;
|
||||
//import com.navinfo.volvo.database.entity.Attachment;
|
||||
//import com.navinfo.volvo.database.entity.User;
|
||||
//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, Attachment.class, User.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();
|
||||
//
|
||||
// public abstract UserDao getUserDao();
|
||||
//
|
||||
// /**
|
||||
// * 数据库秘钥
|
||||
// */
|
||||
// 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;
|
||||
// }
|
||||
//}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.navinfo.volvo.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
|
||||
@Dao
|
||||
interface GreetingMessageDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg check: GreetingMessage)
|
||||
|
||||
@Query("SELECT * FROM GreetingMessage where id =:id")
|
||||
fun findCheckManagerById(id: Long): GreetingMessage?
|
||||
|
||||
@Query("SELECT * FROM GreetingMessage")
|
||||
fun findList(): List<GreetingMessage>
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.navinfo.volvo.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.navinfo.volvo.model.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>
|
||||
}
|
@ -3,7 +3,7 @@ package com.navinfo.volvo.database.dao
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import com.navinfo.volvo.model.User
|
||||
import com.navinfo.volvo.database.entity.User
|
||||
|
||||
@Dao
|
||||
interface UserDao {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.navinfo.volvo.model
|
||||
package com.navinfo.volvo.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
@ -8,7 +8,7 @@ import com.navinfo.volvo.tools.GsonUtil
|
||||
|
||||
@Entity(tableName = "Attachment")
|
||||
data class Attachment(
|
||||
@PrimaryKey()
|
||||
@PrimaryKey
|
||||
var id: String,
|
||||
var pathUrl: String,
|
||||
var attachmentType: AttachmentType
|
@ -0,0 +1,44 @@
|
||||
package com.navinfo.volvo.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity(tableName = "GreetingMessage")
|
||||
@TypeConverters(AttachmentConverters::class)
|
||||
data class GreetingMessage @JvmOverloads constructor(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var uuid:Long = 0,
|
||||
var id: Long = 0,
|
||||
var searchValue: String? = "",
|
||||
var createBy: String? = "",
|
||||
var createTime: String? = "",
|
||||
var updateBy: String? = "",
|
||||
var updateTime: String? = "",
|
||||
var remark: String? = "",
|
||||
var name: String? = "",
|
||||
var imageUrl: String? = "",
|
||||
var mediaUrl: String? = "",
|
||||
var who: String? = "",
|
||||
var toWho: String? = "",
|
||||
var sendDate: String? = "",
|
||||
var status: String? = "",
|
||||
var isSkip: String? = "",
|
||||
var skipUrl: String? = "",
|
||||
var startTime: String? = "",
|
||||
var endTime: String? = "",
|
||||
var sendVehicle: String? = "",
|
||||
var sendSex: String? = "",
|
||||
var sendAge: String? = "",
|
||||
var sendNum: String? = "",
|
||||
var sendVins: String? = "",
|
||||
var sendType: String? = "",
|
||||
var del: String? = "",
|
||||
var version: String? = "",
|
||||
/**
|
||||
* 附件列表
|
||||
*/
|
||||
var attachment: MutableList<Attachment> = mutableListOf()
|
||||
) {
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.navinfo.volvo.model
|
||||
package com.navinfo.volvo.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
@ -7,8 +7,6 @@ import androidx.room.TypeConverters
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.navinfo.volvo.tools.GsonUtil
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalTime
|
||||
import javax.inject.Inject
|
||||
|
||||
@Entity(tableName = "User")
|
@ -3,7 +3,7 @@ package com.navinfo.volvo.di.module
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.navinfo.volvo.database.AppDatabase
|
||||
import com.navinfo.volvo.database.dao.MessageDao
|
||||
import com.navinfo.volvo.database.dao.GreetingMessageDao
|
||||
import com.navinfo.volvo.database.dao.UserDao
|
||||
import com.tencent.wcdb.database.SQLiteCipherSpec
|
||||
import com.tencent.wcdb.room.db.WCDBOpenHelperFactory
|
||||
@ -45,7 +45,7 @@ class DatabaseModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideMessageDao(database: AppDatabase): MessageDao {
|
||||
fun provideMessageDao(database: AppDatabase): GreetingMessageDao {
|
||||
return database.getMessageDao()
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,6 @@ package com.navinfo.volvo.http
|
||||
|
||||
class DefaultResponse<T> {
|
||||
var code: Int = 0
|
||||
var message: String = ""
|
||||
var msg: String = ""
|
||||
var data: T? = null
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
package com.navinfo.volvo.http
|
||||
|
||||
import com.navinfo.volvo.db.dao.entity.Attachment
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.create
|
||||
import java.io.File
|
||||
|
||||
class NavinfoVolvoCall {
|
||||
companion object {
|
||||
|
@ -1,46 +0,0 @@
|
||||
package com.navinfo.volvo.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
|
||||
@Entity(tableName = "message")
|
||||
@TypeConverters(AttachmentConverters::class)
|
||||
data class Message @JvmOverloads constructor(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
|
||||
var netId: String = "",
|
||||
/**
|
||||
*标题
|
||||
*/
|
||||
var title: String = "",
|
||||
/**
|
||||
* 信息内容
|
||||
*/
|
||||
var message: String = "",
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
var optionDate: String = "",
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
var sendDate: String = "",
|
||||
/**
|
||||
* 信息状态
|
||||
*/
|
||||
var status: Int = 1,
|
||||
/**
|
||||
* 发送者ID
|
||||
*/
|
||||
var fromId: String = "",
|
||||
/**
|
||||
* 接收者ID
|
||||
*/
|
||||
var toId: String = "",
|
||||
/**
|
||||
* 附件列表
|
||||
*/
|
||||
var attachment: MutableList<Attachment> = mutableListOf()
|
||||
)
|
@ -1,6 +1,6 @@
|
||||
package com.navinfo.volvo.model.network
|
||||
package com.navinfo.volvo.model.messagelist
|
||||
|
||||
data class NetworkPostMessage(
|
||||
data class NetworkMessageListPost(
|
||||
val name: String,//问候名称,非必填项
|
||||
val who: String, //我是谁
|
||||
val toWho: String, //发送给谁
|
@ -0,0 +1,8 @@
|
||||
package com.navinfo.volvo.model.messagelist
|
||||
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
|
||||
data class NetworkMessageListResponse(
|
||||
val total: Int,
|
||||
val rows: List<GreetingMessage>
|
||||
)
|
@ -1,9 +1,10 @@
|
||||
package com.navinfo.volvo.repository
|
||||
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.model.network.NetworkPostMessage
|
||||
import com.navinfo.volvo.http.DefaultResponse
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListPost
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
|
||||
import com.navinfo.volvo.util.NetResult
|
||||
|
||||
interface NetworkDataSource {
|
||||
suspend fun getCardList(message: NetworkPostMessage): NetResult<List<Message>>
|
||||
suspend fun getCardList(message: NetworkMessageListPost): NetResult<DefaultResponse<NetworkMessageListResponse>>
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
package com.navinfo.volvo.repository
|
||||
|
||||
import com.navinfo.volvo.database.AppDatabase
|
||||
import com.navinfo.volvo.database.dao.GreetingMessageDao
|
||||
import com.navinfo.volvo.di.scope.IoDispatcher
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.model.network.NetworkPostMessage
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
import com.navinfo.volvo.http.DefaultResponse
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListPost
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
|
||||
import com.navinfo.volvo.repository.service.NetworkService
|
||||
import com.navinfo.volvo.tools.GsonUtil
|
||||
import com.navinfo.volvo.util.NetResult
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import javax.inject.Inject
|
||||
@ -17,17 +19,22 @@ import javax.inject.Inject
|
||||
|
||||
class NetworkDataSourceImp @Inject constructor(
|
||||
private val netWorkService: NetworkService,
|
||||
private val messageDao: GreetingMessageDao,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
|
||||
) : NetworkDataSource {
|
||||
|
||||
override suspend fun getCardList(message: NetworkPostMessage): NetResult<List<Message>> =
|
||||
override suspend fun getCardList(message: NetworkMessageListPost): NetResult<DefaultResponse<NetworkMessageListResponse>> =
|
||||
withContext(ioDispatcher) {
|
||||
return@withContext try {
|
||||
val stringBody = GsonUtil.getInstance().toJson(message).toRequestBody("application/json;charset=utf-8".toMediaType())
|
||||
val stringBody = GsonUtil.getInstance().toJson(message)
|
||||
.toRequestBody("application/json;charset=utf-8".toMediaType())
|
||||
val result = netWorkService.queryCardListByApp(stringBody)
|
||||
if (result.isSuccessful) {
|
||||
val list = result.body()
|
||||
NetResult.Success(list)
|
||||
val body = result.body()
|
||||
val list: MutableList<GreetingMessage> =
|
||||
listOf(body!!.data!!.rows) as MutableList<GreetingMessage>
|
||||
messageDao.insert(*list.map { it }.toTypedArray())
|
||||
NetResult.Success(body)
|
||||
} else {
|
||||
NetResult.Success(null)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.navinfo.volvo.repository.service
|
||||
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.http.DefaultResponse
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
@ -8,5 +9,5 @@ import retrofit2.http.POST
|
||||
|
||||
interface NetworkService {
|
||||
@POST("/navi/cardDelivery/queryCardListByApp")
|
||||
suspend fun queryCardListByApp(@Body body: RequestBody): Response<List<Message>>
|
||||
suspend fun queryCardListByApp(@Body body: RequestBody): Response<DefaultResponse<NetworkMessageListResponse>>
|
||||
}
|
@ -2,7 +2,6 @@ package com.navinfo.volvo.ui
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
@ -11,10 +10,26 @@ import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.easytools.tools.FileUtils
|
||||
import com.elvishew.xlog.BuildConfig
|
||||
import com.elvishew.xlog.LogConfiguration
|
||||
import com.elvishew.xlog.LogLevel
|
||||
import com.elvishew.xlog.XLog
|
||||
import com.elvishew.xlog.interceptor.BlacklistTagsFilterInterceptor
|
||||
import com.elvishew.xlog.printer.AndroidPrinter
|
||||
import com.elvishew.xlog.printer.ConsolePrinter
|
||||
import com.elvishew.xlog.printer.Printer
|
||||
import com.elvishew.xlog.printer.file.FilePrinter
|
||||
import com.elvishew.xlog.printer.file.backup.NeverBackupStrategy
|
||||
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.hjq.permissions.OnPermissionCallback
|
||||
import com.hjq.permissions.Permission
|
||||
import com.hjq.permissions.XXPermissions
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.databinding.ActivityMainBinding
|
||||
import com.navinfo.volvo.utils.SystemConstant
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -41,7 +56,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onGranted(permissions: MutableList<String>, all: Boolean) {
|
||||
if (!all) {
|
||||
Toast.makeText(this@MainActivity, "获取部分权限成功,但部分权限未正常授予", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this@MainActivity, "获取部分权限成功,但部分权限未正常授予", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
// 在SD卡创建项目目录
|
||||
@ -50,7 +66,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onDenied(permissions: MutableList<String>, never: Boolean) {
|
||||
if (never) {
|
||||
Toast.makeText(this@MainActivity, "永久拒绝授权,请手动授权文件读写权限", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this@MainActivity, "永久拒绝授权,请手动授权文件读写权限", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
// 如果是被永久拒绝就跳转到应用权限系统设置页面
|
||||
XXPermissions.startPermissionActivity(this@MainActivity, permissions)
|
||||
} else {
|
||||
@ -132,10 +149,11 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val consolePrinter: Printer = ConsolePrinter() // 通过 System.out 打印日志到控制台的打印器
|
||||
|
||||
val filePrinter: Printer = FilePrinter.Builder("${SystemConstant.ROOT_PATH}/Logs") // 指定保存日志文件的路径
|
||||
.fileNameGenerator(DateFileNameGenerator()) // 指定日志文件名生成器,默认为 ChangelessFileNameGenerator("log")
|
||||
.backupStrategy(NeverBackupStrategy()) // 指定日志文件备份策略,默认为 FileSizeBackupStrategy(1024 * 1024)
|
||||
.build()
|
||||
val filePrinter: Printer =
|
||||
FilePrinter.Builder("${SystemConstant.ROOT_PATH}/Logs") // 指定保存日志文件的路径
|
||||
.fileNameGenerator(DateFileNameGenerator()) // 指定日志文件名生成器,默认为 ChangelessFileNameGenerator("log")
|
||||
.backupStrategy(NeverBackupStrategy()) // 指定日志文件备份策略,默认为 FileSizeBackupStrategy(1024 * 1024)
|
||||
.build()
|
||||
|
||||
XLog.init( // 初始化 XLog
|
||||
config, // 指定日志配置,如果不指定,会默认使用 new LogConfiguration.Builder().build()
|
||||
|
@ -7,18 +7,18 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
|
||||
class MessageAdapter : RecyclerView.Adapter<MessageAdapter.MyViewHolder>() {
|
||||
|
||||
var itemList: MutableList<Message> = mutableListOf()
|
||||
var itemList: MutableList<GreetingMessage> = mutableListOf()
|
||||
|
||||
fun addItem(message: Message) {
|
||||
fun addItem(message: GreetingMessage) {
|
||||
itemList.add(message)
|
||||
notifyItemInserted(itemList.size - 1)
|
||||
}
|
||||
|
||||
fun setItem(messageList: MutableList<Message>){
|
||||
fun setItem(messageList: MutableList<GreetingMessage>){
|
||||
itemList = messageList
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@ -35,8 +35,8 @@ class MessageAdapter : RecyclerView.Adapter<MessageAdapter.MyViewHolder>() {
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
val message = itemList[position]
|
||||
holder.toName.text = message.fromId
|
||||
holder.messageText.text = message.message
|
||||
holder.toName.text = message.toWho
|
||||
holder.messageText.text = message.name
|
||||
holder.sendTime.text = message.sendDate
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import com.easytools.tools.DateUtils
|
||||
import com.easytools.tools.FileUtils
|
||||
import com.elvishew.xlog.XLog
|
||||
import com.navinfo.volvo.databinding.FragmentCameraBinding
|
||||
import com.navinfo.volvo.ui.message.ObtainMessageViewModel
|
||||
import com.navinfo.volvo.ui.fragments.message.ObtainMessageViewModel
|
||||
import com.navinfo.volvo.utils.SystemConstant
|
||||
import com.otaliastudios.cameraview.CameraListener
|
||||
import com.otaliastudios.cameraview.CameraView
|
||||
|
@ -3,8 +3,9 @@ package com.navinfo.volvo.ui.fragments.home
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.volvo.model.Message
|
||||
import com.navinfo.volvo.model.network.NetworkPostMessage
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListPost
|
||||
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
|
||||
import com.navinfo.volvo.repository.NetworkDataSource
|
||||
import com.navinfo.volvo.util.NetResult
|
||||
import com.navinfo.volvo.util.asLiveData
|
||||
@ -18,18 +19,18 @@ class MessageViewModel @Inject constructor(
|
||||
private val _isLoading = MutableLiveData<Boolean>()
|
||||
val isLoading = _isLoading.asLiveData()
|
||||
|
||||
private val _messageList = MutableLiveData<List<Message>>()
|
||||
private val _messageList = MutableLiveData<List<GreetingMessage>>()
|
||||
val messageList = _messageList.asLiveData()
|
||||
|
||||
fun getMessageList() {
|
||||
_isLoading.postValue(true)
|
||||
viewModelScope.launch {
|
||||
val messagePost = NetworkPostMessage(who = "北京测试", toWho = "volvo测试")
|
||||
val messagePost = NetworkMessageListPost(who = "北京测试", toWho = "volvo测试")
|
||||
when (val result = repository.getCardList(messagePost)) {
|
||||
is NetResult.Success -> {
|
||||
_isLoading.value = false
|
||||
if (result.data != null) {
|
||||
val list = result.data
|
||||
val list = (result.data.data as NetworkMessageListResponse).rows
|
||||
_messageList.value = list
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navinfo.volvo.database.AppDatabase
|
||||
import com.navinfo.volvo.model.User
|
||||
import com.navinfo.volvo.database.entity.User
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoginViewModel @Inject constructor(private val dataBase: AppDatabase) : ViewModel() {
|
||||
|
@ -25,11 +25,10 @@ import com.gredicer.datetimepicker.DateTimePickerFragment
|
||||
import com.hjq.permissions.OnPermissionCallback
|
||||
import com.hjq.permissions.Permission
|
||||
import com.hjq.permissions.XXPermissions
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.RecorderLifecycleObserver
|
||||
import com.navinfo.volvo.databinding.FragmentObtainMessageBinding
|
||||
import com.navinfo.volvo.db.dao.entity.AttachmentType
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.database.entity.AttachmentType
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
import com.navinfo.volvo.ui.markRequiredInRed
|
||||
import com.navinfo.volvo.utils.EasyMediaFile
|
||||
import com.navinfo.volvo.utils.SystemConstant
|
||||
@ -65,13 +64,13 @@ class ObtainMessageFragment: Fragment() {
|
||||
_binding = FragmentObtainMessageBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
obtainMessageViewModel.setCurrentMessage(Message())
|
||||
obtainMessageViewModel.setCurrentMessage(GreetingMessage())
|
||||
|
||||
obtainMessageViewModel?.getMessageLiveData()?.observe(
|
||||
viewLifecycleOwner, Observer {
|
||||
// 初始化界面显示内容
|
||||
if(it.title?.isNotEmpty() == true)
|
||||
binding.tvMessageTitle?.setText(it.title)
|
||||
if(it.name?.isNotEmpty() == true)
|
||||
binding.tvMessageTitle?.setText(it.name)
|
||||
if (it.sendDate?.isNotEmpty() == true) {
|
||||
binding.btnSendTime.text = it.sendDate
|
||||
}
|
||||
@ -131,7 +130,7 @@ class ObtainMessageFragment: Fragment() {
|
||||
android.R.layout.simple_dropdown_item_1line, android.R.id.text1, sendToArray)
|
||||
binding.edtSendTo.onItemSelectedListener = object: OnItemSelectedListener {
|
||||
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
|
||||
obtainMessageViewModel.getMessageLiveData().value?.toId = sendToArray[p2]
|
||||
obtainMessageViewModel.getMessageLiveData().value?.toWho = sendToArray[p2]
|
||||
}
|
||||
|
||||
override fun onNothingSelected(p0: AdapterView<*>?) {
|
||||
@ -287,7 +286,7 @@ class ObtainMessageFragment: Fragment() {
|
||||
binding.btnObtainMessageConfirm.setOnClickListener {
|
||||
// 检查当前输入数据
|
||||
val messageData = obtainMessageViewModel.getMessageLiveData().value
|
||||
if (messageData?.title?.isEmpty() == true) {
|
||||
if (messageData?.name?.isEmpty() == true) {
|
||||
val toolTipRelativeLayout =
|
||||
binding.ttTitle
|
||||
val toolTip = ToolTip()
|
||||
@ -328,7 +327,7 @@ class ObtainMessageFragment: Fragment() {
|
||||
toolTipRelativeLayout.showToolTipForView(toolTip, binding.tvUploadPic)
|
||||
}
|
||||
|
||||
if (messageData?.fromId?.isEmpty()==true) {
|
||||
if (messageData?.who?.isEmpty()==true) {
|
||||
val toolTipRelativeLayout =
|
||||
binding.ttSendFrom
|
||||
val toolTip = ToolTip()
|
||||
@ -338,7 +337,7 @@ class ObtainMessageFragment: Fragment() {
|
||||
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
|
||||
toolTipRelativeLayout.showToolTipForView(toolTip, binding.edtSendFrom)
|
||||
}
|
||||
if (messageData?.toId?.isEmpty()==true) {
|
||||
if (messageData?.toWho?.isEmpty()==true) {
|
||||
val toolTipRelativeLayout =
|
||||
binding.ttSendTo
|
||||
val toolTip = ToolTip()
|
||||
|
@ -3,12 +3,12 @@ package com.navinfo.volvo.ui.fragments.message
|
||||
import androidx.lifecycle.*
|
||||
import com.easytools.tools.ToastUtils
|
||||
import com.elvishew.xlog.XLog
|
||||
import com.navinfo.volvo.db.dao.entity.Attachment
|
||||
import com.navinfo.volvo.db.dao.entity.AttachmentType
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.database.entity.Attachment
|
||||
import com.navinfo.volvo.database.entity.AttachmentType
|
||||
import com.navinfo.volvo.database.entity.GreetingMessage
|
||||
import com.navinfo.volvo.http.NavinfoVolvoCall
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import java.io.File
|
||||
@ -16,21 +16,21 @@ import java.util.*
|
||||
|
||||
|
||||
class ObtainMessageViewModel: ViewModel() {
|
||||
private val msgLiveData: MutableLiveData<Message> by lazy {
|
||||
MutableLiveData<Message>()
|
||||
private val msgLiveData: MutableLiveData<GreetingMessage> by lazy {
|
||||
MutableLiveData<GreetingMessage>()
|
||||
}
|
||||
|
||||
fun setCurrentMessage(msg: Message) {
|
||||
fun setCurrentMessage(msg: GreetingMessage) {
|
||||
msgLiveData.postValue(msg)
|
||||
}
|
||||
|
||||
fun getMessageLiveData(): MutableLiveData<Message> {
|
||||
fun getMessageLiveData(): MutableLiveData<GreetingMessage> {
|
||||
return msgLiveData
|
||||
}
|
||||
|
||||
// 更新消息标题
|
||||
fun updateMessageTitle(title: String) {
|
||||
this.msgLiveData.value?.title = title
|
||||
this.msgLiveData.value?.name = title
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
@ -75,13 +75,13 @@ class ObtainMessageViewModel: ViewModel() {
|
||||
|
||||
// 更新发送人
|
||||
fun updateMessageSendFrom(sendFrom: String) {
|
||||
this.msgLiveData.value?.fromId = sendFrom
|
||||
this.msgLiveData.value?.who = sendFrom
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
// 更新接收人
|
||||
fun updateMessageSendTo(sendTo: String) {
|
||||
this.msgLiveData.value?.toId = sendTo
|
||||
this.msgLiveData.value?.toWho = sendTo
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
}
|
||||
|
||||
@ -96,14 +96,14 @@ class ObtainMessageViewModel: ViewModel() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val requestFile: RequestBody =
|
||||
RequestBody.create(MediaType.parse("multipart/form-data"), attachmentFile)
|
||||
RequestBody.create("multipart/form-data".toMediaTypeOrNull(), attachmentFile)
|
||||
val body = MultipartBody.Part.createFormData("picture", attachmentFile.getName(), requestFile)
|
||||
val result = NavinfoVolvoCall.getApi().uploadAttachment(body)
|
||||
XLog.d(result.code)
|
||||
if (result.code == 200) { // 请求成功
|
||||
// 获取上传后的结果
|
||||
} else {
|
||||
ToastUtils.showToast(result.message)
|
||||
ToastUtils.showToast(result.msg)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.showToast(e.message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user