mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-25 17:42:29 +02:00
Move selectedUserId handling to OpenScale class
This commit is contained in:
@@ -213,7 +213,8 @@ public class ScreenshotRecorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void prepareData() {
|
private void prepareData() {
|
||||||
openScale.addScaleUser(getTestUser());
|
int userId = openScale.addScaleUser(getTestUser());
|
||||||
|
openScale.selectScaleUser(userId);
|
||||||
|
|
||||||
List<ScaleMeasurement> scaleMeasurementList = getTestMeasurements();
|
List<ScaleMeasurement> scaleMeasurementList = getTestMeasurements();
|
||||||
|
|
||||||
|
@@ -138,12 +138,18 @@ public class OpenScale {
|
|||||||
scaleDB.close();
|
scaleDB.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addScaleUser(final ScaleUser user)
|
public int addScaleUser(final ScaleUser user) {
|
||||||
{
|
return (int)userDAO.insert(user);
|
||||||
long userId = userDAO.insert(user);
|
}
|
||||||
|
|
||||||
|
public void selectScaleUser(int userId) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
prefs.edit().putInt("selectedUserId", (int)userId).commit();
|
prefs.edit().putInt("selectedUserId", userId).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedScaleUserId() {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
return prefs.getInt("selectedUserId", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ScaleUser> getScaleUserList()
|
public List<ScaleUser> getScaleUserList()
|
||||||
@@ -161,8 +167,7 @@ public class OpenScale {
|
|||||||
ScaleUser scaleUser = new ScaleUser();
|
ScaleUser scaleUser = new ScaleUser();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
if (selectedUserId == -1) {
|
if (selectedUserId == -1) {
|
||||||
return scaleUser;
|
return scaleUser;
|
||||||
@@ -355,8 +360,7 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int[] getCountsOfMonth(int year) {
|
public int[] getCountsOfMonth(int year) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
int [] numOfMonth = new int[12];
|
int [] numOfMonth = new int[12];
|
||||||
|
|
||||||
@@ -375,8 +379,7 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ScaleMeasurement> getScaleDataOfMonth(int year, int month) {
|
public List<ScaleMeasurement> getScaleDataOfMonth(int year, int month) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
Calendar startCalender = Calendar.getInstance();
|
Calendar startCalender = Calendar.getInstance();
|
||||||
Calendar endCalender = Calendar.getInstance();
|
Calendar endCalender = Calendar.getInstance();
|
||||||
@@ -389,8 +392,7 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ScaleMeasurement> getScaleDataOfYear(int year) {
|
public List<ScaleMeasurement> getScaleDataOfYear(int year) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
Calendar startCalender = Calendar.getInstance();
|
Calendar startCalender = Calendar.getInstance();
|
||||||
Calendar endCalender = Calendar.getInstance();
|
Calendar endCalender = Calendar.getInstance();
|
||||||
@@ -430,18 +432,15 @@ public class OpenScale {
|
|||||||
public void registerFragment(FragmentUpdateListener fragment) {
|
public void registerFragment(FragmentUpdateListener fragment) {
|
||||||
fragmentList.add(fragment);
|
fragmentList.add(fragment);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
scaleMeasurementList = measurementDAO.getAll(selectedUserId);
|
scaleMeasurementList = measurementDAO.getAll(selectedUserId);
|
||||||
|
|
||||||
fragment.updateOnView(scaleMeasurementList);
|
fragment.updateOnView(scaleMeasurementList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateScaleData()
|
public void updateScaleData() {
|
||||||
{
|
int selectedUserId = getSelectedScaleUserId();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
scaleMeasurementList = measurementDAO.getAll(selectedUserId);
|
scaleMeasurementList = measurementDAO.getAll(selectedUserId);
|
||||||
|
|
||||||
|
@@ -62,8 +62,7 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
|
|||||||
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
|
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
|
||||||
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
|
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int userId = selectedUser.getId();
|
||||||
int userId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
byte cmdByte[] = {(byte)0x10, (byte)userId, gender, age, height};
|
byte cmdByte[] = {(byte)0x10, (byte)userId, gender, age, height};
|
||||||
|
|
||||||
|
@@ -285,7 +285,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = prefs.getInt("selectedUserId", -1);
|
int userId = OpenScale.getInstance(context).getSelectedScaleUserId();
|
||||||
|
|
||||||
return uniqueNumber + userId;
|
return uniqueNumber + userId;
|
||||||
}
|
}
|
||||||
|
@@ -257,7 +257,7 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
|
|||||||
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = prefs.getInt("selectedUserId", -1);
|
int userId = OpenScale.getInstance(context).getSelectedScaleUserId();
|
||||||
|
|
||||||
return uniqueNumber + userId;
|
return uniqueNumber + userId;
|
||||||
}
|
}
|
||||||
|
@@ -154,7 +154,7 @@ public class BluetoothYunmaiMini extends BluetoothCommunication {
|
|||||||
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = prefs.getInt("selectedUserId", -1);
|
int userId = OpenScale.getInstance(context).getSelectedScaleUserId();
|
||||||
|
|
||||||
return uniqueNumber + userId;
|
return uniqueNumber + userId;
|
||||||
}
|
}
|
||||||
|
@@ -152,7 +152,7 @@ public class BluetoothYunmaiSE extends BluetoothCommunication {
|
|||||||
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = prefs.getInt("selectedUserId", -1);
|
int userId = OpenScale.getInstance(context).getSelectedScaleUserId();
|
||||||
|
|
||||||
return uniqueNumber + userId;
|
return uniqueNumber + userId;
|
||||||
}
|
}
|
||||||
|
@@ -301,8 +301,9 @@ public class DataEntryActivity extends Activity {
|
|||||||
private class onClickListenerAdd implements View.OnClickListener {
|
private class onClickListenerAdd implements View.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
int selectedUserId = openScale.getSelectedScaleUserId();
|
||||||
|
|
||||||
if (selectedUserId == -1) {
|
if (selectedUserId == -1) {
|
||||||
AlertDialog.Builder infoDialog = new AlertDialog.Builder(context);
|
AlertDialog.Builder infoDialog = new AlertDialog.Builder(context);
|
||||||
@@ -317,7 +318,6 @@ public class DataEntryActivity extends Activity {
|
|||||||
measurement.saveTo(scaleMeasurement);
|
measurement.saveTo(scaleMeasurement);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
|
||||||
openScale.addScaleData(scaleMeasurement);
|
openScale.addScaleData(scaleMeasurement);
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
|
@@ -246,9 +246,7 @@ public class UserSettingsActivity extends Activity {
|
|||||||
lastUserId = scaleUser.get(0).getId();
|
lastUserId = scaleUser.get(0).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
openScale.selectScaleUser(lastUserId);
|
||||||
prefs.edit().putInt("selectedUserId", lastUserId).commit();
|
|
||||||
|
|
||||||
openScale.updateScaleData();
|
openScale.updateScaleData();
|
||||||
|
|
||||||
Intent returnIntent = new Intent();
|
Intent returnIntent = new Intent();
|
||||||
@@ -325,13 +323,10 @@ public class UserSettingsActivity extends Activity {
|
|||||||
scaleUser.setId(id);
|
scaleUser.setId(id);
|
||||||
openScale.updateScaleUser(scaleUser);
|
openScale.updateScaleUser(scaleUser);
|
||||||
} else {
|
} else {
|
||||||
openScale.addScaleUser(scaleUser);
|
id = openScale.addScaleUser(scaleUser);
|
||||||
|
|
||||||
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size() - 1).getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
openScale.selectScaleUser(id);
|
||||||
prefs.edit().putInt("selectedUserId", id).commit();
|
|
||||||
|
|
||||||
openScale.updateScaleData();
|
openScale.updateScaleData();
|
||||||
|
|
||||||
|
@@ -476,13 +476,13 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
if (parent.getChildCount() > 0) {
|
if (parent.getChildCount() > 0) {
|
||||||
((TextView) parent.getChildAt(0)).setTextColor(Color.GRAY);
|
((TextView) parent.getChildAt(0)).setTextColor(Color.GRAY);
|
||||||
|
|
||||||
List<ScaleUser> scaleUserList = OpenScale.getInstance(getContext()).getScaleUserList();
|
OpenScale openScale = OpenScale.getInstance(getContext());
|
||||||
|
|
||||||
|
List<ScaleUser> scaleUserList = openScale.getScaleUserList();
|
||||||
ScaleUser scaleUser = scaleUserList.get(position);
|
ScaleUser scaleUser = scaleUserList.get(position);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
openScale.selectScaleUser(scaleUser.getId());
|
||||||
prefs.edit().putInt("selectedUserId", scaleUser.getId()).commit();
|
openScale.updateScaleData();
|
||||||
OpenScale.getInstance(getContext()).updateScaleData();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -263,8 +263,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
|
int selectedUserId = OpenScale.getInstance(getContext()).getSelectedScaleUserId();
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
|
||||||
|
|
||||||
if (selectedUserId == -1)
|
if (selectedUserId == -1)
|
||||||
{
|
{
|
||||||
|
@@ -125,8 +125,7 @@ public class BackupPreferences extends PreferenceFragment {
|
|||||||
List<ScaleUser> scaleUserList = openScale.getScaleUserList();
|
List<ScaleUser> scaleUserList = openScale.getScaleUserList();
|
||||||
|
|
||||||
if (!scaleUserList.isEmpty()) {
|
if (!scaleUserList.isEmpty()) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
openScale.selectScaleUser(scaleUserList.get(0).getId());
|
||||||
prefs.edit().putInt("selectedUserId", scaleUserList.get(0).getId()).commit();
|
|
||||||
openScale.updateScaleData();
|
openScale.updateScaleData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -247,10 +247,10 @@ public class MeasurementPreferences extends PreferenceFragment implements Shared
|
|||||||
|
|
||||||
deleteAllDialog.setPositiveButton(getResources().getString(R.string.label_yes), new DialogInterface.OnClickListener() {
|
deleteAllDialog.setPositiveButton(getResources().getString(R.string.label_yes), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
OpenScale openScale = OpenScale.getInstance(getActivity().getApplicationContext());
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
int selectedUserId = openScale.getSelectedScaleUserId();
|
||||||
|
|
||||||
OpenScale.getInstance(getActivity().getApplicationContext()).clearScaleData(selectedUserId);
|
openScale.clearScaleData(selectedUserId);
|
||||||
|
|
||||||
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.info_data_all_deleted), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.info_data_all_deleted), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@@ -41,15 +41,13 @@ public class UsersPreferences extends PreferenceFragment {
|
|||||||
updateUserPreferences();
|
updateUserPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserPreferences()
|
private void updateUserPreferences() {
|
||||||
{
|
OpenScale openScale = OpenScale.getInstance(getActivity().getApplicationContext());
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
|
||||||
int selectedUserId = prefs.getInt("selectedUserId", -1);
|
int selectedUserId = openScale.getSelectedScaleUserId();
|
||||||
|
|
||||||
getPreferenceScreen().removeAll();
|
getPreferenceScreen().removeAll();
|
||||||
|
|
||||||
OpenScale openScale = OpenScale.getInstance(getActivity().getApplicationContext());
|
|
||||||
|
|
||||||
List<ScaleUser> scaleUserList = openScale.getScaleUserList();
|
List<ScaleUser> scaleUserList = openScale.getScaleUserList();
|
||||||
|
|
||||||
for (ScaleUser scaleUser : scaleUserList)
|
for (ScaleUser scaleUser : scaleUserList)
|
||||||
|
Reference in New Issue
Block a user