From 663d6464d511093b117761753794e5b2baff0921 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 5 Aug 2019 11:11:07 +0200 Subject: [PATCH 01/22] upgrade libs --- build.gradle | 2 +- wear/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 571b6b73d3..58540aaac2 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.4.2' classpath 'com.google.gms:google-services:4.3.0' - classpath 'io.fabric.tools:gradle:1.30.0' + classpath 'io.fabric.tools:gradle:1.31.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/wear/build.gradle b/wear/build.gradle index 3aa0b97506..7e6500fe56 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' ext { wearableVersion = "2.4.0" - playServicesWearable = "16.0.1" + playServicesWearable = "17.0.0" } def generateGitBuild = { -> From 89d2ff9de8450e593a6e576bd9b4add8545ba67d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 5 Aug 2019 14:12:39 +0200 Subject: [PATCH 02/22] LoopFragment -> kotlin --- .../plugins/aps/loop/LoopFragment.java | 145 ------------------ .../plugins/aps/loop/LoopFragment.kt | 105 +++++++++++++ .../plugins/aps/loop/LoopPlugin.java | 20 +-- .../loop/events/EventLoopSetLastRunGui.java | 14 -- .../aps/loop/events/EventLoopSetLastRunGui.kt | 8 + .../aps/loop/events/EventLoopUpdateGui.java | 9 -- .../aps/loop/events/EventLoopUpdateGui.kt | 8 + .../general/automation/AutomationFragment.kt | 9 +- .../general/automation/AutomationPlugin.kt | 25 ++- .../automation/dialogs/EditEventDialog.kt | 17 +- .../general/tidepool/TidepoolFragment.kt | 5 +- .../general/tidepool/TidepoolPlugin.kt | 15 +- .../nightscout/androidaps/utils/DateUtil.java | 5 +- 13 files changed, 186 insertions(+), 199 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java deleted file mode 100644 index 951631eb0c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java +++ /dev/null @@ -1,145 +0,0 @@ -package info.nightscout.androidaps.plugins.aps.loop; - - -import android.app.Activity; -import android.os.Bundle; -import android.text.Html; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; - -import com.squareup.otto.Subscribe; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui; -import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; -import info.nightscout.androidaps.plugins.common.SubscriberFragment; -import info.nightscout.androidaps.utils.FabricPrivacy; - -public class LoopFragment extends SubscriberFragment { - @BindView(R.id.loop_run) - Button runNowButton; - @BindView(R.id.loop_lastrun) - TextView lastRunView; - @BindView(R.id.loop_lastenact) - TextView lastEnactView; - @BindView(R.id.loop_source) - TextView sourceView; - @BindView(R.id.loop_request) - TextView requestView; - @BindView(R.id.loop_constraintsprocessed) - TextView constraintsProcessedView; - @BindView(R.id.loop_constraints) - TextView constraintsView; - @BindView(R.id.loop_tbrsetbypump) - TextView tbrSetByPumpView; - @BindView(R.id.loop_smbsetbypump) - TextView smbSetByPumpView; - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - try { - View view = inflater.inflate(R.layout.loop_fragment, container, false); - unbinder = ButterKnife.bind(this, view); - return view; - } catch (Exception e) { - FabricPrivacy.logException(e); - } - return null; - } - - @OnClick(R.id.loop_run) - void onRunClick() { - lastRunView.setText(MainApp.gs(R.string.executing)); - new Thread(() -> LoopPlugin.getPlugin().invoke("Loop button", true)).start(); - } - - @Subscribe - public void onStatusEvent(final EventLoopUpdateGui ev) { - updateGUI(); - } - - @Subscribe - public void onStatusEvent(final EventLoopSetLastRunGui ev) { - clearGUI(); - final Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(() -> { - synchronized (LoopFragment.this) { - if (lastRunView != null) lastRunView.setText(ev.text); - } - }); - } - - - @Override - protected void updateGUI() { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(() -> { - synchronized (LoopFragment.this) { - if (!isBound()) return; - LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; - if (lastRun != null) { - requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : ""); - constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : ""); - sourceView.setText(lastRun.source != null ? lastRun.source : ""); - lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : ""); - lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : ""); - tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : ""); - smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : ""); - - String constraints = ""; - if (lastRun.constraintsProcessed != null) { - Constraint allConstraints = new Constraint<>(0d); - if (lastRun.constraintsProcessed.rateConstraint != null) - allConstraints.copyReasons(lastRun.constraintsProcessed.rateConstraint); - if (lastRun.constraintsProcessed.smbConstraint != null) - allConstraints.copyReasons(lastRun.constraintsProcessed.smbConstraint); - constraints = allConstraints.getMostLimitedReasons(); - } - constraintsView.setText(constraints); - } - } - }); - } - - void clearGUI() { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(() -> { - synchronized (LoopFragment.this) { - if (isBound()) { - requestView.setText(""); - constraintsProcessedView.setText(""); - sourceView.setText(""); - lastRunView.setText(""); - lastEnactView.setText(""); - tbrSetByPumpView.setText(""); - smbSetByPumpView.setText(""); - } - } - }); - } - - boolean isBound() { - return requestView != null - && constraintsProcessedView != null - && sourceView != null - && lastRunView != null - && lastEnactView != null - && tbrSetByPumpView != null - && smbSetByPumpView != null - && constraintsView != null - && runNowButton != null; - } -} 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 new file mode 100644 index 0000000000..9c8da50aa8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -0,0 +1,105 @@ +package info.nightscout.androidaps.plugins.aps.loop + + +import android.os.Bundle +import android.text.Html +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +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) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + loop_run.setOnClickListener { + loop_lastrun.text = MainApp.gs(R.string.executing) + Thread { LoopPlugin.getPlugin().invoke("Loop button", true) }.start() + } + + disposable += RxBus + .toObservable(EventLoopUpdateGui::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + updateGUI() + }, { + FabricPrivacy.logException(it) + }) + + disposable += RxBus + .toObservable(EventLoopSetLastRunGui::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + clearGUI() + loop_lastrun.text = it.text + }, { + FabricPrivacy.logException(it) + }) + } + + override fun onStop() { + super.onStop() + disposable.clear() + } + + fun updateGUI() { + val lastRun = LoopPlugin.lastRun + lastRun?.let { + loop_request.text = it.request?.toSpanned() ?: "" + loop_constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: "" + loop_source.text = it.source ?: "" + loop_lastrun.text = it.lastAPSRun?.let { lastrun -> DateUtil.dateAndTimeString(lastrun.time) } + ?: "" + loop_lastenact.text = it.lastAPSRun?.let { lastEnact -> DateUtil.dateAndTimeString(lastEnact.time) } + ?: "" + loop_tbrsetbypump.text = it.tbrSetByPump?.let { tbrSetByPump -> Html.fromHtml(tbrSetByPump.toHtml()) } + ?: "" + loop_smbsetbypump.text = it.smbSetByPump?.let { smbSetByPump -> Html.fromHtml(smbSetByPump.toHtml()) } + ?: "" + + val constraints = + it.constraintsProcessed?.let { constraintsProcessed -> + val allConstraints = Constraint(0.0) + constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) } + constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) } + allConstraints.mostLimitedReasons + } ?: "" + loop_constraints.text = constraints + } + } + + internal fun clearGUI() { + loop_request.text = "" + loop_constraints.text = "" + loop_constraintsprocessed.text = "" + loop_source.text = "" + loop_lastrun.text = "" + loop_lastenact.text = "" + loop_tbrsetbypump.text = "" + loop_smbsetbypump.text = "" + } +} 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 8569341ccd..e68bf9c30d 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 @@ -10,6 +10,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.SystemClock; + import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; @@ -47,6 +48,7 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; @@ -278,7 +280,7 @@ public class LoopPlugin extends PluginBase { String message = MainApp.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons(); if (L.isEnabled(L.APS)) log.debug(message); - MainApp.bus().post(new EventLoopSetLastRunGui(message)); + RxBus.INSTANCE.send(new EventLoopSetLastRunGui(message)); return; } final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); @@ -292,7 +294,7 @@ public class LoopPlugin extends PluginBase { if (!ProfileFunctions.getInstance().isProfileValid("Loop")) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.noprofileselected)); - MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected))); + RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected))); return; } @@ -307,7 +309,7 @@ public class LoopPlugin extends PluginBase { // Check if we have any result if (result == null) { - MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noapsselected))); + RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.noapsselected))); return; } @@ -349,14 +351,14 @@ public class LoopPlugin extends PluginBase { if (isSuspended()) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.loopsuspended)); - MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.loopsuspended))); + RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.loopsuspended))); return; } if (pump.isSuspended()) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.pumpsuspended)); - MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.pumpsuspended))); + RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.pumpsuspended))); return; } @@ -372,7 +374,7 @@ public class LoopPlugin extends PluginBase { lastRun.tbrSetByPump = waiting; if (resultAfterConstraints.bolusRequested) lastRun.smbSetByPump = waiting; - MainApp.bus().post(new EventLoopUpdateGui()); + RxBus.INSTANCE.send(new EventLoopUpdateGui()); FabricPrivacy.getInstance().logCustom("APSRequest"); applyTBRRequest(resultAfterConstraints, profile, new Callback() { @Override @@ -393,11 +395,11 @@ public class LoopPlugin extends PluginBase { LoopPlugin.getPlugin().invoke("tempBasalFallback", allowNotification, true); }).start(); } - MainApp.bus().post(new EventLoopUpdateGui()); + RxBus.INSTANCE.send(new EventLoopUpdateGui()); } }); } - MainApp.bus().post(new EventLoopUpdateGui()); + RxBus.INSTANCE.send(new EventLoopUpdateGui()); } }); } else { @@ -451,7 +453,7 @@ public class LoopPlugin extends PluginBase { } } - MainApp.bus().post(new EventLoopUpdateGui()); + RxBus.INSTANCE.send(new EventLoopUpdateGui()); } finally { if (L.isEnabled(L.APS)) log.debug("invoke end"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java deleted file mode 100644 index 0d2a45f528..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.aps.loop.events; - -import info.nightscout.androidaps.events.EventUpdateGui; - -/** - * Created by mike on 05.08.2016. - */ -public class EventLoopSetLastRunGui extends EventUpdateGui { - public String text = null; - - public EventLoopSetLastRunGui(String text) { - this.text = text; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.kt new file mode 100644 index 0000000000..19c7e92c5c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.kt @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.aps.loop.events + +import info.nightscout.androidaps.events.EventUpdateGui + +/** + * Created by mike on 05.08.2016. + */ +class EventLoopSetLastRunGui(val text: String) : EventUpdateGui() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java deleted file mode 100644 index f746dfb0a0..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.nightscout.androidaps.plugins.aps.loop.events; - -import info.nightscout.androidaps.events.EventUpdateGui; - -/** - * Created by mike on 05.08.2016. - */ -public class EventLoopUpdateGui extends EventUpdateGui { -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.kt new file mode 100644 index 0000000000..89507d85f8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.kt @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.aps.loop.events + +import info.nightscout.androidaps.events.EventUpdateGui + +/** + * Created by mike on 05.08.2016. + */ +class EventLoopUpdateGui : EventUpdateGui() 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 97f9fa0ba3..eec353bd20 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 @@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus 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.events.EventAutomationUpdateGui +import info.nightscout.androidaps.utils.FabricPrivacy import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable @@ -56,13 +57,17 @@ class AutomationFragment : Fragment() { sb.append("\n") } automation_logView.text = sb.toString() - }, {}) + }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventAutomationDataChanged::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ eventListAdapter?.notifyDataSetChanged() - }, {}) + }, { + FabricPrivacy.logException(it) + }) } override fun onStop() { 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 fac8c8250f..8090015ec1 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,6 +21,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutos 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 io.reactivex.disposables.CompositeDisposable @@ -79,11 +80,15 @@ object AutomationPlugin : PluginBase(PluginDescription() ctx.stopService(Intent(ctx, LocationService::class.java)) ctx.startService(Intent(ctx, LocationService::class.java)) } - }, {}) + }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventAutomationDataChanged::class.java) .observeOn(Schedulers.io()) - .subscribe({ storeToSP() }, {}) + .subscribe({ storeToSP() }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventLocationChange::class.java) .observeOn(Schedulers.io()) @@ -92,19 +97,27 @@ object AutomationPlugin : PluginBase(PluginDescription() log.debug("Grabbed location: $it.location.latitude $it.location.longitude Provider: $it.location.provider") processActions() } - }, {}) + }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventChargingState::class.java) .observeOn(Schedulers.io()) - .subscribe({ processActions() }, {}) + .subscribe({ processActions() }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventNetworkChange::class.java) .observeOn(Schedulers.io()) - .subscribe({ processActions() }, {}) + .subscribe({ processActions() }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventAutosensCalculationFinished::class.java) .observeOn(Schedulers.io()) - .subscribe({ processActions() }, {}) + .subscribe({ processActions() }, { + FabricPrivacy.logException(it) + }) } override fun onStop() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt index d3012e0553..1f5725335e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.plugins.general.automation.AutomationEvent import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin import info.nightscout.androidaps.plugins.general.automation.events.* import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector +import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.ToastUtils import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -100,7 +101,9 @@ class EditEventDialog : DialogFragment() { .subscribe({ actionListAdapter?.notifyDataSetChanged() showPreconditions() - }, {}) + }, { + FabricPrivacy.logException(it) + }) ) disposable.add(RxBus .toObservable(EventAutomationAddAction::class.java) @@ -108,7 +111,9 @@ class EditEventDialog : DialogFragment() { .subscribe({ event.addAction(it.action) actionListAdapter?.notifyDataSetChanged() - }, {}) + }, { + FabricPrivacy.logException(it) + }) ) disposable.add(RxBus .toObservable(EventAutomationUpdateTrigger::class.java) @@ -116,7 +121,9 @@ class EditEventDialog : DialogFragment() { .subscribe({ event.trigger = it.trigger automation_triggerDescription.text = event.trigger.friendlyDescription() - }, {}) + }, { + FabricPrivacy.logException(it) + }) ) disposable.add(RxBus .toObservable(EventAutomationUpdateAction::class.java) @@ -124,7 +131,9 @@ class EditEventDialog : DialogFragment() { .subscribe({ event.actions[it.position] = it.action actionListAdapter?.notifyDataSetChanged() - }, {}) + }, { + FabricPrivacy.logException(it) + }) ) } 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 7fc21ca510..e9817b32a8 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 @@ -12,6 +12,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI +import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.SP import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -46,7 +47,9 @@ class TidepoolFragment : Fragment() { tidepool_status.text = TidepoolUploader.connectionStatus.name tidepool_log.text = TidepoolPlugin.textLog tidepool_logscrollview.fullScroll(ScrollView.FOCUS_DOWN) - }, {}) + }, { + FabricPrivacy.logException(it) + }) ) } 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 94e6d2bf2e..897fde8902 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 @@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolU import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit import info.nightscout.androidaps.receivers.ChargingStateReceiver import info.nightscout.androidaps.receivers.NetworkChangeReceiver +import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.ToastUtils @@ -56,7 +57,7 @@ object TidepoolPlugin : PluginBase(PluginDescription() .toObservable(EventTidepoolDoUpload::class.java) .observeOn(Schedulers.io()) .subscribe({ doUpload() }, { - log.error(it.message) + FabricPrivacy.logException(it) }) disposable += RxBus .toObservable(EventTidepoolResetData::class.java) @@ -70,12 +71,14 @@ object TidepoolPlugin : PluginBase(PluginDescription() TidepoolUploader.doLogin() } }, { - log.error(it.message) + FabricPrivacy.logException(it) }) disposable += RxBus .toObservable(EventTidepoolStatus::class.java) .observeOn(Schedulers.io()) - .subscribe({ event -> addToLog(event) }, {}) + .subscribe({ event -> addToLog(event) }, { + FabricPrivacy.logException(it) + }) disposable += RxBus .toObservable(EventNewBG::class.java) .observeOn(Schedulers.io()) @@ -90,7 +93,7 @@ object TidepoolPlugin : PluginBase(PluginDescription() && RateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt())) doUpload() }, { - log.error(it.message) + FabricPrivacy.logException(it) }) disposable += RxBus .toObservable(EventPreferenceChange::class.java) @@ -102,13 +105,13 @@ object TidepoolPlugin : PluginBase(PluginDescription() ) TidepoolUploader.resetInstance() }, { - log.error(it.message) + FabricPrivacy.logException(it) }) disposable += RxBus .toObservable(EventNetworkChange::class.java) .observeOn(Schedulers.io()) .subscribe({}, { - log.error(it.message) + FabricPrivacy.logException(it) }) // TODO start upload on wifi connect } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java b/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java index 9196f3a060..d592347d1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java @@ -39,10 +39,8 @@ public class DateUtil { * * @param isoDateString the iso date string * @return the date - * @throws Exception the exception */ - public static Date fromISODateString(String isoDateString) - throws Exception { + public static Date fromISODateString(String isoDateString) { DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); DateTime dateTime = DateTime.parse(isoDateString, parser); @@ -148,6 +146,7 @@ public class DateUtil { } public static String dateAndTimeString(long mills) { + if (mills == 0) return ""; return dateString(mills) + " " + timeString(mills); } From 9608f5185f80a7f05775aff186d008925f2a8396 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 5 Aug 2019 16:04:16 +0200 Subject: [PATCH 03/22] lint warnings --- .../androidaps/plugins/aps/loop/LoopFragment.kt | 14 +++++++------- .../plugins/general/tidepool/TidepoolPlugin.kt | 11 +++-------- .../nightscout/androidaps/utils/BolusWizard.kt | 6 +++--- .../nightscout/androidaps/utils/HtmlHelper.kt | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.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 9c8da50aa8..17273d49a5 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 @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.aps.loop import android.os.Bundle -import android.text.Html import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,6 +14,7 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui 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 io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable @@ -59,6 +59,7 @@ class LoopFragment : Fragment() { }, { FabricPrivacy.logException(it) }) + updateGUI() } override fun onStop() { @@ -67,18 +68,17 @@ class LoopFragment : Fragment() { } fun updateGUI() { - val lastRun = LoopPlugin.lastRun - lastRun?.let { + LoopPlugin.lastRun?.let { loop_request.text = it.request?.toSpanned() ?: "" loop_constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: "" loop_source.text = it.source ?: "" - loop_lastrun.text = it.lastAPSRun?.let { lastrun -> DateUtil.dateAndTimeString(lastrun.time) } + loop_lastrun.text = it.lastAPSRun?.let { lastRun -> DateUtil.dateAndTimeString(lastRun.time) } ?: "" loop_lastenact.text = it.lastAPSRun?.let { lastEnact -> DateUtil.dateAndTimeString(lastEnact.time) } ?: "" - loop_tbrsetbypump.text = it.tbrSetByPump?.let { tbrSetByPump -> Html.fromHtml(tbrSetByPump.toHtml()) } + loop_tbrsetbypump.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) } ?: "" - loop_smbsetbypump.text = it.smbSetByPump?.let { smbSetByPump -> Html.fromHtml(smbSetByPump.toHtml()) } + loop_smbsetbypump.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) } ?: "" val constraints = @@ -92,7 +92,7 @@ class LoopFragment : Fragment() { } } - internal fun clearGUI() { + private fun clearGUI() { loop_request.text = "" loop_constraints.text = "" loop_constraintsprocessed.text = "" 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 897fde8902..b7896d7e56 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 @@ -21,10 +21,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolU import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit import info.nightscout.androidaps.receivers.ChargingStateReceiver import info.nightscout.androidaps.receivers.NetworkChangeReceiver -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SP -import info.nightscout.androidaps.utils.T -import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.androidaps.utils.* import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers @@ -44,8 +41,7 @@ object TidepoolPlugin : PluginBase(PluginDescription() private var disposable: CompositeDisposable = CompositeDisposable() private val listLog = ArrayList() - @Suppress("DEPRECATION") // API level 24 to replace call - var textLog: Spanned = Html.fromHtml("") + var textLog: Spanned = HtmlHelper.fromHtml("") operator fun CompositeDisposable.plusAssign(disposable: Disposable) { add(disposable) @@ -150,8 +146,7 @@ object TidepoolPlugin : PluginBase(PluginDescription() newTextLog.append(log.toPreparedHtml()) } } - @Suppress("DEPRECATION") // API level 24 to replace call - textLog = Html.fromHtml(newTextLog.toString()) + textLog = HtmlHelper.fromHtml(newTextLog.toString()) } catch (e: OutOfMemoryError) { ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, "Out of memory!\nStop using this phone !!!", R.raw.error) } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt index 61b54fed0d..b741e4656c 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt @@ -2,7 +2,6 @@ package info.nightscout.androidaps.utils import android.content.Context import android.content.Intent -import android.text.Html import androidx.appcompat.app.AlertDialog import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R @@ -189,7 +188,8 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, calculatedTotalInsulin = 0.0 } - val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.bolusStep ?: 0.1 + val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.bolusStep + ?: 0.1 calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep) insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value() @@ -273,7 +273,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, val builder = AlertDialog.Builder(context) builder.setTitle(MainApp.gs(R.string.confirmation)) - builder.setMessage(Html.fromHtml(confirmMessage)) + builder.setMessage(HtmlHelper.fromHtml(confirmMessage)) builder.setPositiveButton(MainApp.gs(R.string.ok)) { _, _ -> synchronized(builder) { if (accepted) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt new file mode 100644 index 0000000000..b79fe884b4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.utils + +import android.os.Build +import android.text.Html +import android.text.Spanned + +object HtmlHelper { + fun fromHtml(source: String): Spanned { + // API level 24 to replace call + @Suppress("DEPRECATION") + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY) + else -> Html.fromHtml(source) + } + } +} \ No newline at end of file From c1a1cc310869237205070cd07ee7c639402ad31a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 6 Aug 2019 01:19:24 +0200 Subject: [PATCH 04/22] ProfileViewerDialog -> kotlin --- .../automation/dialogs/EditActionDialog.kt | 1 - .../general/overview/OverviewFragment.java | 8 +- .../fragments/ProfileViewerDialog.java | 135 --- .../fragments/ProfileViewerDialog.kt | 74 ++ .../TreatmentsProfileSwitchFragment.java | 9 +- app/src/main/res/layout/close.xml | 34 + .../res/layout/profileviewer_fragment.xml | 858 +++++++++--------- app/src/main/res/values/strings.xml | 2 + 8 files changed, 550 insertions(+), 571 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt create mode 100644 app/src/main/res/layout/close.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt index bb4ffcbebf..48669c9ed8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Button import androidx.fragment.app.DialogFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.plugins.bus.RxBus diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 46fd37d8fd..25d9d483f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -633,9 +633,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); } else if (item.getTitle().equals(MainApp.gs(R.string.danar_viewprofile))) { - ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis()); + Bundle args = new Bundle(); + args.putLong("time", DateUtil.now()); + ProfileViewerDialog pvd = new ProfileViewerDialog(); + pvd.setArguments(args); FragmentManager manager = getFragmentManager(); - pvd.show(manager, "ProfileViewDialog"); + if (manager != null) + pvd.show(manager, "ProfileViewDialog"); } else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) { DefaultValueHelper defHelper = new DefaultValueHelper(); double target = defHelper.determineEatingSoonTT(profile.getUnits()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java deleted file mode 100644 index a3b6234a22..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java +++ /dev/null @@ -1,135 +0,0 @@ -package info.nightscout.androidaps.plugins.treatments.fragments; - -import android.os.Bundle; -import androidx.fragment.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.DecimalFormatter; - -/** - * Created by adrian on 17/08/17. - */ - -public class ProfileViewerDialog extends DialogFragment { - - private long time; - - @BindView(R.id.profileview_noprofile) - TextView noProfile; - @BindView(R.id.profileview_invalidprofile) - TextView invalidProfile; - @BindView(R.id.profileview_units) - TextView units; - @BindView(R.id.profileview_dia) - TextView dia; - @BindView(R.id.profileview_activeprofile) - TextView activeProfile; - @BindView(R.id.profileview_ic) - TextView ic; - @BindView(R.id.profileview_isf) - TextView isf; - @BindView(R.id.profileview_basal) - TextView basal; - @BindView(R.id.profileview_target) - TextView target; - @BindView(R.id.profileview_datedelimiter) - View dateDelimiter; - @BindView(R.id.profileview_datelayout) - LinearLayout dateLayout; - @BindView(R.id.profileview_date) - TextView dateTextView; - @BindView(R.id.profileview_reload) - Button refreshButton; - @BindView(R.id.basal_graph) - ProfileGraph basalGraph; - - private Unbinder unbinder; - - public static ProfileViewerDialog newInstance(long time) { - ProfileViewerDialog dialog = new ProfileViewerDialog(); - - Bundle args = new Bundle(); - args.putLong("time", time); - dialog.setArguments(args); - - return dialog; - } - - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - time = getArguments().getLong("time"); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (unbinder != null) - unbinder.unbind(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.profileviewer_fragment, container, false); - - unbinder = ButterKnife.bind(this, view); - - refreshButton.setVisibility(View.GONE); - dateDelimiter.setVisibility(View.VISIBLE); - dateLayout.setVisibility(View.VISIBLE); - - setContent(); - return view; - } - - @Override - public void onResume() { - ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes(); - params.width = ViewGroup.LayoutParams.MATCH_PARENT; - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); - super.onResume(); - } - - private void setContent() { - Profile profile = null; - ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time); - if (profileSwitch != null && profileSwitch.profileJson != null) { - profile = profileSwitch.getProfileObject(); - } - if (profile != null) { - noProfile.setVisibility(View.GONE); - units.setText(profile.getUnits()); - dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h"); - activeProfile.setText(profileSwitch.getCustomizedName()); - dateTextView.setText(DateUtil.dateAndTimeString(profileSwitch.date)); - ic.setText(profile.getIcList()); - isf.setText(profile.getIsfList()); - basal.setText(profile.getBasalList()); - target.setText(profile.getTargetList()); - basalGraph.show(profile); - - if (profile.isValid("ProfileViewDialog")) - invalidProfile.setVisibility(View.GONE); - else - invalidProfile.setVisibility(View.VISIBLE); - } else { - noProfile.setVisibility(View.VISIBLE); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt new file mode 100644 index 0000000000..e0c9ef1dda --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt @@ -0,0 +1,74 @@ +package info.nightscout.androidaps.plugins.treatments.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil +import kotlinx.android.synthetic.main.close.* +import kotlinx.android.synthetic.main.profileviewer_fragment.* + +/** + * Created by adrian on 17/08/17. + */ + +class ProfileViewerDialog : DialogFragment() { + private var time: Long = 0 + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + // load data from bundle + (savedInstanceState ?: arguments)?.let { bundle -> + time = bundle.getLong("time", 0) + } + + return inflater.inflate(R.layout.profileviewer_fragment, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + close.setOnClickListener { dismiss() } + + profileview_reload.visibility = View.GONE + profileview_datedelimiter.visibility = View.VISIBLE + profileview_datelayout.visibility = View.VISIBLE + profileview_noprofile.visibility = View.VISIBLE + + val profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time) + profileSwitch?.profileObject?.let { + profileview_units.text = it.units + profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia) + profileview_activeprofile.text = profileSwitch.customizedName + profileview_date.text = DateUtil.dateAndTimeString(profileSwitch.date) + profileview_ic.text = it.icList + profileview_isf.text = it.isfList + profileview_basal.text = it.basalList + profileview_target.text = it.targetList + basal_graph.show(it) + + profileview_noprofile.visibility = View.GONE + profileview_invalidprofile.visibility = if (it.isValid("ProfileViewDialog")) View.GONE else View.VISIBLE + } + } + + override fun onResume() { + dialog.window?.let { + val params = it.attributes + params.width = ViewGroup.LayoutParams.MATCH_PARENT + params.height = ViewGroup.LayoutParams.MATCH_PARENT + it.attributes = params + } + super.onResume() + } + + override fun onSaveInstanceState(bundle: Bundle) { + super.onSaveInstanceState(bundle) + bundle.putLong("time", time) + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java index 5d5919f69f..1113dabbee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -159,10 +159,13 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen break; case R.id.profileswitch_date: case R.id.profileswitch_name: - long time = ((ProfileSwitch) v.getTag()).date; - ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(time); + Bundle args = new Bundle(); + args.putLong("time", ((ProfileSwitch) v.getTag()).date); + ProfileViewerDialog pvd = new ProfileViewerDialog(); + pvd.setArguments(args); FragmentManager manager = getFragmentManager(); - pvd.show(manager, "ProfileViewDialog"); + if (manager != null) + pvd.show(manager, "ProfileViewDialog"); break; } } diff --git a/app/src/main/res/layout/close.xml b/app/src/main/res/layout/close.xml new file mode 100644 index 0000000000..a500295275 --- /dev/null +++ b/app/src/main/res/layout/close.xml @@ -0,0 +1,34 @@ + + + + +