diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index e59b15b8ca..75eb9e8aaa 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -518,4 +518,9 @@ public class MainApp extends DaggerApplication { return (int) (dp * scale + 0.5f); } + @Deprecated + public ResourceHelper getResourceHelper() { + return resourceHelper; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java index 1792d9534c..03b5db36b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java @@ -31,6 +31,8 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; +import javax.inject.Inject; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; @@ -51,10 +53,13 @@ import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.resources.ResourceHelper; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; public class TDDStatsActivity extends NoSplashAppCompatActivity { + @Inject ResourceHelper resourceHelper; + private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class); private CompositeDisposable disposable = new CompositeDisposable(); @@ -80,7 +85,7 @@ public class TDDStatsActivity extends NoSplashAppCompatActivity { disposable.add(RxBus.Companion.getINSTANCE() .toObservable(EventPumpStatusChanged.class) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(event -> statusView.setText(event.getStatus()), exception -> FabricPrivacy.getInstance().logException(exception)) + .subscribe(event -> statusView.setText(event.getStatus(resourceHelper)), exception -> FabricPrivacy.getInstance().logException(exception)) ); disposable.add(RxBus.Companion.getINSTANCE() .toObservable(EventDanaRSyncStatus.class) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt index 9a03b752b9..a8e8ba3195 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt @@ -99,7 +99,7 @@ class BolusProgressDialog : DaggerDialogFragment() { disposable.add(rxBus .toObservable(EventPumpStatusChanged::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ overview_bolusprogress_status.text = it.getStatus() }) { fabricPrivacy.logException(it) } + .subscribe({ overview_bolusprogress_status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) } ) disposable.add(rxBus .toObservable(EventDismissBolusProgressIfRunning::class.java) diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt index 3d25bc1ca5..cc92defe8d 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt +++ b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.events -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.resources.ResourceHelper class EventPumpStatusChanged : EventStatus { @@ -14,49 +14,44 @@ class EventPumpStatusChanged : EventStatus { DISCONNECTED } - var sStatus: Status = Status.DISCONNECTED - var sSecondsElapsed = 0 - var sPerfomingAction = "" + var status: Status = Status.DISCONNECTED + var secondsElapsed = 0 + private var performingAction = "" var error = "" constructor(status: Status) { - sStatus = status - sSecondsElapsed = 0 + this.status = status + secondsElapsed = 0 error = "" } constructor(status: Status, secondsElapsed: Int) { - sStatus = status - sSecondsElapsed = secondsElapsed + this.status = status + this.secondsElapsed = secondsElapsed error = "" } constructor(status: Status, error: String) { - sStatus = status - sSecondsElapsed = 0 + this.status = status + secondsElapsed = 0 this.error = error } constructor(action: String) { - sStatus = Status.PERFORMING - sSecondsElapsed = 0 - sPerfomingAction = action + status = Status.PERFORMING + secondsElapsed = 0 + performingAction = action } // status for startup wizard - override fun getStatus(): String { - if (sStatus == Status.CONNECTING) - return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed) - else if (sStatus == Status.HANDSHAKING) - return MainApp.gs(R.string.handshaking) - else if (sStatus == Status.CONNECTED) - return MainApp.gs(R.string.connected) - else if (sStatus == Status.PERFORMING) - return sPerfomingAction - else if (sStatus == Status.DISCONNECTING) - return MainApp.gs(R.string.disconnecting) - else if (sStatus == Status.DISCONNECTED) - return "" - return "" + override fun getStatus(resourceHelper: ResourceHelper): String { + return when (status) { + Status.CONNECTING -> String.format(resourceHelper.gs(R.string.danar_history_connectingfor), secondsElapsed) + Status.HANDSHAKING -> resourceHelper.gs(R.string.handshaking) + Status.CONNECTED -> resourceHelper.gs(R.string.connected) + Status.PERFORMING -> performingAction + Status.DISCONNECTING -> resourceHelper.gs(R.string.disconnecting) + Status.DISCONNECTED -> "" + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt b/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt index 193c3b1fdb..360b62f0e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt +++ b/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt @@ -1,6 +1,8 @@ package info.nightscout.androidaps.events +import info.nightscout.androidaps.utils.resources.ResourceHelper + // pass string to startup wizard abstract class EventStatus :Event() { - abstract fun getStatus() : String + abstract fun getStatus(resourceHelper: ResourceHelper) : String } \ No newline at end of file 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 0aa43fe891..6d6f08cc5a 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 @@ -114,7 +114,7 @@ public class NSClientPlugin extends PluginBase { .toObservable(EventNSClientStatus.class) .observeOn(Schedulers.io()) .subscribe(event -> { - status = event.getStatus(); + status = event.getStatus(MainApp.instance().getResourceHelper()); RxBus.Companion.getINSTANCE().send(new EventNSClientUpdateGUI()); }, exception -> FabricPrivacy.getInstance().logException(exception)) ); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.kt index 4d0c9dcd6e..dfe4ede8d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.kt @@ -1,7 +1,8 @@ package info.nightscout.androidaps.plugins.general.nsclient.events import info.nightscout.androidaps.events.EventStatus +import info.nightscout.androidaps.utils.resources.ResourceHelper class EventNSClientStatus(var text: String) : EventStatus() { - override fun getStatus(): String = text + override fun getStatus(resourceHelper: ResourceHelper): String = text } 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 8dc3aeed21..5fe6138ca3 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 @@ -451,7 +451,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList disposable.add(rxBus .toObservable(EventPumpStatusChanged.class) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(event -> updatePumpStatus(event.getStatus()), + .subscribe(event -> updatePumpStatus(event.getStatus(resourceHelper)), exception -> FabricPrivacy.getInstance().logException(exception) )); disposable.add(rxBus 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 c4720f1695..d7078511b2 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 @@ -119,18 +119,18 @@ class DanaRFragment : DaggerFragment() { .observeOn(AndroidSchedulers.mainThread()) .subscribe({ when { - it.sStatus == EventPumpStatusChanged.Status.CONNECTING -> + it.status == EventPumpStatusChanged.Status.CONNECTING -> @Suppress("SetTextI18n") - danar_btconnection?.text = "{fa-bluetooth-b spin} ${it.sSecondsElapsed}s" - it.sStatus == EventPumpStatusChanged.Status.CONNECTED -> + danar_btconnection?.text = "{fa-bluetooth-b spin} ${it.secondsElapsed}s" + it.status == EventPumpStatusChanged.Status.CONNECTED -> @Suppress("SetTextI18n") danar_btconnection?.text = "{fa-bluetooth}" - it.sStatus == EventPumpStatusChanged.Status.DISCONNECTED -> + it.status == EventPumpStatusChanged.Status.DISCONNECTED -> @Suppress("SetTextI18n") danar_btconnection?.text = "{fa-bluetooth-b}" } - if (it.getStatus() != "") { - dana_pumpstatus?.text = it.getStatus() + if (it.getStatus(resourceHelper) != "") { + dana_pumpstatus?.text = it.getStatus(resourceHelper) dana_pumpstatuslayout?.visibility = View.VISIBLE } else { dana_pumpstatuslayout?.visibility = View.GONE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt index 2e6cf10b29..6a84a5e4c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt @@ -62,7 +62,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { disposable += rxBus .toObservable(EventPumpStatusChanged::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ danar_history_status.text = it.getStatus() }) { fabricPrivacy.logException(it) } + .subscribe({ danar_history_status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) } disposable += rxBus .toObservable(EventDanaRSyncStatus::class.java) .observeOn(AndroidSchedulers.mainThread()) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 59dfe5526d..293d46545a 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -180,7 +180,7 @@ class SWDefinition @Inject constructor( .label(R.string.nsclientinternal_secret_dialogtitle) .comment(R.string.nsclientinternal_secret_dialogmessage)) .add(SWBreak()) - .add(SWEventListener(this, EventNSClientStatus::class.java) + .add(SWEventListener(resourceHelper, rxBus, EventNSClientStatus::class.java) .label(R.string.status) .initialStatus(NSClientPlugin.getPlugin().status) ) @@ -294,7 +294,7 @@ class SWDefinition @Inject constructor( .text(R.string.readstatus) .action { configBuilderPlugin.commandQueue.readStatus("Clicked connect to pump", null) } .visibility { configBuilderPlugin.activePump != null }) - .add(SWEventListener(this, EventPumpStatusChanged::class.java)) + .add(SWEventListener(resourceHelper, rxBus, EventPumpStatusChanged::class.java)) .validator { configBuilderPlugin.activePump != null && configBuilderPlugin.activePump!!.isInitialized } private val screenAps = SWScreen(R.string.configbuilder_aps) .skippable(false) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.java deleted file mode 100644 index a791452d5c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.nightscout.androidaps.setupwizard; - -import android.content.Context; -import android.widget.LinearLayout; -import android.widget.TextView; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.events.EventStatus; -import info.nightscout.androidaps.plugins.bus.RxBus; -import info.nightscout.androidaps.setupwizard.elements.SWItem; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.CompositeDisposable; - - -public class SWEventListener extends SWItem { - private static Logger log = LoggerFactory.getLogger(SWEventListener.class); - private CompositeDisposable disposable = new CompositeDisposable(); - - private int textLabel = 0; - private String status = ""; - TextView textView; - SWDefinition definition; - - SWEventListener(SWDefinition definition, Class clazz) { - super(Type.LISTENER); - this.definition = definition; - disposable.add(RxBus.Companion.getINSTANCE() - .toObservable(clazz) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(event -> { - status = ((EventStatus) event).getStatus(); - if (textView != null) - textView.setText((textLabel != 0 ? MainApp.gs(textLabel) : "") + " " + status); - }) - ); - - } - - public SWEventListener label(int newLabel) { - this.textLabel = newLabel; - return this; - } - - SWEventListener initialStatus(String status) { - this.status = status; - return this; - } - - @Override - public void generateDialog(LinearLayout layout) { - Context context = layout.getContext(); - - textView = new TextView(context); - textView.setId(layout.generateViewId()); - textView.setText((textLabel != 0 ? MainApp.gs(textLabel) : "") + " " + status); - layout.addView(textView); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt new file mode 100644 index 0000000000..22bc131995 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWEventListener.kt @@ -0,0 +1,53 @@ +package info.nightscout.androidaps.setupwizard + +import android.view.View +import android.widget.LinearLayout +import android.widget.TextView +import info.nightscout.androidaps.events.EventStatus +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.setupwizard.elements.SWItem +import info.nightscout.androidaps.utils.resources.ResourceHelper +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable + +class SWEventListener constructor( + private val resourceHelper: ResourceHelper, + rxBus: RxBusWrapper, + clazz: Class +) : SWItem(Type.LISTENER) { + + private val disposable = CompositeDisposable() + private var textLabel = 0 + private var status = "" + var textView: TextView? = null + + // TODO: Adrian how to clear disposable in this case? + init { + disposable.add(rxBus + .toObservable(clazz) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { event: Any -> + status = (event as EventStatus).getStatus(resourceHelper) + textView?.text = (if (textLabel != 0) resourceHelper.gs(textLabel) else "") + " " + status + } + ) + } + + override fun label(newLabel: Int): SWEventListener { + textLabel = newLabel + return this + } + + fun initialStatus(status: String): SWEventListener { + this.status = status + return this + } + + override fun generateDialog(layout: LinearLayout) { + val context = layout.context + textView = TextView(context) + textView?.id = View.generateViewId() + textView?.text = (if (textLabel != 0) resourceHelper.gs(textLabel) else "") + " " + status + layout.addView(textView) + } +} \ No newline at end of file