allow refrest temp targets from NS & fix bugs
This commit is contained in:
parent
a96bc52e01
commit
61a8cad4e8
13 changed files with 84 additions and 30 deletions
|
@ -46,7 +46,7 @@ import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
|||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventNewTempTargetRange;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.client.data.NSSgv;
|
||||
|
@ -595,7 +595,7 @@ public class DataService extends IntentService {
|
|||
*/
|
||||
|
||||
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||
if (trJson.getString("eventType").equals("Temporary Target")) {
|
||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temporary Target")) {
|
||||
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
|
@ -610,10 +610,11 @@ public class DataService extends IntentService {
|
|||
newRecord.low = trJson.getDouble("targetBottom");
|
||||
newRecord.high = trJson.getDouble("targetTop");
|
||||
newRecord.reason = trJson.getString("reason");
|
||||
newRecord._id = trJson.getString("_id");
|
||||
daoTempTargets.createIfNotExists(newRecord);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Adding TempTarget record to database: " + newRecord.toString());
|
||||
MainApp.bus().post(new EventNewTempTargetRange());
|
||||
log.debug("Adding TempTarget record to database: " + newRecord.log());
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} else if (list.size() == 1) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating TempTarget record in database: " + trJson.getString("_id"));
|
||||
|
@ -624,26 +625,26 @@ public class DataService extends IntentService {
|
|||
record.high = trJson.getDouble("targetTop");
|
||||
record.reason = trJson.getString("reason");
|
||||
daoTempTargets.update(record);
|
||||
MainApp.bus().post(new EventNewTempTargetRange());
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRemoveTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||
if (trJson.getString("eventType").equals("Temporary Target")) {
|
||||
if (trJson.has("_id")) {
|
||||
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
|
||||
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", trJson.getString("_id")).or().eq("timeIndex", trJson.getLong("mills"));
|
||||
where.eq("_id", trJson.getString("_id"));
|
||||
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
|
||||
List<TempTarget> list = daoTempTargets.query(preparedQuery);
|
||||
|
||||
if (list.size() == 1) {
|
||||
TempTarget record = list.get(0);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Removing TempTarget record from database: " + record.toString());
|
||||
log.debug("Removing TempTarget record from database: " + record.log());
|
||||
daoTempTargets.delete(record);
|
||||
MainApp.bus().post(new EventNewTempTargetRange());
|
||||
MainApp.bus().post(new EventTempTargetRangeChange());
|
||||
} else {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("TempTarget not found database: " + trJson.toString());
|
||||
|
|
|
@ -130,7 +130,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
public void resetTreatments() {
|
||||
try {
|
||||
|
||||
TableUtils.dropTable(connectionSource, Treatment.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||
} catch (SQLException e) {
|
||||
|
@ -138,6 +137,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void resetTempTargets() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, TempTarget.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Dao<TempBasal, Long> getDaoTempBasals() throws SQLException {
|
||||
return getDao(TempBasal.class);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
package info.nightscout.androidaps.plugins.TempTargetRange;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -18,19 +24,21 @@ import java.util.List;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventNewTempTargetRange;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
/**
|
||||
* Created by mike on 13/01/17.
|
||||
*/
|
||||
|
||||
public class TempTargetRangeFragment extends Fragment implements FragmentBase {
|
||||
public class TempTargetRangeFragment extends Fragment implements View.OnClickListener, FragmentBase {
|
||||
|
||||
private static TempTargetRangePlugin tempTargetRangePlugin = new TempTargetRangePlugin();
|
||||
|
||||
|
@ -40,6 +48,7 @@ public class TempTargetRangeFragment extends Fragment implements FragmentBase {
|
|||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
Button refreshFromNS;
|
||||
|
||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempTargetsViewHolder> {
|
||||
|
||||
|
@ -117,10 +126,41 @@ public class TempTargetRangeFragment extends Fragment implements FragmentBase {
|
|||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(tempTargetRangePlugin.getList());
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
refreshFromNS = (Button) view.findViewById(R.id.temptargetrange_refreshfromnightscout);
|
||||
refreshFromNS.setOnClickListener(this);
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.temptargetrange_refreshfromnightscout:
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
|
||||
if(nsUploadOnly){
|
||||
ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled));
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
|
||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||
builder.setMessage(this.getContext().getString(R.string.refreshtemptargetsfromnightscout));
|
||||
builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
MainApp.getDbHelper().resetTempTargets();
|
||||
tempTargetRangePlugin.initializeData();
|
||||
updateGUI();
|
||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(this.getContext().getString(R.string.cancel), null);
|
||||
builder.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
@ -134,7 +174,7 @@ public class TempTargetRangeFragment extends Fragment implements FragmentBase {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewTempTargetRange ev) {
|
||||
public void onStatusEvent(final EventTempTargetRangeChange ev) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,8 @@ package info.nightscout.androidaps.plugins.TempTargetRange;
|
|||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,7 +11,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventNewTempTargetRange;
|
||||
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
|
||||
|
||||
/**
|
||||
* Created by mike on 13/01/17.
|
||||
|
@ -81,11 +76,11 @@ public class TempTargetRangePlugin implements PluginBase {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewTempTargetRange ev) {
|
||||
|
||||
public void onStatusEvent(final EventTempTargetRangeChange ev) {
|
||||
initializeData();
|
||||
}
|
||||
|
||||
private void initializeData() {
|
||||
public void initializeData() {
|
||||
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * 24);
|
||||
tempTargets = MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false);
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ package info.nightscout.androidaps.plugins.TempTargetRange.events;
|
|||
* Created by mike on 13.01.2017.
|
||||
*/
|
||||
|
||||
public class EventNewTempTargetRange {
|
||||
public class EventTempTargetRangeChange {
|
||||
}
|
|
@ -157,7 +157,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
|
||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||
builder.setMessage(this.getContext().getString(R.string.refreshfromnightscout));
|
||||
builder.setMessage(this.getContext().getString(R.string.refreshtreatmentsfromnightscout));
|
||||
builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
MainApp.getDbHelper().resetTreatments();
|
||||
|
|
|
@ -9,6 +9,14 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/temptargetrange_refreshfromnightscout"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="@string/temptargetrange_refreshfromnightscout" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/temptargetrange_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
<string name="objectives_pumpstatusavailableinns">Статус на помпа в NS</string>
|
||||
<string name="rate">Стойност</string>
|
||||
<string name="reason">Основание</string>
|
||||
<string name="refreshfromnightscout">Искате ли да обновите treatments от Nightscout</string>
|
||||
<string name="refreshtreatmentsfromnightscout">Искате ли да обновите treatments от Nightscout</string>
|
||||
<string name="safety">Безопасност</string>
|
||||
<string name="setextendedbolusquestion">Задай нов удължен болусs:</string>
|
||||
<string name="setbasalquestion">Приложи нов временен базал:</string>
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
<string name="objectives_pumpstatusavailableinns">Stav pumpy dostupný v NS</string>
|
||||
<string name="rate">Hodnota</string>
|
||||
<string name="reason">Zdůvodnění</string>
|
||||
<string name="refreshfromnightscout">Opravdu aktualizovat ošetření z NS</string>
|
||||
<string name="refreshtreatmentsfromnightscout">Opravdu aktualizovat ošetření z NS</string>
|
||||
<string name="safety">Bezpečnost</string>
|
||||
<string name="danar_useextended_title">Použít kombo bolusy pro >200%</string>
|
||||
<string name="setextendedbolusquestion">Spustit nový kombo bolus:</string>
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
<string name="setextendedbolusquestion">Setze neuen extended Bolus:</string>
|
||||
<string name="setbasalquestion">Akzeptiere neue temp Basalrate:</string>
|
||||
<string name="danar_useextended_title">Benutze extended Bolus für hohe temps (\>200%)></string>
|
||||
<string name="refreshfromnightscout">Möchtest du die Treatments von Nightscout abrufen</string>
|
||||
<string name="refreshtreatmentsfromnightscout">Möchtest du die Treatments von Nightscout abrufen</string>
|
||||
<string name="objectives_pumpstatusavailableinns">Pumpen Status verfügbar in NS</string>
|
||||
<string name="overview_newtempbasal_percent_label">% (100% = current)</string>
|
||||
<string name="overview_newtempbasal_basal_label">Basal Wert</string>
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
<string name="loop_constraintsprocessed_label">Tras procesar limitaciones</string>
|
||||
<string name="loop_setbypump_label">Definido por la bomba</string>
|
||||
<string name="openapsma_lastenact_label">Última aceptada</string>
|
||||
<string name="refreshfromnightscout">¿Quieres actualizar tratamientos de Nightscout?</string>
|
||||
<string name="refreshtreatmentsfromnightscout">¿Quieres actualizar tratamientos de Nightscout?</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancelar</string>
|
||||
<string name="noapsselected">NO APS Seleccionado</string>
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
<string name="loop_constraintsprocessed_label">After processed constraints</string>
|
||||
<string name="loop_setbypump_label">Set by pump</string>
|
||||
<string name="openapsma_lastenact_label">최근 주입</string>
|
||||
<string name="refreshfromnightscout">나이트스카우트에서 Treatments를 새로고치시겠습니까</string>
|
||||
<string name="refreshtreatmentsfromnightscout">나이트스카우트에서 Treatments를 새로고치시겠습니까</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">취소</string>
|
||||
<string name="noapsselected">NO APS SELECTED OR PROVIDED RESULT</string>
|
||||
|
|
|
@ -107,7 +107,8 @@
|
|||
<string name="loop_constraintsprocessed_label">After processed constraints</string>
|
||||
<string name="loop_setbypump_label">Set by pump</string>
|
||||
<string name="openapsma_lastenact_label">Last enacted</string>
|
||||
<string name="refreshfromnightscout">Do you want to refresh treatments from Nightscout</string>
|
||||
<string name="refreshtreatmentsfromnightscout">Do you want to refresh treatments from Nightscout</string>
|
||||
<string name="refreshtemptargetsfromnightscout">Do you want to refresh temp targets from Nightscout</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="noapsselected">NO APS SELECTED OR PROVIDED RESULT</string>
|
||||
|
@ -399,4 +400,5 @@
|
|||
<string name="sms_minago">%dmin ago</string>
|
||||
<string name="localprofile">Local Profile</string>
|
||||
<string name="temptargetrange">Temp Target</string>
|
||||
<string name="temptargetrange_refreshfromnightscout">Refresh temp targets from NS</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue