1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-02-06 17:13:36 +01:00

add subpages for the table fragment to increase performance

add gpl3 license notice for sanitas sbf 70 source code
fix yearly graph december bug
This commit is contained in:
OliE 2017-05-04 16:49:29 +02:00
parent 4ca8934015
commit 75c6caa955
4 changed files with 127 additions and 17 deletions

View File

@ -1,3 +1,19 @@
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
* 2017 jflesch <jflesch@kwain.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.health.openscale.core.bluetooth;
import android.bluetooth.BluetoothAdapter;
@ -17,10 +33,6 @@ import java.util.LinkedList;
import java.util.Queue;
import java.util.UUID;
/**
* Created by jflesch on 30/04/17.
*/
public class BluetoothSanitasSbf70 extends BluetoothCommunication {
public final static String TAG = "BluetoothSanitasSbf70";

View File

@ -324,7 +324,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
Calendar end_cal = Calendar.getInstance();
start_cal.set(year, Calendar.JANUARY, 1, 0, 0, 0);
end_cal.set(year, Calendar.DECEMBER, 1, 0, 0, 0);
end_cal.set(year+1, Calendar.JANUARY, 1, 0, 0, 0);
Cursor cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query

View File

@ -23,6 +23,7 @@ import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
@ -36,6 +37,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
@ -61,7 +63,8 @@ import com.health.openscale.gui.views.WeightMeasurementView;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ListIterator;
import lecho.lib.hellocharts.util.ChartUtils;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
@ -69,9 +72,12 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
private View tableView;
private TableLayout tableDataView;
private SharedPreferences prefs;
private LinearLayout subpageView;
private ArrayList <MeasurementView> measurementsList;
private int selectedSubpageNr;
public TableFragment() {
}
@ -80,7 +86,9 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
tableView = inflater.inflate(R.layout.fragment_table, container, false);
subpageView = (LinearLayout) tableView.findViewById(R.id.subpageView);
tableDataView = (TableLayout) tableView.findViewById(R.id.tableDataView);
tableView.findViewById(R.id.btnImportData).setOnClickListener(new onClickListenerImport());
@ -109,12 +117,55 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
OpenScale.getInstance(getContext()).registerFragment(this);
selectedSubpageNr = 0;
return tableView;
}
@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList)
{
{
final int maxSize = 20;
int subpageCount = (int)Math.ceil(scaleDataList.size() / (double)maxSize);
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());
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.setPadding(10, 10, 20, 10);
subpageView.addView(subpageNrView);
}
TextView selectedSubpageNrView = (TextView) subpageView.getChildAt(selectedSubpageNr+1);
selectedSubpageNrView.setTypeface(null, Typeface.BOLD);
selectedSubpageNrView.setTextColor(ChartUtils.COLOR_BLUE);
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());
subpageView.addView(moveSubpageRight);
tableDataView.removeAllViews();
TableRow tableHeader = new TableRow(tableView.getContext());
@ -152,17 +203,17 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
tableDataView.addView(tableHeader);
ListIterator<ScaleData> scaleDataItr = scaleDataList.listIterator();
int displayCount = 0;
for (int i = (maxSize * selectedSubpageNr); i<scaleDataList.size(); i++) {
ScaleData scaleData = scaleDataList.get(i);
while (scaleDataItr.hasNext()) {
ScaleData scaleData = scaleDataItr.next();
ScaleData prevScaleData;
if (scaleDataItr.hasNext()) {
prevScaleData = scaleDataItr.next();
scaleDataItr.previous();
} else {
if (i >= scaleDataList.size()-1) {
prevScaleData = new ScaleData();
} else {
prevScaleData = scaleDataList.get(i+1);
}
TableRow dataRow = new TableRow(tableView.getContext());
@ -208,6 +259,13 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
}*/
tableDataView.addView(dataRow);
displayCount++;
if (maxSize <= displayCount) {
break;
}
}
}
@ -399,7 +457,37 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
}
}
@Override
private class onClickListenerMoveSubpageLeft implements View.OnClickListener {
@Override
public void onClick(View v) {
if (selectedSubpageNr > 0) {
selectedSubpageNr--;
updateOnView(OpenScale.getInstance(getContext()).getScaleDataList());
}
}
}
private class onClickListenerMoveSubpageRight implements View.OnClickListener {
@Override
public void onClick(View v) {
if (selectedSubpageNr < (subpageView.getChildCount() - 3)) {
selectedSubpageNr++;
updateOnView(OpenScale.getInstance(getContext()).getScaleDataList());
}
}
}
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(getContext()).getScaleDataList());
}
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {

View File

@ -5,6 +5,15 @@
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="@+id/subpageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -18,7 +27,8 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_gravity="center">
<TableLayout
android:id="@+id/tableDataView"