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

Commit

Permalink
refactor: pre-build logs
Browse files Browse the repository at this point in the history
Add new Google services for crash analytics.
Fix graph init onPause.
Add notification redirection to MainActivity
  • Loading branch information
aoudiamoncef committed Feb 9, 2018
1 parent 371778a commit 3da0598
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified app/google-services.json.enc
Binary file not shown.
79 changes: 38 additions & 41 deletions app/src/main/java/science/apolline/service/sensor/IOIOService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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()
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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"

}
}
2 changes: 1 addition & 1 deletion app/src/main/java/science/apolline/utils/CheckUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
27 changes: 21 additions & 6 deletions app/src/main/java/science/apolline/view/Fragment/IOIOFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3da0598

Please sign in to comment.