mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-14 04:34:18 +02:00
persisting state of toggle action buttons
This commit is contained in:
@@ -86,8 +86,6 @@ public class DataEntryActivity extends Activity {
|
|||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private boolean editMode;
|
|
||||||
private boolean isExpand;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -96,8 +94,6 @@ public class DataEntryActivity extends Activity {
|
|||||||
setContentView(R.layout.activity_dataentry);
|
setContentView(R.layout.activity_dataentry);
|
||||||
|
|
||||||
context = this;
|
context = this;
|
||||||
editMode = false;
|
|
||||||
isExpand = false;
|
|
||||||
|
|
||||||
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
|
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
|
||||||
|
|
||||||
@@ -151,8 +147,8 @@ public class DataEntryActivity extends Activity {
|
|||||||
imageViewDelete.setOnClickListener(new onClickListenerDelete());
|
imageViewDelete.setOnClickListener(new onClickListenerDelete());
|
||||||
btnLeft.setOnClickListener(new onClickListenerLeft());
|
btnLeft.setOnClickListener(new onClickListenerLeft());
|
||||||
btnRight.setOnClickListener(new onClickListenerRight());
|
btnRight.setOnClickListener(new onClickListenerRight());
|
||||||
switchEditMode.setOnClickListener(new onCheckedChangeEditMode());
|
switchEditMode.setOnClickListener(new onClickListenerToggleButton());
|
||||||
expandButton.setOnClickListener(new onClickListenerExpand());
|
expandButton.setOnClickListener(new onClickListenerToggleButton());
|
||||||
|
|
||||||
updateOnView();
|
updateOnView();
|
||||||
}
|
}
|
||||||
@@ -172,7 +168,7 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
// keep edit mode state if we are moving to left or right
|
// keep edit mode state if we are moving to left or right
|
||||||
if (editMode) {
|
if (prefs.getBoolean(String.valueOf(switchEditMode.getId()), false)) {
|
||||||
setViewMode(MeasurementView.MeasurementViewMode.EDIT);
|
setViewMode(MeasurementView.MeasurementViewMode.EDIT);
|
||||||
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_GREEN));
|
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_GREEN));
|
||||||
} else {
|
} else {
|
||||||
@@ -180,7 +176,7 @@ public class DataEntryActivity extends Activity {
|
|||||||
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isExpand) {
|
if (prefs.getBoolean(String.valueOf(expandButton.getId()), false)) {
|
||||||
expandButton.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_ORANGE));
|
expandButton.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_ORANGE));
|
||||||
} else {
|
} else {
|
||||||
expandButton.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
expandButton.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
||||||
@@ -209,7 +205,7 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
// show selected scale data
|
// show selected scale data
|
||||||
for (MeasurementView measuremt : dataEntryMeasurements) {
|
for (MeasurementView measuremt : dataEntryMeasurements) {
|
||||||
measuremt.setExpand(isExpand);
|
measuremt.setExpand(prefs.getBoolean(String.valueOf(expandButton.getId()), false));
|
||||||
measuremt.updateValue(selectedScaleData);
|
measuremt.updateValue(selectedScaleData);
|
||||||
measuremt.updateDiff(selectedScaleData, lastData);
|
measuremt.updateDiff(selectedScaleData, lastData);
|
||||||
}
|
}
|
||||||
@@ -442,19 +438,18 @@ public class DataEntryActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class onCheckedChangeEditMode implements View.OnClickListener {
|
private class onClickListenerToggleButton implements View.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
editMode = !editMode;
|
FloatingActionButton actionButton = (FloatingActionButton) v;
|
||||||
|
|
||||||
updateOnView();
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class onClickListenerExpand implements View.OnClickListener {
|
if (prefs.getBoolean(String.valueOf(actionButton.getId()), false)) {
|
||||||
@Override
|
prefs.edit().putBoolean(String.valueOf(actionButton.getId()), false).commit();
|
||||||
public void onClick(View v) {
|
} else {
|
||||||
isExpand = !isExpand;
|
prefs.edit().putBoolean(String.valueOf(actionButton.getId()), true).commit();
|
||||||
|
}
|
||||||
|
|
||||||
updateOnView();
|
updateOnView();
|
||||||
}
|
}
|
||||||
|
@@ -247,28 +247,46 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
setFormatter(new SimpleLineChartValueFormatter(1));
|
setFormatter(new SimpleLineChartValueFormatter(1));
|
||||||
|
|
||||||
|
|
||||||
if(prefs.getBoolean("weightEnable", true) && diagramWeight.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("weightEnable", true) && prefs.getBoolean(String.valueOf(diagramWeight.getId()), true)) {
|
||||||
lines.add(lineWeight);
|
lines.add(lineWeight);
|
||||||
|
diagramWeight.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_VIOLET));
|
||||||
|
} else {
|
||||||
|
diagramWeight.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prefs.getBoolean("fatEnable", true) && diagramFat.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("fatEnable", true) && prefs.getBoolean(String.valueOf(diagramFat.getId()), true)) {
|
||||||
lines.add(lineFat);
|
lines.add(lineFat);
|
||||||
|
diagramFat.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_ORANGE));
|
||||||
|
} else {
|
||||||
|
diagramFat.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prefs.getBoolean("waterEnable", true) && diagramWater.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("waterEnable", true) && prefs.getBoolean(String.valueOf(diagramWater.getId()), true)) {
|
||||||
lines.add(lineWater);
|
lines.add(lineWater);
|
||||||
|
diagramWater.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_BLUE));
|
||||||
|
} else {
|
||||||
|
diagramWater.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prefs.getBoolean("muscleEnable", true) && diagramMuscle.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("muscleEnable", true) && prefs.getBoolean(String.valueOf(diagramMuscle.getId()), true)) {
|
||||||
lines.add(lineMuscle);
|
lines.add(lineMuscle);
|
||||||
|
diagramMuscle.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_GREEN));
|
||||||
|
} else {
|
||||||
|
diagramMuscle.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prefs.getBoolean("waistEnable", false) && diagramWaist.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("waistEnable", false) && prefs.getBoolean(String.valueOf(diagramWaist.getId()), false)) {
|
||||||
lines.add(lineWaist);
|
lines.add(lineWaist);
|
||||||
|
diagramWaist.setBackgroundTintList(ColorStateList.valueOf(Color.MAGENTA));
|
||||||
|
} else {
|
||||||
|
diagramWaist.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prefs.getBoolean("hipEnable", false) && diagramHip.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
if(prefs.getBoolean("hipEnable", false) && prefs.getBoolean(String.valueOf(diagramHip.getId()), false)) {
|
||||||
lines.add(lineHip);
|
lines.add(lineHip);
|
||||||
|
diagramHip.setBackgroundTintList(ColorStateList.valueOf(Color.YELLOW));
|
||||||
|
} else {
|
||||||
|
diagramHip.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
LineChartData lineData = new LineChartData(lines);
|
LineChartData lineData = new LineChartData(lines);
|
||||||
@@ -393,10 +411,12 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FloatingActionButton actionButton = (FloatingActionButton) v;
|
FloatingActionButton actionButton = (FloatingActionButton) v;
|
||||||
|
|
||||||
if (actionButton.getBackgroundTintList().getDefaultColor() != Color.parseColor("#d3d3d3")) {
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
actionButton.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
|
|
||||||
|
if (prefs.getBoolean(String.valueOf(actionButton.getId()), true)) {
|
||||||
|
prefs.edit().putBoolean(String.valueOf(actionButton.getId()), false).commit();
|
||||||
} else {
|
} else {
|
||||||
actionButton.setBackgroundTintList(ColorStateList.valueOf(actionButton.getRippleColor()));
|
prefs.edit().putBoolean(String.valueOf(actionButton.getId()), true).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
generateColumnData();
|
generateColumnData();
|
||||||
|
Reference in New Issue
Block a user