Merge branch 'dev' into pull/1975

This commit is contained in:
Milos Kozak 2019-08-24 18:28:01 +02:00
commit cdb42f671f
32 changed files with 188 additions and 188 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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"
}

View file

@ -16,6 +16,7 @@ public class AutomationEvent {
private Trigger trigger = new TriggerConnector();
private List<Action> 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++) {

View file

@ -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)
}

View file

@ -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() {
@ -171,7 +164,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() {

View file

@ -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<EventListAdapter.ViewHolder> {
@ -51,6 +54,7 @@ class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder>
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<EventListAdapter.ViewHolder>
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<EventListAdapter.ViewHolder>
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<EventListAdapter.ViewHolder>
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);
}
}
}

View file

@ -113,6 +113,7 @@ public class NSClientPlugin extends PluginBase {
context.unbindService(mConnection);
nsClientReceiverDelegate.unregisterReceivers();
super.onStop();
}
@Subscribe

View file

@ -71,6 +71,7 @@ public class OverviewPlugin extends PluginBase {
@Override
protected void onStop() {
MainApp.bus().unregister(this);
super.onStop();
}
@Subscribe

View file

@ -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() {

View file

@ -98,6 +98,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
@Override
protected void onStop() {
MainApp.bus().unregister(this);
super.onStop();
}
@Subscribe

View file

@ -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)
}

View file

@ -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<EventTidepoolStatus>()
var textLog: Spanned = HtmlHelper.fromHtml("")
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
add(disposable)
}
override fun onStart() {
super.onStart()
disposable += RxBus

View file

@ -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) {

View file

@ -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) {

View file

@ -100,6 +100,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
serviceRunning = false;
MainApp.bus().unregister(this);
super.onStop();
}

View file

@ -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

View file

@ -65,6 +65,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
context.unbindService(mConnection);
MainApp.bus().unregister(this);
super.onStop();
}
private ServiceConnection mConnection = new ServiceConnection() {

View file

@ -68,6 +68,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
context.unbindService(mConnection);
MainApp.bus().unregister(this);
super.onStop();
}
private ServiceConnection mConnection = new ServiceConnection() {

View file

@ -123,6 +123,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
context.unbindService(mConnection);
MainApp.bus().unregister(this);
super.onStop();
}
@Override

View file

@ -71,6 +71,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
context.unbindService(mConnection);
MainApp.bus().unregister(this);
super.onStop();
}
private ServiceConnection mConnection = new ServiceConnection() {

View file

@ -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

View file

@ -128,6 +128,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
protected void onStop() {
MainApp.bus().unregister(this);
super.onStop();
}
@Subscribe

View file

@ -110,6 +110,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
@Override
protected void onStop() {
MainApp.bus().register(this);
super.onStop();
}
public TreatmentService getService() {
@ -294,14 +295,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<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) {
List<Treatment> 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);
}

View file

@ -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)
}

View file

@ -1,9 +1,6 @@
package info.nightscout.androidaps.utils;
import android.content.Context;
import android.os.Handler;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
@ -15,6 +12,10 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -24,6 +25,7 @@ import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -77,8 +79,7 @@ public class TimeListEdit {
}
private void buildView() {
layout = (LinearLayout) view.findViewById(resLayoutId);
layout.removeAllViews();
layout = view.findViewById(resLayoutId);
textlabel = new TextView(context);
textlabel.setText(label);
@ -96,72 +97,63 @@ public class TimeListEdit {
}
// last "plus" to append new interval
float factor = layout.getContext().getResources().getDisplayMetrics().density;
finalAdd = new ImageView(context);
finalAdd.setImageResource(R.drawable.add);
LinearLayout.LayoutParams illp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams illp = new LinearLayout.LayoutParams((int) (35d * factor), (int) (35 * factor));
illp.setMargins(0, 25, 0, 25); // llp.setMargins(left, top, right, bottom);
illp.gravity = Gravity.CENTER;
layout.addView(finalAdd);
finalAdd.setLayoutParams(illp);
finalAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addItem(itemsCount(), itemsCount() > 0 ? secondFromMidnight(itemsCount() - 1) + ONEHOURINSECONDS : 0, 0, 0);
callSave();
log();
fillView();
}
finalAdd.setOnClickListener(view -> {
addItem(itemsCount(), itemsCount() > 0 ? secondFromMidnight(itemsCount() - 1) + ONEHOURINSECONDS : 0, 0, 0);
callSave();
log();
fillView();
});
fillView();
}
private void inflateRow(int i) {
private void inflateRow(final int position) {
LayoutInflater inflater = LayoutInflater.from(context);
View childview = intervals[i] = inflater.inflate(R.layout.timelistedit_element, layout, false);
spinners[i] = new SpinnerHelper(childview.findViewById(R.id.timelistedit_time));
numberPickers1[i] = (NumberPicker) childview.findViewById(R.id.timelistedit_edit1);
numberPickers2[i] = (NumberPicker) childview.findViewById(R.id.timelistedit_edit2);
addButtons[i] = (ImageView) childview.findViewById(R.id.timelistedit_add);
removeButtons[i] = (ImageView) childview.findViewById(R.id.timelistedit_remove);
View childView = intervals[position] = inflater.inflate(R.layout.timelistedit_element, layout, false);
spinners[position] = new SpinnerHelper(childView.findViewById(R.id.timelistedit_time));
numberPickers1[position] = childView.findViewById(R.id.timelistedit_edit1);
numberPickers2[position] = childView.findViewById(R.id.timelistedit_edit2);
addButtons[position] = childView.findViewById(R.id.timelistedit_add);
removeButtons[position] = childView.findViewById(R.id.timelistedit_remove);
final int fixedPos = i;
addButtons[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int seconds = secondFromMidnight(fixedPos);
addItem(fixedPos, seconds, 0, 0);
// for here for the rest of values
for (int i = fixedPos + 1; i < itemsCount(); i++) {
if (secondFromMidnight(i - 1) >= secondFromMidnight(i)) {
editItem(i, secondFromMidnight(i - 1) + ONEHOURINSECONDS, value1(i), value2(i));
}
addButtons[position].setOnClickListener(view -> {
int seconds = secondFromMidnight(position);
addItem(position, seconds, 0, 0);
// for here for the rest of values
for (int i = position + 1; i < itemsCount(); i++) {
if (secondFromMidnight(i - 1) >= secondFromMidnight(i)) {
editItem(i, secondFromMidnight(i - 1) + ONEHOURINSECONDS, value1(i), value2(i));
}
while (itemsCount() > 24 || secondFromMidnight(itemsCount() - 1) > 23 * ONEHOURINSECONDS)
removeItem(itemsCount() - 1);
callSave();
log();
fillView();
}
while (itemsCount() > 24 || secondFromMidnight(itemsCount() - 1) > 23 * ONEHOURINSECONDS)
removeItem(itemsCount() - 1);
callSave();
log();
fillView();
});
removeButtons[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeItem(fixedPos);
callSave();
log();
fillView();
}
removeButtons[position].setOnClickListener(view -> {
removeItem(position);
callSave();
log();
fillView();
});
spinners[i].setOnItemSelectedListener(
spinners[position].setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int seconds = DateUtil.toSeconds(spinners[fixedPos].getSelectedItem().toString());
editItem(fixedPos, seconds, value1(fixedPos), value2(fixedPos));
public void onItemSelected(AdapterView<?> parent, View view, int selected, long id) {
int seconds = ((SpinnerAdapter) spinners[position].getAdapter()).valueForPosition(selected);
editItem(position, seconds, value1(position), value2(position));
log();
callSave();
fillView();
@ -173,30 +165,10 @@ public class TimeListEdit {
}
);
numberPickers1[i].setTextWatcher(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
editItem(fixedPos, secondFromMidnight(fixedPos), SafeParse.stringToDouble(numberPickers1[fixedPos].getText()), value2(fixedPos));
callSave();
log();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
numberPickers2[i].setTextWatcher(new TextWatcher() {
numberPickers1[position].setTextWatcher(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
editItem(fixedPos, secondFromMidnight(fixedPos), value1(fixedPos), SafeParse.stringToDouble(numberPickers2[fixedPos].getText()));
editItem(position, secondFromMidnight(position), SafeParse.stringToDouble(numberPickers1[position].getText()), value2(position));
callSave();
log();
}
@ -212,7 +184,27 @@ public class TimeListEdit {
}
});
layout.addView(childview);
numberPickers2[position].setTextWatcher(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
editItem(position, secondFromMidnight(position), value1(position), SafeParse.stringToDouble(numberPickers2[position].getText()));
callSave();
log();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
layout.addView(childView);
}
private void fillView() {
@ -220,7 +212,7 @@ public class TimeListEdit {
if (i < itemsCount()) {
intervals[i].setVisibility(View.VISIBLE);
buildInterval(i);
} else if (i <= inflatedUntil){
} else if (i <= inflatedUntil) {
intervals[i].setVisibility(View.GONE);
}
}
@ -232,9 +224,8 @@ public class TimeListEdit {
}
}
private View buildInterval(int i) {
private void buildInterval(int i) {
SpinnerHelper timeSpinner = spinners[i];
View childview = intervals[i];
final NumberPicker editText1 = numberPickers1[i];
final NumberPicker editText2 = numberPickers2[i];
@ -263,29 +254,38 @@ public class TimeListEdit {
addButtons[i].setVisibility(View.VISIBLE);
}
return childview;
}
class SpinnerAdapter extends ArrayAdapter<CharSequence> {
List<Integer> values;
SpinnerAdapter(@NonNull Context context, int resource, final @NonNull List<CharSequence> objects, final @NonNull List<Integer> values) {
super(context, resource, objects);
this.values = values;
}
int valueForPosition(int position) {
return values.get(position);
}
}
private void fillSpinner(final SpinnerHelper spinner, int secondsFromMidnight, int previous, int next) {
int posInList = 0;
ArrayList<CharSequence> timeList = new ArrayList<>();
ArrayList<Integer> timeListValues = new ArrayList<>();
int pos = 0;
for (int t = previous + ONEHOURINSECONDS; t < next; t += ONEHOURINSECONDS) {
timeList.add(DateUtil.timeStringFromSeconds(t));
timeListValues.add(t);
if (secondsFromMidnight == t) posInList = pos;
pos++;
}
final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
R.layout.spinner_centered, timeList);
final SpinnerAdapter adapter = new SpinnerAdapter(context,
R.layout.spinner_centered, timeList, timeListValues);
spinner.setAdapter(adapter);
final int finalPosInList = posInList;
new Handler().postDelayed(new Runnable() {
public void run() {
spinner.setSelection(finalPosInList, false);
adapter.notifyDataSetChanged();
}
}, 100);
spinner.setSelection(posInList, false);
adapter.notifyDataSetChanged();
}
private int itemsCount() {
@ -362,7 +362,7 @@ public class TimeListEdit {
}
private void addItem(int index, int timeAsSeconds, double value1, double value2) {
if(itemsCount()>inflatedUntil) {
if (itemsCount() > inflatedUntil) {
layout.removeView(finalAdd);
inflateRow(++inflatedUntil);
layout.addView(finalAdd);
@ -389,10 +389,8 @@ public class TimeListEdit {
}
private void log() {
if (log.isDebugEnabled()) {
for (int i = 0; i < data1.length(); i++) {
log.debug(i + ": @" + DateUtil.timeStringFromSeconds(secondFromMidnight(i)) + " " + value1(i) + (data2 != null ? " " + value2(i) : ""));
}
for (int i = 0; i < data1.length(); i++) {
log.debug(i + ": @" + DateUtil.timeStringFromSeconds(secondFromMidnight(i)) + " " + value1(i) + (data2 != null ? " " + value2(i) : ""));
}
}
@ -400,9 +398,9 @@ public class TimeListEdit {
if (save != null) save.run();
}
public void updateLabel(String txt){
public void updateLabel(String txt) {
this.label = txt;
if(textlabel!=null)
if (textlabel != null)
textlabel.setText(txt);
}
}

View file

@ -11,6 +11,27 @@
android:background="@color/ribbonDefault"
android:padding="8dp">
<CheckBox
android:id="@+id/automation_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/viewEventTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/automation_enabled"
android:layout_alignBottom="@+id/automation_enabled"
android:layout_centerVertical="true"
android:layout_marginTop="6dp"
android:layout_toStartOf="@+id/iconTrash"
android:layout_toEndOf="@id/automation_enabled"
android:text="Title"
android:textAlignment="viewStart"
android:textStyle="bold" />
<ImageView
android:id="@+id/iconTrash"
android:layout_width="wrap_content"
@ -22,25 +43,11 @@
android:src="@drawable/ic_trash_outline" />
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/iconLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toStartOf="@id/iconTrash"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">
android:layout_below="@id/automation_enabled"
android:orientation="horizontal" />
<TextView
android:id="@+id/viewEventTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/iconLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</LinearLayout>
</RelativeLayout>

View file

@ -33,16 +33,16 @@
<ImageView
android:id="@+id/timelistedit_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:src="@drawable/add" />
<ImageView
android:id="@+id/timelistedit_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:src="@drawable/remove" />

View file

@ -1175,7 +1175,7 @@
<string name="glucoseisnotavailable">Γλυκόζη δεν είναι διαθέσιμη</string>
<string name="glucosecomparedmgdl">Γλυκόζη %1$s %2$.0f %3$s</string>
<string name="glucosecomparedmmol">Γλυκόζη %1$s %2$.1f %3$s</string>
<string name="percentagecompared">Προφίλ % %1$s %2$d</string>
<string name="percentagecompared">Προφίλ %% %1$s %2$d</string>
<string name="iobcompared">ΙΟΒ %1$s %2$.1f</string>
<string name="and">Και</string>
<string name="or">ή</string>
@ -1238,7 +1238,6 @@
<string name="old_version">παλιά έκδοση</string>
<string name="very_old_version">πολύ παλιά έκδοση</string>
<string name="new_version_warning">Νέα έκδοση για τουλάχιστον %1$d ημέρες διαθέσιμη! Επιστροφή σε LGS μετά από 60 ημέρες, το κύκλωμα θα απενεργοποιηθεί μετά από 90 ημέρες</string>
<string name="scale_insulin_activity">Γραφική κλίμακα δραστηριότητας ινσουλίνης [U/min]</string>
<string name="twohours">ρες</string>
<string name="formatinsulinunits">%1$.2fU</string>
<string name="dexcom_app_patched">Εφαρμογή Dexcom (τροποποιημένη)</string>

View file

@ -1179,7 +1179,7 @@ L\'ENSEMBLE DES RISQUES LIÉS À LA QUALITÉ ET À LA PERFORMANCE DU PROGRAMME S
<string name="glucoseisnotavailable">La glycémie n\'est pas disponible</string>
<string name="glucosecomparedmgdl">Glycémie %1$s %2$.0f %3$s</string>
<string name="glucosecomparedmmol">Glycémie %1$s %2$.1f %3$s</string>
<string name="percentagecompared">Profil % %1$s %2$d</string>
<string name="percentagecompared">Profil %% %1$s %2$d</string>
<string name="iobcompared">IA %1$s %2$.1f</string>
<string name="and">Et</string>
<string name="or">Ou</string>
@ -1250,7 +1250,6 @@ L\'ENSEMBLE DES RISQUES LIÉS À LA QUALITÉ ET À LA PERFORMANCE DU PROGRAMME S
<string name="old_version">ancienne version</string>
<string name="very_old_version">très ancienne version</string>
<string name="new_version_warning">Une nouvelle version est disponible depuis au moins %1$d jours ! Retour au traitement par pompe assistée par capteur (Arrêt par Glycémie Basse (AGB), Low Glucose Suspend (LGS) ) après 60 jours et la Boucle sera désactivée après 90 jours</string>
<string name="scale_insulin_activity">Courbe de l\'activité de l\'insuline [U/min]</string>
<string name="twohours">2 h</string>
<string name="formatinsulinunits">%1$.2fU</string>
<string name="dexcom_app_patched">App Dexcom (patchée)</string>
@ -1415,6 +1414,7 @@ L\'ENSEMBLE DES RISQUES LIÉS À LA QUALITÉ ET À LA PERFORMANCE DU PROGRAMME S
<string name="medtronic_cmd_cant_cancel_tbr_stop_op">Impossible d\'annuler le DBT (TBR) actuel. Arrêt de l\'opération.</string>
<string name="medtronic_cmd_set_profile_pattern_overflow">Le nouveau profil a échoué car le taux basal suivant est trop élevé : %1$s</string>
<string name="medtronic_cmd_bolus_could_not_be_delivered">Le Bolus n\'a pas pu être délivré.</string>
<string name="medtronic_cmd_bolus_could_not_be_delivered_no_insulin">Le Bolus n\'a pas pu être délivré, car la quantité d\'insuline disponible (%1$.2f) est inférieure à celle requise (%2$.2f).</string>
<string name="medtronic_cmd_tbr_could_not_be_delivered">DBT n\'a pas pu être défini.</string>
<string name="medtronic_cmd_cant_cancel_tbr">Impossible d\'annuler le DBT actuel.</string>
<string name="medtronic_cmd_basal_profile_could_not_be_set">Le profil Basal n\'a pas pu être défini.</string>

View file

@ -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