From 979d9cff22806f213b420452ab4a68fcbaf021b6 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 31 五月 2021 17:43:49 +0800
Subject: [PATCH] 1. 修复多项可能引起空指针崩溃的bug; 2. 新建子任务时默认执行人员从全体人员改为当前用户; 3. 新建子任务时默认执行时间强制固定为总任务对应的时段内,确保子任务执行时间不会超出总任务范围。

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