mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-29 11:10:35 +02:00
Remove subpage view from table fragment
This commit is contained in:
@@ -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<MeasurementView> 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<ScaleMeasurement> 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<MeasurementView> 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<MeasurementView> visibleMeasurements;
|
||||
private List<ScaleMeasurement> scaleMeasurements;
|
||||
private int measurementsToShow = 0;
|
||||
|
||||
private Spanned[][] stringCache;
|
||||
|
||||
public void setMeasurements(List<MeasurementView> visibleMeasurements,
|
||||
List<ScaleMeasurement> scaleMeasurements,
|
||||
int maxSize) {
|
||||
List<ScaleMeasurement> 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
|
||||
|
@@ -4,44 +4,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
android:gravity="center"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="left"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/subpageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:orientation="horizontal">
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="right"
|
||||
android:layout_weight="0.9"
|
||||
android:orientation="horizontal">
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tableHeaderView"
|
||||
android:layout_width="match_parent"
|
||||
|
Reference in New Issue
Block a user