diff --git a/.idea/misc.xml b/.idea/misc.xml index 21e99e2dc0..cd77a1f062 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 3fb00628d9..17bee8a4c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,34 +27,34 @@ PASSWORD=xintai2018 RELEASE=false # 模块版本 ## 工程内模块 -MOGO_COMMONS_VERSION=1.2.1.11 -MOGO_UTILS_VERSION=1.2.1.11 -MAP_AMAP_VERSION=1.2.1.11 -MAP_AUTONAVI_VERSION=1.2.1.11 -MOGO_MAP_VERSION=1.2.1.11 -MOGO_MAP_API_VERSION=1.2.1.11 -MOGO_SERVICE_VERSION=1.2.1.11 -MOGO_SERVICE_API_VERSION=1.2.1.11 -MOGO_CONNECTION_VERSION=1.2.1.11 -MOGO_MODULE_APPS_VERSION=1.2.1.11 -MOGO_MODULE_NAVI_VERSION=1.2.1.11 -MOGO_MODULE_SHARE_VERSION=1.2.1.11 -MOGO_MODULE_COMMON_VERSION=1.2.1.11 -MOGO_MODULE_MAIN_VERSION=1.2.1.11 -MOGO_MODULE_MAP_VERSION=1.2.1.11 -MOGO_MODULE_SERVICE_VERSION=1.2.1.11 -MOGO_MODULE_EXTENSIONS_VERSION=1.2.1.11 -MOGO_MODULE_SEARCH_VERSION=1.2.1.11 -MOGO_MODULE_BACK_VERSION=1.2.1.11 -MOGO_MODULE_GPS_SIMULATOR_VERSION=1.2.1.11 -MOGO_MODULE_GPS_SIMULATOR_DEBUG_VERSION=1.2.1.11 -MOGO_MODULE_GPS_SIMULATOR_NOOP_VERSION=1.2.1.11 -MOGO_MODULE_AUTHORIZE_VERSION=1.2.1.11 -MOGO_MODULE_GUIDE_VERSION=1.2.1.11 -MOGO_MODULE_MEDIA_VERSION=1.2.1.11 +MOGO_COMMONS_VERSION=1.2.1.12 +MOGO_UTILS_VERSION=1.2.1.12 +MAP_AMAP_VERSION=1.2.1.12 +MAP_AUTONAVI_VERSION=1.2.1.12 +MOGO_MAP_VERSION=1.2.1.12 +MOGO_MAP_API_VERSION=1.2.1.12 +MOGO_SERVICE_VERSION=1.2.1.12 +MOGO_SERVICE_API_VERSION=1.2.1.12 +MOGO_CONNECTION_VERSION=1.2.1.12 +MOGO_MODULE_APPS_VERSION=1.2.1.12 +MOGO_MODULE_NAVI_VERSION=1.2.1.12 +MOGO_MODULE_SHARE_VERSION=1.2.1.12 +MOGO_MODULE_COMMON_VERSION=1.2.1.13 +MOGO_MODULE_MAIN_VERSION=1.2.1.12 +MOGO_MODULE_MAP_VERSION=1.2.1.12 +MOGO_MODULE_SERVICE_VERSION=1.2.1.12 +MOGO_MODULE_EXTENSIONS_VERSION=1.2.1.12 +MOGO_MODULE_SEARCH_VERSION=1.2.1.12 +MOGO_MODULE_BACK_VERSION=1.2.1.12 +MOGO_MODULE_GPS_SIMULATOR_VERSION=1.2.1.12 +MOGO_MODULE_GPS_SIMULATOR_DEBUG_VERSION=1.2.1.12 +MOGO_MODULE_GPS_SIMULATOR_NOOP_VERSION=1.2.1.12 +MOGO_MODULE_AUTHORIZE_VERSION=1.2.1.12 +MOGO_MODULE_GUIDE_VERSION=1.2.1.12 +MOGO_MODULE_MEDIA_VERSION=1.2.1.12 -MOGO_MODULE_MAIN_LAUNCHER_VERSION = 1.2.1.11 -MOGO_MODULE_MAIN_INDEPENDENT_VERSION = 1.2.1.11 +MOGO_MODULE_MAIN_LAUNCHER_VERSION = 1.2.1.12 +MOGO_MODULE_MAIN_INDEPENDENT_VERSION = 1.2.1.12 MOGO_MODULE_OBU_VERSION = 1.2.1.10-SNAPSHOT diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/EventPanelModuleProvider.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/EventPanelModuleProvider.kt index 3844f9ac65..bc03a308b7 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/EventPanelModuleProvider.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/EventPanelModuleProvider.kt @@ -16,6 +16,7 @@ import com.mogo.utils.logger.Logger import com.zhidao.mogo.module.event.panel.EventPanelConstants.MODULE_NAME import com.zhidao.mogo.module.event.panel.EventPanelConstants.PATH_NAME import com.zhidao.mogo.module.event.panel.fragment.EventPanelFragment +import com.zhidao.mogo.module.event.panel.util.MogoApiManager /** * 事件面板provider @@ -31,6 +32,7 @@ class EventPanelModuleProvider : IEventPanelProvider { */ override fun init(context: Context) { Logger.d(MODULE_NAME, "模块初始化====") + MogoApiManager.init(context) } override fun createFragment(context: Context, data: Bundle?): Fragment? { diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/bean/TripRecord.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/bean/TripRecord.kt index d5405f99f6..5600c1a9fd 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/bean/TripRecord.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/bean/TripRecord.kt @@ -9,10 +9,9 @@ import androidx.room.PrimaryKey * @author */ @Entity -class TripRecord { - @PrimaryKey(autoGenerate = true) - var id:Int = 0 - var canUsed:Boolean = true - var isUsed:Boolean = false - var entity:String? = null -} \ No newline at end of file +data class TripRecord(@PrimaryKey(autoGenerate = true) + var id: Int = 0, + var canUsed: Boolean = true, + var isUsed: Boolean = false, + var entity: String? = null, + var recordTime: Long = 0) \ No newline at end of file diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDao.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDao.kt index bf25058a49..f67c4e7c61 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDao.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDao.kt @@ -2,10 +2,12 @@ package com.zhidao.mogo.module.event.panel.dao import androidx.room.* import com.zhidao.mogo.module.event.panel.bean.TripRecord +import io.reactivex.Flowable @Dao interface TripRecordDao { -// fun getAllTripRecord():List + @Query(value = "SELECT * FROM TripRecord") + fun getAllTripRecord():Flowable> @Insert fun insert(vararg tripRecord: TripRecord) diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDatabase.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDatabase.kt index dd4f77900e..92dafed8a4 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDatabase.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/dao/TripRecordDatabase.kt @@ -9,11 +9,17 @@ import com.zhidao.mogo.module.event.panel.bean.TripRecord @Database(entities = [TripRecord::class], version = 1, exportSchema = false) abstract class TripRecordDatabase : RoomDatabase() { companion object{ - const val DB_NAME = "TripRecordDatabase.db" + private var instance:TripRecordDatabase? = null + fun getInstance(context: Context):TripRecordDatabase{ + if (instance == null) { + synchronized(TripRecordDatabase::class.java) { + if (instance == null) { + instance = Room.databaseBuilder(context, TripRecordDatabase::class.java, "TripRecordDatabase.db").build() + } + } + } + return instance!! + } } - fun create(context: Context):TripRecordDatabase { - return Room.databaseBuilder(context, TripRecordDatabase::class.java, DB_NAME).build() - } - abstract fun getTripRecordDao():TripRecordDao } \ No newline at end of file diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/fragment/TripRecordFragment.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/fragment/TripRecordFragment.kt index b72d062d20..ba2b47b00b 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/fragment/TripRecordFragment.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/fragment/TripRecordFragment.kt @@ -1,31 +1,55 @@ package com.zhidao.mogo.module.event.panel.fragment +import android.util.Log import com.mogo.commons.mvp.MvpFragment import com.zhidao.mogo.module.event.panel.R +import com.zhidao.mogo.module.event.panel.bean.TripRecord import com.zhidao.mogo.module.event.panel.presenter.TripRecordPresenter +import kotlinx.android.synthetic.main.module_event_panel_fragment_trip_record.* +import kotlin.random.Random /** * 出行动态fragment */ +const val TAG = "TripRecordFragment" class TripRecordFragment: MvpFragment() { - /** - * 布局资源 - * - * @return - */ + private val tripRecordList = ArrayList() override fun getLayoutId(): Int = R.layout.module_event_panel_fragment_trip_record - /** - * 初始化控件,必须在初始化完成之后才可以实例化presenter,避免 - * presenter 生命周期错乱 - */ override fun initViews() { + btnInsert.setOnClickListener { + val tripRecord = TripRecord() + val random = Random.nextInt(10) + tripRecord.entity = "entity: $random" + tripRecord.recordTime = System.currentTimeMillis() + tripRecordList.add(tripRecord) + mPresenter.insertTripRecord(tripRecord) + Log.d(TAG, "insert over: $tripRecord") + } + + btnDelete.setOnClickListener { + val random = Random.nextInt(tripRecordList.size) + val tripRecord = tripRecordList.removeAt(random) + mPresenter.deleteTripRecords(tripRecord) + Log.d(TAG, "delete over: $tripRecord") + } + + btnUpdate.setOnClickListener { + val random = Random.nextInt(tripRecordList.size) + val tripRecord = tripRecordList[random] + Log.d(TAG,"before update: $tripRecord") + tripRecord.recordTime = System.currentTimeMillis() + mPresenter.updateTripRecords(tripRecord) + Log.d(TAG, "update over: $tripRecord") + } + + btnQuery.setOnClickListener { + Log.d(TAG, "local list: $tripRecordList") + mPresenter.queryAllTripRecord() + } + + } - /** - * 创建 presenter 实例 - * - * @return - */ override fun createPresenter(): TripRecordPresenter = TripRecordPresenter(this) } \ No newline at end of file diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/presenter/TripRecordPresenter.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/presenter/TripRecordPresenter.kt index de0347a980..f6f3478c80 100644 --- a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/presenter/TripRecordPresenter.kt +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/presenter/TripRecordPresenter.kt @@ -1,15 +1,35 @@ package com.zhidao.mogo.module.event.panel.presenter -import com.alibaba.android.arouter.launcher.ARouter +import android.util.Log import com.mogo.commons.mvp.Presenter -import com.mogo.service.IMogoServiceApis -import com.mogo.service.MogoServicePaths +import com.zhidao.mogo.module.event.panel.bean.TripRecord +import com.zhidao.mogo.module.event.panel.dao.TripRecordDatabase import com.zhidao.mogo.module.event.panel.fragment.TripRecordFragment +import io.reactivex.schedulers.Schedulers +import kotlin.concurrent.thread class TripRecordPresenter(view: TripRecordFragment) : Presenter(view) { - private val serviceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(view.context) as IMogoServiceApis - - init { - + fun queryAllTripRecord() { + val disposable = TripRecordDatabase.getInstance(context).getTripRecordDao().getAllTripRecord().subscribeOn(Schedulers.io()).subscribe { + Log.d("TripRecordFragment", "db query: $it") + } } -} \ No newline at end of file + + fun insertTripRecord(vararg records: TripRecord) { + thread { + TripRecordDatabase.getInstance(context).getTripRecordDao().insert(*records) + } + } + + fun updateTripRecords(vararg records: TripRecord) { + thread { + TripRecordDatabase.getInstance(context).getTripRecordDao().update(*records) + } + } + + fun deleteTripRecords(vararg records: TripRecord) { + thread { + TripRecordDatabase.getInstance(context).getTripRecordDao().delete(*records) + } + } +} diff --git a/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/util/MogoApiManager.kt b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/util/MogoApiManager.kt new file mode 100644 index 0000000000..d4d52b3c2d --- /dev/null +++ b/modules/mogo-module-event-panel/src/main/java/com/zhidao/mogo/module/event/panel/util/MogoApiManager.kt @@ -0,0 +1,14 @@ +package com.zhidao.mogo.module.event.panel.util + +import android.content.Context +import com.alibaba.android.arouter.launcher.ARouter +import com.mogo.service.IMogoServiceApis +import com.mogo.service.MogoServicePaths + +object MogoApiManager { + lateinit var serviceApis:IMogoServiceApis + + fun init(context: Context) { + serviceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis + } +} \ No newline at end of file diff --git a/modules/mogo-module-event-panel/src/main/res/layout/module_event_panel_fragment_event_panel.xml b/modules/mogo-module-event-panel/src/main/res/layout/module_event_panel_fragment_event_panel.xml index 2088b87141..c3858db7bc 100644 --- a/modules/mogo-module-event-panel/src/main/res/layout/module_event_panel_fragment_event_panel.xml +++ b/modules/mogo-module-event-panel/src/main/res/layout/module_event_panel_fragment_event_panel.xml @@ -2,8 +2,7 @@ + android:layout_height="match_parent"> @@ -12,4 +13,49 @@ android:text="Trip Record" android:textColor="#fff" android:textSize="40sp" /> + +