diff --git a/.travis.yml b/.travis.yml index 881e7bd..98eee96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_install: - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" - ls -all - - openssl aes-256-cbc -K $encrypted_8365e54d34ef_key -iv $encrypted_8365e54d34ef_iv -in ${TRAVIS_BUILD_DIR}/app/google-services.json.enc -out ${TRAVIS_BUILD_DIR}/app/google-services.json -d + - openssl aes-256-cbc -K $encrypted_1f0900b4d867_key -iv $encrypted_1f0900b4d867_iv -in ${TRAVIS_BUILD_DIR}/app/google-services.json.enc -out ${TRAVIS_BUILD_DIR}/app/google-services.json -d - cp local.properties.ci local.properties - docker pull influxdb - docker run --name=influxdb -d -p 127.0.0.1:8086:8086 influxdb diff --git a/app/google-services.json.enc b/app/google-services.json.enc index 89aef4b..33e9966 100644 Binary files a/app/google-services.json.enc and b/app/google-services.json.enc differ 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 823cf5a..f9ee8b3 100644 --- a/app/src/main/java/science/apolline/service/sensor/IOIOService.kt +++ b/app/src/main/java/science/apolline/service/sensor/IOIOService.kt @@ -14,7 +14,6 @@ import android.os.IBinder import android.support.v4.app.NotificationCompat import android.util.Log import com.google.android.gms.location.LocationRequest -import io.reactivex.Scheduler import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers @@ -50,7 +49,7 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { private val locationProvider = ReactiveLocationProvider(this) private val disposable = CompositeDisposable() - + private var location: Location? = null override fun createIOIOLooper(): IOIOLooper { @@ -74,18 +73,10 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { uartIn_ = uart_!!.inputStream inputTemp = ioio_.openAnalogInput(44) inputHum = ioio_.openAnalogInput(42) - initChannels(applicationContext) - val notification = NotificationCompat.Builder(applicationContext, "default") - .setContentTitle("IOIO service is running") - .setTicker("IOIO service is running") - .setContentText("collect of air quality is running") - .setOngoing(true) - .build() - startForeground(101, notification) + launchForegroundServiceNotification(applicationContext) } - @Throws(ConnectionLostException::class, InterruptedException::class) override fun loop() { Log.e("ioioService", "loop") @@ -100,11 +91,11 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { error("Android reactive location error" + it.toString()) } .subscribe { t -> - position = Position(t!!.provider, GeoHashHelper.encode(t.latitude,t.longitude), "no") + position = Position(t!!.provider, GeoHashHelper.encode(t.latitude, t.longitude), "no") //info("Position in observer" + position.toString()) } ) - }else{ + } else { position = Position() } @@ -148,13 +139,13 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { Thread.sleep(freq.toLong()) info("Position Hash :" + position.geohash) - persistData(data,position) + persistData(data, position) } } } - private fun persistData(data: IOIOData, pos:Position?) { + private fun persistData(data: IOIOData, pos: Position?) { val d1 = System.currentTimeMillis() * 1000000 val device = Device(AndroidUuid.getAndroidUuid(), "LOA", d1, pos, data.toJson(), 0) doAsync { @@ -163,9 +154,7 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { } } - override fun onBind(intent: Intent): IBinder? { - return null - } + override fun onBind(intent: Intent): IBinder? = null override fun onUnbind(intent: Intent?): Boolean { if (!disposable.isDisposed) { @@ -182,31 +171,39 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger { Log.e(this.javaClass.name, "onDestroy") } - fun initChannels(context: Context) { + fun launchForegroundServiceNotification(context: Context) { + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val n: Notification + val intent = Intent(context, MainActivity::class.java) + val pendingIntent = PendingIntent.getActivity(context,0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + if (Build.VERSION.SDK_INT < 26) { - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val intent = Intent(context, MainActivity::class.java) - val n: Notification - val pendingIntent = PendingIntent.getActivity(context, - 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) - - val builder = Notification.Builder(context,"default") - .setContentTitle("Apolline service is running...") - .setContentText("IOIO sensor is collecting data...") - .setContentIntent(pendingIntent) - .setSmallIcon(R.drawable.logo_apolline) - .setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.logo_apolline)) - n = builder.build() - n.flags = n.flags or (Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT) - notificationManager.notify(0, n) - } else { - - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val channel = NotificationChannel("default", - "Channel name", - NotificationManager.IMPORTANCE_DEFAULT) - channel.description = "Channel description" + + }else{ + val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT) + channel.description = "Apolline notification channel" notificationManager.createNotificationChannel(channel) } + + n = NotificationCompat.Builder(applicationContext, CHANNEL_ID) + .setContentTitle("IOIO service is running") + .setTicker("IOIO service is running") + .setContentText("collect of air quality is running") + .setSmallIcon(R.drawable.logo_apolline) + .setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.logo_apolline)) + .setContentIntent(pendingIntent) + .build() + + n.flags = n.flags or (Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT) + + startForeground(SERVICE_ID, n) + } + + companion object { + + private const val SERVICE_ID: Int = 101 + private const val CHANNEL_ID = "science.apolline" + private const val CHANNEL_NAME = "Apolline" + } } diff --git a/app/src/main/java/science/apolline/utils/CheckUtility.kt b/app/src/main/java/science/apolline/utils/CheckUtility.kt index 0e6f368..e4a841e 100644 --- a/app/src/main/java/science/apolline/utils/CheckUtility.kt +++ b/app/src/main/java/science/apolline/utils/CheckUtility.kt @@ -124,7 +124,7 @@ object CheckUtility : AnkoLogger{ alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes") { _, _ -> val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) context.startActivity(intent) - } + } alertDialog.show() } } diff --git a/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.kt b/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.kt index 992a776..5b45d77 100644 --- a/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.kt +++ b/app/src/main/java/science/apolline/view/Fragment/IOIOFragment.kt @@ -30,6 +30,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers import org.jetbrains.anko.AnkoLogger +import org.jetbrains.anko.info import science.apolline.R import science.apolline.models.IOIOData import science.apolline.service.sensor.IOIOService @@ -113,9 +114,6 @@ class IOIOFragment : Fragment(), LifecycleOwner, OnChartValueSelectedListener, A // velo = view.findViewById(R.id.fragment_ioio_velo); // voiture = view.findViewById(R.id.fragment_ioio_voiture); // other = view.findViewById(R.id.fragment_ioio_other); - - dataList = createMultiSet() - initGraph() } //init graph on create view @@ -299,6 +297,8 @@ class IOIOFragment : Fragment(), LifecycleOwner, OnChartValueSelectedListener, A override fun onStart() { + dataList = createMultiSet() + initGraph() super.onStart() disposable.add(viewModel.deviceListObserver .subscribeOn(Schedulers.io()) @@ -334,25 +334,40 @@ class IOIOFragment : Fragment(), LifecycleOwner, OnChartValueSelectedListener, A }) } + + override fun onResume() { + super.onResume() + } override fun onPause() { - super.onPause() MoveViewJob.getInstance(null, 0.0F, 0.0F, null, null) + super.onPause() } override fun onStop() { - super.onStop() if (!disposable.isDisposed) { disposable.clear() } MoveViewJob.getInstance(null, 0f, 0f, null, null) + super.onStop() + } + + override fun onDestroyView() { + if (!disposable.isDisposed) { + disposable.dispose() + } + MoveViewJob.getInstance(null, 0f, 0f, null, null) + mChart.clear() + super.onDestroyView() + info("onDestroyView") } override fun onDestroy() { - super.onDestroy() if (!disposable.isDisposed) { disposable.dispose() } MoveViewJob.getInstance(null, 0f, 0f, null, null) + super.onDestroy() + info("onDestroy") } companion object {