VirtualPumpFragment -> kotlin
This commit is contained in:
parent
688218fa40
commit
c867ae1104
4 changed files with 89 additions and 128 deletions
|
@ -74,14 +74,11 @@ class AutomationFragment : Fragment() {
|
|||
|
||||
@Synchronized
|
||||
private fun updateGui() {
|
||||
if (eventListAdapter == null) return
|
||||
eventListAdapter?.notifyDataSetChanged()
|
||||
val sb = StringBuilder()
|
||||
for (l in AutomationPlugin.executionLog.reversed()) {
|
||||
sb.append(l)
|
||||
sb.append("\n")
|
||||
}
|
||||
automation_logView.text = sb.toString()
|
||||
for (l in AutomationPlugin.executionLog.reversed())
|
||||
sb.append(l).append("\n")
|
||||
automation_logView?.text = sb.toString()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.virtual;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
|
||||
public class VirtualPumpFragment extends Fragment {
|
||||
private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
TextView basaBasalRateView;
|
||||
TextView tempBasalView;
|
||||
TextView extendedBolusView;
|
||||
TextView batteryView;
|
||||
TextView reservoirView;
|
||||
TextView pumpTypeView;
|
||||
TextView pumpSettingsView;
|
||||
|
||||
|
||||
private static Handler sLoopHandler = new Handler();
|
||||
private static Runnable sRefreshLoop = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (sRefreshLoop == null) {
|
||||
sRefreshLoop = () -> {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(this::updateGui);
|
||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||
};
|
||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.virtualpump_fragment, container, false);
|
||||
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
||||
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
||||
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
|
||||
batteryView = (TextView) view.findViewById(R.id.virtualpump_battery);
|
||||
reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir);
|
||||
pumpTypeView = (TextView) view.findViewById(R.id.virtualpump_type);
|
||||
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventVirtualPumpUpdateGui.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPause() {
|
||||
super.onPause();
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
protected void updateGui() {
|
||||
VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin();
|
||||
basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U");
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
tempBasalView.setText(activeTemp.toStringFull());
|
||||
} else {
|
||||
tempBasalView.setText("");
|
||||
}
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (activeExtendedBolus != null) {
|
||||
extendedBolusView.setText(activeExtendedBolus.toString());
|
||||
} else {
|
||||
extendedBolusView.setText("");
|
||||
}
|
||||
batteryView.setText(virtualPump.batteryPercent + "%");
|
||||
reservoirView.setText(virtualPump.reservoirInUnits + "U");
|
||||
|
||||
virtualPump.refreshConfiguration();
|
||||
|
||||
PumpType pumpType = virtualPump.getPumpType();
|
||||
|
||||
pumpTypeView.setText(pumpType.getDescription());
|
||||
|
||||
String template = MainApp.gs(R.string.virtualpump_pump_def);
|
||||
|
||||
|
||||
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package info.nightscout.androidaps.plugins.pump.virtual
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
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.events.EventExtendedBolusChange
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.virtualpump_fragment.*
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class VirtualPumpFragment : Fragment() {
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
private val loopHandler = Handler()
|
||||
private lateinit var refreshLoop: Runnable
|
||||
|
||||
init {
|
||||
refreshLoop = Runnable {
|
||||
activity?.runOnUiThread { updateGui() }
|
||||
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.virtualpump_fragment, container, false)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventVirtualPumpUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGui() }, { FabricPrivacy.logException(it) })
|
||||
)
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventTempBasalChange::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGui() }, { FabricPrivacy.logException(it) })
|
||||
)
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventExtendedBolusChange::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGui() }, { FabricPrivacy.logException(it) })
|
||||
)
|
||||
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||
updateGui()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
loopHandler.removeCallbacks(refreshLoop)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun updateGui() {
|
||||
val virtualPump = VirtualPumpPlugin.getPlugin()
|
||||
virtualpump_basabasalrate?.text = MainApp.gs(R.string.pump_basebasalrate, virtualPump.baseBasalRate)
|
||||
virtualpump_tempbasal?.text = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
|
||||
?: ""
|
||||
virtualpump_extendedbolus?.text = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() ?: ""
|
||||
virtualpump_battery?.text = MainApp.gs(R.string.format_percent, virtualPump.batteryPercent)
|
||||
virtualpump_reservoir?.text = MainApp.gs(R.string.formatinsulinunits, virtualPump.reservoirInUnits.toDouble())
|
||||
|
||||
virtualPump.refreshConfiguration()
|
||||
val pumpType = virtualPump.pumpType
|
||||
|
||||
virtualpump_type?.text = pumpType.description
|
||||
virtualpump_type_def?.text = pumpType.getFullDescription(MainApp.gs(R.string.virtualpump_pump_def), pumpType.hasExtendedBasals())
|
||||
}
|
||||
}
|
|
@ -1602,6 +1602,7 @@
|
|||
<string name="format_bg_isf">%1$s ISF: %2$.1f</string>
|
||||
<string name="format_carbs_ic">%1$.0fg IC: %2$.1f</string>
|
||||
<string name="format_cob_ic">%1$.1fg IC: %2$.1f</string>
|
||||
<string name="format_percent">%1$d%%</string>
|
||||
<string name="boluswizard">Bolus wizard</string>
|
||||
<string name="unit_minute_short">min</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue