2021-05-06 22:57:47 +02:00
|
|
|
package sushi.hardcore.aira
|
|
|
|
|
2021-05-08 19:54:10 +02:00
|
|
|
import android.content.Context
|
2021-05-06 22:57:47 +02:00
|
|
|
import android.content.Intent
|
|
|
|
import android.content.ServiceConnection
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import sushi.hardcore.aira.background_service.AIRAService
|
|
|
|
|
|
|
|
open class ServiceBoundActivity: AppCompatActivity() {
|
|
|
|
protected lateinit var airaService: AIRAService
|
|
|
|
protected lateinit var serviceConnection: ServiceConnection
|
|
|
|
protected lateinit var serviceIntent: Intent
|
|
|
|
|
|
|
|
protected fun isServiceInitialized(): Boolean {
|
|
|
|
return ::airaService.isInitialized
|
|
|
|
}
|
|
|
|
|
2021-05-08 19:54:10 +02:00
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
2021-05-06 22:57:47 +02:00
|
|
|
if (::airaService.isInitialized) {
|
|
|
|
airaService.isAppInBackground = true
|
|
|
|
airaService.uiCallbacks = null
|
|
|
|
unbindService(serviceConnection)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 19:54:10 +02:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2021-05-06 22:57:47 +02:00
|
|
|
if (!::serviceIntent.isInitialized) {
|
|
|
|
serviceIntent = Intent(this, AIRAService::class.java)
|
|
|
|
}
|
2021-05-08 19:54:10 +02:00
|
|
|
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
|
2021-05-06 22:57:47 +02:00
|
|
|
}
|
|
|
|
}
|