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:
@@ -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) {
|
||||
|
@@ -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()
|
||||
{
|
||||
|
Reference in New Issue
Block a user