more work on treatments fragment

This commit is contained in:
Milos Kozak 2017-05-16 17:48:58 +02:00
parent 3ee9bf5ff7
commit 8c5ce7290d
5 changed files with 65 additions and 109 deletions

View file

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

View file

@ -429,7 +429,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
if (useExtendedBoluses) {
List<TempBasal> merged = new ArrayList<TempBasal>();
merged.addAll(tempBasals);
merged.addAll(extendedBoluses);
if (useExtendedBoluses)
merged.addAll(extendedBoluses);
class CustomComparator implements Comparator<TempBasal> {
public int compare(TempBasal object1, TempBasal object2) {

View file

@ -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("");

View file

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

View file

@ -5,18 +5,39 @@
tools:context=".plugins.Treatments.TreatmentsFragment">
<android.support.v4.view.ViewPager
android:id="@+id/treatments_pager"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.PagerTabStrip
android:id="@+id/treatments_tabstrip"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.PagerTabStrip>
android:layout_height="wrap_content"
android:orientation="horizontal">
</android.support.v4.view.ViewPager>
<TextView
android:id="@+id/treatments_treatments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/treatments" />
<TextView
android:id="@+id/treatments_tempbasals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/tempbasals" />
</LinearLayout>
<FrameLayout
android:id="@+id/treatments_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>