button refresh treatments from nightscout

This commit is contained in:
Milos Kozak 2016-06-06 12:17:37 +02:00
parent 21a3434463
commit bd47fb8624
3 changed files with 27 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.Treatments; package info.nightscout.androidaps.plugins.Treatments;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
@ -9,6 +10,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.Dao;
@ -34,8 +36,9 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.client.broadcasts.Intents;
public class TreatmentsFragment extends Fragment { public class TreatmentsFragment extends Fragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class); private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
RecyclerView recyclerView; RecyclerView recyclerView;
@ -43,6 +46,7 @@ public class TreatmentsFragment extends Fragment {
TextView iobTotal; TextView iobTotal;
TextView activityTotal; TextView activityTotal;
Button refreshFromNS;
private static DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0"); private static DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
@ -171,17 +175,24 @@ public class TreatmentsFragment extends Fragment {
iobTotal = (TextView) view.findViewById(R.id.treatments_iobtotal); iobTotal = (TextView) view.findViewById(R.id.treatments_iobtotal);
activityTotal = (TextView) view.findViewById(R.id.treatments_iobactivitytotal); activityTotal = (TextView) view.findViewById(R.id.treatments_iobactivitytotal);
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
refreshFromNS.setOnClickListener(this);
return view; return view;
} }
/* @Override
// TODO: Rename method, update argument and hook method into UI event public void onClick(View view) {
public void onButtonPressed(Uri uri) { switch (view.getId()) {
if (mListener != null) { case R.id.treatments_reshreshfromnightscout:
mListener.onFragmentInteraction(uri); MainApp.getDbHelper().resetTreatments();
initializeData();
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
break;
} }
} }
*/
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);

View file

@ -12,4 +12,5 @@ public interface Intents {
// App -> NSClient // App -> NSClient
String ACTION_DATABASE = "info.nightscout.client.DBACCESS"; String ACTION_DATABASE = "info.nightscout.client.DBACCESS";
String ACTION_RESTART = "info.nightscout.client.RESTART";
} }

View file

@ -47,6 +47,13 @@
android:paddingLeft="10dp" /> android:paddingLeft="10dp" />
</LinearLayout> </LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refresh treatments from Nightscout"
android:id="@+id/treatments_reshreshfromnightscout"
android:layout_gravity="center_horizontal" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/treatments_recyclerview" android:id="@+id/treatments_recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"