更新问候消息

This commit is contained in:
squallzhjch 2023-01-04 17:19:29 +08:00
parent 9492580b84
commit cdb057e477
26 changed files with 361 additions and 334 deletions

View File

@ -136,7 +136,7 @@ dependencies {
// https://github.com/elvishew/xLog/blob/master/README_ZH.md // https://github.com/elvishew/xLog/blob/master/README_ZH.md
implementation 'com.elvishew:xlog:1.10.1' 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" exclude group: "com.android.support"
} }
} }

View File

@ -53,5 +53,4 @@
android:value="" /> android:value="" />
<meta-data android:name="ScopedStorage" android:value="true" /> <meta-data android:name="ScopedStorage" android:value="true" />
</application> </application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest> </manifest>

View File

@ -2,19 +2,19 @@ package com.navinfo.volvo.database
import androidx.room.Database import androidx.room.Database
import androidx.room.RoomDatabase 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.database.dao.UserDao
import com.navinfo.volvo.model.Attachment import com.navinfo.volvo.database.entity.Attachment
import com.navinfo.volvo.model.Message import com.navinfo.volvo.database.entity.GreetingMessage
import com.navinfo.volvo.model.User import com.navinfo.volvo.database.entity.User
@Database( @Database(
entities = [Message::class, Attachment::class, User::class], entities = [GreetingMessage::class, Attachment::class, User::class],
version = 1, version = 1,
exportSchema = false exportSchema = false
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun getMessageDao(): MessageDao abstract fun getMessageDao(): GreetingMessageDao
abstract fun getUserDao(): UserDao abstract fun getUserDao(): UserDao
} }

View File

@ -1,191 +1,191 @@
package com.navinfo.volvo.database; //package com.navinfo.volvo.database;
//
//
import android.content.Context; //import android.content.Context;
//
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.room.Database; //import androidx.room.Database;
import androidx.room.Room; //import androidx.room.Room;
import androidx.room.RoomDatabase; //import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase; //import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper; //import androidx.sqlite.db.SupportSQLiteOpenHelper;
//
import com.navinfo.volvo.database.dao.MessageDao; //import com.navinfo.volvo.database.dao.MessageDao;
import com.navinfo.volvo.database.dao.UserDao; //import com.navinfo.volvo.database.dao.UserDao;
import com.navinfo.volvo.model.Message; //import com.navinfo.volvo.database.entity.Message;
import com.navinfo.volvo.model.Attachment; //import com.navinfo.volvo.database.entity.Attachment;
import com.navinfo.volvo.model.User; //import com.navinfo.volvo.database.entity.User;
import com.tencent.wcdb.database.SQLiteCipherSpec; //import com.tencent.wcdb.database.SQLiteCipherSpec;
import com.tencent.wcdb.database.SQLiteDatabase; //import com.tencent.wcdb.database.SQLiteDatabase;
//
import com.tencent.wcdb.room.db.WCDBOpenHelperFactory; //import com.tencent.wcdb.room.db.WCDBOpenHelperFactory;
//
import android.os.AsyncTask; //import android.os.AsyncTask;
import android.util.Log; //import android.util.Log;
//
import com.tencent.wcdb.repair.BackupKit; //import com.tencent.wcdb.repair.BackupKit;
import com.tencent.wcdb.repair.RecoverKit; //import com.tencent.wcdb.repair.RecoverKit;
import com.tencent.wcdb.room.db.WCDBDatabase; //import com.tencent.wcdb.room.db.WCDBDatabase;
//
@Database(entities = {Message.class, Attachment.class, User.class}, version = 1, exportSchema = false) //@Database(entities = {Message.class, Attachment.class, User.class}, version = 1, exportSchema = false)
public abstract class MapLifeDataBase extends RoomDatabase { //public abstract class MapLifeDataBase extends RoomDatabase {
// marking the instance as volatile to ensure atomic access to the variable // // marking the instance as volatile to ensure atomic access to the variable
/** // /**
* 数据库单例对象 // * 数据库单例对象
*/ // */
private static volatile MapLifeDataBase INSTANCE; // private static volatile MapLifeDataBase INSTANCE;
//
/** // /**
* 要素数据库类 // * 要素数据库类
*/ // */
public abstract MessageDao getMessageDao(); // public abstract MessageDao getMessageDao();
//
public abstract UserDao getUserDao(); // public abstract UserDao getUserDao();
//
/** // /**
* 数据库秘钥 // * 数据库秘钥
*/ // */
private final static String DB_PASSWORD = "123456"; // private final static String DB_PASSWORD = "123456";
//
public static MapLifeDataBase getDatabase(final Context context, final String name) { // public static MapLifeDataBase getDatabase(final Context context, final String name) {
if (INSTANCE == null) { // if (INSTANCE == null) {
synchronized (MapLifeDataBase.class) { // synchronized (MapLifeDataBase.class) {
if (INSTANCE == null) { // if (INSTANCE == null) {
// [WCDB] To use Room library with WCDB, pass a WCDBOpenHelper factory object // // [WCDB] To use Room library with WCDB, pass a WCDBOpenHelper factory object
// to the database builder with .openHelperFactory(...). In the factory object, // // to the database builder with .openHelperFactory(...). In the factory object,
// you can specify passphrase and cipher options to open or create encrypted // // you can specify passphrase and cipher options to open or create encrypted
// database, as well as optimization options like asynchronous checkpoint. // // database, as well as optimization options like asynchronous checkpoint.
SQLiteCipherSpec cipherSpec = new SQLiteCipherSpec() // SQLiteCipherSpec cipherSpec = new SQLiteCipherSpec()
.setPageSize(1024) // .setPageSize(1024)
.setSQLCipherVersion(3); // .setSQLCipherVersion(3);
WCDBOpenHelperFactory factory = new WCDBOpenHelperFactory() // WCDBOpenHelperFactory factory = new WCDBOpenHelperFactory()
.passphrase(DB_PASSWORD.getBytes()) // passphrase to the database, remove this line for plain-text // .passphrase(DB_PASSWORD.getBytes()) // passphrase to the database, remove this line for plain-text
.cipherSpec(cipherSpec) // cipher to use, remove for default settings // .cipherSpec(cipherSpec) // cipher to use, remove for default settings
.writeAheadLoggingEnabled(true) // enable WAL mode, remove if not needed // .writeAheadLoggingEnabled(true) // enable WAL mode, remove if not needed
.asyncCheckpointEnabled(true); // enable asynchronous checkpoint, remove if not needed // .asyncCheckpointEnabled(true); // enable asynchronous checkpoint, remove if not needed
//
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), MapLifeDataBase.class, name) // INSTANCE = Room.databaseBuilder(context.getApplicationContext(), MapLifeDataBase.class, name)
//
// [WCDB] Specify open helper to use WCDB database implementation instead // // [WCDB] Specify open helper to use WCDB database implementation instead
// of the Android framework. // // of the Android framework.
.openHelperFactory((SupportSQLiteOpenHelper.Factory) factory) // .openHelperFactory((SupportSQLiteOpenHelper.Factory) factory)
//
// Wipes and rebuilds instead of migrating if no Migration object. // // Wipes and rebuilds instead of migrating if no Migration object.
// Migration is not part of this codelab. // // Migration is not part of this codelab.
.fallbackToDestructiveMigration().addCallback(sRoomDatabaseCallback).build(); // .fallbackToDestructiveMigration().addCallback(sRoomDatabaseCallback).build();
} // }
} // }
} // }
return INSTANCE; // return INSTANCE;
} // }
//
/** // /**
* Override the onOpen method to populate the database. // * Override the onOpen method to populate the database.
* For this sample, we clear the database every time it is created or opened. // * For this sample, we clear the database every time it is created or opened.
* <p> // * <p>
* If you want to populate the database only when the database is created for the 1st time, // * If you want to populate the database only when the database is created for the 1st time,
* override RoomDatabase.Callback()#onCreate // * override RoomDatabase.Callback()#onCreate
*/ // */
private static Callback sRoomDatabaseCallback = new Callback() { // private static Callback sRoomDatabaseCallback = new Callback() {
//
@Override // @Override
public void onOpen(@NonNull SupportSQLiteDatabase db) { // public void onOpen(@NonNull SupportSQLiteDatabase db) {
super.onOpen(db); // super.onOpen(db);
// If you want to keep the data through app restarts, // // If you want to keep the data through app restarts,
// comment out the following line. // // comment out the following line.
new PopulateDbAsync(INSTANCE).execute(); // new PopulateDbAsync(INSTANCE).execute();
} // }
}; // };
//
/** // /**
* Populate the database in the background. // * Populate the database in the background.
* If you want to start with more words, just add them. // * If you want to start with more words, just add them.
*/ // */
private static class PopulateDbAsync extends AsyncTask<Void, Void, Void> { // private static class PopulateDbAsync extends AsyncTask<Void, Void, Void> {
//
private final MessageDao messageDao; // private final MessageDao messageDao;
//
PopulateDbAsync(MapLifeDataBase db) { // PopulateDbAsync(MapLifeDataBase db) {
messageDao = db.getMessageDao(); // messageDao = db.getMessageDao();
} // }
//
@Override // @Override
protected Void doInBackground(final Void... params) { // protected Void doInBackground(final Void... params) {
// Start the app with a clean database every time. // // Start the app with a clean database every time.
// Not needed if you only populate on creation. // // Not needed if you only populate on creation.
//mDao.deleteAll(); // //mDao.deleteAll();
Log.e("qj", "doInBackground"); // Log.e("qj", "doInBackground");
return null; // return null;
} // }
} // }
//
/** // /**
* 数据恢复 // * 数据恢复
*/ // */
protected boolean recoverData() { // protected boolean recoverData() {
if (INSTANCE != null) { // if (INSTANCE != null) {
SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase(); // SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase();
RecoverKit recover = new RecoverKit(sqlite, // 要恢复到的目标 DB // RecoverKit recover = new RecoverKit(sqlite, // 要恢复到的目标 DB
sqlite.getPath() + "-backup", // 备份文件 // sqlite.getPath() + "-backup", // 备份文件
DB_PASSWORD.getBytes() // 加密备份文件的密钥 DB 密钥 // DB_PASSWORD.getBytes() // 加密备份文件的密钥 DB 密钥
); // );
int result = recover.run(false); // fatal 参数传 false 表示遇到错误忽略并继续 // int result = recover.run(false); // fatal 参数传 false 表示遇到错误忽略并继续
// 若传 true 遇到错误则中止并返回 FAILED // // 若传 true 遇到错误则中止并返回 FAILED
switch (result) { // switch (result) {
case RecoverKit.RESULT_OK: // case RecoverKit.RESULT_OK:
/* 成功 */ // /* 成功 */
Log.e("qj", "sRoomDatabaseCallback==RecoverKit成功"); // Log.e("qj", "sRoomDatabaseCallback==RecoverKit成功");
return true; // return true;
case RecoverKit.RESULT_CANCELED: /* 取消操作 */ // case RecoverKit.RESULT_CANCELED: /* 取消操作 */
Log.e("qj", "sRoomDatabaseCallback==RecoverKit取消操作"); // Log.e("qj", "sRoomDatabaseCallback==RecoverKit取消操作");
break; // break;
case RecoverKit.RESULT_FAILED: /* 失败 */ // case RecoverKit.RESULT_FAILED: /* 失败 */
Log.e("qj", "sRoomDatabaseCallback==RecoverKit失败"); // Log.e("qj", "sRoomDatabaseCallback==RecoverKit失败");
break; // break;
//
} // }
//
recover.release(); // recover.release();
} // }
//
return false; // return false;
} // }
//
/** // /**
* 备份数据 // * 备份数据
*/ // */
protected boolean backup() { // protected boolean backup() {
Log.e("qj", "sRoomDatabaseCallback===backup==start"); // Log.e("qj", "sRoomDatabaseCallback===backup==start");
if (INSTANCE != null) { // if (INSTANCE != null) {
//备份文件 // //备份文件
SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase(); // SQLiteDatabase sqlite = ((WCDBDatabase) INSTANCE.getOpenHelper().getWritableDatabase()).getInnerDatabase();
BackupKit backup = new BackupKit(sqlite, // 要备份的 DB // BackupKit backup = new BackupKit(sqlite, // 要备份的 DB
sqlite.getPath() + "-backup", // 备份文件 // sqlite.getPath() + "-backup", // 备份文件
"123456".getBytes(), // 加密备份文件的密钥 DB 密钥 // "123456".getBytes(), // 加密备份文件的密钥 DB 密钥
0, null); // 0, null);
int result = backup.run(); // int result = backup.run();
switch (result) { // switch (result) {
case BackupKit.RESULT_OK: // case BackupKit.RESULT_OK:
/* 成功 */ // /* 成功 */
Log.e("qj", "sRoomDatabaseCallback==成功"); // Log.e("qj", "sRoomDatabaseCallback==成功");
return true; // return true;
case BackupKit.RESULT_CANCELED: // case BackupKit.RESULT_CANCELED:
/* 取消操作 */ // /* 取消操作 */
Log.e("qj", "sRoomDatabaseCallback==取消操作"); // Log.e("qj", "sRoomDatabaseCallback==取消操作");
break; // break;
case BackupKit.RESULT_FAILED: // case BackupKit.RESULT_FAILED:
/* 失败 */ // /* 失败 */
Log.e("qj", "sRoomDatabaseCallback==失败"); // Log.e("qj", "sRoomDatabaseCallback==失败");
break; // break;
} // }
//
backup.release(); // backup.release();
} // }
Log.e("qj", "sRoomDatabaseCallback===backup==end"); // Log.e("qj", "sRoomDatabaseCallback===backup==end");
return false; // return false;
} // }
//
protected void release() { // protected void release() {
INSTANCE = null; // INSTANCE = null;
} // }
} //}

View File

@ -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>
}

View File

@ -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>
}

View File

@ -3,7 +3,7 @@ package com.navinfo.volvo.database.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import com.navinfo.volvo.model.User import com.navinfo.volvo.database.entity.User
@Dao @Dao
interface UserDao { interface UserDao {

View File

@ -1,4 +1,4 @@
package com.navinfo.volvo.model package com.navinfo.volvo.database.entity
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@ -8,7 +8,7 @@ import com.navinfo.volvo.tools.GsonUtil
@Entity(tableName = "Attachment") @Entity(tableName = "Attachment")
data class Attachment( data class Attachment(
@PrimaryKey() @PrimaryKey
var id: String, var id: String,
var pathUrl: String, var pathUrl: String,
var attachmentType: AttachmentType var attachmentType: AttachmentType

View File

@ -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()
) {
}

View File

@ -1,4 +1,4 @@
package com.navinfo.volvo.model package com.navinfo.volvo.database.entity
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@ -7,8 +7,6 @@ import androidx.room.TypeConverters
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.navinfo.volvo.tools.GsonUtil import com.navinfo.volvo.tools.GsonUtil
import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.NotNull
import java.time.LocalDateTime
import java.time.LocalTime
import javax.inject.Inject import javax.inject.Inject
@Entity(tableName = "User") @Entity(tableName = "User")

View File

@ -3,7 +3,7 @@ package com.navinfo.volvo.di.module
import android.content.Context import android.content.Context
import androidx.room.Room import androidx.room.Room
import com.navinfo.volvo.database.AppDatabase 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.navinfo.volvo.database.dao.UserDao
import com.tencent.wcdb.database.SQLiteCipherSpec import com.tencent.wcdb.database.SQLiteCipherSpec
import com.tencent.wcdb.room.db.WCDBOpenHelperFactory import com.tencent.wcdb.room.db.WCDBOpenHelperFactory
@ -45,7 +45,7 @@ class DatabaseModule {
@Singleton @Singleton
@Provides @Provides
fun provideMessageDao(database: AppDatabase): MessageDao { fun provideMessageDao(database: AppDatabase): GreetingMessageDao {
return database.getMessageDao() return database.getMessageDao()
} }

View File

@ -2,6 +2,6 @@ package com.navinfo.volvo.http
class DefaultResponse<T> { class DefaultResponse<T> {
var code: Int = 0 var code: Int = 0
var message: String = "" var msg: String = ""
var data: T? = null var data: T? = null
} }

View File

@ -1,10 +1,7 @@
package com.navinfo.volvo.http package com.navinfo.volvo.http
import com.navinfo.volvo.db.dao.entity.Attachment
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.io.File
class NavinfoVolvoCall { class NavinfoVolvoCall {
companion object { companion object {

View File

@ -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()
)

View File

@ -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 name: String,//问候名称,非必填项
val who: String, //我是谁 val who: String, //我是谁
val toWho: String, //发送给谁 val toWho: String, //发送给谁

View File

@ -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>
)

View File

@ -1,9 +1,10 @@
package com.navinfo.volvo.repository package com.navinfo.volvo.repository
import com.navinfo.volvo.model.Message import com.navinfo.volvo.http.DefaultResponse
import com.navinfo.volvo.model.network.NetworkPostMessage import com.navinfo.volvo.model.messagelist.NetworkMessageListPost
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
import com.navinfo.volvo.util.NetResult import com.navinfo.volvo.util.NetResult
interface NetworkDataSource { interface NetworkDataSource {
suspend fun getCardList(message: NetworkPostMessage): NetResult<List<Message>> suspend fun getCardList(message: NetworkMessageListPost): NetResult<DefaultResponse<NetworkMessageListResponse>>
} }

View File

@ -1,15 +1,17 @@
package com.navinfo.volvo.repository 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.di.scope.IoDispatcher
import com.navinfo.volvo.model.Message import com.navinfo.volvo.database.entity.GreetingMessage
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.repository.service.NetworkService import com.navinfo.volvo.repository.service.NetworkService
import com.navinfo.volvo.tools.GsonUtil import com.navinfo.volvo.tools.GsonUtil
import com.navinfo.volvo.util.NetResult import com.navinfo.volvo.util.NetResult
import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.FormBody
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
import javax.inject.Inject import javax.inject.Inject
@ -17,17 +19,22 @@ import javax.inject.Inject
class NetworkDataSourceImp @Inject constructor( class NetworkDataSourceImp @Inject constructor(
private val netWorkService: NetworkService, private val netWorkService: NetworkService,
private val messageDao: GreetingMessageDao,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher @IoDispatcher private val ioDispatcher: CoroutineDispatcher
) : NetworkDataSource { ) : NetworkDataSource {
override suspend fun getCardList(message: NetworkPostMessage): NetResult<List<Message>> = override suspend fun getCardList(message: NetworkMessageListPost): NetResult<DefaultResponse<NetworkMessageListResponse>> =
withContext(ioDispatcher) { withContext(ioDispatcher) {
return@withContext try { 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) val result = netWorkService.queryCardListByApp(stringBody)
if (result.isSuccessful) { if (result.isSuccessful) {
val list = result.body() val body = result.body()
NetResult.Success(list) val list: MutableList<GreetingMessage> =
listOf(body!!.data!!.rows) as MutableList<GreetingMessage>
messageDao.insert(*list.map { it }.toTypedArray())
NetResult.Success(body)
} else { } else {
NetResult.Success(null) NetResult.Success(null)
} }

View File

@ -1,6 +1,7 @@
package com.navinfo.volvo.repository.service 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 okhttp3.RequestBody
import retrofit2.Response import retrofit2.Response
import retrofit2.http.Body import retrofit2.http.Body
@ -8,5 +9,5 @@ import retrofit2.http.POST
interface NetworkService { interface NetworkService {
@POST("/navi/cardDelivery/queryCardListByApp") @POST("/navi/cardDelivery/queryCardListByApp")
suspend fun queryCardListByApp(@Body body: RequestBody): Response<List<Message>> suspend fun queryCardListByApp(@Body body: RequestBody): Response<DefaultResponse<NetworkMessageListResponse>>
} }

View File

@ -2,7 +2,6 @@ package com.navinfo.volvo.ui
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
@ -11,10 +10,26 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController 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.bottomnavigation.BottomNavigationView
import com.google.android.material.dialog.MaterialAlertDialogBuilder 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.R
import com.navinfo.volvo.databinding.ActivityMainBinding import com.navinfo.volvo.databinding.ActivityMainBinding
import com.navinfo.volvo.utils.SystemConstant
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint @AndroidEntryPoint
@ -41,7 +56,8 @@ class MainActivity : AppCompatActivity() {
override fun onGranted(permissions: MutableList<String>, all: Boolean) { override fun onGranted(permissions: MutableList<String>, all: Boolean) {
if (!all) { if (!all) {
Toast.makeText(this@MainActivity, "获取部分权限成功,但部分权限未正常授予", Toast.LENGTH_SHORT).show() Toast.makeText(this@MainActivity, "获取部分权限成功,但部分权限未正常授予", Toast.LENGTH_SHORT)
.show()
return return
} }
// 在SD卡创建项目目录 // 在SD卡创建项目目录
@ -50,7 +66,8 @@ class MainActivity : AppCompatActivity() {
override fun onDenied(permissions: MutableList<String>, never: Boolean) { override fun onDenied(permissions: MutableList<String>, never: Boolean) {
if (never) { if (never) {
Toast.makeText(this@MainActivity, "永久拒绝授权,请手动授权文件读写权限", Toast.LENGTH_SHORT).show() Toast.makeText(this@MainActivity, "永久拒绝授权,请手动授权文件读写权限", Toast.LENGTH_SHORT)
.show()
// 如果是被永久拒绝就跳转到应用权限系统设置页面 // 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(this@MainActivity, permissions) XXPermissions.startPermissionActivity(this@MainActivity, permissions)
} else { } else {
@ -132,10 +149,11 @@ class MainActivity : AppCompatActivity() {
val consolePrinter: Printer = ConsolePrinter() // 通过 System.out 打印日志到控制台的打印器 val consolePrinter: Printer = ConsolePrinter() // 通过 System.out 打印日志到控制台的打印器
val filePrinter: Printer = FilePrinter.Builder("${SystemConstant.ROOT_PATH}/Logs") // 指定保存日志文件的路径 val filePrinter: Printer =
.fileNameGenerator(DateFileNameGenerator()) // 指定日志文件名生成器,默认为 ChangelessFileNameGenerator("log") FilePrinter.Builder("${SystemConstant.ROOT_PATH}/Logs") // 指定保存日志文件的路径
.backupStrategy(NeverBackupStrategy()) // 指定日志文件备份策略,默认为 FileSizeBackupStrategy(1024 * 1024) .fileNameGenerator(DateFileNameGenerator()) // 指定日志文件名生成器,默认为 ChangelessFileNameGenerator("log")
.build() .backupStrategy(NeverBackupStrategy()) // 指定日志文件备份策略,默认为 FileSizeBackupStrategy(1024 * 1024)
.build()
XLog.init( // 初始化 XLog XLog.init( // 初始化 XLog
config, // 指定日志配置,如果不指定,会默认使用 new LogConfiguration.Builder().build() config, // 指定日志配置,如果不指定,会默认使用 new LogConfiguration.Builder().build()

View File

@ -7,18 +7,18 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.navinfo.volvo.R import com.navinfo.volvo.R
import com.navinfo.volvo.model.Message import com.navinfo.volvo.database.entity.GreetingMessage
class MessageAdapter : RecyclerView.Adapter<MessageAdapter.MyViewHolder>() { 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) itemList.add(message)
notifyItemInserted(itemList.size - 1) notifyItemInserted(itemList.size - 1)
} }
fun setItem(messageList: MutableList<Message>){ fun setItem(messageList: MutableList<GreetingMessage>){
itemList = messageList itemList = messageList
notifyDataSetChanged() notifyDataSetChanged()
} }
@ -35,8 +35,8 @@ class MessageAdapter : RecyclerView.Adapter<MessageAdapter.MyViewHolder>() {
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val message = itemList[position] val message = itemList[position]
holder.toName.text = message.fromId holder.toName.text = message.toWho
holder.messageText.text = message.message holder.messageText.text = message.name
holder.sendTime.text = message.sendDate holder.sendTime.text = message.sendDate
} }

View File

@ -13,7 +13,7 @@ import com.easytools.tools.DateUtils
import com.easytools.tools.FileUtils import com.easytools.tools.FileUtils
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import com.navinfo.volvo.databinding.FragmentCameraBinding 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.navinfo.volvo.utils.SystemConstant
import com.otaliastudios.cameraview.CameraListener import com.otaliastudios.cameraview.CameraListener
import com.otaliastudios.cameraview.CameraView import com.otaliastudios.cameraview.CameraView

View File

@ -3,8 +3,9 @@ package com.navinfo.volvo.ui.fragments.home
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.navinfo.volvo.model.Message import com.navinfo.volvo.database.entity.GreetingMessage
import com.navinfo.volvo.model.network.NetworkPostMessage import com.navinfo.volvo.model.messagelist.NetworkMessageListPost
import com.navinfo.volvo.model.messagelist.NetworkMessageListResponse
import com.navinfo.volvo.repository.NetworkDataSource import com.navinfo.volvo.repository.NetworkDataSource
import com.navinfo.volvo.util.NetResult import com.navinfo.volvo.util.NetResult
import com.navinfo.volvo.util.asLiveData import com.navinfo.volvo.util.asLiveData
@ -18,18 +19,18 @@ class MessageViewModel @Inject constructor(
private val _isLoading = MutableLiveData<Boolean>() private val _isLoading = MutableLiveData<Boolean>()
val isLoading = _isLoading.asLiveData() val isLoading = _isLoading.asLiveData()
private val _messageList = MutableLiveData<List<Message>>() private val _messageList = MutableLiveData<List<GreetingMessage>>()
val messageList = _messageList.asLiveData() val messageList = _messageList.asLiveData()
fun getMessageList() { fun getMessageList() {
_isLoading.postValue(true) _isLoading.postValue(true)
viewModelScope.launch { viewModelScope.launch {
val messagePost = NetworkPostMessage(who = "北京测试", toWho = "volvo测试") val messagePost = NetworkMessageListPost(who = "北京测试", toWho = "volvo测试")
when (val result = repository.getCardList(messagePost)) { when (val result = repository.getCardList(messagePost)) {
is NetResult.Success -> { is NetResult.Success -> {
_isLoading.value = false _isLoading.value = false
if (result.data != null) { if (result.data != null) {
val list = result.data val list = (result.data.data as NetworkMessageListResponse).rows
_messageList.value = list _messageList.value = list
} }
} }

View File

@ -5,7 +5,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.navinfo.volvo.database.AppDatabase import com.navinfo.volvo.database.AppDatabase
import com.navinfo.volvo.model.User import com.navinfo.volvo.database.entity.User
import javax.inject.Inject import javax.inject.Inject
class LoginViewModel @Inject constructor(private val dataBase: AppDatabase) : ViewModel() { class LoginViewModel @Inject constructor(private val dataBase: AppDatabase) : ViewModel() {

View File

@ -25,11 +25,10 @@ import com.gredicer.datetimepicker.DateTimePickerFragment
import com.hjq.permissions.OnPermissionCallback import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions import com.hjq.permissions.XXPermissions
import com.navinfo.volvo.R
import com.navinfo.volvo.RecorderLifecycleObserver import com.navinfo.volvo.RecorderLifecycleObserver
import com.navinfo.volvo.databinding.FragmentObtainMessageBinding import com.navinfo.volvo.databinding.FragmentObtainMessageBinding
import com.navinfo.volvo.db.dao.entity.AttachmentType import com.navinfo.volvo.database.entity.AttachmentType
import com.navinfo.volvo.db.dao.entity.Message import com.navinfo.volvo.database.entity.GreetingMessage
import com.navinfo.volvo.ui.markRequiredInRed import com.navinfo.volvo.ui.markRequiredInRed
import com.navinfo.volvo.utils.EasyMediaFile import com.navinfo.volvo.utils.EasyMediaFile
import com.navinfo.volvo.utils.SystemConstant import com.navinfo.volvo.utils.SystemConstant
@ -65,13 +64,13 @@ class ObtainMessageFragment: Fragment() {
_binding = FragmentObtainMessageBinding.inflate(inflater, container, false) _binding = FragmentObtainMessageBinding.inflate(inflater, container, false)
val root: View = binding.root val root: View = binding.root
obtainMessageViewModel.setCurrentMessage(Message()) obtainMessageViewModel.setCurrentMessage(GreetingMessage())
obtainMessageViewModel?.getMessageLiveData()?.observe( obtainMessageViewModel?.getMessageLiveData()?.observe(
viewLifecycleOwner, Observer { viewLifecycleOwner, Observer {
// 初始化界面显示内容 // 初始化界面显示内容
if(it.title?.isNotEmpty() == true) if(it.name?.isNotEmpty() == true)
binding.tvMessageTitle?.setText(it.title) binding.tvMessageTitle?.setText(it.name)
if (it.sendDate?.isNotEmpty() == true) { if (it.sendDate?.isNotEmpty() == true) {
binding.btnSendTime.text = it.sendDate binding.btnSendTime.text = it.sendDate
} }
@ -131,7 +130,7 @@ class ObtainMessageFragment: Fragment() {
android.R.layout.simple_dropdown_item_1line, android.R.id.text1, sendToArray) android.R.layout.simple_dropdown_item_1line, android.R.id.text1, sendToArray)
binding.edtSendTo.onItemSelectedListener = object: OnItemSelectedListener { binding.edtSendTo.onItemSelectedListener = object: OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) { 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<*>?) { override fun onNothingSelected(p0: AdapterView<*>?) {
@ -287,7 +286,7 @@ class ObtainMessageFragment: Fragment() {
binding.btnObtainMessageConfirm.setOnClickListener { binding.btnObtainMessageConfirm.setOnClickListener {
// 检查当前输入数据 // 检查当前输入数据
val messageData = obtainMessageViewModel.getMessageLiveData().value val messageData = obtainMessageViewModel.getMessageLiveData().value
if (messageData?.title?.isEmpty() == true) { if (messageData?.name?.isEmpty() == true) {
val toolTipRelativeLayout = val toolTipRelativeLayout =
binding.ttTitle binding.ttTitle
val toolTip = ToolTip() val toolTip = ToolTip()
@ -328,7 +327,7 @@ class ObtainMessageFragment: Fragment() {
toolTipRelativeLayout.showToolTipForView(toolTip, binding.tvUploadPic) toolTipRelativeLayout.showToolTipForView(toolTip, binding.tvUploadPic)
} }
if (messageData?.fromId?.isEmpty()==true) { if (messageData?.who?.isEmpty()==true) {
val toolTipRelativeLayout = val toolTipRelativeLayout =
binding.ttSendFrom binding.ttSendFrom
val toolTip = ToolTip() val toolTip = ToolTip()
@ -338,7 +337,7 @@ class ObtainMessageFragment: Fragment() {
.withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW) .withAnimationType(ToolTip.AnimationType.FROM_MASTER_VIEW)
toolTipRelativeLayout.showToolTipForView(toolTip, binding.edtSendFrom) toolTipRelativeLayout.showToolTipForView(toolTip, binding.edtSendFrom)
} }
if (messageData?.toId?.isEmpty()==true) { if (messageData?.toWho?.isEmpty()==true) {
val toolTipRelativeLayout = val toolTipRelativeLayout =
binding.ttSendTo binding.ttSendTo
val toolTip = ToolTip() val toolTip = ToolTip()

View File

@ -3,12 +3,12 @@ package com.navinfo.volvo.ui.fragments.message
import androidx.lifecycle.* import androidx.lifecycle.*
import com.easytools.tools.ToastUtils import com.easytools.tools.ToastUtils
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import com.navinfo.volvo.db.dao.entity.Attachment import com.navinfo.volvo.database.entity.Attachment
import com.navinfo.volvo.db.dao.entity.AttachmentType import com.navinfo.volvo.database.entity.AttachmentType
import com.navinfo.volvo.db.dao.entity.Message import com.navinfo.volvo.database.entity.GreetingMessage
import com.navinfo.volvo.http.NavinfoVolvoCall import com.navinfo.volvo.http.NavinfoVolvoCall
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody import okhttp3.MultipartBody
import okhttp3.RequestBody import okhttp3.RequestBody
import java.io.File import java.io.File
@ -16,21 +16,21 @@ import java.util.*
class ObtainMessageViewModel: ViewModel() { class ObtainMessageViewModel: ViewModel() {
private val msgLiveData: MutableLiveData<Message> by lazy { private val msgLiveData: MutableLiveData<GreetingMessage> by lazy {
MutableLiveData<Message>() MutableLiveData<GreetingMessage>()
} }
fun setCurrentMessage(msg: Message) { fun setCurrentMessage(msg: GreetingMessage) {
msgLiveData.postValue(msg) msgLiveData.postValue(msg)
} }
fun getMessageLiveData(): MutableLiveData<Message> { fun getMessageLiveData(): MutableLiveData<GreetingMessage> {
return msgLiveData return msgLiveData
} }
// 更新消息标题 // 更新消息标题
fun updateMessageTitle(title: String) { fun updateMessageTitle(title: String) {
this.msgLiveData.value?.title = title this.msgLiveData.value?.name = title
this.msgLiveData.postValue(this.msgLiveData.value) this.msgLiveData.postValue(this.msgLiveData.value)
} }
@ -75,13 +75,13 @@ class ObtainMessageViewModel: ViewModel() {
// 更新发送人 // 更新发送人
fun updateMessageSendFrom(sendFrom: String) { fun updateMessageSendFrom(sendFrom: String) {
this.msgLiveData.value?.fromId = sendFrom this.msgLiveData.value?.who = sendFrom
this.msgLiveData.postValue(this.msgLiveData.value) this.msgLiveData.postValue(this.msgLiveData.value)
} }
// 更新接收人 // 更新接收人
fun updateMessageSendTo(sendTo: String) { fun updateMessageSendTo(sendTo: String) {
this.msgLiveData.value?.toId = sendTo this.msgLiveData.value?.toWho = sendTo
this.msgLiveData.postValue(this.msgLiveData.value) this.msgLiveData.postValue(this.msgLiveData.value)
} }
@ -96,14 +96,14 @@ class ObtainMessageViewModel: ViewModel() {
viewModelScope.launch { viewModelScope.launch {
try { try {
val requestFile: RequestBody = 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 body = MultipartBody.Part.createFormData("picture", attachmentFile.getName(), requestFile)
val result = NavinfoVolvoCall.getApi().uploadAttachment(body) val result = NavinfoVolvoCall.getApi().uploadAttachment(body)
XLog.d(result.code) XLog.d(result.code)
if (result.code == 200) { // 请求成功 if (result.code == 200) { // 请求成功
// 获取上传后的结果 // 获取上传后的结果
} else { } else {
ToastUtils.showToast(result.message) ToastUtils.showToast(result.msg)
} }
} catch (e: Exception) { } catch (e: Exception) {
ToastUtils.showToast(e.message) ToastUtils.showToast(e.message)