1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 09:44:31 +02:00

Add support for user bound preferences

This commit is contained in:
Erik Johansson
2018-02-26 21:59:19 +01:00
parent b4d11190cc
commit 24c3fb371b
2 changed files with 20 additions and 0 deletions

View File

@@ -194,6 +194,18 @@ public class OpenScale {
public void deleteScaleUser(int id) {
userDAO.delete(userDAO.get(id));
selectedScaleUser = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Remove user specific settings
SharedPreferences.Editor editor = prefs.edit();
final String prefix = ScaleUser.getPreferenceKey(id, "");
for (String key : prefs.getAll().keySet()) {
if (key.startsWith(prefix)) {
editor.remove(key);
}
}
editor.apply();
}
public void updateScaleUser(ScaleUser user) {

View File

@@ -152,6 +152,14 @@ public class ScaleUser {
return Converters.fromKilogram(initialWeight, scaleUnit);
}
public static String getPreferenceKey(int userId, String key) {
return String.format("user.%d.%s", userId, key);
}
public String getPreferenceKey(String key) {
return getPreferenceKey(getId(), key);
}
@Override
public String toString()
{