Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
refactor: cleaning code before release v2.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rOmAiin062 committed Jan 8, 2019
1 parent cded477 commit 8be60aa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: ")
}
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/science/apolline/utils/QueryBDDAsyncTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QueryBDDAsyncTask(activity: SettingsActivity.DataErasePreferenceFragment)
//Prevent leak
private val weakActivity: WeakReference<Activity>
private var mActivity : SettingsActivity.DataErasePreferenceFragment
private var TO_MILLISECONDS : Int = 1000000

init{
weakActivity = WeakReference(activity.activity)
Expand All @@ -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
}
Expand All @@ -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()
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/science/apolline/utils/QuerySynchro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ class SettingsActivity : AppCompatPreferenceActivity() {
dateLastSyncTxt = view.findViewById<TextView>(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 {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@
<string name="pref_title_collect_data_frequency">Data collection</string>
<string name="pref_summary_collect_data_frequency">Data collection frequency</string>
<string-array name="pref_collect_data_frequency_titles">
<item>Toutes les secondes</item>
<item>Toutes les 2 secondes</item>
<item>Toutes les 5 secondes</item>
<item>Toutes les 10 secondes</item>
<item>Every second</item>
<item>Every 2 seconds</item>
<item>Every 5 seconds</item>
<item>Every 10 seconds</item>
</string-array>
<string-array name="pref_collect_data_frequency_values">
<item>1</item>
Expand Down

0 comments on commit 8be60aa

Please sign in to comment.