[Feat]全览模式展示新基建图标
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.util.*
|
||||
|
||||
@Entity(tableName = "t_device")
|
||||
data class Infrastructure(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id")
|
||||
var id: Int,
|
||||
|
||||
@ColumnInfo(name = "category")
|
||||
var category: Int,
|
||||
|
||||
@ColumnInfo(name = "ip")
|
||||
var ip: String?,
|
||||
|
||||
@ColumnInfo(name = "lon")
|
||||
var lon: String?,
|
||||
|
||||
@ColumnInfo(name = "lat")
|
||||
var lat: String?,
|
||||
|
||||
@ColumnInfo(name = "heading")
|
||||
var heading: Int,
|
||||
|
||||
@ColumnInfo(name = "geohash")
|
||||
var geoHash: String?
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
class OverViewManager private constructor() {
|
||||
|
||||
private object Holder {
|
||||
val INSTANCE = OverViewManager()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
Holder.INSTANCE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface OverviewDao {
|
||||
// 0表示摄像头,8表示红绿灯
|
||||
@Query("SELECT * FROM t_device WHERE category = :category")
|
||||
suspend fun listInfStructures(category: Int): List<Infrastructure>
|
||||
|
||||
@Query("SELECT * FROM t_device")
|
||||
suspend fun listAllInfStructures(): List<Infrastructure>
|
||||
|
||||
@Query("UPDATE t_device SET geohash = :geoHash WHERE id = :id")
|
||||
suspend fun updateGeoHash(id: Int, geoHash: String)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [Infrastructure::class], version = 1, exportSchema = false)
|
||||
abstract class OverviewDb: RoomDatabase() {
|
||||
abstract fun overviewDao(): OverviewDao
|
||||
|
||||
companion object {
|
||||
private const val DB_PATH = "database/t_device.db"
|
||||
private const val INTERNAL_DB_NAME = "t_device.db"
|
||||
|
||||
private var db: OverviewDb? = null
|
||||
|
||||
fun getDb(context: Context): OverviewDb {
|
||||
if (db == null) {
|
||||
db = Room.databaseBuilder(context.applicationContext, OverviewDb::class.java, INTERNAL_DB_NAME)
|
||||
.createFromAsset(DB_PATH)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
return db!!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
|
||||
fun <T : ViewModel> AppCompatActivity.obtainViewModel(viewModelClass: Class<T>) =
|
||||
ViewModelProviders.of(this, ViewModelFactory.getInstance(application)).get(viewModelClass)
|
||||
|
||||
fun <T : ViewModel> Fragment.obtainViewModel(viewModelClass: Class<T>) =
|
||||
ViewModelProviders.of(this, ViewModelFactory.getInstance(AbsMogoApplication.getApp())).get(viewModelClass)
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mogo.eagle.core.function.overview
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.mogo.eagle.core.function.overview.vm.OverViewModel
|
||||
|
||||
class ViewModelFactory private constructor(
|
||||
private val overviewDao: OverviewDao
|
||||
) : ViewModelProvider.NewInstanceFactory() {
|
||||
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>) =
|
||||
with(modelClass) {
|
||||
when {
|
||||
isAssignableFrom(OverViewModel::class.java) ->
|
||||
OverViewModel(overviewDao)
|
||||
else ->
|
||||
throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}")
|
||||
}
|
||||
} as T
|
||||
|
||||
companion object {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Volatile private var INSTANCE: ViewModelFactory? = null
|
||||
|
||||
fun getInstance(application: Application) =
|
||||
INSTANCE ?: synchronized(ViewModelFactory::class.java) {
|
||||
INSTANCE ?: ViewModelFactory(
|
||||
OverviewDb.getDb(application).overviewDao())
|
||||
.also { INSTANCE = it }
|
||||
}
|
||||
|
||||
@VisibleForTesting fun destroyInstance() {
|
||||
INSTANCE = null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.mogo.eagle.core.function.overview.vm
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.*
|
||||
import com.mogo.eagle.core.function.overview.Infrastructure
|
||||
import com.mogo.eagle.core.function.overview.OverviewDao
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.lang.Exception
|
||||
|
||||
class OverViewModel(
|
||||
private val overviewDao: OverviewDao
|
||||
) : ViewModel() {
|
||||
private val _infStructures = MutableLiveData<List<Infrastructure>>()
|
||||
val infStructures
|
||||
get() = _infStructures
|
||||
|
||||
private val _infStructuresMap = _infStructures
|
||||
.switchMap { infStructures ->
|
||||
liveData {
|
||||
val map = HashMap<String, ArrayList<Infrastructure>>()
|
||||
infStructures.forEach {
|
||||
val geoHash = it.geoHash
|
||||
if (geoHash == null) {
|
||||
return@forEach
|
||||
} else {
|
||||
if (!map.containsKey(geoHash)) {
|
||||
val list = ArrayList<Infrastructure>()
|
||||
list.add(it)
|
||||
map[geoHash] = list
|
||||
} else {
|
||||
map[geoHash]?.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
emit(map)
|
||||
}
|
||||
}
|
||||
val infStructuresMap
|
||||
get() = _infStructuresMap
|
||||
|
||||
fun fetchInfStructures() {
|
||||
viewModelScope.launch {
|
||||
val data = try {
|
||||
// 只查找摄像头
|
||||
overviewDao.listInfStructures(0)
|
||||
// overviewDao.listAllInfStructures()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.e("cff", "${e.cause}${e.message}")
|
||||
null
|
||||
}
|
||||
data?.let {
|
||||
_infStructures.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateGeoHash(id: Int, geoHash: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
overviewDao.updateGeoHash(id, geoHash)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.e("cff", "${e.cause}${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Reference in New Issue
Block a user