mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
SyncManager: First version
This commit is contained in:
@@ -324,6 +324,16 @@ public class Preferences
|
||||
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);
|
||||
@@ -332,6 +342,7 @@ public class Preferences
|
||||
public void setSyncEnabled(boolean enabled)
|
||||
{
|
||||
storage.putBoolean("pref_sync_enabled", enabled);
|
||||
if(enabled) for (Listener l : listeners) l.onSyncEnabled();
|
||||
}
|
||||
|
||||
|
||||
@@ -357,6 +368,10 @@ public class Preferences
|
||||
default void onNotificationsChanged()
|
||||
{
|
||||
}
|
||||
|
||||
default void onSyncEnabled()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public interface Storage
|
||||
|
||||
@@ -158,10 +158,15 @@ public class ListHabitsBehavior
|
||||
habit.getId());
|
||||
}
|
||||
|
||||
public void onSyncKeyOffer(@NotNull String key)
|
||||
public void onSyncKeyOffer(@NotNull String syncKey, @NotNull String encryptionKey)
|
||||
{
|
||||
if(prefs.getSyncKey().equals(syncKey)) {
|
||||
screen.showMessage(Message.SYNC_KEY_ALREADY_INSTALLED);
|
||||
return;
|
||||
}
|
||||
screen.showConfirmInstallSyncKey(() -> {
|
||||
prefs.setSyncKey(key);
|
||||
prefs.setSyncKey(syncKey);
|
||||
prefs.setEncryptionKey(encryptionKey);
|
||||
prefs.setSyncEnabled(true);
|
||||
screen.showMessage(Message.SYNC_ENABLED);
|
||||
});
|
||||
@@ -170,7 +175,7 @@ public class ListHabitsBehavior
|
||||
public enum Message
|
||||
{
|
||||
COULD_NOT_EXPORT, IMPORT_SUCCESSFUL, IMPORT_FAILED, DATABASE_REPAIRED,
|
||||
COULD_NOT_GENERATE_BUG_REPORT, FILE_NOT_RECOGNIZED, SYNC_ENABLED
|
||||
COULD_NOT_GENERATE_BUG_REPORT, FILE_NOT_RECOGNIZED, SYNC_ENABLED, SYNC_KEY_ALREADY_INSTALLED
|
||||
}
|
||||
|
||||
public interface BugReporter
|
||||
|
||||
Reference in New Issue
Block a user