basic overview fragment + some gui fixes

This commit is contained in:
Milos Kozak 2016-06-07 23:36:22 +02:00
parent 701e6a2055
commit 3b883dee31
14 changed files with 194 additions and 98 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.tabs;
package info.nightscout.androidaps;
/**
* Created by mike on 07.06.2016.

View file

@ -10,12 +10,12 @@ import android.view.MenuItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.ProfileViewer.ProfileViewerFragment;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.tabs.*;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.Test.TestFragment;
public class MainActivity extends AppCompatActivity
implements ObjectivesFragment.OnFragmentInteractionListener,
@ -39,7 +39,7 @@ public class MainActivity extends AppCompatActivity
// Register all tabs in app here
mAdapter = new TabPageAdapter(getSupportFragmentManager());
mAdapter.registerNewFragment("Test", TestFragment.newInstance());
mAdapter.registerNewFragment("Overview", OverviewFragment.newInstance());
mAdapter.registerNewFragment("Treatments", treatmentsFragment = TreatmentsFragment.newInstance());
mAdapter.registerNewFragment("TempBasals", tempBasalsFragment = TempBasalsFragment.newInstance());
mAdapter.registerNewFragment("Profile", ProfileViewerFragment.newInstance());

View file

@ -28,7 +28,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.tabs.Config;
import info.nightscout.androidaps.Config;
import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv;
@ -114,7 +114,7 @@ public class DataService extends IntentService {
log.debug("XDRIPREC BG " + bgReading.toString());
try {
MainApp.instance().getDbHelper().getDaoBgReadings().update(bgReading);
MainApp.instance().getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
} catch (SQLException e) {
e.printStackTrace();
}
@ -296,7 +296,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = new JSONObject(sgvstring);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().getDaoBgReadings().update(bgReading);
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
if (Config.logIncommingData)
log.debug("ADD: Stored new BG: " + bgReading.toString());
}
@ -308,7 +308,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = jsonArray.getJSONObject(i);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().getDaoBgReadings().update(bgReading);
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
if (Config.logIncommingData)
log.debug("ADD: Stored new BG: " + bgReading.toString());
}

View file

@ -53,13 +53,6 @@ public class BgReading {
raw = sgv.getFiltered();
}
public String valInUnit(String units) {
DecimalFormat formatMmol = new DecimalFormat("0.0");
DecimalFormat formatMgdl = new DecimalFormat("0");
if (units.equals(Constants.MGDL)) return formatMgdl.format(value);
else return formatMmol.format(value/18d);
}
public Double valueToUnits(String units) {
if (units.equals(Constants.MGDL))
return value;
@ -74,7 +67,7 @@ public class BgReading {
@Override
public String toString() {
return "TempBasal{" +
return "BgReading{" +
"timeIndex=" + timeIndex +
", timestamp=" + timestamp +
", date=" + new Date(timestamp) +

View file

@ -0,0 +1,104 @@
package info.nightscout.androidaps.plugins.Overview;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.client.data.NSProfile;
public class OverviewFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
TextView bg;
public static OverviewFragment newInstance() {
OverviewFragment fragment = new OverviewFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.overview_fragment, container, false);
bg = (TextView) view.findViewById(R.id.overview_bg);
return view;
}
private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
private void updateData() {
BgReading bgReading = MainApp.getDbHelper().lastBg();
NSProfile profile = MainApp.getNSProfile();
if (profile != null && bgReading != null && bg != null)
bg.setText(bgReading.valueToUnitsToString(profile.getUnits()));
}
@Subscribe
public void onStatusEvent(final EventTempBasalChange ev) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateData();
}
});
else
log.debug("EventTempBasalChange: Activity is null");
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateData();
}
});
else
log.debug("EventNewBG: Activity is null");
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
updateData();
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.ProfileViewer;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
@ -9,6 +10,9 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
@ -17,6 +21,8 @@ import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.client.data.NSProfile;
public class ProfileViewerFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(ProfileViewerFragment.class);
private static TextView noProfile;
private static TextView dia;
private static TextView activeProfile;
@ -77,7 +83,7 @@ public class ProfileViewerFragment extends Fragment {
isf.setText(profile.getIsfList());
basal.setText(profile.getBasalList());
target.setText(profile.getTargetList());
}
}
private void registerBus() {
try {
@ -90,6 +96,15 @@ public class ProfileViewerFragment extends Fragment {
@Subscribe
public void onStatusEvent(final EventNewBasalProfile ev) {
setContent();
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setContent();
}
});
else
log.debug("EventNewBG: Activity is null");
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.TempBasals;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@ -68,7 +69,7 @@ public class TempBasalsFragment extends Fragment {
fake.percent = 150;
fake.isAbsolute = false;
fake.isExtended = false;
dao.create(fake);
dao.createOrUpdate(fake);
// **************** TESTING CREATE FAKE RECORD *****************
QueryBuilder<TempBasal, Long> queryBuilder = dao.queryBuilder();
@ -83,9 +84,6 @@ public class TempBasalsFragment extends Fragment {
if (recyclerView != null) {
recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasals), false);
}
updateTotalIOB();
}
@ -208,7 +206,7 @@ public class TempBasalsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tempbasals_fragment, container, false);
View view = inflater.inflate(R.layout.tempbasals_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.tempbasals_recyclerview);
recyclerView.setHasFixedSize(true);
@ -260,18 +258,32 @@ public class TempBasalsFragment extends Fragment {
@Subscribe
public void onStatusEvent(final EventTempBasalChange ev) {
initializeData();
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateTotalIOB();
recyclerView.getAdapter().notifyDataSetChanged();
}
});
else
log.debug("EventTempBasalChange: Activity is null");
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateTotalIOB();
recyclerView.getAdapter().notifyDataSetChanged();
}
});
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateTotalIOB();
recyclerView.getAdapter().notifyDataSetChanged();
}
});
else
log.debug("EventNewBG: Activity is null");
}
@Override

View file

@ -1,41 +0,0 @@
package info.nightscout.androidaps.plugins.Test;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import info.nightscout.androidaps.R;
/**
* Created by mike on 30.05.2016.
*/
public class TestFragment extends Fragment {
private static TextView textView;
private static TestFragment instance;
public TestFragment() {
super();
}
public static TestFragment newInstance() {
if (instance == null)
instance = new TestFragment();
return instance;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstance) {
View layout = inflater.inflate(R.layout.test_fragment, container, false);
textView = (TextView) layout.findViewById(R.id.position);
Bundle bundle = getArguments();
if (bundle != null) {
textView.setText("This is page of tab " + bundle.getString("name"));
}
return layout;
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.Treatments;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -249,23 +250,31 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
@Subscribe
public void onStatusEvent(final EventTreatmentChange ev) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
initializeData();
}
});
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
initializeData();
}
});
else
log.debug("EventTreatmentChange: Activity is null");
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateTotalIOB();
recyclerView.getAdapter().notifyDataSetChanged(); }
});
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateTotalIOB();
recyclerView.getAdapter().notifyDataSetChanged();
}
});
else
log.debug("EventNewBG: Activity is null");
}
@Override
@ -281,7 +290,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.

View file

@ -8,7 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.tabs.Config;
import info.nightscout.androidaps.Config;
public class xDripReceiver extends WakefulBroadcastReceiver {

View file

@ -8,7 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.tabs.Config;
import info.nightscout.androidaps.Config;
public class NSClientDataReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(NSClientDataReceiver.class);

View file

@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.Overview.OverviewFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/overview_bg"
android:layout_gravity="left|top"
android:textSize="100dp" />
</FrameLayout>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/position"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:gravity="center"
android:text="This is some page">
</TextView>