From 533433afd8421d6697605d6c4321b41063a1100f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 31 Mar 2020 10:10:48 +0200 Subject: [PATCH] DataService refactor --- .../dependencyInjection/ReceiversModule.kt | 4 ++- .../androidaps/receivers/DataReceiver.java | 25 ------------------- .../androidaps/receivers/DataReceiver.kt | 22 ++++++++++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java create mode 100644 app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ReceiversModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ReceiversModule.kt index 08b3711a6c..9427d5555a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ReceiversModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ReceiversModule.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.dependencyInjection import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkBluetoothStateReceiver +import info.nightscout.androidaps.receivers.DataReceiver import info.nightscout.androidaps.receivers.KeepAliveReceiver import info.nightscout.androidaps.receivers.NetworkChangeReceiver import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver @@ -11,8 +12,9 @@ import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver @Suppress("unused") abstract class ReceiversModule { + @ContributesAndroidInjector abstract fun contributesDataReceiver(): DataReceiver @ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver @ContributesAndroidInjector abstract fun contributesNetworkChangeReceiver(): NetworkChangeReceiver - @ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver @ContributesAndroidInjector abstract fun contributesRileyLinkBluetoothStateReceiver(): RileyLinkBluetoothStateReceiver + @ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java deleted file mode 100644 index 48b5d479f7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java +++ /dev/null @@ -1,25 +0,0 @@ -package info.nightscout.androidaps.receivers; - -import android.content.Context; -import android.content.Intent; -import androidx.legacy.content.WakefulBroadcastReceiver; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; -import info.nightscout.androidaps.services.DataService; - -public class DataReceiver extends WakefulBroadcastReceiver { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATASERVICE); - - @Override - public void onReceive(Context context, Intent intent) { - if (L.isEnabled(L.DATASERVICE)) - log.debug("onReceive " + intent); - startWakefulService(context, new Intent(context, DataService.class) - .setAction(intent.getAction()) - .putExtras(intent)); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt new file mode 100644 index 0000000000..f8fb246f22 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.receivers + +import android.content.Context +import android.content.Intent +import androidx.legacy.content.WakefulBroadcastReceiver +import dagger.android.AndroidInjection +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.services.DataService +import javax.inject.Inject + +open class DataReceiver : WakefulBroadcastReceiver() { + @Inject lateinit var aapsLogger: AAPSLogger + + override fun onReceive(context: Context, intent: Intent) { + AndroidInjection.inject(this, context) + aapsLogger.debug(LTag.DATASERVICE, "onReceive $intent") + startWakefulService(context, Intent(context, DataService::class.java) + .setAction(intent.action) + .putExtras(intent)) + } +} \ No newline at end of file