fix: 增加Realm依赖
This commit is contained in:
parent
80a42c8387
commit
56c5badcf0
@ -3,8 +3,8 @@ plugins {
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'kotlin-kapt'
|
||||
id 'com.google.dagger.hilt.android'
|
||||
id 'realm-android'
|
||||
}
|
||||
apply plugin: "realm-android"
|
||||
android {
|
||||
namespace 'com.navinfo.omqs'
|
||||
compileSdk 33
|
||||
|
@ -7,7 +7,7 @@ enum class StatusEnum(val status: Int) {
|
||||
ERROR(4), DONE(5), UPDATE(6)
|
||||
}
|
||||
|
||||
open class OfflineMapCityBean : RealmObject{
|
||||
open class OfflineMapCityBean{
|
||||
var id: String = ""
|
||||
var fileName: String = ""
|
||||
var name: String = ""
|
||||
|
@ -4,7 +4,7 @@ import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
|
||||
open class OfflineMapCityRealmObject(): RealmObject() {
|
||||
open class OfflineMapCityRealmObject(){
|
||||
@PrimaryKey
|
||||
var id: String = ""
|
||||
var fileName: String=""
|
||||
|
@ -9,11 +9,9 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.bean.LoginUserBean
|
||||
import com.navinfo.omqs.bean.OfflineMapCityRealmObject
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import kotlinx.coroutines.*
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import okio.IOException
|
||||
import java.io.File
|
||||
import java.math.BigInteger
|
||||
@ -64,7 +62,7 @@ class LoginViewModel(
|
||||
loginUser.value = LoginUserBean(username = "admin", password = "123456")
|
||||
}
|
||||
|
||||
fun initRealm() {
|
||||
private fun initRealm() {
|
||||
val password = "password".encodeToByteArray().copyInto(ByteArray(64))
|
||||
// 1110000011000010111001101110011011101110110111101110010011001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
Log.d("", "密码是: ${BigInteger(1, password).toString(2).padStart(64, '0')}")
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
<variable
|
||||
name="cityBean"
|
||||
type="com.navinfo.omqs.bean.OfflineMapCityBean" />
|
||||
type="com.navinfo.collect.library.data.entity.OfflineMapCityBean" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath "io.realm:realm-gradle-plugin:10.10.1"
|
||||
classpath "io.realm:realm-gradle-plugin:10.11.1"
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.navinfo.collect.library.data.entity
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
enum class StatusEnum(val status: Int) {
|
||||
NONE(0), WAITING(1), LOADING(2), PAUSE(3),
|
||||
ERROR(4), DONE(5), UPDATE(6)
|
||||
}
|
||||
|
||||
open class OfflineMapCityBean @JvmOverloads constructor(@PrimaryKey var id: String = "",
|
||||
var fileName: String = "",
|
||||
var name: String = "",
|
||||
var url: String = "",
|
||||
var version: Long = 0L,
|
||||
var fileSize: Long = 0L,
|
||||
var currentSize: Long = 0L,
|
||||
var status: Int =0) : RealmObject(){
|
||||
// status的转换对象
|
||||
var statusEnum:StatusEnum
|
||||
get() {
|
||||
return try {
|
||||
StatusEnum.values().find { it.status == status }!!
|
||||
} catch (e: IllegalArgumentException) {
|
||||
StatusEnum.NONE
|
||||
}
|
||||
}
|
||||
set(value) {
|
||||
status = value.status
|
||||
}
|
||||
|
||||
fun getFileSizeText(): String {
|
||||
return if (fileSize < 1024.0)
|
||||
"$fileSize B"
|
||||
else if (fileSize < 1048576.0)
|
||||
"%.2f K".format(fileSize / 1024.0)
|
||||
else if (fileSize < 1073741824.0)
|
||||
"%.2f M".format(fileSize / 1048576.0)
|
||||
else
|
||||
"%.2f M".format(fileSize / 1073741824.0)
|
||||
}
|
||||
|
||||
// constructor(){
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.navinfo.collect.library.data.entity
|
||||
|
||||
import io.realm.RealmModel
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
import io.realm.annotations.RealmClass
|
||||
|
||||
@RealmClass
|
||||
open class OfflineMapCityRealmObject: RealmModel {
|
||||
@PrimaryKey
|
||||
var id: String = ""
|
||||
var fileName: String=""
|
||||
var name: String = ""
|
||||
var url: String = ""
|
||||
var version: Long = 0
|
||||
var fileSize: Long = 0
|
||||
var currentSize:Long = 0
|
||||
var status:Int = 0
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
constructor(
|
||||
id: String,
|
||||
fileName: String,
|
||||
name: String,
|
||||
url: String,
|
||||
version: Long,
|
||||
fileSize: Long,
|
||||
currentSize: Long,
|
||||
status: Int
|
||||
) {
|
||||
this.id = id
|
||||
this.fileName = fileName
|
||||
this.name = name
|
||||
this.url = url
|
||||
this.version = version
|
||||
this.fileSize = fileSize
|
||||
this.currentSize = currentSize
|
||||
this.status = status
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user