From e3864138492d1d3280710a1ba7162d9dd7542404 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 28 八月 2020 18:22:16 +0800
Subject: [PATCH] 1. 新增问题和删除修改功能(调试中) 2. 轨迹记录功能开放为所有类型的场景都记录
---
app/src/main/java/cn/flightfeather/thirdapp/common/database/DbFactory.kt | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/cn/flightfeather/thirdapp/common/database/DbFactory.kt b/app/src/main/java/cn/flightfeather/thirdapp/common/database/DbFactory.kt
index d46e875..ce71fa6 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/common/database/DbFactory.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/common/database/DbFactory.kt
@@ -8,24 +8,32 @@
* @author riku
* Date: 2019/5/16
*/
-class DbFactory private constructor(application: CommonApplication){
+class DbFactory private constructor(private val application: CommonApplication){
+
+ private var daoSession: DaoSession? = null
+
+ init {
+ daoSession = application.daoSession
+ }
companion object {
@Volatile
- private lateinit var daoSession: DaoSession
+ private var mDbFactory: DbFactory? = null
//鏁版嵁搴撳垵濮嬪寲
@JvmStatic
@Synchronized
fun init(application: CommonApplication) {
- daoSession = application.daoSession
+ if (mDbFactory == null) {
+ mDbFactory = DbFactory(application)
+ }
}
//鑾峰彇鏁版嵁搴撴搷浣滃璞aoSession
fun getGreenDaoObservable(): Observable<DaoSession> {
return Observable.create { emitter ->
- daoSession.let {
+ mDbFactory?.daoSession?.let {
emitter.onNext(it)
emitter.onComplete()
}
@@ -33,7 +41,10 @@
}
fun getInstance(): DaoSession {
- return daoSession
+ if (mDbFactory == null) {
+ mDbFactory = DbFactory(CommonApplication.getInstance())
+ }
+ return mDbFactory!!.daoSession!!
}
}
}
\ No newline at end of file
--
Gitblit v1.9.3