From e0421b509c81a33f4a8a33741e8efafd7651eb07 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 21 Aug 2019 17:41:54 +0200 Subject: [PATCH 01/30] LocationService: invoke startForeground in onCreate(). --- .../info/nightscout/androidaps/services/LocationService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java index feec4dcab8..485ad1823a 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java @@ -86,6 +86,8 @@ public class LocationService extends Service { @Override public void onCreate() { + super.onCreate(); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification()); if (L.isEnabled(L.LOCATION)) log.debug("onCreate"); From 450a25c3b847c3eea1a2c607efe17b52b891643d Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Wed, 21 Aug 2019 17:38:01 +0100 Subject: [PATCH 02/30] Allow for Battery Optimization failing on some platforms --- .../setupwizard/SetupWizardActivity.java | 2 +- .../androidaps/utils/AndroidPermission.java | 36 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java index 3064228fd3..f998b343a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java @@ -226,7 +226,7 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity { } @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == AndroidPermission.CASE_BATTERY) updateButtons(); diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 7963ae0545..42f24dff69 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -3,7 +3,9 @@ package info.nightscout.androidaps.utils; import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; @@ -11,6 +13,7 @@ import android.os.Build; import android.os.PowerManager; import android.provider.Settings; +import androidx.appcompat.app.AlertDialog; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -45,10 +48,26 @@ public class AndroidPermission { ActivityCompat.requestPermissions(activity, permission, requestCode); } if (testBattery) { - Intent i = new Intent(); - i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); - i.setData(Uri.parse("package:" + activity.getPackageName())); - activity.startActivityForResult(i, CASE_BATTERY); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + try { + Intent i = new Intent(); + i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + i.setData(Uri.parse("package:" + activity.getPackageName())); + activity.startActivityForResult(i, CASE_BATTERY); + } catch (ActivityNotFoundException e) { + SP.putBoolean(R.string.key_permission_battery_optimization_failed, true); + + AlertDialog.Builder alert = new AlertDialog.Builder(activity); + alert.setMessage(R.string.alert_dialog_permission_battery_optimization_failed); + alert.setPositiveButton(R.string.ok, null); + alert.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + activity.recreate(); + } + }); + alert.show(); + } } } @@ -60,9 +79,12 @@ public class AndroidPermission { public static boolean permissionNotGranted(Context context, String permission) { boolean selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; if (permission.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { - PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - String packageName = context.getPackageName(); - selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && !SP.getBoolean(R.string.key_permission_battery_optimization_failed, false)) { + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + String packageName = context.getPackageName(); + selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName); + } } return !selfCheck; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2029c7023d..6a77b5acf7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,8 @@ DanaR Bluetooth device Always use basal absolute values Please reboot your phone or restart AndroidAPS from the System Settings \notherwise Android APS will not have logging (important to track and verify that the algorithms are working correctly)! + key_permission_battery_optimization_failed + This device does not appear to support battery optimization whitelisting - you may experience performance issues. Some buttons to quickly access common features Enter advanced log book entries. From d0335e56fa37ea3d7e4589d96840fedc30387df7 Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Wed, 21 Aug 2019 17:45:31 +0100 Subject: [PATCH 03/30] Allow for Battery Optimization failing on some platforms --- .../nightscout/androidaps/setupwizard/SetupWizardActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java index f998b343a2..3064228fd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java @@ -226,7 +226,7 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity { } @Override - public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == AndroidPermission.CASE_BATTERY) updateButtons(); From 2384573831aa09dc39e360278fea656ce7a8ac2f Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Wed, 21 Aug 2019 20:41:29 +0100 Subject: [PATCH 04/30] Fix for fill canula double bolus --- .../androidaps/plugins/treatments/TreatmentsPlugin.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index a9284dd366..1f1e03ec9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -294,14 +294,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } + /** + * Returns all Treatments after specified timestamp. Also returns invalid entries (required to + * map "Fill Canulla" entries to history (and not to add double bolus for it) + * + * @param fromTimestamp + * @return + */ @Override public List getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) { List in5minback = new ArrayList<>(); long time = System.currentTimeMillis(); synchronized (treatments) { for (Treatment t : treatments) { - if (!t.isValid) - continue; if (t.date <= time && t.date >= fromTimestamp) in5minback.add(t); } From fb6bcfdccd42fb7991a7a0a226ab03b5607fdee6 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 22 Aug 2019 11:12:15 +0200 Subject: [PATCH 05/30] Log an uncaught exception before it crashes the app. --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index f539f2e33f..f2edd23882 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -139,6 +139,8 @@ public class MainApp extends Application { sConstraintsChecker = new ConstraintChecker(); sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class); + Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> log.error("Uncaught exception crashing app", ex)); + try { if (FabricPrivacy.fabricEnabled()) { Fabric.with(this, new Crashlytics()); From 75be27485cf41aedf7a469a303dc07244fa3555d Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Thu, 22 Aug 2019 10:29:13 +0100 Subject: [PATCH 06/30] Typo in battery optimization code --- .../java/info/nightscout/androidaps/utils/AndroidPermission.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 42f24dff69..3a9d8909b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -67,6 +67,7 @@ public class AndroidPermission { } }); alert.show(); + } } } } From 6d91938b3f97311af56fb9397a0becde7a21eaa4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 23 Aug 2019 21:48:00 +0200 Subject: [PATCH 07/30] allow disable automation event --- .../general/automation/AutomationEvent.java | 14 ++++-- .../general/automation/AutomationPlugin.kt | 2 +- .../general/automation/EventListAdapter.java | 13 ++++++ .../main/res/layout/automation_event_item.xml | 43 +++++++++++-------- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java index b92dadc89b..6eb3be382b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java @@ -16,6 +16,7 @@ public class AutomationEvent { private Trigger trigger = new TriggerConnector(); private List actions = new ArrayList<>(); private String title; + private boolean enabled = true; public void setTitle(String title) { this.title = title; @@ -33,6 +34,14 @@ public class AutomationEvent { return actions; } + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean newState) { + enabled = newState; + } + public TriggerConnector getPreconditions() { TriggerConnector trigger = new TriggerConnector(TriggerConnector.Type.AND); for (Action action : actions) { @@ -55,6 +64,7 @@ public class AutomationEvent { try { // title o.put("title", title); + o.put("enabled", enabled); // trigger o.put("trigger", trigger.toJSON()); // actions @@ -72,11 +82,9 @@ public class AutomationEvent { public AutomationEvent fromJSON(String data) { try { JSONObject d = new JSONObject(data); - // title title = d.optString("title", ""); - // trigger + enabled = d.optBoolean("enabled", true); trigger = Trigger.instantiate(d.getString("trigger")); - // actions JSONArray array = d.getJSONArray("actions"); actions.clear(); for (int i = 0; i < array.length(); i++) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index 2ab2c91411..a2a84890fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -171,7 +171,7 @@ object AutomationPlugin : PluginBase(PluginDescription() if (L.isEnabled(L.AUTOMATION)) log.debug("processActions") for (event in automationEvents) { - if (event.trigger.shouldRun() && event.preconditions.shouldRun()) { + if (event.isEnabled() && event.trigger.shouldRun() && event.preconditions.shouldRun()) { val actions = event.actions for (action in actions) { action.doAction(object : Callback() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java index 4bbd4a0959..b4c6fb1f11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -20,8 +21,10 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.automation.actions.Action; import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog; +import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged; import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; class EventListAdapter extends RecyclerView.Adapter { @@ -51,6 +54,7 @@ class EventListAdapter extends RecyclerView.Adapter public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final AutomationEvent event = mEventList.get(position); holder.eventTitle.setText(event.getTitle()); + holder.enabled.setChecked(event.isEnabled()); holder.iconLayout.removeAllViews(); // trigger icons @@ -77,6 +81,13 @@ class EventListAdapter extends RecyclerView.Adapter addImage(res, holder.context, holder.iconLayout); } + // enabled event + holder.enabled.setOnCheckedChangeListener((buttonView, isChecked) -> { + event.setEnabled(isChecked); + notifyDataSetChanged(); + RxBus.INSTANCE.send(new EventAutomationDataChanged()); + }); + // remove event holder.iconTrash.setOnClickListener(v -> { mEventList.remove(event); @@ -107,6 +118,7 @@ class EventListAdapter extends RecyclerView.Adapter final TextView eventTitle; final Context context; final ImageView iconTrash; + final CheckBox enabled; ViewHolder(View view, Context context) { super(view); @@ -115,6 +127,7 @@ class EventListAdapter extends RecyclerView.Adapter rootLayout = view.findViewById(R.id.rootLayout); iconLayout = view.findViewById(R.id.iconLayout); iconTrash = view.findViewById(R.id.iconTrash); + enabled = view.findViewById(R.id.automation_enabled); } } } diff --git a/app/src/main/res/layout/automation_event_item.xml b/app/src/main/res/layout/automation_event_item.xml index ce377a6aa0..6cbc138278 100644 --- a/app/src/main/res/layout/automation_event_item.xml +++ b/app/src/main/res/layout/automation_event_item.xml @@ -11,6 +11,27 @@ android:background="@color/ribbonDefault" android:padding="8dp"> + + + + + android:layout_below="@id/automation_enabled" + android:orientation="horizontal" /> - - - - - \ No newline at end of file From a6ea69bad0a6730add1dd5d67ca1accecd52fb0f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 10:56:36 +0200 Subject: [PATCH 08/30] Cleanup --- .../androidaps/plugins/aps/loop/LoopFragment.kt | 6 +----- .../plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt | 6 +----- .../plugins/aps/openAPSMA/OpenAPSMAFragment.kt | 6 +----- .../plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt | 8 +++----- .../plugins/general/automation/AutomationFragment.kt | 6 +----- .../plugins/general/automation/AutomationPlugin.kt | 11 ++--------- .../plugins/general/nsclient/NSClientPlugin.java | 1 + .../plugins/general/overview/OverviewPlugin.java | 1 + .../PersistentNotificationPlugin.java | 1 + .../smsCommunicator/SmsCommunicatorPlugin.java | 1 + .../plugins/general/tidepool/TidepoolFragment.kt | 5 ----- .../plugins/general/tidepool/TidepoolPlugin.kt | 6 ------ .../androidaps/plugins/general/wear/WearPlugin.java | 1 + .../plugins/profile/ns/NSProfilePlugin.java | 1 + .../plugins/pump/common/PumpPluginAbstract.java | 1 + .../androidaps/plugins/pump/danaR/DanaRFragment.kt | 10 +--------- .../androidaps/plugins/pump/danaR/DanaRPlugin.java | 1 + .../plugins/pump/danaRKorean/DanaRKoreanPlugin.java | 1 + .../androidaps/plugins/pump/danaRS/DanaRSPlugin.java | 1 + .../plugins/pump/danaRv2/DanaRv2Plugin.java | 1 + .../plugins/pump/medtronic/MedtronicFragment.kt | 10 +--------- .../plugins/pump/virtual/VirtualPumpPlugin.java | 1 + .../plugins/treatments/TreatmentsPlugin.java | 1 + .../androidaps/utils/CompositeDisposablePlusAssign.kt | 9 +++++++++ 24 files changed, 33 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/CompositeDisposablePlusAssign.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index b4aa6b0991..1a5caa42aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -15,19 +15,15 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.loop_fragment.* class LoopFragment : Fragment() { private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.loop_fragment, container, false) 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 763c93aa8c..59dc5956e9 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 @@ -15,9 +15,9 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.JSONFormatter +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.openapsama_fragment.* import org.json.JSONArray import org.json.JSONException @@ -27,10 +27,6 @@ class OpenAPSAMAFragment : Fragment() { private val log = LoggerFactory.getLogger(L.APS) private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.openapsama_fragment, container, false) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt index 6525641332..1f002a4688 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt @@ -13,9 +13,9 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.JSONFormatter +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.openapsama_fragment.* import org.slf4j.LoggerFactory @@ -23,10 +23,6 @@ class OpenAPSMAFragment : Fragment() { private val log = LoggerFactory.getLogger(L.APS) private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.openapsma_fragment, container, false) 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 c102b65173..264473c146 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 @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB +import android.annotation.SuppressLint import android.os.Bundle import android.text.TextUtils import android.view.LayoutInflater @@ -15,9 +16,9 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.JSONFormatter +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.openapsama_fragment.* import org.json.JSONArray import org.json.JSONException @@ -27,10 +28,6 @@ class OpenAPSSMBFragment : Fragment() { private val log = LoggerFactory.getLogger(L.APS) private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.openapsama_fragment, container, false) @@ -85,6 +82,7 @@ class OpenAPSSMBFragment : Fragment() { openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) } catch (e: JSONException) { log.error("Unhandled exception", e) + @SuppressLint("SetTextl18n") openapsma_iobdata.text = "JSONException see log for details" } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt index 0bf996bd52..661944d098 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt @@ -12,9 +12,9 @@ import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDi import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.automation_fragment.* class AutomationFragment : Fragment() { @@ -22,10 +22,6 @@ class AutomationFragment : Fragment() { private var disposable: CompositeDisposable = CompositeDisposable() private var eventListAdapter: EventListAdapter? = null - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.automation_fragment, container, false) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index a2a84890fc..00a76778d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -21,12 +21,8 @@ import info.nightscout.androidaps.plugins.general.automation.triggers.* import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.services.LocationService -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SP -import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.* import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.json.JSONArray import org.json.JSONException @@ -60,10 +56,6 @@ object AutomationPlugin : PluginBase(PluginDescription() } } - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onStart() { val context = MainApp.instance().applicationContext if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) @@ -131,6 +123,7 @@ object AutomationPlugin : PluginBase(PluginDescription() loopHandler.removeCallbacks(refreshLoop) val context = MainApp.instance().applicationContext context.stopService(Intent(context, LocationService::class.java)) + super.onStop() } private fun storeToSP() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index b5ff92ee0e..4b6072ee1e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -113,6 +113,7 @@ public class NSClientPlugin extends PluginBase { context.unbindService(mConnection); nsClientReceiverDelegate.unregisterReceivers(); + super.onStop(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java index 9633c8fbbe..4301ad6ec0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java @@ -71,6 +71,7 @@ public class OverviewPlugin extends PluginBase { @Override protected void onStop() { MainApp.bus().unregister(this); + super.onStop(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index e06dc741be..8582a5e277 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -113,6 +113,7 @@ public class PersistentNotificationPlugin extends PluginBase { protected void onStop() { MainApp.bus().unregister(this); MainApp.instance().stopService(new Intent(MainApp.instance(), DummyService.class)); + super.onStop(); } private void triggerNotificationUpdate() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java index 14dcb169c4..095997daf9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -98,6 +98,7 @@ public class SmsCommunicatorPlugin extends PluginBase { @Override protected void onStop() { MainApp.bus().unregister(this); + super.onStop(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt index 86eb704bab..8566f25703 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt @@ -16,17 +16,12 @@ import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.SP import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.tidepool_fragment.* class TidepoolFragment : Fragment() { private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.tidepool_fragment, container, false) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt index b7896d7e56..78ad0ab37d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.general.tidepool -import android.text.Html import android.text.Spanned import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp @@ -23,7 +22,6 @@ import info.nightscout.androidaps.receivers.ChargingStateReceiver import info.nightscout.androidaps.receivers.NetworkChangeReceiver import info.nightscout.androidaps.utils.* import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.slf4j.LoggerFactory import java.util.* @@ -43,10 +41,6 @@ object TidepoolPlugin : PluginBase(PluginDescription() private val listLog = ArrayList() var textLog: Spanned = HtmlHelper.fromHtml("") - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - override fun onStart() { super.onStart() disposable += RxBus diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java index 69e327a21b..53b421ace3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java @@ -91,6 +91,7 @@ public class WearPlugin extends PluginBase { protected void onStop() { MainApp.bus().unregister(this); disposable.clear(); + super.onStop(); } private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java index 88faee377a..a6088f5515 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java @@ -65,6 +65,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface { @Override protected void onStop() { MainApp.bus().unregister(this); + super.onStop(); } public void handleNewData(Intent intent) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 3deda538be..fa68e55616 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -100,6 +100,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter serviceRunning = false; MainApp.bus().unregister(this); + super.onStop(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 377e417274..f67c09817d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -27,13 +27,9 @@ import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog import info.nightscout.androidaps.queue.events.EventQueueChanged -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SetWarnColor -import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.* import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.danar_fragment.* import org.slf4j.LoggerFactory @@ -41,10 +37,6 @@ class DanaRFragment : Fragment() { private val log = LoggerFactory.getLogger(L.PUMP) private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - private val loopHandler = Handler() private lateinit var refreshLoop: Runnable diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java index 80d0390390..6a01c5fed8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java @@ -65,6 +65,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { context.unbindService(mConnection); MainApp.bus().unregister(this); + super.onStop(); } private ServiceConnection mConnection = new ServiceConnection() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java index 07df7fb29f..64eccf05f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java @@ -68,6 +68,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { context.unbindService(mConnection); MainApp.bus().unregister(this); + super.onStop(); } private ServiceConnection mConnection = new ServiceConnection() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 1e38ccc312..19005509cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -123,6 +123,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte context.unbindService(mConnection); MainApp.bus().unregister(this); + super.onStop(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index 65fb602ff4..607f7346b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -71,6 +71,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { context.unbindService(mConnection); MainApp.bus().unregister(this); + super.onStop(); } private ServiceConnection mConnection = new ServiceConnection() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index a77de2e4a4..6bbe2057a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -35,13 +35,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.events.EventQueueChanged -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SetWarnColor -import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.* import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.medtronic_fragment.* import org.slf4j.LoggerFactory @@ -50,10 +46,6 @@ class MedtronicFragment : Fragment() { private val log = LoggerFactory.getLogger(L.PUMP) private var disposable: CompositeDisposable = CompositeDisposable() - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - private val loopHandler = Handler() private lateinit var refreshLoop: Runnable diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index 1c2cf1f954..6b561bc41d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -128,6 +128,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override protected void onStop() { MainApp.bus().unregister(this); + super.onStop(); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index a9284dd366..8b18c61851 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -110,6 +110,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override protected void onStop() { MainApp.bus().register(this); + super.onStop(); } public TreatmentService getService() { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CompositeDisposablePlusAssign.kt b/app/src/main/java/info/nightscout/androidaps/utils/CompositeDisposablePlusAssign.kt new file mode 100644 index 0000000000..1f2fb892e5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/CompositeDisposablePlusAssign.kt @@ -0,0 +1,9 @@ +package info.nightscout.androidaps.utils + +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.disposables.Disposable + +operator fun CompositeDisposable.plusAssign(disposable: Disposable) { + add(disposable) +} + From 06d69ea252692fe6fdb1b5c6f2ae1b01c36525e0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 17:43:21 +0200 Subject: [PATCH 09/30] fix test --- .../plugins/general/automation/AutomationEventTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.java index a40bcdb2fe..e3030b8a91 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.java @@ -22,7 +22,7 @@ public class AutomationEventTest { event.addAction(new ActionLoopEnable()); // export to json - final String eventJsonExpected = "{\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\"}\",\"title\":\"Test\",\"actions\":[\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable\\\"}\"]}"; + final String eventJsonExpected = "{\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\"}\",\"title\":\"Test\",\"actions\":[\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable\\\"}\"],\"enabled\":true}"; Assert.assertEquals(eventJsonExpected, event.toJSON()); // clone From 719f90a3ac877b962cbad2963fd227df902ff970 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 18:33:04 +0200 Subject: [PATCH 10/30] remove ctx from PersistentNotificationPlugin --- .../PersistentNotificationPlugin.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index 8582a5e277..3e23bd9b16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -55,14 +55,13 @@ public class PersistentNotificationPlugin extends PluginBase { private Notification notification; public static PersistentNotificationPlugin getPlugin() { - if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance()); + if (plugin == null) plugin = new PersistentNotificationPlugin(); return plugin; } public static final String CHANNEL_ID = "AndroidAPS-Ongoing"; public static final int ONGOING_NOTIFICATION_ID = 4711; - private final Context ctx; /// For Android Auto /// Intents are not declared in manifest and not consumed, this is intentionally because actually we can't do anything with @@ -76,7 +75,7 @@ public class PersistentNotificationPlugin extends PluginBase { /// End Android Auto - private PersistentNotificationPlugin(Context ctx) { + private PersistentNotificationPlugin() { super(new PluginDescription() .mainType(PluginType.GENERAL) .neverVisible(true) @@ -86,7 +85,6 @@ public class PersistentNotificationPlugin extends PluginBase { .showInList(false) .description(R.string.description_persistent_notification) ); - this.ctx = ctx; } @Override @@ -101,7 +99,7 @@ public class PersistentNotificationPlugin extends PluginBase { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager = - (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); @SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_HIGH); @@ -186,7 +184,7 @@ public class PersistentNotificationPlugin extends PluginBase { .setPackage(PACKAGE); PendingIntent msgReadPendingIntent = - PendingIntent.getBroadcast(ctx, + PendingIntent.getBroadcast(MainApp.instance(), ONGOING_NOTIFICATION_ID, msgReadIntent, PendingIntent.FLAG_UPDATE_CURRENT); @@ -198,7 +196,7 @@ public class PersistentNotificationPlugin extends PluginBase { .setPackage(PACKAGE); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( - ctx, + MainApp.instance(), ONGOING_NOTIFICATION_ID, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); @@ -218,12 +216,12 @@ public class PersistentNotificationPlugin extends PluginBase { /// End Android Auto } - NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID); + NotificationCompat.Builder builder = new NotificationCompat.Builder(MainApp.instance(), CHANNEL_ID); builder.setOngoing(true); builder.setOnlyAlertOnce(true); builder.setCategory(NotificationCompat.CATEGORY_STATUS); builder.setSmallIcon(MainApp.getNotificationIcon()); - Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), MainApp.getIcon()); + Bitmap largeIcon = BitmapFactory.decodeResource(MainApp.instance().getResources(), MainApp.getIcon()); builder.setLargeIcon(largeIcon); builder.setContentTitle(line1 != null ? line1 : MainApp.gs(R.string.noprofileset)); builder.setContentText(line2 != null ? line2 : MainApp.gs(R.string.noprofileset)); @@ -236,9 +234,9 @@ public class PersistentNotificationPlugin extends PluginBase { /// End Android Auto - Intent resultIntent = new Intent(ctx, MainActivity.class); + Intent resultIntent = new Intent(MainApp.instance(), MainActivity.class); - TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx); + TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainApp.instance()); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = @@ -248,7 +246,7 @@ public class PersistentNotificationPlugin extends PluginBase { ); builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = - (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); android.app.Notification notification = builder.build(); mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification); From 792a1d7ddde38e4bf17794b5a07d52a6daba6e9d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 18:58:17 +0200 Subject: [PATCH 11/30] code cleanup --- .../androidaps/utils/AndroidPermission.java | 37 ++++++------------- app/src/main/res/values/strings.xml | 1 - 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 3a9d8909b3..11d584bb87 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -5,7 +5,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; @@ -13,7 +12,6 @@ import android.os.Build; import android.os.PowerManager; import android.provider.Settings; -import androidx.appcompat.app.AlertDialog; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -32,6 +30,8 @@ public class AndroidPermission { public static final int CASE_BATTERY = 0x4; public static final int CASE_PHONE_STATE = 0x5; + private static boolean permission_battery_optimization_failed = false; + @SuppressLint("BatteryLife") private static void askForPermission(Activity activity, String[] permission, Integer requestCode) { boolean test = false; @@ -48,27 +48,15 @@ public class AndroidPermission { ActivityCompat.requestPermissions(activity, permission, requestCode); } if (testBattery) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - try { - Intent i = new Intent(); - i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); - i.setData(Uri.parse("package:" + activity.getPackageName())); - activity.startActivityForResult(i, CASE_BATTERY); - } catch (ActivityNotFoundException e) { - SP.putBoolean(R.string.key_permission_battery_optimization_failed, true); - - AlertDialog.Builder alert = new AlertDialog.Builder(activity); - alert.setMessage(R.string.alert_dialog_permission_battery_optimization_failed); - alert.setPositiveButton(R.string.ok, null); - alert.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - activity.recreate(); - } - }); - alert.show(); - } - } + try { + Intent i = new Intent(); + i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + i.setData(Uri.parse("package:" + activity.getPackageName())); + activity.startActivityForResult(i, CASE_BATTERY); + } catch (ActivityNotFoundException e) { + permission_battery_optimization_failed = true; + OKDialog.show(activity, MainApp.gs(R.string.permission), MainApp.gs(R.string.alert_dialog_permission_battery_optimization_failed), activity::recreate); + } } } @@ -80,8 +68,7 @@ public class AndroidPermission { public static boolean permissionNotGranted(Context context, String permission) { boolean selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; if (permission.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && !SP.getBoolean(R.string.key_permission_battery_optimization_failed, false)) { + if (!permission_battery_optimization_failed) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); String packageName = context.getPackageName(); selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a77b5acf7..2bb2753b66 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,7 +38,6 @@ DanaR Bluetooth device Always use basal absolute values Please reboot your phone or restart AndroidAPS from the System Settings \notherwise Android APS will not have logging (important to track and verify that the algorithms are working correctly)! - key_permission_battery_optimization_failed This device does not appear to support battery optimization whitelisting - you may experience performance issues. Some buttons to quickly access common features From 224926d38c179efb4e15f0ecfa802cf631bcc9b6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 19:03:19 +0200 Subject: [PATCH 12/30] New Crowdin translations (#1978) * New translations strings.xml (French) * New translations strings.xml (Greek) * New translations strings.xml (Greek) * New translations insight_exceptions.xml (Greek) * New translations strings.xml (Greek) * New translations strings.xml (Polish) --- .../res/values-el-rGR/insight_exceptions.xml | 8 ++ app/src/main/res/values-el-rGR/strings.xml | 108 ++++++++++++++++++ app/src/main/res/values-pl-rPL/strings.xml | 6 +- 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-el-rGR/insight_exceptions.xml b/app/src/main/res/values-el-rGR/insight_exceptions.xml index e19a9b177d..0ebc1db351 100644 --- a/app/src/main/res/values-el-rGR/insight_exceptions.xml +++ b/app/src/main/res/values-el-rGR/insight_exceptions.xml @@ -4,4 +4,12 @@ Αποτυχία σύνδεσης Απώλεια σύνδεσης Σύζευξη απορρίφθηκε + Αποτυχία δημιουργίας σύνδεσης + Τέλος χρονικού ορίου + Μέγιστος αριθμός τύπων bolus ήδη τρέχει + Μη ενεργός TBR για ακύρωση + Μη ενεργός TBR για αλλαγή + Όχι τέτοιο bolus για ακύρωση + Η αντλία είναι ήδη σε αυτό το στάδιο + Δεν επιτρέπεται το στάδιο Run diff --git a/app/src/main/res/values-el-rGR/strings.xml b/app/src/main/res/values-el-rGR/strings.xml index 13e36d84ae..a14b9e6e77 100644 --- a/app/src/main/res/values-el-rGR/strings.xml +++ b/app/src/main/res/values-el-rGR/strings.xml @@ -146,6 +146,7 @@ Τελευταία εφαρμογή ΟΚ Ακύρωση + Κλείσιμο ΔΕΝ ΕΠΙΛΕΧΘΗΚΕ APS Ή ΒΡΕΘΗΚΕ ΑΠΟΤΕΛΕΣΜΑ Ασφάλεια Προσθήκη απενεργοποιημένη @@ -830,6 +831,7 @@ Μη συμβατό δευτερόλεπτο λεπτό + %1$.2f h ώρα ημέρα εβδομάδα @@ -1079,6 +1081,7 @@ Σφάλμα ταχύτητας Υπέρβαση του ορίου ινσουλίνης Ελάχιστο αίτημα για αλλαγή [%] + Το Ανοιχτό κύκλωμα θα εμφανίσει νέο μήνυμα αλλαγής μόνο αν η αλλαγή είναι μεγαλύτερη από αυτήν τη τιμή %. Προεπιλεγμένη τιμή 20% Παρακαλώ συνδέστε την αντλία στο τηλέφωνο! Αναζήτηση συσκευών… Περιμένετε… @@ -1188,6 +1191,7 @@ Αυτόματο Αυτοματισμός == ∑ %1$s U + U/h g/U /U Αλλαγή αρχείου αισθητήρα σε NS @@ -1234,7 +1238,14 @@ Κατάσταση: Ενέργεια: ΙΟΒ [U]: + Γλυκόζη [%1$s]: + ΔΙΑΓΡ + Προσθ + Αντιγραφή + Προσθήκη νέου Έλεγχος Έκδοσης + Έλεγχος υπογραφής + Διαπιστώσαμε ότι εκτελείτε μη έγκυρη έκδοση. Κύκλωμα απενεργοποιήθηκε! παλιά έκδοση πολύ παλιά έκδοση Νέα έκδοση για τουλάχιστον %1$d ημέρες διαθέσιμη! Επιστροφή σε LGS μετά από 60 ημέρες, το κύκλωμα θα απενεργοποιηθεί μετά από 90 ημέρες @@ -1243,9 +1254,52 @@ Εφαρμογή Dexcom (τροποποιημένη) DXCM Λάβετε τις τιμές BG από την εφαρμογή του Dexcom. + Ειδοποίηση + Ειδοποίηση: %1$s + Μην: + Προφίλ ποσοστό + Ποσοστό [%]: + Έναρξη προφίλ %1$d%% για %2$d λεπτά + Έναρξη προφίλ %1$d%% + υπάρχει + δεν υπάρχει + Προσ. στόχος %1$s + WiFi SSID %1$s %2$s + Autosens %1$s %2$s %% + Autosens % + %3$s %1$s %2$s + Διαφορά BG + Τρέχουσα θέση + Τοποθεσία + Lat: + Lon: + Αποστ [m]: + Όνομα: + Η τοποθεσία είναι %1$s + Τελευταίο Bolus + Τελευταίο bolus %1$s %2$s λεπτά πριν + COB + COB %1$s %2$.0f + Όνομα εργασίας + Όνομα συμβάντος + Επεξεργασία + Επιλέξτε έναν τύπο δράσης: + Επιλέξτε έναν τύπο ενεργοποίησης: + Αν: + Έπειτα: + Ενεργοποιήσεις: + ΜΕΤΑΚΙΝΗΣΗ + Προϋποθέσεις: + Η λειτουργία δεν υποστηρίζεται από την αντλία ή/και οδηγό. + Η λειτουργία δεν υποστηρίζεται ΑΚΟΜΑ από την αντλία. + Η ολοκλήρωση της αντλίας για τη Medtronic, απαιτεί τη συσκευή RileyLink και το συγκεκριμένο μοντέλο αντλίας + Σειριακός Αριθμός Αντλίας + Τύπος Αντλίας + Συχνότητα Αντλίας + Η καθυστέρηση πριν το bolus ξεκίνησε (s) Μέγιστο Bolus στην αντλία (U) Μέγιστος Βασικός στην αντλία (U/h) Αποκωδικοποίηση Medtronic @@ -1299,16 +1353,67 @@ Επαναφορά Bluetooth… Σφάλμα Bluetooth + Bluetooth Έτοιμο + Δεν ξεκίνησε + Αρχικοποίηση του RileyLink… + RileyLink Σφάλμα + Ρύθμιση του RileyLink και της αντλίας + Πρόβλημα σύνδεσης με την Αντλία + Συνδέθηκε + Η συσκευή δεν είναι RileyLink + Το RileyLink μη προσπελάσιμο + Bluetooth απενεργοποιημένο + Δεν υπάρχει προσαρμογέας Bluetooth + TuneUp απέτυχε + Η αντλία δεν είναι διαθέσιμη + Το Pod δεν είναι διαθέσιμο + Μη ορισμένο + Αντλία Medtronic + Omnipod + Σφάλματα + Δεν ορίστηκε # Serial. + Serial # μη έγκυρο. + Δεν ορίστηκε Τύπος Αντλίας. + Τύπος Αντλίας δεν υποστηρίζεται. + Δεν ορίστηκε Συχνότητα Αντλίας. + Συχνότητα Αντλίας δεν υποστηρίζεται. + Διεύθυνση RileyLink μη έγκυρη. + Ο τύπος αντλίας που ανιχνεύτηκε δεν είναι ο ίδιος με αυτόν που ορίστηκε. + Τα προφίλ βασικού δεν είναι ενεργοποιημένα στην αντλία. + Το βασικό προφίλ που ορίστηκε στην αντλία είναι λάθoς (πρέπει να είναι STD). + Λάθος τύπος TBR ορίστηκε στην αντλία (πρέπει να είναι Absolute). + Λάθος μέγιστο bolus ορίστηκε στην αντλία (πρέπει να είναι %1$.2f). + Λάθος μέγιστο Βασικού ορίστηκε στην αντλία (πρέπει να είναι %1$.2f). + Λειτουργία δεν είναι δυνατή. \n\n Χρειάζεται να ρυθμίσετε την αντλία Medtronic πρώτα, προτού να μπορέσετε να χρησιμοποιήσετε αυτή την λειτουργία. + Απαιτήθηκε αλλαγή ώρας πάνω από 24h. + Βασικοί + Ρύθμιση παραμέτρων + Ειδοποιήσεις + Στατιστικά + Άγνωστα + Όλα + Ιστορικό Αντλίας Medtronic + Ποτέ δεν επικοινωνήσατε + Ξύπνημα + Σφάλμα με επικοινωνία + Λήξη χρόνου επικοινωνίας + Πρόβλημα επικοινωνίας με Αντλία + Η αντλία δεν είναι διαθέσιμη + Μη έγκυρη παραμετροποίηση + Ενεργή + Sleeping + Ακυρώσατε τον Bolus, αφού είχε ήδη σταλεί στην αντλία. Επειδή η αντλία Medtronic δεν υποστηρίζει ακύρωση, θα χρειαστεί να ακυρωθεί χειροκίνητα. Βάλτε την αντλία σε αναστολή λειτουργίας και μετά κάντε Συνέχιση (αν θέλετε να ακυρώσετε ακόμα). Η εφαρμογή θα πάρει τις αλλαγές, στην επόμενη ενημέρωση (σε λιγότερο από 5 λεπτά). Αδυναμία ανάγνωσης τρέχοντος TBR. Αδυναμία ακύρωσης τρέχοντος TBR. Αναστολή λειτουργίας. Η δημιουργία προφίλ απέτυχε, επειδή ακολουθώντας πρότυπα, έχετε υπερβολικά μεγάλο βασικό ρυθμό: %1$s Το Bolus δεν μπορεί να χορηγηθεί. + Το Bolus δεν μπορεί να παραδοθεί διότι η διαθέσιμη ποσότητα ινσουλίνης (%1$.2f) είναι μικρότερη από αυτήν που ζητείται (%2$.2f). TBR δεν μπορεί να μπει. Αδυναμία ακύρωσης τρέχοντος TBR. Το Βασικό Προφίλ δεν μπορεί να τοποθετηθεί. @@ -1327,6 +1432,9 @@ Αποσυνδεδεμένο για %1$d ώρες %2$d λεπτά Αποσυνδεδεμένο για %1$d μέρες %2$d ώρες %2$.1fg %3$.2f]]> + Bolus constraint applied: %2$.2fU to %3$.2fU]]> + !!!!! Μικρή απορρόφηση υδατανθράκων ανιχνεύτηκε: %2$d%% της ώρας. Τσεκάρετε τους υπολογισμούς σας. COB μπορεί να είναι κλειστό]]> + %1$.0f / %2$d U %1$d ημέρα %1$d ημέρες diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml index cf8df22345..371fe786c3 100644 --- a/app/src/main/res/values-pl-rPL/strings.xml +++ b/app/src/main/res/values-pl-rPL/strings.xml @@ -146,6 +146,7 @@ Ostatnie działanie OK Anuluj + Zamknij NIE WYBRANO APS LUB NIE UZYSKANO WYNIKU Zabezpieczenia Wtyczka jest wyłączona @@ -831,6 +832,7 @@ Niekompatybilny sekunda minuta + %1$.2f h godzina dzień tydzień @@ -1190,6 +1192,7 @@ Auto Automatyzacja == ∑ %1$s U + U/h g/U /U Prześlij zmianę sensora do NS @@ -1247,7 +1250,6 @@ stara wersja bardzo stara wersja Nowa wersja dostępna co najmniej %1$d dni! Powrót do LGS (zawieszania podawania bazy przy niskim poziomie) po 60 dniach, pętla zostanie wyłączona po 90 dniach - Graficzny wykres aktywności insuliny [U/min] 2 h %1$.2fU Apka Dexcom (spatchowana) @@ -1412,6 +1414,7 @@ Nie udało się anulować aktualnej dawki tymczasowej (TBR). Operacja zatrzymania. Ustawienia Profilu nie powiodły się ponieważ następująca wartość jest za duża: %1$s Nie udało się dostarczyć bolusa. + Bolus nie mógł być dostarczony ponieważ Ilość dostępnej insuliny (%1$.2f) jest mniejsza niż wymagany bolus (%2$.2f). Nie udało się ustawić dawki tymczasowej (TBR). Nie udało się anulować bazy tymczasowej (TBR). Profil bazy nie został ustawiony. @@ -1432,6 +1435,7 @@ %2$.1fg %3$.2fU]]> Wprowadzono ograniczenie bolusa: %2$.2fU to %3$.2fU]]> !!!!! Wykryto powolne wchłanianie węglowodanów: %2$d%% czasu. Sprawdź ponownie swoje obliczenia. COB mogą się znacznie różnić !!!!!]]> + %1$.0f / %2$d U %1$d dzień %1$d dni From c53e8d561567979f8e3940fe8880fe45c74f8f5b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 19:33:09 +0200 Subject: [PATCH 13/30] lint issue fix --- .../info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index e68bf9c30d..f14b636262 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -416,7 +416,7 @@ public class LoopPlugin extends PluginBase { .setAutoCancel(true) .setPriority(Notification.PRIORITY_HIGH) .setCategory(Notification.CATEGORY_ALARM) - .setVisibility(Notification.VISIBILITY_PUBLIC); + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); if (SP.getBoolean("wearcontrol", false)) { builder.setLocalOnly(true); } From d57d847bf7b6f77de48b91efca071987fa1dbc3c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 24 Aug 2019 19:33:52 +0200 Subject: [PATCH 14/30] bump 2.4-dev-c --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 316c7cf77d..aa9ca729e4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.4-dev-b" + version "2.4-dev-c" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' From d4d1110d686731f73acf361472fe22ae583f354e Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sun, 25 Aug 2019 14:48:00 +0100 Subject: [PATCH 15/30] - added fake method TBR Percent. If pecent is 0, it calls absolute methods with 0, if not, it calculates value, writes log and then starts absolute method --- .../plugins/pump/medtronic/MedtronicPumpPlugin.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index a16178df18..1158990cd6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -1062,6 +1062,19 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } + @Override + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, + boolean enforceNew) { + if (percent==0) { + return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); + } else { + Double absoluteValue = profile.getBasal() * (percent /100.0d); + LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.2f). Result might not be 100% correct.", percent, absoluteValue); + return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew); + } + } + + private void finishAction(String overviewKey) { if (overviewKey != null) From 2569e66bcee120298e97c79e221930cfec333271 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sun, 25 Aug 2019 19:25:36 +0100 Subject: [PATCH 16/30] - minor change. New absoluteValue is now put through pumpType.determineCorreectBasalValue method, so that we get correct value --- .../plugins/pump/medtronic/MedtronicPumpPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 1158990cd6..f8568299d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -1068,8 +1068,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (percent==0) { return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); } else { - Double absoluteValue = profile.getBasal() * (percent /100.0d); - LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.2f). Result might not be 100% correct.", percent, absoluteValue); + double absoluteValue = profile.getBasal() * (percent /100.0d); + getMDTPumpStatus(); + absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue); + LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue); return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew); } } From b04641e46616832eccaa7b1ecd579dc80ffcb3e1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 15:06:34 +0200 Subject: [PATCH 17/30] Revert "DataService as JobIntentService" This reverts commit e0c2e7d57918c25e8421fb3bb690d51d70120497. --- app/src/main/AndroidManifest.xml | 11 ++--- .../androidaps/receivers/DataReceiver.java | 12 ++--- .../androidaps/services/DataService.java | 47 ++++++++++--------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b40188688c..aeeb53475d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -153,8 +153,7 @@ + android:exported="false" /> @@ -173,7 +172,7 @@ + android:exported="true" /> @@ -240,11 +239,11 @@ + android:exported="true" /> + android:exported="true" /> @@ -285,7 +284,7 @@ + android:exported="true" /> diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java index 95fd6bfb09..6c2e7c6920 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.java @@ -1,9 +1,8 @@ package info.nightscout.androidaps.receivers; -import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import androidx.legacy.content.WakefulBroadcastReceiver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,16 +10,15 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.services.DataService; -public class DataReceiver extends BroadcastReceiver { +public class DataReceiver extends WakefulBroadcastReceiver { private static Logger log = LoggerFactory.getLogger(L.DATASERVICE); @Override public void onReceive(Context context, Intent intent) { if (L.isEnabled(L.DATASERVICE)) log.debug("onReceive " + intent); - // Explicitly specify that GcmIntentService will handle the intent. - ComponentName comp = new ComponentName(context.getPackageName(), - DataService.class.getName()); - DataService.enqueueWork(context, intent.setComponent(comp)); + startWakefulService(context, new Intent(context, DataService.class) + .setAction(intent.getAction()) + .putExtras(intent)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index 24a7698e9a..6b8ac46f11 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -1,13 +1,10 @@ package info.nightscout.androidaps.services; -import android.content.Context; +import android.app.IntentService; import android.content.Intent; import android.os.Bundle; import android.provider.Telephony; -import androidx.annotation.NonNull; -import androidx.core.app.JobIntentService; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -19,16 +16,15 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsTreatment; -import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin; import info.nightscout.androidaps.plugins.source.SourceEversensePlugin; import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin; @@ -38,30 +34,21 @@ import info.nightscout.androidaps.plugins.source.SourcePoctechPlugin; import info.nightscout.androidaps.plugins.source.SourceTomatoPlugin; import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; +import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.SP; -public class DataService extends JobIntentService { +public class DataService extends IntentService { private Logger log = LoggerFactory.getLogger(L.DATASERVICE); - // Service unique ID - static final int SERVICE_JOB_ID = 4378; - - // Enqueuing work in to this service. - public static void enqueueWork(Context context, Intent work) { - enqueueWork(context, DataService.class, SERVICE_JOB_ID, work); + public DataService() { + super("DataService"); + registerBus(); } @Override - public void onDestroy() { - super.onDestroy(); - if (L.isEnabled(L.DATASERVICE)) - log.debug("All work complete"); - } - - @Override - protected void onHandleWork(@NonNull Intent intent) { + protected void onHandleIntent(final Intent intent) { if (L.isEnabled(L.DATASERVICE)) { log.debug("onHandleIntent " + intent); log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras())); @@ -113,7 +100,7 @@ public class DataService extends JobIntentService { Intents.ACTION_REMOVED_TREATMENT.equals(action) || Intents.ACTION_NEW_CAL.equals(action) || Intents.ACTION_NEW_MBG.equals(action)) - ) { + ) { handleNewDataFromNSClient(intent); } else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) { SmsCommunicatorPlugin.getPlugin().handleNewData(intent); @@ -121,6 +108,22 @@ public class DataService extends JobIntentService { if (L.isEnabled(L.DATASERVICE)) log.debug("onHandleIntent exit " + intent); + DataReceiver.completeWakefulIntent(intent); + } + + @Override + public void onDestroy() { + super.onDestroy(); + MainApp.bus().unregister(this); + } + + private void registerBus() { + try { + MainApp.bus().unregister(this); + } catch (RuntimeException x) { + // Ignore + } + MainApp.bus().register(this); } private void handleNewDataFromNSClient(Intent intent) { From 1eff4697fa357d5a8e0fb31359f1971a35a9bb40 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 16:15:16 +0200 Subject: [PATCH 18/30] Fragments cleanup & Synchonized updateGui --- .../plugins/aps/loop/LoopFragment.kt | 10 ++++++-- .../aps/openAPSAMA/OpenAPSAMAFragment.kt | 8 +++++-- .../aps/openAPSMA/OpenAPSMAFragment.kt | 10 ++++++-- .../aps/openAPSSMB/OpenAPSSMBFragment.kt | 10 ++++++-- .../configBuilder/ConfigBuilderFragment.kt | 6 +++-- .../general/automation/AutomationFragment.kt | 23 +++++++++++++------ .../general/tidepool/TidepoolFragment.kt | 10 ++++---- .../plugins/profile/ns/NSProfileFragment.kt | 6 ++++- .../plugins/pump/danaR/DanaRFragment.kt | 20 +++++++++------- .../pump/medtronic/MedtronicFragment.kt | 4 ++-- 10 files changed, 75 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index 1a5caa42aa..2ab594c2a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -36,10 +36,9 @@ class LoopFragment : Fragment() { loop_lastrun.text = MainApp.gs(R.string.executing) Thread { LoopPlugin.getPlugin().invoke("Loop button", true) }.start() } - - updateGUI() } + @Synchronized override fun onResume() { super.onResume() disposable += RxBus @@ -60,14 +59,19 @@ class LoopFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized fun updateGUI() { + if (loop_request == null) return LoopPlugin.lastRun?.let { loop_request.text = it.request?.toSpanned() ?: "" loop_constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: "" @@ -92,7 +96,9 @@ class LoopFragment : Fragment() { } } + @Synchronized private fun clearGUI() { + if (loop_request == null) return loop_request.text = "" loop_constraints.text = "" loop_constraintsprocessed.text = "" 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 59dc5956e9..94747a4597 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 @@ -38,10 +38,9 @@ class OpenAPSAMAFragment : Fragment() { openapsma_run.setOnClickListener { OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false) } - - updateGUI() } + @Synchronized override fun onResume() { super.onResume() @@ -61,14 +60,19 @@ class OpenAPSAMAFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized private fun updateGUI() { + if (openapsma_result == null) return OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult -> openapsma_result.text = JSONFormatter.format(lastAPSResult.json) openapsma_request.text = lastAPSResult.toSpanned() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt index 1f002a4688..1b72f57365 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.kt @@ -35,9 +35,9 @@ class OpenAPSMAFragment : Fragment() { OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false) } - updateGUI() } + @Synchronized override fun onResume() { super.onResume() @@ -57,14 +57,18 @@ class OpenAPSMAFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } - fun updateGUI() { + @Synchronized + private fun updateGUI() { + if (openapsma_result == null) return OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult -> openapsma_result.text = JSONFormatter.format(lastAPSResult.json) openapsma_request.text = lastAPSResult.toSpanned() @@ -81,7 +85,9 @@ class OpenAPSMAFragment : Fragment() { } } + @Synchronized private fun updateResultGUI(text: String) { + if (openapsma_result == null) return openapsma_result.text = text openapsma_glucosestatus.text = "" openapsma_currenttemp.text = "" 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 264473c146..06ad0d01fd 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 @@ -39,10 +39,9 @@ class OpenAPSSMBFragment : Fragment() { openapsma_run.setOnClickListener { OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false) } - - updateGUI() } + @Synchronized override fun onResume() { super.onResume() disposable += RxBus @@ -61,14 +60,19 @@ class OpenAPSSMBFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized fun updateGUI() { + if (openapsma_result == null) return val plugin = OpenAPSSMBPlugin.getPlugin() plugin.lastAPSResult?.let { lastAPSResult -> openapsma_result.text = JSONFormatter.format(lastAPSResult.json) @@ -101,7 +105,9 @@ class OpenAPSSMBFragment : Fragment() { } } + @Synchronized private fun updateResultGUI(text: String) { + if (openapsma_result == null) return openapsma_result.text = text openapsma_glucosestatus.text = "" openapsma_currenttemp.text = "" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt index a8bcda3944..f011ac57cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt @@ -44,10 +44,9 @@ class ConfigBuilderFragment : Fragment() { unlock.visibility = View.GONE }, null) } - - updateGUI() } + @Synchronized override fun onResume() { super.onResume() disposable.add(RxBus @@ -58,13 +57,16 @@ class ConfigBuilderFragment : Fragment() { }, { FabricPrivacy.logException(it) })) + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized private fun updateGUI() { createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE)) createViewsForPlugins(R.string.configbuilder_insulin, R.string.configbuilder_insulin_description, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface::class.java, PluginType.INSULIN)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt index 661944d098..8a0789acea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt @@ -44,19 +44,14 @@ class AutomationFragment : Fragment() { } + @Synchronized override fun onResume() { super.onResume() disposable += RxBus .toObservable(EventAutomationUpdateGui::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ - eventListAdapter?.notifyDataSetChanged() - val sb = StringBuilder() - for (l in AutomationPlugin.executionLog) { - sb.append(l) - sb.append("\n") - } - automation_logView.text = sb.toString() + updateGui() }, { FabricPrivacy.logException(it) }) @@ -68,11 +63,25 @@ class AutomationFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + updateGui() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized + private fun updateGui() { + if (eventListAdapter == null) return + eventListAdapter?.notifyDataSetChanged() + val sb = StringBuilder() + for (l in AutomationPlugin.executionLog) { + sb.append(l) + sb.append("\n") + } + automation_logView.text = sb.toString() + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt index 8566f25703..f83b9cc243 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolFragment.kt @@ -34,6 +34,7 @@ class TidepoolFragment : Fragment() { tidepool_resertstart.setOnClickListener { SP.putLong(R.string.key_tidepool_last_end, 0) } } + @Synchronized override fun onResume() { super.onResume() disposable.add(RxBus @@ -41,16 +42,17 @@ class TidepoolFragment : Fragment() { .observeOn(AndroidSchedulers.mainThread()) .subscribe({ TidepoolPlugin.updateLog() - tidepool_log.text = TidepoolPlugin.textLog - tidepool_status.text = TidepoolUploader.connectionStatus.name - tidepool_log.text = TidepoolPlugin.textLog - tidepool_logscrollview.fullScroll(ScrollView.FOCUS_DOWN) + tidepool_log?.text = TidepoolPlugin.textLog + tidepool_status?.text = TidepoolUploader.connectionStatus.name + tidepool_log?.text = TidepoolPlugin.textLog + tidepool_logscrollview?.fullScroll(ScrollView.FOCUS_DOWN) }, { FabricPrivacy.logException(it) }) ) } + @Synchronized override fun onPause() { super.onPause() disposable.clear() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt index 56abf0008c..7a76283074 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt @@ -90,9 +90,9 @@ class NSProfileFragment : Fragment() { } } } - updateGUI() } + @Synchronized override fun onResume() { super.onResume() disposable.add(RxBus @@ -104,14 +104,18 @@ class NSProfileFragment : Fragment() { FabricPrivacy.logException(it) }) ) + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() } + @Synchronized fun updateGUI() { + if (profileview_noprofile == null) return profileview_noprofile.visibility = View.VISIBLE NSProfilePlugin.getPlugin().profile?.let { profileStore -> diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index f67c09817d..11a8f13412 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -76,9 +76,9 @@ class DanaRFragment : Fragment() { DanaRPump.getInstance().lastConnection = 0 ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked connect to pump", null) } - updateGUI() } + @Synchronized override fun onResume() { super.onResume() MainApp.bus().register(this) @@ -87,8 +87,10 @@ class DanaRFragment : Fragment() { .toObservable(EventDanaRNewStatus::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ updateGUI() }, { FabricPrivacy.logException(it) }) + updateGUI() } + @Synchronized override fun onPause() { super.onPause() disposable.clear() @@ -97,12 +99,12 @@ class DanaRFragment : Fragment() { } @Subscribe - public fun onStatusEvent(c: EventPumpStatusChanged) { + fun onStatusEvent(c: EventPumpStatusChanged) { activity?.runOnUiThread { when { - c.sStatus == EventPumpStatusChanged.CONNECTING -> danar_btconnection.text = "{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s" - c.sStatus == EventPumpStatusChanged.CONNECTED -> danar_btconnection.text = "{fa-bluetooth}" - c.sStatus == EventPumpStatusChanged.DISCONNECTED -> danar_btconnection.text = "{fa-bluetooth-b}" + c.sStatus == EventPumpStatusChanged.CONNECTING -> danar_btconnection?.text = "{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s" + c.sStatus == EventPumpStatusChanged.CONNECTED -> danar_btconnection?.text = "{fa-bluetooth}" + c.sStatus == EventPumpStatusChanged.DISCONNECTED -> danar_btconnection?.text = "{fa-bluetooth-b}" } if (c.textStatus() != "") { dana_pumpstatus.text = c.textStatus() @@ -115,20 +117,22 @@ class DanaRFragment : Fragment() { } @Subscribe - public fun onStatusEvent(s: EventTempBasalChange) = + fun onStatusEvent(s: EventTempBasalChange) = activity?.runOnUiThread { updateGUI() } @Subscribe - public fun onStatusEvent(s: EventExtendedBolusChange) = + fun onStatusEvent(s: EventExtendedBolusChange) = activity?.runOnUiThread { updateGUI() } @Subscribe - public fun onStatusEvent(s: EventQueueChanged) = + fun onStatusEvent(s: EventQueueChanged) = activity?.runOnUiThread { updateGUI() } // GUI functions + @Synchronized internal fun updateGUI() { + if (danar_dailyunits == null) return val pump = DanaRPump.getInstance() val plugin: PumpInterface = ConfigBuilderPlugin.getPlugin().activePump ?: return if (pump.lastConnection != 0L) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index 6bbe2057a1..ada0db37db 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -99,8 +99,6 @@ class MedtronicFragment : Fragment() { MedtronicUtil.displayNotConfiguredDialog(context) } } - - updateGUI() } @Synchronized @@ -133,6 +131,8 @@ class MedtronicFragment : Fragment() { MedtronicUtil.getPumpStatus().verifyConfiguration() updateGUI() }, { FabricPrivacy.logException(it) }) + + updateGUI() } @Synchronized From 4c7b8ef210beb7a6f21fe2257a142c225507262e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 17:33:20 +0200 Subject: [PATCH 19/30] fast >>>Loading ...<<< notification on app start --- .../persistentNotification/DummyService.java | 5 +-- .../PersistentNotificationPlugin.java | 45 ++++++++++--------- .../androidaps/services/LocationService.java | 18 +++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java index 1400185afa..13310d70a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java @@ -31,7 +31,7 @@ public class DummyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); - startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification()); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification()); return START_STICKY; } @@ -48,8 +48,7 @@ public class DummyService extends Service { super.onCreate(); // TODO: I guess this was moved here in order to adhere to the 5 seconds rule to call "startForeground" after a Service was called as Foreground service? // As onCreate() is not called every time a service is started, copied to onStartCommand(). - Notification notification = PersistentNotificationPlugin.getPlugin().updateNotification(); - startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, notification); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification()); MainApp.bus().register(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index 3e23bd9b16..655435f400 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -89,10 +89,10 @@ public class PersistentNotificationPlugin extends PluginBase { @Override protected void onStart() { + super.onStart(); createNotificationChannel(); // make sure channels exist before triggering updates through the bus MainApp.bus().register(this); - triggerNotificationUpdate(); - super.onStart(); + triggerNotificationUpdate(true); } private void createNotificationChannel() { @@ -114,21 +114,23 @@ public class PersistentNotificationPlugin extends PluginBase { super.onStop(); } - private void triggerNotificationUpdate() { + private void triggerNotificationUpdate(boolean boot) { + updateNotification(boot); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) MainApp.instance().startForegroundService(new Intent(MainApp.instance(), DummyService.class)); else MainApp.instance().startService(new Intent(MainApp.instance(), DummyService.class)); } - @Nonnull - public Notification updateNotification() { - String line1 = null; + private void updateNotification(boolean boot) { + String line1; String line2 = null; String line3 = null; NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = null; - if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) { + if (boot) { + line1 = MainApp.gs(R.string.loading); + } else if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) { String line1_aa; String units = ProfileFunctions.getInstance().getProfileUnits(); @@ -214,6 +216,8 @@ public class PersistentNotificationPlugin extends PluginBase { /// Add dot to produce a "more natural sounding result" unreadConversationBuilder.addMessage(line3_aa); /// End Android Auto + } else { + line1 = MainApp.gs(R.string.noprofileset); } NotificationCompat.Builder builder = new NotificationCompat.Builder(MainApp.instance(), CHANNEL_ID); @@ -223,9 +227,9 @@ public class PersistentNotificationPlugin extends PluginBase { builder.setSmallIcon(MainApp.getNotificationIcon()); Bitmap largeIcon = BitmapFactory.decodeResource(MainApp.instance().getResources(), MainApp.getIcon()); builder.setLargeIcon(largeIcon); - builder.setContentTitle(line1 != null ? line1 : MainApp.gs(R.string.noprofileset)); - builder.setContentText(line2 != null ? line2 : MainApp.gs(R.string.noprofileset)); - builder.setSubText(line3 != null ? line3 : MainApp.gs(R.string.noprofileset)); + if (line1 != null) builder.setContentTitle(line1); + if (line2 != null) builder.setContentText(line2); + if (line3 != null) builder.setSubText(line3); /// Android Auto if (unreadConversationBuilder != null) { builder.extend(new NotificationCompat.CarExtender() @@ -251,7 +255,6 @@ public class PersistentNotificationPlugin extends PluginBase { android.app.Notification notification = builder.build(); mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification); this.notification = notification; - return notification; } private String deltastring(double deltaMGDL, double deltaMMOL, String units) { @@ -278,48 +281,50 @@ public class PersistentNotificationPlugin extends PluginBase { public Notification getLastNotification() { if (notification != null) return notification; - else return new Notification(); + else { + throw new IllegalStateException("Notification is null"); + } } @Subscribe public void onStatusEvent(final EventPreferenceChange ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventTempBasalChange ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventExtendedBolusChange ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventAutosensCalculationFinished ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventNewBasalProfile ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventInitializationChanged ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } @Subscribe public void onStatusEvent(final EventRefreshOverview ev) { - triggerNotificationUpdate(); + triggerNotificationUpdate(false); } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java index 485ad1823a..33f92d770a 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java @@ -11,10 +11,14 @@ import android.os.IBinder; import androidx.core.app.ActivityCompat; +import com.squareup.otto.Subscribe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventLocationChange; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.bus.RxBus; @@ -80,14 +84,14 @@ public class LocationService extends Service { super.onStartCommand(intent, flags, startId); if (L.isEnabled(L.LOCATION)) log.debug("onStartCommand"); - startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification()); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification()); return START_STICKY; } @Override public void onCreate() { super.onCreate(); - startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().updateNotification()); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification()); if (L.isEnabled(L.LOCATION)) log.debug("onCreate"); @@ -121,6 +125,7 @@ public class LocationService extends Service { } catch (IllegalArgumentException ex) { log.error("network provider does not exist, " + ex.getMessage()); } + MainApp.bus().register(this); } @Override @@ -138,6 +143,15 @@ public class LocationService extends Service { log.error("fail to remove location listener, ignore", ex); } } + MainApp.bus().unregister(this); + } + + @Subscribe + public void onStatusEvent(EventAppExit event) { + if (L.isEnabled(L.CORE)) + log.debug("EventAppExit received"); + + stopSelf(); } private void initializeLocationManager() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2bb2753b66..4ced519ac1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1668,6 +1668,7 @@ Bolus constraint applied: %2$.2fU to %3$.2fU]]> !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be really off !!!!!]]> %1$.0f / %2$d U + Loading ... %1$d day From 55c1bd1a016827945e70efbb481157868ebe797d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 17:38:24 +0200 Subject: [PATCH 20/30] 2.4-dev-d --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index aa9ca729e4..234d5a0c52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.4-dev-c" + version "2.4-dev-d" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' From 21ee33421852faff5a3ac4090008ea9dc457bef1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 18:42:17 +0200 Subject: [PATCH 21/30] workaround for https://github.com/nightscout/cgm-remote-monitor/issues/4929 --- .../java/info/nightscout/androidaps/data/Profile.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 2bcd3794be..eb6db375f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -164,13 +164,13 @@ public class Profile { try { final JSONObject o = array.getJSONObject(index); long tas = 0; - try { - tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); - } catch (JSONException e) { +// try { +// tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); +// } catch (JSONException e) { String time = o.getString("time"); tas = getShitfTimeSecs(DateUtil.toSeconds(time)); //log.debug(">>>>>>>>>>>> Used recalculated timeAsSecons: " + time + " " + tas); - } +// } double value = o.getDouble("value") * multiplier; sparse.put(tas, value); } catch (JSONException e) { From 775214676ef9566452c997aa1034490283bb9b2f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 20:21:07 +0200 Subject: [PATCH 22/30] fix bug in TimeListEdit --- .../java/info/nightscout/androidaps/data/Profile.java | 11 ++++++----- .../nightscout/androidaps/utils/TimeListEdit.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index eb6db375f1..ee3d50aa16 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -164,18 +164,19 @@ public class Profile { try { final JSONObject o = array.getJSONObject(index); long tas = 0; -// try { -// tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); -// } catch (JSONException e) { + try { String time = o.getString("time"); tas = getShitfTimeSecs(DateUtil.toSeconds(time)); + } catch (JSONException e) { //log.debug(">>>>>>>>>>>> Used recalculated timeAsSecons: " + time + " " + tas); -// } + tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); + } double value = o.getDouble("value") * multiplier; sparse.put(tas, value); - } catch (JSONException e) { + } catch (Exception e) { log.error("Unhandled exception", e); log.error(json.toString()); + FabricPrivacy.logException(e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index 436043fd36..7588a2ed27 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -350,7 +350,7 @@ public class TimeListEdit { data1.put(index, newObject1); if (data2 != null) { JSONObject newObject2 = new JSONObject(); - newObject1.put("time", time); + newObject2.put("time", time); newObject2.put("timeAsSeconds", timeAsSeconds); newObject2.put("value", value2); data2.put(index, newObject2); From 0866b480ac3565a22c5be019dccb42e77932ad47 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 20:30:00 +0200 Subject: [PATCH 23/30] fix reset button in local profile --- .../main/java/info/nightscout/androidaps/utils/TimeListEdit.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index 7588a2ed27..c4fffc9452 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -80,6 +80,7 @@ public class TimeListEdit { private void buildView() { layout = view.findViewById(resLayoutId); + layout.removeAllViewsInLayout(); textlabel = new TextView(context); textlabel.setText(label); From 3fed995d5159c9e8bb8d79a8353310beed25973a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Aug 2019 22:40:54 +0200 Subject: [PATCH 24/30] fix disappearing save button --- .../androidaps/utils/TimeListEdit.java | 4 +- .../main/res/layout/localprofile_fragment.xml | 331 +++++++++--------- 2 files changed, 166 insertions(+), 169 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index c4fffc9452..be8b89dff4 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -236,8 +236,8 @@ public class TimeListEdit { if (i == 0) next = ONEHOURINSECONDS; fillSpinner(timeSpinner, secondFromMidnight(i), previous, next); - editText1.setParams(value1(i), min, max, step, formatter, false, view.findViewById(R.id.localprofile_save)); - editText2.setParams(value2(i), min, max, step, formatter, false, view.findViewById(R.id.localprofile_save)); + editText1.setParams(value1(i), min, max, step, formatter, false,null); + editText2.setParams(value2(i), min, max, step, formatter, false, null); if (data2 == null) { editText2.setVisibility(View.GONE); diff --git a/app/src/main/res/layout/localprofile_fragment.xml b/app/src/main/res/layout/localprofile_fragment.xml index be5f994302..1edeeb0b31 100644 --- a/app/src/main/res/layout/localprofile_fragment.xml +++ b/app/src/main/res/layout/localprofile_fragment.xml @@ -1,197 +1,194 @@ - - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - +