Sync: Improve encryption and preferences API

This commit is contained in:
2020-11-27 10:55:55 -06:00
parent 67ef3bb90c
commit ce0cbb6ee2
9 changed files with 134 additions and 97 deletions

View File

@@ -319,30 +319,29 @@ public class Preferences
return storage.getString("pref_sync_key", "");
}
public void setSyncKey(String key)
{
storage.putString("pref_sync_key", key);
}
public String getEncryptionKey()
{
return storage.getString("pref_encryption_key", "");
}
public void setEncryptionKey(String key)
{
storage.putString("pref_encryption_key", key);
}
public boolean isSyncEnabled()
{
return storage.getBoolean("pref_sync_enabled", false);
}
public void setSyncEnabled(boolean enabled)
public void enableSync(String syncKey, String encKey)
{
storage.putBoolean("pref_sync_enabled", enabled);
if(enabled) for (Listener l : listeners) l.onSyncEnabled();
storage.putBoolean("pref_sync_enabled", true);
storage.putString("pref_sync_key", syncKey);
storage.putString("pref_encryption_key", encKey);
for (Listener l : listeners) l.onSyncEnabled();
}
public void disableSync()
{
storage.putBoolean("pref_sync_enabled", false);
storage.putString("pref_sync_key", "");
storage.putString("pref_encryption_key", "");
}
public boolean areQuestionMarksEnabled()

View File

@@ -165,9 +165,7 @@ public class ListHabitsBehavior
return;
}
screen.showConfirmInstallSyncKey(() -> {
prefs.setSyncKey(syncKey);
prefs.setEncryptionKey(encryptionKey);
prefs.setSyncEnabled(true);
prefs.enableSync(syncKey, encryptionKey);
screen.showMessage(Message.SYNC_ENABLED);
});
}