diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java index 294410a8..c1b5f000 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java @@ -17,11 +17,8 @@ package com.health.openscale.gui.fragments; import android.content.Intent; import android.content.res.Configuration; -import android.graphics.Color; -import android.graphics.Typeface; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.view.Gravity; @@ -30,7 +27,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; @@ -54,13 +50,9 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { private View tableView; private ListView tableDataView; private LinearLayout tableHeaderView; - private LinearLayout subpageView; private List measurementViews; - private int selectedSubpageNr; - private static final String SELECTED_SUBPAGE_NR_KEY = "selectedSubpageNr"; - public TableFragment() { } @@ -70,21 +62,12 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { { tableView = inflater.inflate(R.layout.fragment_table, container, false); - subpageView = tableView.findViewById(R.id.subpageView); - tableDataView = tableView.findViewById(R.id.tableDataView); tableHeaderView = tableView.findViewById(R.id.tableHeaderView); tableDataView.setAdapter(new ListViewAdapter()); tableDataView.setOnItemClickListener(new onClickListenerRow()); - if (savedInstanceState == null) { - selectedSubpageNr = 0; - } - else { - selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY); - } - measurementViews = MeasurementView.getMeasurementList( getContext(), MeasurementView.DateTimeOrder.FIRST); @@ -103,68 +86,9 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { super.onDestroyView(); } - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt(SELECTED_SUBPAGE_NR_KEY, selectedSubpageNr); - } - @Override public void updateOnView(List scaleMeasurementList) { - final int maxSize = 25; - - final int subpageCount = (int)Math.ceil(scaleMeasurementList.size() / (double)maxSize); - if (selectedSubpageNr >= subpageCount) { - selectedSubpageNr = Math.max(0, subpageCount - 1); - } - - subpageView.removeAllViews(); - - Button moveSubpageLeft = new Button(tableView.getContext()); - moveSubpageLeft.setText("<"); - moveSubpageLeft.setPadding(0,0,0,0); - moveSubpageLeft.setTextColor(Color.WHITE); - moveSubpageLeft.setBackground(ContextCompat.getDrawable(tableView.getContext(), R.drawable.flat_selector)); - moveSubpageLeft.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); - moveSubpageLeft.getLayoutParams().height = pxImageDp(20); - moveSubpageLeft.getLayoutParams().width = pxImageDp(50); - moveSubpageLeft.setOnClickListener(new onClickListenerMoveSubpageLeft()); - moveSubpageLeft.setEnabled(selectedSubpageNr > 0); - subpageView.addView(moveSubpageLeft); - - for (int i = 0; i < subpageCount; i++) { - TextView subpageNrView = new TextView(tableView.getContext()); - subpageNrView.setOnClickListener(new onClickListenerSubpageSelect()); - subpageNrView.setText(Integer.toString(i+1)); - subpageNrView.setTextColor(Color.GRAY); - subpageNrView.setPadding(10, 10, 20, 10); - - subpageView.addView(subpageNrView); - } - - if (subpageView.getChildCount() > 1) { - TextView selectedSubpageNrView = (TextView) subpageView.getChildAt(selectedSubpageNr + 1); - if (selectedSubpageNrView != null) { - selectedSubpageNrView.setTypeface(null, Typeface.BOLD); - selectedSubpageNrView.setTextColor(Color.WHITE); - } - } - - Button moveSubpageRight = new Button(tableView.getContext()); - moveSubpageRight.setText(">"); - moveSubpageRight.setPadding(0,0,0,0); - moveSubpageRight.setTextColor(Color.WHITE); - moveSubpageRight.setBackground(ContextCompat.getDrawable(tableView.getContext(), R.drawable.flat_selector)); - moveSubpageRight.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); - moveSubpageRight.getLayoutParams().height = pxImageDp(20); - moveSubpageRight.getLayoutParams().width = pxImageDp(50); - moveSubpageRight.setOnClickListener(new onClickListenerMoveSubpageRight()); - moveSubpageRight.setEnabled(selectedSubpageNr + 1 < subpageCount); - subpageView.addView(moveSubpageRight); - - subpageView.setVisibility(subpageCount > 1 ? View.VISIBLE : View.GONE); - tableHeaderView.removeAllViews(); ArrayList visibleMeasurements = new ArrayList<>(); @@ -185,10 +109,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { } ListViewAdapter adapter = (ListViewAdapter) tableDataView.getAdapter(); - - final int startOffset = maxSize * selectedSubpageNr; - final int endOffset = Math.min(startOffset + maxSize + 1, scaleMeasurementList.size()); - adapter.setMeasurements(visibleMeasurements, scaleMeasurementList.subList(startOffset, endOffset), maxSize); + adapter.setMeasurements(visibleMeasurements, scaleMeasurementList); } private int pxImageDp(float dp) { @@ -204,59 +125,26 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { } } - private class onClickListenerMoveSubpageLeft implements View.OnClickListener { - @Override - public void onClick(View v) { - if (selectedSubpageNr > 0) { - selectedSubpageNr--; - updateOnView(OpenScale.getInstance().getScaleMeasurementList()); - } - } - } - - private class onClickListenerMoveSubpageRight implements View.OnClickListener { - @Override - public void onClick(View v) { - if (selectedSubpageNr < (subpageView.getChildCount() - 3)) { - selectedSubpageNr++; - updateOnView(OpenScale.getInstance().getScaleMeasurementList()); - } - } - } - - private class onClickListenerSubpageSelect implements View.OnClickListener { - @Override - public void onClick(View v) { - TextView nrView = (TextView)v; - - selectedSubpageNr = Integer.parseInt(nrView.getText().toString())-1; - updateOnView(OpenScale.getInstance().getScaleMeasurementList()); - } - } - private class ListViewAdapter extends BaseAdapter { private List visibleMeasurements; private List scaleMeasurements; - private int measurementsToShow = 0; private Spanned[][] stringCache; public void setMeasurements(List visibleMeasurements, - List scaleMeasurements, - int maxSize) { + List scaleMeasurements) { this.visibleMeasurements = visibleMeasurements; this.scaleMeasurements = scaleMeasurements; - measurementsToShow = Math.min(scaleMeasurements.size(), maxSize); - stringCache = new Spanned[measurementsToShow][visibleMeasurements.size()]; + stringCache = new Spanned[scaleMeasurements.size()][visibleMeasurements.size()]; notifyDataSetChanged(); } @Override public int getCount() { - return measurementsToShow; + return scaleMeasurements == null ? 0 : scaleMeasurements.size(); } @Override diff --git a/android_app/app/src/main/res/layout/fragment_table.xml b/android_app/app/src/main/res/layout/fragment_table.xml index bebd0020..19d391a7 100644 --- a/android_app/app/src/main/res/layout/fragment_table.xml +++ b/android_app/app/src/main/res/layout/fragment_table.xml @@ -4,44 +4,6 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - - - -