From defdb28f938acc40a8ff762ce3c6b2264681718f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 1 Oct 2021 11:07:16 +0200 Subject: [PATCH] code cleanup --- .../nightscout/androidaps/MainActivity.kt | 2 +- .../activities/HistoryBrowseActivity.kt | 4 +-- .../activities/SingleFragmentActivity.kt | 4 +-- .../storage/StorageConstraintPlugin.kt | 2 +- .../profile/local/LocalProfilePlugin.kt | 20 ++++++----- .../androidaps/queue/CommandQueue.kt | 3 +- .../setupwizard/SetupWizardActivity.kt | 2 +- .../activities/DialogAppCompatActivity.kt | 2 +- .../activities/NoSplashAppCompatActivity.kt | 4 +-- .../activities/PrefImportListActivity.kt | 2 +- .../androidaps/database/AppRepository.kt | 5 ++- .../androidaps/database/entities/UserEntry.kt | 2 +- .../diaconn/packet/AppConfirmSettingPacket.kt | 2 +- .../diaconn/packet/BasalLimitInquirePacket.kt | 2 +- .../diaconn/packet/BasalPauseSettingPacket.kt | 2 +- .../packet/DisplayTimeInquirePacket.kt | 2 +- .../packet/InjectionBasalSettingPacket.kt | 2 +- .../packet/InjectionMealSettingPacket.kt | 2 +- .../packet/InjectionSnackSettingPacket.kt | 2 +- .../diaconn/packet/LanguageInquirePacket.kt | 2 +- .../diaconn/packet/SneckLimitInquirePacket.kt | 2 +- .../diaconn/packet/SoundInquirePacket.kt | 2 +- .../diaconn/packet/TimeInquirePacket.kt | 2 +- .../packet/TimeInquireResponsePacket.kt | 2 +- .../diaconn/packet/TimeSettingPacket.kt | 2 +- .../comm/MedtronicCommunicationManager.kt | 33 ++++++++++--------- .../driver/comm/OmnipodDashBleManagerImpl.kt | 5 ++- .../dash/driver/comm/pair/LTKExchanger.kt | 4 +-- .../pod/definition/AlertConfiguration.kt | 6 ++-- .../dash/history/data/HistoryRecord.kt | 2 +- .../general/openhumans/OpenHumansUploader.kt | 2 +- .../plugins/pump/common/PumpPluginAbstract.kt | 1 - .../testing/mockers/WearUtilMocker.java | 2 +- 33 files changed, 65 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 8a685a8703..764a5727eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -165,7 +165,7 @@ class MainActivity : NoSplashAppCompatActivity() { actionBarDrawerToggle.syncState() } - public override fun onDestroy() { + override fun onDestroy() { super.onDestroy() disposable.clear() } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt index 5ef938b134..a6a77c9dd2 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt @@ -171,7 +171,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } } - public override fun onPause() { + override fun onPause() { super.onPause() disposable.clear() iobCobCalculator.stopCalculation("onPause") @@ -183,7 +183,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { super.onDestroy() } - public override fun onResume() { + override fun onResume() { super.onResume() disposable.add(rxBus .toObservable(EventAutosensCalculationFinished::class.java) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt index 9b01150122..9421324b66 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt @@ -19,7 +19,7 @@ class SingleFragmentActivity : DaggerAppCompatActivityWithResult() { private var plugin: PluginBase? = null - public override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_single_fragment) plugin = pluginStore.plugins[intent.getIntExtra("plugin", -1)] @@ -52,7 +52,7 @@ class SingleFragmentActivity : DaggerAppCompatActivityWithResult() { return super.onCreateOptionsMenu(menu) } - public override fun attachBaseContext(newBase: Context) { + override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHelper.wrap(newBase)) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.kt index e474c94906..9fb916690b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.kt @@ -50,7 +50,7 @@ class StorageConstraintPlugin @Inject constructor( return value } - open fun availableInternalMemorySize(): Long { + fun availableInternalMemorySize(): Long { val path = Environment.getDataDirectory() val stat = StatFs(path.path) val blockSize = stat.blockSizeLong diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 94d907973a..026bcbb603 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -148,15 +148,17 @@ class LocalProfilePlugin @Inject constructor( fun storeSettings(activity: FragmentActivity? = null) { for (i in 0 until numOfProfiles) { profiles[i].run { - val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_" - sp.putString(localProfileNumbered + "name", name!!) - sp.putBoolean(localProfileNumbered + "mgdl", mgdl) - sp.putDouble(localProfileNumbered + "dia", dia) - sp.putString(localProfileNumbered + "ic", ic.toString()) - sp.putString(localProfileNumbered + "isf", isf.toString()) - sp.putString(localProfileNumbered + "basal", basal.toString()) - sp.putString(localProfileNumbered + "targetlow", targetLow.toString()) - sp.putString(localProfileNumbered + "targethigh", targetHigh.toString()) + name?.let { name -> + val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_" + sp.putString(localProfileNumbered + "name", name) + sp.putBoolean(localProfileNumbered + "mgdl", mgdl) + sp.putDouble(localProfileNumbered + "dia", dia) + sp.putString(localProfileNumbered + "ic", ic.toString()) + sp.putString(localProfileNumbered + "isf", isf.toString()) + sp.putString(localProfileNumbered + "basal", basal.toString()) + sp.putString(localProfileNumbered + "targetlow", targetLow.toString()) + sp.putString(localProfileNumbered + "targethigh", targetHigh.toString()) + } } } sp.putInt(Constants.LOCAL_PROFILE + "_profiles", numOfProfiles) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt index 62bbf228e9..544666adf5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt @@ -172,8 +172,7 @@ class CommandQueue @Inject constructor( // After new command added to the queue // start thread again if not already running - @Synchronized - open fun notifyAboutNewCommand() { + @Synchronized fun notifyAboutNewCommand() { waitForFinishedThread() if (thread == null || thread!!.state == Thread.State.TERMINATED) { thread = QueueThread(this, context, aapsLogger, rxBus, activePlugin, resourceHelper, sp) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt index 71e0703cb0..9d6cd6acac 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt @@ -70,7 +70,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() { } } - public override fun onPause() { + override fun onPause() { super.onPause() disposable.clear() } diff --git a/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt index 14f941a422..6150a62840 100644 --- a/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt @@ -5,7 +5,7 @@ import dagger.android.support.DaggerAppCompatActivity import info.nightscout.androidaps.utils.locale.LocaleHelper open class DialogAppCompatActivity : DaggerAppCompatActivity() { - public override fun attachBaseContext(newBase: Context) { + override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHelper.wrap(newBase)) } } diff --git a/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt index 78e2e009e3..c8f9888ec6 100644 --- a/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt @@ -7,12 +7,12 @@ import info.nightscout.androidaps.utils.locale.LocaleHelper open class NoSplashAppCompatActivity : DaggerAppCompatActivityWithResult() { - public override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setTheme(R.style.AppTheme_NoActionBar) } - public override fun attachBaseContext(newBase: Context) { + override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHelper.wrap(newBase)) } } diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt index 9e29f529f9..9a8f8a588b 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt @@ -127,7 +127,7 @@ class PrefImportListActivity : DaggerAppCompatActivity() { return false } - public override fun attachBaseContext(newBase: Context) { + override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHelper.wrap(newBase)) } } \ No newline at end of file diff --git a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt index eaab40563d..a9bdf2f39c 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt @@ -17,8 +17,7 @@ import javax.inject.Singleton import kotlin.math.roundToInt @OpenForTesting -@Singleton -open class AppRepository @Inject internal constructor( +@Singleton class AppRepository @Inject internal constructor( internal val database: AppDatabase ) { @@ -485,7 +484,7 @@ open class AppRepository @Inject internal constructor( private fun Single>.expand() = this.map { it.map(::expandCarbs).flatten() } private fun Single>.filterOutExtended() = this.map { it.filter { c -> c.duration == 0L } } private fun Single>.fromTo(from: Long, to: Long) = this.map { it.filter { c -> c.timestamp in from..to } } - private fun Single>.until(to: Long) = this.map { it.filter { c -> c.timestamp <= to } } + private infix fun Single>.until(to: Long) = this.map { it.filter { c -> c.timestamp <= to } } private fun Single>.from(start: Long) = this.map { it.filter { c -> c.timestamp >= start } } private fun Single>.sort() = this.map { it.sortedBy { c -> c.timestamp } } diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt index 4b2b56d019..e7a753713a 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt @@ -21,7 +21,7 @@ data class UserEntry( var action: Action, var source: Sources, var note: String, - var values: List + var values: List<@JvmSuppressWildcards ValueWithUnit?> ) : DBEntry, DBEntryWithTime { enum class Action (val colorGroup: ColorGroup) { BOLUS (ColorGroup.InsulinTreatment), diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/AppConfirmSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/AppConfirmSettingPacket.kt index d0805f6a5f..081362f1c6 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/AppConfirmSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/AppConfirmSettingPacket.kt @@ -22,7 +22,7 @@ class AppConfirmSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) buffer.put(reqMsgType) // 명령코드 buffer.putInt(otp) // 응답시 전달받은 opt (random 6digit numbner) diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalLimitInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalLimitInquirePacket.kt index 36a484cf4a..5dc1860e03 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalLimitInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalLimitInquirePacket.kt @@ -20,7 +20,7 @@ class BasalLimitInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalPauseSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalPauseSettingPacket.kt index 69c88187e9..e0557dd9ca 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalPauseSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BasalPauseSettingPacket.kt @@ -21,7 +21,7 @@ class BasalPauseSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) buffer.put(status.toByte()) // (1:pause, 2: cancel pause) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/DisplayTimeInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/DisplayTimeInquirePacket.kt index 9c0692ab45..3d9f9d2769 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/DisplayTimeInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/DisplayTimeInquirePacket.kt @@ -20,7 +20,7 @@ class DisplayTimeInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionBasalSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionBasalSettingPacket.kt index 4e9cbf546b..a912b284d7 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionBasalSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionBasalSettingPacket.kt @@ -20,7 +20,7 @@ class InjectionBasalSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) buffer.put(pattern.toByte()) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionMealSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionMealSettingPacket.kt index ed901b9187..5460a2de20 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionMealSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionMealSettingPacket.kt @@ -21,7 +21,7 @@ class InjectionMealSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) buffer.putShort(amount.toShort()) buffer.putLong(bcDttm) return suffixEncode(buffer) diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionSnackSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionSnackSettingPacket.kt index 5312aa348e..a3b80bba6a 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionSnackSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/InjectionSnackSettingPacket.kt @@ -20,7 +20,7 @@ class InjectionSnackSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) buffer.putShort(amount.toShort()) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/LanguageInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/LanguageInquirePacket.kt index 7bca3e499b..d727abd40f 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/LanguageInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/LanguageInquirePacket.kt @@ -20,7 +20,7 @@ class LanguageInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SneckLimitInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SneckLimitInquirePacket.kt index 983887eccb..d4357b1554 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SneckLimitInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SneckLimitInquirePacket.kt @@ -20,7 +20,7 @@ class SneckLimitInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SoundInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SoundInquirePacket.kt index 790523aff9..883fc8b283 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SoundInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/SoundInquirePacket.kt @@ -20,7 +20,7 @@ class SoundInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquirePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquirePacket.kt index 722e2030d2..2491bea781 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquirePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquirePacket.kt @@ -20,7 +20,7 @@ class TimeInquirePacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) return suffixEncode(buffer) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquireResponsePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquireResponsePacket.kt index 86b1f3befd..0e9436718d 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquireResponsePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeInquireResponsePacket.kt @@ -31,7 +31,7 @@ class TimeInquireResponsePacket( val result2 = getByteToInt(bufferData) if(!isSuccInquireResponseResult(result2)) { failed = true - return; + return } } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeSettingPacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeSettingPacket.kt index ad158bb211..b67b96c623 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeSettingPacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/TimeSettingPacket.kt @@ -25,7 +25,7 @@ class TimeSettingPacket( } override fun encode(msgSeq:Int): ByteArray { - val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END); + val buffer = prefixEncode(msgType, msgSeq, MSG_CON_END) val date = DateTime(time).withZone(DateTimeZone.UTC) buffer.put((date.year - 2000 and 0xff).toByte()) buffer.put((date.monthOfYear and 0xff).toByte()) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt index 4f918f1ceb..3478cfce7c 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt @@ -54,9 +54,12 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth @Inject lateinit var medtronicUtil: MedtronicUtil @Inject lateinit var medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder - private val MAX_COMMAND_TRIES = 3 - private val DEFAULT_TIMEOUT = 2000 - private val RILEYLINK_TIMEOUT: Long = 15 * 60 * 1000 // 15 min + companion object { + + private const val MAX_COMMAND_TRIES = 3 + private const val DEFAULT_TIMEOUT = 2000 + private const val RILEYLINK_TIMEOUT: Long = 15 * 60 * 1000L // 15 min + } var errorResponse: String? = null private set @@ -64,7 +67,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth private var doWakeUpBeforeCommand = true @Inject - fun onInit(): Unit { + fun onInit() { // we can't do this in the constructor, as sp only gets injected after the constructor has returned medtronicPumpStatus.previousConnection = sp.getLong( RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L) @@ -92,7 +95,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth * * @return */ - fun isDeviceReachable(canPreventTuneUp: Boolean): Boolean { + private fun isDeviceReachable(canPreventTuneUp: Boolean): Boolean { val state = medtronicPumpStatus.pumpDeviceState if (state !== PumpDeviceState.PumpUnreachable) medtronicPumpStatus.pumpDeviceState = PumpDeviceState.WakingUp for (retry in 0..4) { @@ -189,6 +192,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth } } + @Suppress("SameParameterValue") @Throws(RileyLinkCommunicationException::class) private fun runCommandWithFrames(commandType: MedtronicCommandType, frames: List>): PumpMessage? { aapsLogger.debug(LTag.PUMPCOMM, "Run command with Frames: " + commandType.name) @@ -266,7 +270,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth while (!done) { // examine current response for problems. val frameData = currentResponse.frameData - if (frameData.size > 0 && currentResponse.frameNumber == expectedFrameNum) { + if (frameData.isNotEmpty() && currentResponse.frameNumber == expectedFrameNum) { // success! got a frame. if (frameData.size != 64) { aapsLogger.warn(LTag.PUMPCOMM, "Expected frame of length 64, got frame of length " + frameData.size) @@ -286,12 +290,12 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth done = true // successful completion } } else { - if (frameData.size == 0) { + if (frameData.isEmpty()) { aapsLogger.error(LTag.PUMPCOMM, "null frame data, retrying") } else if (currentResponse.frameNumber != expectedFrameNum) { aapsLogger.warn(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Expected frame number %d, received %d (retrying)", expectedFrameNum, currentResponse.frameNumber)) - } else if (frameData.size == 0) { + } else if (frameData.isEmpty()) { aapsLogger.warn(LTag.PUMPCOMM, "Frame has zero length, retrying") } failures++ @@ -381,8 +385,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth medtronicPumpStatus.pumpDeviceState = PumpDeviceState.Active // create message - val msg: PumpMessage - msg = bodyData?.let { makePumpMessage(commandType, it) } ?: makePumpMessage(commandType) + val msg: PumpMessage = bodyData?.let { makePumpMessage(commandType, it) } ?: makePumpMessage(commandType) // send and wait for response val response = sendAndListen(msg, timeoutMs) @@ -396,8 +399,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth } // All pump communications go through this function. - @Throws(RileyLinkCommunicationException::class) - protected /*override*/ fun sendAndListen(msg: PumpMessage, timeout_ms: Int): PumpMessage { + @Throws(RileyLinkCommunicationException::class) private /*override*/ fun sendAndListen(msg: PumpMessage, timeout_ms: Int): PumpMessage { return super.sendAndListen(msg, timeout_ms)!! } @@ -451,7 +453,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth return responseData } val contents = response.rawContent - return if (contents.size > 0) { + return if (contents.isNotEmpty()) { if (contents.size >= expectedLength) { aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "%s: Content: %s", method, ByteUtil.shortHexString(contents))) null @@ -493,8 +495,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth for (retries in 0..MAX_COMMAND_TRIES) { try { // create message - var msg: PumpMessage - msg = makePumpMessage(commandType) + val msg: PumpMessage = makePumpMessage(commandType) // send and wait for response var response = sendAndListen(msg, DEFAULT_TIMEOUT + DEFAULT_TIMEOUT * retries) @@ -527,7 +528,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth aapsLogger.debug(LTag.PUMPCOMM, "End Response: {}", ByteUtil.getHex(data)) - var basalProfile: BasalProfile? = medtronicConverter.decodeBasalProfile(medtronicPumpPlugin.pumpDescription.pumpType, data) + val basalProfile: BasalProfile? = medtronicConverter.decodeBasalProfile(medtronicPumpPlugin.pumpDescription.pumpType, data) // checkResponseRawContent(data, commandType) { // basalProfile = medtronicConverter.decodeBasalProfile(medtronicPumpPlugin.pumpDescription.pumpType, data) // } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt index d9fff23aad..a70ff39266 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt @@ -98,7 +98,7 @@ class OmnipodDashBleManagerImpl @Inject constructor( } override fun getStatus(): ConnectionState { - return connection?.let { it.connectionState() } + return connection?.connectionState() ?: NotConnected } // used for sync connections @@ -154,7 +154,7 @@ class OmnipodDashBleManagerImpl @Inject constructor( val ltk = assertPaired() - var eapSqn = podState.increaseEapAkaSequenceNumber() + val eapSqn = podState.increaseEapAkaSequenceNumber() var newSqn = conn.establishSession(ltk, msgSeq, ids, eapSqn) @@ -180,7 +180,6 @@ class OmnipodDashBleManagerImpl @Inject constructor( ?: throw FailedToConnectException("connection lost") } - @kotlin.ExperimentalStdlibApi override fun pairNewPod(): Observable = Observable.create { emitter -> if (!busy.compareAndSet(false, true)) { throw BusyException() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt index da5a5cbb96..543d3a0d7c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt @@ -23,7 +23,6 @@ internal class LTKExchanger( private val keyExchange = KeyExchange(aapsLogger, X25519KeyGenerator(), RandomByteGenerator()) private var seq: Byte = 1 - @kotlin.ExperimentalStdlibApi @Throws(PairingException::class) fun negotiateLTK(): PairResult { val sp1sp2 = PairMessage( @@ -114,7 +113,6 @@ internal class LTKExchanger( keyExchange.validatePodConf(payload) } - @kotlin.ExperimentalStdlibApi private fun sp2(): ByteArray { // This is GetPodStatus command, with page 0 parameter. // We could replace that in the future with the serialized GetPodStatus() @@ -127,7 +125,7 @@ internal class LTKExchanger( val payload = parseKeys(arrayOf(P0), msg.payload)[0] aapsLogger.debug(LTag.PUMPBTCOMM, "P0 payload from pod: ${payload.toHex()}") if (!payload.contentEquals(UNKNOWN_P0_PAYLOAD)) { - aapsLogger.warn(LTag.PUMPBTCOMM, "Reveived invalid P0 payload: ${payload.toHex()}") + aapsLogger.warn(LTag.PUMPBTCOMM, "Received invalid P0 payload: ${payload.toHex()}") } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt index 26b0a5c94e..3dcc266058 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt @@ -17,13 +17,13 @@ class AlertConfiguration( get() { var firstByte = (type.index.toInt() shl 4).toByte() if (enabled) { - firstByte = firstByte or (1 shl 3) + firstByte = firstByte or (1 shl 3).toByte() } if (trigger is AlertTrigger.ReservoirVolumeTrigger) { - firstByte = firstByte or (1 shl 2) + firstByte = firstByte or (1 shl 2).toByte() } if (autoOff) { - firstByte = firstByte or (1 shl 1) + firstByte = firstByte or (1 shl 1).toByte() } firstByte = firstByte or ((durationInMinutes.toInt() shr 8 and 0x01).toByte()) return ByteBuffer.allocate(6) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt index 65a2d5294c..f7510c40b1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt @@ -16,6 +16,6 @@ data class HistoryRecord( ) { fun pumpId(): Long { val entropy = ULID.getEntropy(id) - return ByteBuffer.wrap(entropy).getLong() + return ByteBuffer.wrap(entropy).long } } diff --git a/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansUploader.kt b/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansUploader.kt index ed2c180ba2..469f4aa346 100644 --- a/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansUploader.kt +++ b/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansUploader.kt @@ -267,7 +267,7 @@ class OpenHumansUploader @Inject internal constructor( put("currentTemp", JSONObject(it.currentTempJson)) put("iobData", JSONObject(it.iobDataJson)) put("profile", JSONObject(it.profileJson)) - put("autosensData", JSONObject(it.autosensDataJson)) + put("autosensData", JSONObject(it.autosensDataJson ?: "")) put("mealData", JSONObject(it.mealDataJson)) put("isMicroBolusAllowed", it.isMicroBolusAllowed) put("result", JSONObject(it.resultJson)) diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt index 6314f5e668..39c4f9ecd6 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt @@ -69,7 +69,6 @@ abstract class PumpPluginAbstract protected constructor( protected var displayConnectionMessages = false var pumpType: PumpType = PumpType.GENERIC_AAPS - get() = field set(value) { field = value pumpDescription.fillFor(value) diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java index e3f24e878e..5e6ac597db 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java @@ -58,7 +58,7 @@ public class WearUtilMocker { return REF_NOW - (Constants.DAY_IN_MS * d + Constants.HOUR_IN_MS * h + Constants.MINUTE_IN_MS * m + Constants.SECOND_IN_MS * s); } - private static Answer bundleToDataMapMock = invocation -> { + private static final Answer bundleToDataMapMock = invocation -> { DataMap map = new DataMap(); Bundle bundle = invocation.getArgument(0); for(String key: bundle.keySet()) {