From 8be60aac76d7322aeb938fca7fd9f39c5efd947c Mon Sep 17 00:00:00 2001 From: romaiin062 Date: Tue, 8 Jan 2019 16:15:26 +0100 Subject: [PATCH] refactor: cleaning code before release v2.4.6 --- .../science/apolline/service/sensor/IOIOService.kt | 3 ++- .../service/synchronisation/SyncInfluxDBJob.kt | 8 ++++---- .../java/science/apolline/utils/QueryBDDAsyncTask.kt | 12 ++++++------ .../main/java/science/apolline/utils/QuerySynchro.kt | 2 -- .../apolline/view/activity/SettingsActivity.kt | 2 -- app/src/main/res/values/strings.xml | 8 ++++---- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/science/apolline/service/sensor/IOIOService.kt b/app/src/main/java/science/apolline/service/sensor/IOIOService.kt index d3d933c..1dbb86e 100644 --- a/app/src/main/java/science/apolline/service/sensor/IOIOService.kt +++ b/app/src/main/java/science/apolline/service/sensor/IOIOService.kt @@ -59,6 +59,7 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { private var DEVICE_NAME = "Apolline00" private var DEVICE_UUID = "ffffffff-ffff-ffff-ffff-ffffffffffff" private var COLLECT_DATA_FREQ: Int = 1 + private var TO_MILLISECONDS: Int = 1000 override fun createIOIOLooper(): IOIOLooper { @@ -159,7 +160,7 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { setServiceStatus(false) error("Unable to start IOIOService: " + e.printStackTrace()) } - Thread.sleep((COLLECT_DATA_FREQ * 1000).toLong()) + Thread.sleep((COLLECT_DATA_FREQ * TO_MILLISECONDS).toLong()) info("Position Hash :" + position.geohash) persistData(data, position) setServiceStatus(true) diff --git a/app/src/main/java/science/apolline/service/synchronisation/SyncInfluxDBJob.kt b/app/src/main/java/science/apolline/service/synchronisation/SyncInfluxDBJob.kt index 170e602..50c65c1 100644 --- a/app/src/main/java/science/apolline/service/synchronisation/SyncInfluxDBJob.kt +++ b/app/src/main/java/science/apolline/service/synchronisation/SyncInfluxDBJob.kt @@ -19,8 +19,6 @@ import science.apolline.service.database.TimestampSyncDao import science.apolline.service.networks.ApiUtils import science.apolline.utils.CheckUtility import science.apolline.utils.CheckUtility.isNetworkConnected -import java.text.SimpleDateFormat -import java.util.* /** * Created by sparow on 19/01/2018. @@ -36,6 +34,8 @@ class SyncInfluxDBJob : Job(Params(PRIORITY) private lateinit var timestampModel: TimestampSyncDao private var SYNC_MOD = 2 // Wi-Fi only private lateinit var mPrefs: SharedPreferences + private var TO_MILLISECONDS: Int = 1000000 + override fun onAdded() { info("onAdded: ") } @@ -88,7 +88,7 @@ class SyncInfluxDBJob : Job(Params(PRIORITY) var t = TimestampSync(System.currentTimeMillis()) val lastSyncDate: Long = timestampModel.getLastSync() - var nbUnSynced: Long = sensorModel.getSensorNotSyncCountByDate(t.date * 1000000, lastSyncDate * 1000000) + var nbUnSynced: Long = sensorModel.getSensorNotSyncCountByDate(t.date * TO_MILLISECONDS, lastSyncDate * TO_MILLISECONDS) info("actualDate ${t.date}") info("last sync = $lastSyncDate") @@ -101,7 +101,7 @@ class SyncInfluxDBJob : Job(Params(PRIORITY) for (i in 1..attempt) { //val dataNotSync = sensorModel.getUnSync(MAX_LENGTH) - val dataNotSync = sensorModel.getUnSyncByDate(t.date * 1000000 ,lastSyncDate * 1000000 ,MAX_LENGTH) + val dataNotSync = sensorModel.getUnSyncByDate(t.date * TO_MILLISECONDS ,lastSyncDate * TO_MILLISECONDS ,MAX_LENGTH) if (dataNotSync.isNotEmpty()) { info("UnSync to sync is :" + dataNotSync.size) diff --git a/app/src/main/java/science/apolline/utils/QueryBDDAsyncTask.kt b/app/src/main/java/science/apolline/utils/QueryBDDAsyncTask.kt index 3320dd0..2a4334b 100644 --- a/app/src/main/java/science/apolline/utils/QueryBDDAsyncTask.kt +++ b/app/src/main/java/science/apolline/utils/QueryBDDAsyncTask.kt @@ -13,6 +13,7 @@ class QueryBDDAsyncTask(activity: SettingsActivity.DataErasePreferenceFragment) //Prevent leak private val weakActivity: WeakReference private var mActivity : SettingsActivity.DataErasePreferenceFragment + private var TO_MILLISECONDS : Int = 1000000 init{ weakActivity = WeakReference(activity.activity) @@ -23,12 +24,13 @@ class QueryBDDAsyncTask(activity: SettingsActivity.DataErasePreferenceFragment) protected override fun doInBackground(vararg params:String):Int { val sensorModel = AppDatabase.getInstance(mActivity.context).sensorDao() val timestampSyncDao = AppDatabase.getInstance(mActivity.context).timestampSyncDao() - when(params[0]) + var arg0 = params[0] + when(arg0) { "getSensorCount" -> return sensorModel.getSensorCount().toInt() - "getSensorSyncCount" -> return sensorModel.getSensorSyncCountByDate(timestampSyncDao.getLastSync() * 1000000).toInt() - "getSensorNotSyncCount" -> return sensorModel.getSensorNotSyncCountByDate(timestampSyncDao.getLastSync() * 1000000).toInt() - "deleteDataSync" -> sensorModel.deleteDataSyncByDate(timestampSyncDao.getLastSync() * 1000000) + "getSensorSyncCount" -> return sensorModel.getSensorSyncCountByDate(timestampSyncDao.getLastSync() * TO_MILLISECONDS).toInt() + "getSensorNotSyncCount" -> return sensorModel.getSensorNotSyncCountByDate(timestampSyncDao.getLastSync() * TO_MILLISECONDS).toInt() + "deleteDataSync" -> sensorModel.deleteDataSyncByDate(timestampSyncDao.getLastSync() * TO_MILLISECONDS) else -> return 0 } @@ -37,7 +39,5 @@ class QueryBDDAsyncTask(activity: SettingsActivity.DataErasePreferenceFragment) protected override fun onPostExecute(countSyncData:Int) { val activity = weakActivity.get() ?: return - Log.i("","Count Data Sync : " + countSyncData.toString()) - //activity.onBackPressed() } } \ No newline at end of file diff --git a/app/src/main/java/science/apolline/utils/QuerySynchro.kt b/app/src/main/java/science/apolline/utils/QuerySynchro.kt index d774298..a37e93f 100644 --- a/app/src/main/java/science/apolline/utils/QuerySynchro.kt +++ b/app/src/main/java/science/apolline/utils/QuerySynchro.kt @@ -32,7 +32,5 @@ class QuerySynchro(activity: SettingsActivity.DataErasePreferenceFragment) : Asy protected override fun onPostExecute(countSyncData:Long) { val activity = weakActivity.get() ?: return - Log.i("","GetLastSync : " + countSyncData.toString()) - //activity.onBackPressed() } } diff --git a/app/src/main/java/science/apolline/view/activity/SettingsActivity.kt b/app/src/main/java/science/apolline/view/activity/SettingsActivity.kt index c2cd4a1..a9a60c8 100644 --- a/app/src/main/java/science/apolline/view/activity/SettingsActivity.kt +++ b/app/src/main/java/science/apolline/view/activity/SettingsActivity.kt @@ -277,8 +277,6 @@ class SettingsActivity : AppCompatPreferenceActivity() { dateLastSyncTxt = view.findViewById(R.id.date_last_sync) var dateLastSync = QuerySynchro(this).execute("getLastSync").get() dateLastSyncTxt.setText(Date(dateLastSync).toString()) - - Toast.makeText(view.context, dateLastSync.toString(), Toast.LENGTH_LONG).show() } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e186ec8..31c7950 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -128,10 +128,10 @@ Data collection Data collection frequency - Toutes les secondes - Toutes les 2 secondes - Toutes les 5 secondes - Toutes les 10 secondes + Every second + Every 2 seconds + Every 5 seconds + Every 10 seconds 1