From d18c05205ca31aae266f5ae145e441d1a5f5f2a7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 7 Sep 2021 12:08:19 +0200 Subject: [PATCH] Resolve warnings --- .../nightscout/androidaps/MainActivity.kt | 2 - .../activities/HistoryBrowseActivity.kt | 6 ++- .../RequestDexcomPermissionActivity.kt | 2 - .../TreatmentsTemporaryBasalsFragment.kt | 1 - .../aps/openAPSAMA/OpenAPSAMAFragment.kt | 2 - .../aps/openAPSSMB/OpenAPSSMBFragment.kt | 2 - .../objectives/ObjectivesPlugin.kt | 1 - .../objectives/objectives/Objective3.kt | 1 - .../SignatureVerifierPlugin.kt | 1 - .../general/actions/ActionsFragment.kt | 5 ++- .../plugins/general/food/FoodFragment.kt | 4 -- .../general/maintenance/MaintenancePlugin.kt | 4 +- .../nsclient/services/NSClientService.kt | 3 -- .../general/overview/OverviewFragment.kt | 5 ++- .../activities/QuickWizardListActivity.kt | 4 +- .../smsCommunicator/SmsCommunicatorPlugin.kt | 10 ----- .../profile/local/LocalProfilePlugin.kt | 22 +++++----- .../pump/virtual/VirtualPumpFragment.kt | 26 ++++++------ .../androidaps/utils/JSONFormatter.kt | 1 - .../androidaps/utils/PercentageSplitter.kt | 2 +- .../res/layout/treatments_tempbasals_item.xml | 1 + .../SignatureVerifierPluginTest.kt | 1 - .../SmsCommunicatorPluginTest.kt | 1 - .../SimpleItemTouchHelperCallback.kt | 4 +- .../androidaps/extensions/BlockExtension.kt | 4 +- .../extensions/HexByteArrayConversion.kt | 3 +- .../maintenance/PrefFileListProvider.kt | 3 +- .../formats/EncryptedPrefsFormat.kt | 3 +- .../validators/PinStrengthValidator.kt | 1 - .../formats/EncryptedPrefsFormatTest.kt | 1 - .../androidaps/danars/DanaRSPlugin.kt | 7 ++-- .../danars/activities/EnterPinActivity.kt | 1 - .../danars/comm/DanaRSPacketHistory.kt | 1 - .../androidaps/danars/services/BLEComm.kt | 4 -- .../danars/services/DanaRSService.kt | 1 - .../comm/DanaRSPacketHistoryAlarmTest.kt | 1 - .../pump/medtronic/MedtronicPumpPlugin.kt | 1 + .../comm/ui/MedtronicUIPostprocessor.kt | 2 +- .../general/openhumans/OpenHumansAPI.kt | 1 + .../general/openhumans/OpenHumansUploader.kt | 17 ++++---- .../pump/common/sync/PumpSyncStorage.kt | 42 ++++++++++--------- 41 files changed, 90 insertions(+), 114 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 42559a543b..8a685a8703 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -95,7 +95,6 @@ class MainActivity : NoSplashAppCompatActivity() { private lateinit var binding: ActivityMainBinding - @kotlin.ExperimentalStdlibApi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Iconify.with(FontAwesomeModule()) @@ -361,7 +360,6 @@ class MainActivity : NoSplashAppCompatActivity() { // Correct place for calling setUserStats() would be probably MainApp // but we need to have it called at least once a day. Thus this location - @kotlin.ExperimentalStdlibApi private fun setUserStats() { if (!fabricPrivacy.fabricEnabled()) return val closedLoopEnabled = if (constraintChecker.isClosedLoopAllowed().value()) "CLOSED_LOOP_ENABLED" else "CLOSED_LOOP_DISABLED" 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 ba2b1e0bfa..5ef938b134 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt @@ -151,7 +151,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } val dm = DisplayMetrics() - windowManager?.defaultDisplay?.getMetrics(dm) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + display?.getRealMetrics(dm) + else + @Suppress("DEPRECATION") windowManager.defaultDisplay.getMetrics(dm) + axisWidth = if (dm.densityDpi <= 120) 3 else if (dm.densityDpi <= 160) 10 else if (dm.densityDpi <= 320) 35 else if (dm.densityDpi <= 420) 50 else if (dm.densityDpi <= 560) 70 else 80 binding.bgGraph.gridLabelRenderer?.gridColor = resourceHelper.gc(R.color.graphgrid) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt index c5b03dc0f5..fd01500652 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/RequestDexcomPermissionActivity.kt @@ -7,10 +7,8 @@ import javax.inject.Inject class RequestDexcomPermissionActivity : DialogAppCompatActivity() { @Inject lateinit var dexcomPlugin: DexcomPlugin - @kotlin.ExperimentalStdlibApi private val requestCode = "AndroidAPS <3".map { it.code }.sum() - @kotlin.ExperimentalStdlibApi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) requestPermissions(arrayOf(DexcomPlugin.PERMISSION), requestCode) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt index 590fef204f..c856386cb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -190,7 +190,6 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { override fun getItemCount(): Int = tempBasalList.size - @Deprecated("remove remove functionality after finish") inner class TempBasalsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val binding = TreatmentsTempbasalsItemBinding.bind(itemView) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt index 1c4de77907..acbbf1191b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt @@ -58,7 +58,6 @@ class OpenAPSAMAFragment : DaggerFragment() { } @Synchronized - @kotlin.ExperimentalStdlibApi override fun onResume() { super.onResume() @@ -91,7 +90,6 @@ class OpenAPSAMAFragment : DaggerFragment() { } @Synchronized - @kotlin.ExperimentalStdlibApi private fun updateGUI() { if (_binding == null) return openAPSAMAPlugin.lastAPSResult?.let { lastAPSResult -> diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt index f5e03f602f..61e52b0821 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt @@ -59,7 +59,6 @@ class OpenAPSSMBFragment : DaggerFragment() { } @Synchronized - @kotlin.ExperimentalStdlibApi override fun onResume() { super.onResume() disposable += rxBus @@ -91,7 +90,6 @@ class OpenAPSSMBFragment : DaggerFragment() { } @Synchronized - @kotlin.ExperimentalStdlibApi fun updateGUI() { if (_binding == null) return openAPSSMBPlugin.lastAPSResult?.let { lastAPSResult -> diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index 3368f86919..670d164503 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -100,7 +100,6 @@ class ObjectivesPlugin @Inject constructor( sp.putBoolean(R.string.key_objectiveusescale, false) } - @kotlin.ExperimentalStdlibApi fun completeObjectives(activity: FragmentActivity, request: String) { val requestCode = sp.getString(R.string.key_objectives_request_code, "") var url = sp.getString(R.string.key_nsclientinternal_url, "").lowercase(Locale.getDefault()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.kt index 5247e18fac..2ccd96f3b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.kt @@ -29,7 +29,6 @@ class Objective3 @Inject constructor(injector: HasAndroidInjector) : Objective(i override fun specialActionEnabled(): Boolean = nsClientPlugin.nsClientService?.isConnected == true && nsClientPlugin.nsClientService?.hasWriteAuth == true - @kotlin.ExperimentalStdlibApi override fun specialAction(activity: FragmentActivity, input: String) { objectivesPlugin.completeObjectives(activity, input) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt index 7c41902a08..d4a7a73dca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt @@ -152,7 +152,6 @@ class SignatureVerifierPlugin @Inject constructor( return sb.toString() } - @kotlin.ExperimentalStdlibApi fun singleCharUnMap(shortHash: String): String { val array = ByteArray(shortHash.length) val sb = StringBuilder() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 60fc700dcf..ada8f9eab0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -115,7 +115,10 @@ class ActionsFragment : DaggerFragment() { savedInstanceState: Bundle?): View? { //check screen width dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + activity?.display?.getRealMetrics(dm) + else + @Suppress("DEPRECATION") activity?.windowManager?.defaultDisplay?.getMetrics(dm) val screenWidth = dm.widthPixels val screenHeight = dm.heightPixels diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt index 364f64e180..97f780e842 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt @@ -67,7 +67,6 @@ class FoodFragment : DaggerFragment() { return binding.root } - @kotlin.ExperimentalStdlibApi override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -129,7 +128,6 @@ class FoodFragment : DaggerFragment() { } @Synchronized - @kotlin.ExperimentalStdlibApi override fun onResume() { super.onResume() disposable.add(rxBus @@ -141,7 +139,6 @@ class FoodFragment : DaggerFragment() { swapAdapter() } - @kotlin.ExperimentalStdlibApi private fun swapAdapter() { disposable += repository .getFoodData() @@ -202,7 +199,6 @@ class FoodFragment : DaggerFragment() { } } - @kotlin.ExperimentalStdlibApi private fun filterData() { val textFilter = binding.filter.text.toString() val categoryFilter = binding.category.selectedItem?.toString() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt index c6868b4337..73395d4e96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt @@ -73,7 +73,7 @@ class MaintenancePlugin @Inject constructor( val files = logDir.listFiles { _: File?, name: String -> (name.startsWith("AndroidAPS") && name.endsWith(".zip")) } - if (files.isEmpty()) return + if (files == null || files.isEmpty()) return Arrays.sort(files) { f1: File, f2: File -> f2.name.compareTo(f1.name) } var delFiles = listOf(*files) val amount = sp.getInt(R.string.key_logshipper_amount, keep) @@ -109,7 +109,7 @@ class MaintenancePlugin @Inject constructor( (name.startsWith("AndroidAPS") && (name.endsWith(".log") || name.endsWith(".zip") && !name.endsWith(loggerUtils.suffix))) - } + } ?: emptyArray() Arrays.sort(files) { f1: File, f2: File -> f2.name.compareTo(f1.name) } val result = listOf(*files) var toIndex = amount diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt index dd31516ac3..8d0a8691c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt @@ -112,7 +112,6 @@ class NSClientService : DaggerService() { var latestDateInReceivedData: Long = 0 @SuppressLint("WakelockTimeout") - @kotlin.ExperimentalStdlibApi override fun onCreate() { super.onCreate() wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService") @@ -236,7 +235,6 @@ class NSClientService : DaggerService() { return START_STICKY } - @kotlin.ExperimentalStdlibApi fun initialize() { dataCounter = 0 readPreferences() @@ -651,7 +649,6 @@ class NSClientService : DaggerService() { } } - @kotlin.ExperimentalStdlibApi fun restart() { destroy() initialize() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 7c76aa568a..cfc0eaac7e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -138,7 +138,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList _binding = it //check screen width dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + activity?.display?.getRealMetrics(dm) + else + @Suppress("DEPRECATION") activity?.windowManager?.defaultDisplay?.getMetrics(dm) }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt index d79d3f51f4..ebc3770488 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt @@ -64,12 +64,12 @@ class QuickWizardListActivity : NoSplashAppCompatActivity() { val manager = fragmentManager val editQuickWizardDialog = EditQuickWizardDialog() val bundle = Bundle() - bundle.putInt("position", adapterPosition) + bundle.putInt("position", bindingAdapterPosition) editQuickWizardDialog.arguments = bundle editQuickWizardDialog.show(manager, "EditQuickWizardDialog") } removeButton.setOnClickListener { - quickWizard.remove(adapterPosition) + quickWizard.remove(bindingAdapterPosition) rxBus.send(EventQuickWizardChange()) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index ac70ef612f..f78d83b4e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -181,7 +181,6 @@ class SmsCommunicatorPlugin @Inject constructor( } @Suppress("SpellCheckingInspection") - @kotlin.ExperimentalStdlibApi override fun doWork(): Result { val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) @@ -224,7 +223,6 @@ class SmsCommunicatorPlugin @Inject constructor( return false } - @kotlin.ExperimentalStdlibApi fun processSms(receivedSms: Sms) { if (!isEnabled(PluginType.GENERAL)) { aapsLogger.debug(LTag.SMS, "Ignoring SMS. Plugin disabled.") @@ -341,7 +339,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true } - @kotlin.ExperimentalStdlibApi private fun processLOOP(divided: Array, receivedSms: Sms) { when (divided[1].uppercase(Locale.getDefault())) { "DISABLE", "STOP" -> { @@ -470,7 +467,6 @@ class SmsCommunicatorPlugin @Inject constructor( } } - @kotlin.ExperimentalStdlibApi private fun processNSCLIENT(divided: Array, receivedSms: Sms) { if (divided[1].uppercase(Locale.getDefault()) == "RESTART") { rxBus.send(EventNSClientRestart()) @@ -480,7 +476,6 @@ class SmsCommunicatorPlugin @Inject constructor( sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) } - @kotlin.ExperimentalStdlibApi private fun processHELP(divided: Array, receivedSms: Sms) { when { divided.size == 1 -> { @@ -567,7 +562,6 @@ class SmsCommunicatorPlugin @Inject constructor( } } - @kotlin.ExperimentalStdlibApi private fun processPROFILE(divided: Array, receivedSms: Sms) { // load profiles val anInterface = activePlugin.activeProfileSource val store = anInterface.profile @@ -621,7 +615,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true } - @kotlin.ExperimentalStdlibApi private fun processBASAL(divided: Array, receivedSms: Sms) { if (divided[1].uppercase(Locale.getDefault()) == "CANCEL" || divided[1].uppercase(Locale.getDefault()) == "STOP") { val passCode = generatePassCode() @@ -738,7 +731,6 @@ class SmsCommunicatorPlugin @Inject constructor( } } - @kotlin.ExperimentalStdlibApi private fun processEXTENDED(divided: Array, receivedSms: Sms) { if (divided[1].uppercase(Locale.getDefault()) == "CANCEL" || divided[1].uppercase(Locale.getDefault()) == "STOP") { val passCode = generatePassCode() @@ -905,7 +897,6 @@ class SmsCommunicatorPlugin @Inject constructor( return retVal } - @kotlin.ExperimentalStdlibApi private fun processCARBS(divided: Array, receivedSms: Sms) { var grams = SafeParse.stringToInt(divided[1]) var time = dateUtil.now() @@ -949,7 +940,6 @@ class SmsCommunicatorPlugin @Inject constructor( } } - @kotlin.ExperimentalStdlibApi private fun processTARGET(divided: Array, receivedSms: Sms) { val isMeal = divided[1].equals("MEAL", ignoreCase = true) val isActivity = divided[1].equals("ACTIVITY", ignoreCase = true) 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 96a487249e..a474bb86c8 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 @@ -357,16 +357,18 @@ class LocalProfilePlugin @Inject constructor( try { for (i in 0 until numOfProfiles) { profiles[i].run { - val profile = JSONObject() - profile.put("dia", dia) - profile.put("carbratio", ic) - profile.put("sens", isf) - profile.put("basal", basal) - profile.put("target_low", targetLow) - profile.put("target_high", targetHigh) - profile.put("units", if (mgdl) Constants.MGDL else Constants.MMOL) - profile.put("timezone", TimeZone.getDefault().id) - store.put(name, profile) + name?.let { name -> + val profile = JSONObject() + profile.put("dia", dia) + profile.put("carbratio", ic) + profile.put("sens", isf) + profile.put("basal", basal) + profile.put("target_low", targetLow) + profile.put("target_high", targetHigh) + profile.put("units", if (mgdl) Constants.MGDL else Constants.MMOL) + profile.put("timezone", TimeZone.getDefault().id) + store.put(name, profile) + } } } if (numOfProfiles > 0) json.put("defaultProfile", currentProfile()?.name) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.kt index f2eb4bb5e1..2c014279ef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.virtual import android.os.Bundle import android.os.Handler +import android.os.HandlerThread import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -10,6 +11,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.databinding.VirtualpumpFragmentBinding import info.nightscout.androidaps.events.EventExtendedBolusChange import info.nightscout.androidaps.events.EventTempBasalChange +import info.nightscout.androidaps.extensions.toStringFull import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -17,7 +19,6 @@ import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUp import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T -import info.nightscout.androidaps.extensions.toStringFull import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import io.reactivex.disposables.CompositeDisposable @@ -37,15 +38,8 @@ class VirtualPumpFragment : DaggerFragment() { private val disposable = CompositeDisposable() - private val loopHandler = Handler() private lateinit var refreshLoop: Runnable - - init { - refreshLoop = Runnable { - activity?.runOnUiThread { updateGui() } - loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) - } - } + private lateinit var handler: Handler private var _binding: VirtualpumpFragmentBinding? = null @@ -58,7 +52,11 @@ class VirtualPumpFragment : DaggerFragment() { return binding.root } - @Synchronized + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) + } + @Synchronized override fun onResume() { super.onResume() disposable += rxBus @@ -73,7 +71,11 @@ class VirtualPumpFragment : DaggerFragment() { .toObservable(EventExtendedBolusChange::class.java) .observeOn(aapsSchedulers.main) .subscribe({ updateGui() }, fabricPrivacy::logException) - loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) + refreshLoop = Runnable { + activity?.runOnUiThread { updateGui() } + handler.postDelayed(refreshLoop, T.mins(1).msecs()) + } + handler.postDelayed(refreshLoop, T.mins(1).msecs()) updateGui() } @@ -81,7 +83,7 @@ class VirtualPumpFragment : DaggerFragment() { override fun onPause() { super.onPause() disposable.clear() - loopHandler.removeCallbacks(refreshLoop) + handler.removeCallbacksAndMessages(null) } @Synchronized diff --git a/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.kt b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.kt index adda9f9cc2..73c83207ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.kt @@ -17,7 +17,6 @@ class JSONFormatter @Inject constructor( private val aapsLogger: AAPSLogger ) { - @kotlin.ExperimentalStdlibApi fun format(jsonString: String?): Spanned { jsonString ?: return fromHtml("") val visitor = JsonVisitor(1, '\t') diff --git a/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.kt b/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.kt index 3e38a2088c..96d1ad6b49 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.kt @@ -15,6 +15,6 @@ object PercentageSplitter { */ fun pureName(name: String): String { val percentageMatch = splitPattern.matcher(name) - return if (percentageMatch.find()) percentageMatch.group(1).trim { it <= ' ' } else name + return if (percentageMatch.find()) (percentageMatch.group(1) as String).trim { it <= ' ' } else name } } \ No newline at end of file diff --git a/app/src/main/res/layout/treatments_tempbasals_item.xml b/app/src/main/res/layout/treatments_tempbasals_item.xml index cd9d6fcc4f..ff42255451 100644 --- a/app/src/main/res/layout/treatments_tempbasals_item.xml +++ b/app/src/main/res/layout/treatments_tempbasals_item.xml @@ -164,6 +164,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="5dp" + android:visibility="gone" android:text="@string/remove_button" android:textAlignment="viewEnd" android:textColor="@android:color/holo_orange_light" /> diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt index 5c847314ba..b54fd71efd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt @@ -11,7 +11,6 @@ import org.junit.Assert import org.junit.Test import org.mockito.Mock -@kotlin.ExperimentalStdlibApi class SignatureVerifierPluginTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index 01261b62fc..fe2197fc1f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -58,7 +58,6 @@ import java.util.* SmsManager::class, CommandQueue::class, LocalProfilePlugin::class, DateUtil::class, OneTimePassword::class, UserEntryLogger::class, LoopPlugin::class, AppRepository::class, DateUtil::class, AutosensDataStore::class) -@kotlin.ExperimentalStdlibApi class SmsCommunicatorPluginTest : TestBaseWithProfile() { @Mock lateinit var sp: SP diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt index 849e5c6a26..1e633d4627 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt @@ -41,12 +41,12 @@ class SimpleItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter return false } // Notify the adapter of the move - mAdapter.onItemMove(source.adapterPosition, target.adapterPosition) + mAdapter.onItemMove(source.absoluteAdapterPosition, target.absoluteAdapterPosition) return true } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, i: Int) { // Notify the adapter of the dismissal - mAdapter.onItemDismiss(viewHolder.adapterPosition) + mAdapter.onItemDismiss(viewHolder.absoluteAdapterPosition) } override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/BlockExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/BlockExtension.kt index a07e88cc39..972a602573 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/BlockExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/BlockExtension.kt @@ -15,7 +15,7 @@ private fun getShiftedTimeSecs(originalSeconds: Int, timeShiftHours: Int): Int { fun List.shiftBlock(multiplier: Double, timeShiftHours: Int): List { val newList = arrayListOf() - for (hour in 0..23) newList.add(Block(1000 * 60 * 60, blockValueBySeconds(hour * 3600, multiplier, timeShiftHours))) + for (hour in 0..23) newList.add(Block(1000L * 60 * 60, blockValueBySeconds(hour * 3600, multiplier, timeShiftHours))) for (i in newList.indices.reversed()) { if (i > 0) if (newList[i].amount == newList[i - 1].amount) { @@ -29,7 +29,7 @@ fun List.shiftBlock(multiplier: Double, timeShiftHours: Int): List fun List.shiftTargetBlock(timeShiftHours: Int): List { val newList = arrayListOf() for (hour in 0..23) - newList.add(TargetBlock(1000 * 60 * 60, lowTargetBlockValueBySeconds(hour * 3600, timeShiftHours), highTargetBlockValueBySeconds(hour * 3600, timeShiftHours))) + newList.add(TargetBlock(1000L * 60 * 60, lowTargetBlockValueBySeconds(hour * 3600, timeShiftHours), highTargetBlockValueBySeconds(hour * 3600, timeShiftHours))) for (i in newList.indices.reversed()) { if (i > 0) if (newList[i].lowTarget == newList[i - 1].lowTarget && newList[i].highTarget == newList[i - 1].highTarget) { diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/HexByteArrayConversion.kt b/core/src/main/java/info/nightscout/androidaps/extensions/HexByteArrayConversion.kt index 9976da33ba..5f846581ae 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/HexByteArrayConversion.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/HexByteArrayConversion.kt @@ -18,7 +18,6 @@ fun ByteArray.toHex() : String{ return result.toString() } -@kotlin.ExperimentalStdlibApi fun String.hexStringToByteArray(): ByteArray { val result = ByteArray(length / 2) @@ -29,7 +28,7 @@ fun String.hexStringToByteArray(): ByteArray { val secondIndex = HEX_CHARS.indexOf(lowerCased[i + 1]) val octet = firstIndex.shl(4).or(secondIndex) - result.set(i.shr(1), octet.toByte()) + result[i.shr(1)] = octet.toByte() } return result diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt index c501b9cef0..189251db92 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt @@ -26,8 +26,7 @@ class PrefFileListProvider @Inject constructor( private val classicPrefsFormat: ClassicPrefsFormat, private val encryptedPrefsFormat: EncryptedPrefsFormat, private val storage: Storage, - private val versionCheckerUtils: VersionCheckerUtils, - context: Context + private val versionCheckerUtils: VersionCheckerUtils ) { private val path = File(Environment.getExternalStorageDirectory().toString()) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt index 575de38876..6afeb854b5 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt @@ -105,7 +105,6 @@ class EncryptedPrefsFormat @Inject constructor( } } - @kotlin.ExperimentalStdlibApi override fun loadPreferences(file: File, masterPassword: String?): Prefs { val entries: MutableMap = mutableMapOf() @@ -214,7 +213,7 @@ class EncryptedPrefsFormat @Inject constructor( } catch (e: IOException) { throw PrefIOError(file.absolutePath) } catch (e: JSONException) { - throw PrefFormatError("Mallformed preferences JSON file: $e") + throw PrefFormatError("Malformed preferences JSON file: $e") } } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt index 300ea2f380..8e98ee1fe3 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt @@ -6,7 +6,6 @@ class PinStrengthValidator(val _customErrorMessage: String?) : Validator(_custom val regex = "[0-9]{3,6}".toRegex() - @kotlin.ExperimentalStdlibApi override fun isValid(editText: EditText): Boolean { return try { val value = editText.text.toString() diff --git a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormatTest.kt b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormatTest.kt index 4094ff8a71..dba07234bc 100644 --- a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormatTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormatTest.kt @@ -22,7 +22,6 @@ import java.io.File @PowerMockIgnore("javax.crypto.*") @RunWith(PowerMockRunner::class) @PrepareForTest(File::class) -@kotlin.ExperimentalStdlibApi class EncryptedPrefsFormatTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index 412fe01956..a73ea6b675 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -33,7 +33,7 @@ import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInf import info.nightscout.androidaps.plugins.pump.common.bolusInfo.TemporaryBasalStorage import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.utils.* -import info.nightscout.androidaps.utils.T.Companion.mins +import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -141,7 +141,6 @@ class DanaRSPlugin @Inject constructor( commandQueue.readStatus("DeviceChanged", null) } - @kotlin.ExperimentalStdlibApi override fun connect(reason: String) { aapsLogger.debug(LTag.PUMP, "RS connect from: $reason") if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") { @@ -371,7 +370,7 @@ class DanaRSPlugin @Inject constructor( } } } - temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), mins(durationInMinutes.toLong()).msecs(), percentRate.toDouble(), false, tbrType, 0L, 0L)) + temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), T.mins(durationInMinutes.toLong()).msecs(), percentRate.toDouble(), false, tbrType, 0L, 0L)) // Convert duration from minutes to hours aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal $percentRate% for $durationInMinutes minutes (doLowTemp || doHighTemp)") result = if (percentRate == 0 && durationInMinutes > 30) { @@ -418,7 +417,7 @@ class DanaRSPlugin @Inject constructor( aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set") return result } - temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), mins(durationInMinutes.toLong()).msecs(), percent.toDouble(), false, tbrType, 0L, 0L)) + temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), T.mins(durationInMinutes.toLong()).msecs(), percent.toDouble(), false, tbrType, 0L, 0L)) val connectionOK: Boolean = if (durationInMinutes == 15 || durationInMinutes == 30) { danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes) ?: false diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/activities/EnterPinActivity.kt b/danars/src/main/java/info/nightscout/androidaps/danars/activities/EnterPinActivity.kt index 33268cb1e2..7161850604 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/activities/EnterPinActivity.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/activities/EnterPinActivity.kt @@ -33,7 +33,6 @@ class EnterPinActivity : NoSplashAppCompatActivity() { private lateinit var binding: DanarsEnterPinActivityBinding - @kotlin.ExperimentalStdlibApi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DanarsEnterPinActivityBinding.inflate(layoutInflater) diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt index 351e8a413a..5cbb2ecff0 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt @@ -60,7 +60,6 @@ abstract class DanaRSPacketHistory( return request } - @kotlin.ExperimentalStdlibApi override fun handleMessage(data: ByteArray) { val error: Int totalCount = 0 diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt index 51d16a88eb..9ae06c3fe3 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt @@ -90,7 +90,6 @@ class BLEComm @Inject internal constructor( private var uartWrite: BluetoothGattCharacteristic? = null @Synchronized - @kotlin.ExperimentalStdlibApi fun connect(from: String, address: String?): Boolean { aapsLogger.debug(LTag.PUMPBTCOMM, "Initializing BLEComm.") if (bluetoothManager == null) { @@ -227,7 +226,6 @@ class BLEComm @Inject internal constructor( bluetoothGatt = null } - @kotlin.ExperimentalStdlibApi private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized @@ -384,7 +382,6 @@ class BLEComm @Inject internal constructor( } } - @kotlin.ExperimentalStdlibApi private fun readDataParsing(receivedData: ByteArray) { //aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< readDataParsing " + DanaRS_Packet.toHexString(receivedData)) var packetIsValid = false @@ -518,7 +515,6 @@ class BLEComm @Inject internal constructor( writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) } - @kotlin.ExperimentalStdlibApi // 1st packet response private fun processConnectResponse(decryptedBuffer: ByteArray) { // response OK v1 diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt index d98579bd21..ab5d1e13a0 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt @@ -97,7 +97,6 @@ class DanaRSService : DaggerService() { val isConnecting: Boolean get() = bleComm.isConnecting - @kotlin.ExperimentalStdlibApi fun connect(from: String, address: String): Boolean { return bleComm.connect(from, address) } diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt index 953e851d3d..d3307c9d2a 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt @@ -31,7 +31,6 @@ class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() { } @Test - @kotlin.ExperimentalStdlibApi fun runTest() { val packet = DanaRSPacketHistoryAlarm(packetInjector, 0) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt index c480316c8e..36b1c0f7dd 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt @@ -851,6 +851,7 @@ class MedtronicPumpPlugin @Inject constructor( } //aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate); + @Suppress("UNCHECKED_CAST") val responseTask2 = rileyLinkMedtronicService.medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData, arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList?) if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task") diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt index 86afbc0014..621a17666b 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt @@ -143,7 +143,7 @@ class MedtronicUIPostprocessor @Inject constructor( } private fun postProcessSettings(uiTask: MedtronicUITask) { - val settings = uiTask.result as? Map ?: return + @Suppress("UNCHECKED_CAST") val settings = uiTask.result as? Map ?: return medtronicUtil.settings = settings var checkValue: PumpSettingDTO diff --git a/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansAPI.kt b/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansAPI.kt index 4d93eba5d2..69bca72f66 100644 --- a/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansAPI.kt +++ b/openhumans/src/main/java/info/nightscout/androidaps/plugin/general/openhumans/OpenHumansAPI.kt @@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugin.general.openhumans.dagger.BaseUrl import info.nightscout.androidaps.plugin.general.openhumans.dagger.ClientId import info.nightscout.androidaps.plugin.general.openhumans.dagger.ClientSecret import info.nightscout.androidaps.plugin.general.openhumans.dagger.RedirectUrl +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.* import okio.BufferedSink 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 88e9a3bb30..ed2c180ba2 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 @@ -5,7 +5,6 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent -import android.os.Build import android.util.DisplayMetrics import android.view.WindowManager import androidx.core.app.NotificationCompat @@ -225,16 +224,20 @@ class OpenHumansUploader @Inject internal constructor( tags.add("ApplicationInfo") val deviceInfo = JSONObject() - deviceInfo.put("brand", Build.BRAND) - deviceInfo.put("device", Build.DEVICE) - deviceInfo.put("manufacturer", Build.MANUFACTURER) - deviceInfo.put("model", Build.MODEL) - deviceInfo.put("product", Build.PRODUCT) + deviceInfo.put("brand", android.os.Build.BRAND) + deviceInfo.put("device", android.os.Build.DEVICE) + deviceInfo.put("manufacturer", android.os.Build.MANUFACTURER) + deviceInfo.put("model", android.os.Build.MODEL) + deviceInfo.put("product", android.os.Build.PRODUCT) zos.writeFile("DeviceInfo.json", deviceInfo.toString().toByteArray()) tags.add("DeviceInfo") val displayMetrics = DisplayMetrics() - (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(displayMetrics) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + context.display?.getRealMetrics(displayMetrics) + else + @Suppress("DEPRECATION") (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(displayMetrics) + val displayInfo = JSONObject() displayInfo.put("height", displayMetrics.heightPixels) displayInfo.put("width", displayMetrics.widthPixels) diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt index 592674088a..ef8866d040 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt @@ -1,9 +1,7 @@ package info.nightscout.androidaps.plugins.pump.common.sync -import com.google.gson.Gson -import com.google.gson.GsonBuilder -import com.thoughtworks.xstream.security.AnyTypePermission import com.thoughtworks.xstream.XStream +import com.thoughtworks.xstream.security.AnyTypePermission import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.logging.AAPSLogger @@ -23,17 +21,20 @@ class PumpSyncStorage @Inject constructor( val aapsLogger: AAPSLogger ) { - val pumpSyncStorageKey: String = "pump_sync_storage_xstream_v2" + companion object { + + const val pumpSyncStorageKey: String = "pump_sync_storage_xstream_v2" + const val TBR: String = "TBR" + const val BOLUS: String = "BOLUS" + } + var pumpSyncStorage: MutableMap> = mutableMapOf() - var TBR: String = "TBR" - var BOLUS: String = "BOLUS" - var storageInitialized: Boolean = false - var gson: Gson = GsonBuilder().create() - var xstream: XStream = XStream() + private var storageInitialized: Boolean = false + private var xstream: XStream = XStream() init { initStorage() - cleanOldStorage(); + cleanOldStorage() } fun initStorage() { @@ -43,10 +44,11 @@ class PumpSyncStorage @Inject constructor( var loaded = false if (sp.contains(pumpSyncStorageKey)) { - val jsonData: String = sp.getString(pumpSyncStorageKey, ""); + val jsonData: String = sp.getString(pumpSyncStorageKey, "") if (jsonData.isNotBlank()) { xstream.addPermission(AnyTypePermission.ANY) + @Suppress("UNCHECKED_CAST") pumpSyncStorage = xstream.fromXML(jsonData, MutableMap::class.java) as MutableMap> aapsLogger.debug(LTag.PUMP, String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size)) @@ -69,7 +71,7 @@ class PumpSyncStorage @Inject constructor( } } - fun cleanOldStorage(): Unit { + private fun cleanOldStorage() { val oldSpKeys = setOf("pump_sync_storage", "pump_sync_storage_xstream") for (oldSpKey in oldSpKeys) { @@ -78,16 +80,16 @@ class PumpSyncStorage @Inject constructor( } } - fun isStorageEmpty(): Boolean { + private fun isStorageEmpty(): Boolean { return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty() } fun getBoluses(): MutableList { - return pumpSyncStorage[BOLUS]!!; + return pumpSyncStorage[BOLUS]!! } fun getTBRs(): MutableList { - return pumpSyncStorage[TBR]!!; + return pumpSyncStorage[TBR]!! } fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { @@ -135,11 +137,11 @@ class PumpSyncStorage @Inject constructor( } fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { - val timenow: Long = System.currentTimeMillis() - val temporaryId = creator.generateTempId(timenow) + val timeNow: Long = System.currentTimeMillis() + val temporaryId = creator.generateTempId(timeNow) val response = pumpSync.addTemporaryBasalWithTempId( - timenow, + timeNow, temporaryBasal.rate, (temporaryBasal.durationInSeconds * 1000L), temporaryBasal.isAbsolute, @@ -151,12 +153,12 @@ class PumpSyncStorage @Inject constructor( if (response && writeToInternalHistory) { val innerList: MutableList = pumpSyncStorage[TBR]!! - innerList.add(PumpDbEntry(temporaryId, timenow, creator.model(), creator.serialNumber(), null, temporaryBasal)) + innerList.add(PumpDbEntry(temporaryId, timeNow, creator.model(), creator.serialNumber(), null, temporaryBasal)) pumpSyncStorage[BOLUS] = innerList saveStorage() } - return response; + return response } fun removeBolusWithTemporaryId(temporaryId: Long) {