From 8c5ce7290d3377158346e992f663ff7131e40bd3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 May 2017 17:48:58 +0200 Subject: [PATCH] more work on treatments fragment --- .../Treatments/TreatmentsFragment.java | 83 ++++++++----------- .../plugins/Treatments/TreatmentsPlugin.java | 3 +- .../TreatmentsTempBasalsFragment.java | 2 +- .../TreatmentsFromHistoryFragment.java | 49 ----------- .../main/res/layout/treatments_fragment.xml | 37 +++++++-- 5 files changed, 65 insertions(+), 109 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index c2043b6474..c875f7a3c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -5,11 +5,13 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,7 +20,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment; import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment; -public class TreatmentsFragment extends Fragment { +public class TreatmentsFragment extends Fragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class); private static TreatmentsPlugin treatmentsPlugin = new TreatmentsPlugin(); @@ -27,57 +29,13 @@ public class TreatmentsFragment extends Fragment { return treatmentsPlugin; } - SectionsPagerAdapter sectionsPagerAdapter; - ViewPager viewPager; - Context context; + TextView treatmentsTab; + TextView tempBasalsTab; Fragment bolusFragment; Fragment tempBasalsFragment; - public class SectionsPagerAdapter extends FragmentPagerAdapter { - - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - // getItem is called to instantiate the fragment for the given page. - switch (position){ - case 0: - return bolusFragment; - case 1: - return tempBasalsFragment; -/* - case 2: - return iobcobActiveFragmentObject; - case 3: - return basalvsTempBasalObject; -*/ - default: - return null; - } - } - - @Override - public int getCount() { - // Show 1 total pages. - return 2; - } - - @Override - public CharSequence getPageTitle(int position) { - switch (position) { - case 0: - return getString(R.string.bolus); - case 1: - return getString(R.string.tempbasals); - } - return null; - } - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -86,11 +44,36 @@ public class TreatmentsFragment extends Fragment { bolusFragment = new TreatmentsBolusFragment(); tempBasalsFragment = new TreatmentsTempBasalsFragment(); - sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager()); - viewPager = (ViewPager) view.findViewById(R.id.treatments_pager); - viewPager.setAdapter(sectionsPagerAdapter); + treatmentsTab = (TextView) view.findViewById(R.id.treatments_treatments); + tempBasalsTab = (TextView) view.findViewById(R.id.treatments_tempbasals); + treatmentsTab.setOnClickListener(this); + tempBasalsTab.setOnClickListener(this); context = getContext(); + setFragment(bolusFragment); + return view; } + + @Override + public void onClick(View v) { + + switch (v.getId()) { + case R.id.treatments_treatments: + setFragment(bolusFragment); + break; + case R.id.treatments_tempbasals: + setFragment(tempBasalsFragment); + break; + + } + } + + private void setFragment(Fragment selectedFragment) { + FragmentTransaction ft = getChildFragmentManager().beginTransaction(); + ft.replace(R.id.treatments_fragment_container, selectedFragment); // f2_container is your FrameLayout container + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + ft.addToBackStack(null); + ft.commit(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index bed0cd1c43..b712da9a3f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -429,7 +429,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { if (useExtendedBoluses) { List merged = new ArrayList(); merged.addAll(tempBasals); - merged.addAll(extendedBoluses); + if (useExtendedBoluses) + merged.addAll(extendedBoluses); class CustomComparator implements Comparator { public int compare(TempBasal object1, TempBasal object2) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempBasalsFragment.java index d54b7e83ed..e549ac8ea6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempBasalsFragment.java @@ -71,7 +71,7 @@ public class TreatmentsTempBasalsFragment extends Fragment { } holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.duration) + " min"); if (tempBasal.isAbsolute) { - holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.absolute) + " U/h"); + holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.timeStart)) + " U/h"); holder.percent.setText(""); } else { holder.absolute.setText(""); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryFragment.java index 5a942d8c9d..f0c867ae33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryFragment.java @@ -27,57 +27,11 @@ public class TreatmentsFromHistoryFragment extends Fragment { return treatmentsPlugin; } - SectionsPagerAdapter sectionsPagerAdapter; - ViewPager viewPager; - Context context; Fragment bolusFragment; Fragment tempBasalsFragment; - public class SectionsPagerAdapter extends FragmentPagerAdapter { - - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - // getItem is called to instantiate the fragment for the given page. - switch (position){ - case 0: - return bolusFragment; - case 1: - return tempBasalsFragment; -/* - case 2: - return iobcobActiveFragmentObject; - case 3: - return basalvsTempBasalObject; -*/ - default: - return null; - } - } - - @Override - public int getCount() { - // Show 1 total pages. - return 2; - } - - @Override - public CharSequence getPageTitle(int position) { - switch (position) { - case 0: - return getString(R.string.bolus); - case 1: - return getString(R.string.tempbasals); - } - return null; - } - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -86,9 +40,6 @@ public class TreatmentsFromHistoryFragment extends Fragment { bolusFragment = new TreatmentsBolusFragment(); tempBasalsFragment = new TreatmentsTempBasalsFragment(); - sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager()); - viewPager = (ViewPager) view.findViewById(R.id.treatments_pager); - viewPager.setAdapter(sectionsPagerAdapter); context = getContext(); return view; diff --git a/app/src/main/res/layout/treatments_fragment.xml b/app/src/main/res/layout/treatments_fragment.xml index aae18872f4..bcc7dd9725 100644 --- a/app/src/main/res/layout/treatments_fragment.xml +++ b/app/src/main/res/layout/treatments_fragment.xml @@ -5,18 +5,39 @@ tools:context=".plugins.Treatments.TreatmentsFragment"> - + android:layout_height="match_parent" + android:orientation="vertical"> - - + android:layout_height="wrap_content" + android:orientation="horizontal"> - + + + + + + + +