Commit 5f1a0bb8 authored by 王雷's avatar 王雷

新增push数据库

parent b79ec945
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
buildscript { buildscript {
ext.kotlin_version = '1.3.60' ext.kotlin_version = '1.3.60'
ext.lintVersion = '26.5.0' ext.lintVersion = '26.5.0'
ext.lifecycle_version = "2.2.5"
repositories { repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// 阿里云镜像 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// 阿里云镜像
......
...@@ -2,6 +2,7 @@ apply plugin: 'com.android.library' ...@@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: "com.whl.gradle-publish-plugin" apply plugin: "com.whl.gradle-publish-plugin"
apply plugin: 'kotlin-kapt'
android { android {
compileSdkVersion 29 compileSdkVersion 29
...@@ -47,10 +48,22 @@ dependencies { ...@@ -47,10 +48,22 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.tencent.mars:mars-xlog:1.2.4' implementation 'com.tencent.mars:mars-xlog:1.2.4'
// For Kotlin use kapt instead of annotationProcessor (注意这个注释)
kapt "androidx.room:room-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$lifecycle_version"
kapt "androidx.room:room-compiler:$lifecycle_version"
implementation "androidx.room:room-ktx:$lifecycle_version"
api "androidx.lifecycle:lifecycle-extensions:2.2.0"
api "androidx.lifecycle:lifecycle-runtime:2.2.0"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.2.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0"
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
api "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
} }
group 'com.qmai.android.log' group 'com.qmai.android.log'
version '1.0.0-SNAPSHOT' version '1.0.1-SNAPSHOT'
gradlePublish { gradlePublish {
......
...@@ -29,7 +29,7 @@ class LogInit private constructor() { ...@@ -29,7 +29,7 @@ class LogInit private constructor() {
logConfig.logdir = cachePath logConfig.logdir = cachePath
logConfig.nameprefix = "log" logConfig.nameprefix = "log"
logConfig.pubkey = ""; logConfig.pubkey = "";
logConfig.compressmode = Xlog.ZLIB_MODE; logConfig.compressmode = Xlog.ZLIB_MODE
logConfig.compresslevel = 0 logConfig.compresslevel = 0
logConfig.cachedir = cachePath logConfig.cachedir = cachePath
logConfig.cachedays = 0 logConfig.cachedays = 0
......
...@@ -3,7 +3,7 @@ package com.qimai.log ...@@ -3,7 +3,7 @@ package com.qimai.log
import android.os.Parcelable import android.os.Parcelable
/** /**
* @tag 名字 * @tag 文件名字
*/ */
class UploadConfig(var tag: String): java.io.Serializable { class UploadConfig(var tag: String): java.io.Serializable {
......
package com.qimai.log.database
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/**
* 获取数据库操作类
*/
class AppDataBaseVm(application: Application) : AndroidViewModel(application) {
private val mDataBse: PushNotifiInfoDao by lazy {
PushNotifiDataBase.getDatabase(application).pushInfoDao()
}
fun insertPushInfo(notifiInfo: PushNotifiInfo) {
viewModelScope.launch(Dispatchers.IO) {
mDataBse.insert(notifiInfo)
}
}
fun updatePushInfo(msg_id: String, status: Boolean, errorMsg: String? = null) {
viewModelScope.launch(Dispatchers.IO) {
mDataBse.updateStatus(msg_id, status, errorMsg)
}
}
}
\ No newline at end of file
package com.qimai.log.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
/**
*
*/
@Database(entities = [PushNotifiInfo::class], version = 1, exportSchema = false)
abstract class PushNotifiDataBase : RoomDatabase() {
abstract fun pushInfoDao(): PushNotifiInfoDao
companion object {
// Singleton prevents multiple instances of database opening at the
// same time.
@Volatile
private var INSTANCE: PushNotifiDataBase? = null
fun getDatabase(context: Context): PushNotifiDataBase {
val tempInstance = INSTANCE
if (tempInstance != null) {
return tempInstance
}
synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
PushNotifiDataBase::class.java,
"push_database"
).build()
INSTANCE = instance
return instance
}
}
}
}
\ No newline at end of file
package com.qimai.log.database
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "push_info")
data class PushNotifiInfo @JvmOverloads
constructor(
@PrimaryKey @ColumnInfo(name = "msg_id") val msg_id: String, //消息id
@ColumnInfo(name = "status") var status: Boolean, // 状态
@ColumnInfo(name = "error_msg") var errorMsg: String? = null, //错误原因
@ColumnInfo(name = "push_type") val pushType: String, //用的什么推送
@ColumnInfo(name = "rawText") var rawText: String? = null, //原始信息
@ColumnInfo(name = "time") var time: String? = null, //格式化时间
@ColumnInfo(name = "device_id") var deviceId: String? = null, //推送的devicedId
@ColumnInfo(name = "model") var model: String? = null, //手机型号
@ColumnInfo(name = "app_version") var version: String? = null, //app版本
@ColumnInfo(name = "time_stamp")var timeStamp:String?=null //时间戳
) {
}
\ No newline at end of file
package com.qimai.log.database
import androidx.room.*
/**
* 数据库操作类
*/
@Dao
interface PushNotifiInfoDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(word: PushNotifiInfo)
@Query("update push_info set status= :status ,error_msg = :errorMsg where msg_id=:msg_id")
suspend fun updateStatus(msg_id: String, status: Boolean,errorMsg:String?=null)
}
\ No newline at end of file
package com.qimai.android.tools
import android.content.res.Resources
import android.util.TypedValue
//float值转为sp像素
val Float.sp
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
Resources.getSystem().displayMetrics
)
//float像素值转为dp
val Float.dp
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
this,
Resources.getSystem().displayMetrics
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment