mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Add sync preferences to settings screen
This commit is contained in:
@@ -29,10 +29,6 @@ import java.util.*;
|
||||
|
||||
public class Preferences
|
||||
{
|
||||
|
||||
public static final String DEFAULT_SYNC_SERVER =
|
||||
"https://sync.loophabits.org";
|
||||
|
||||
@NonNull
|
||||
private final Storage storage;
|
||||
|
||||
@@ -130,16 +126,6 @@ public class Preferences
|
||||
else return new Timestamp(unixTime);
|
||||
}
|
||||
|
||||
public long getLastSync()
|
||||
{
|
||||
return storage.getLong("last_sync", 0);
|
||||
}
|
||||
|
||||
public void setLastSync(long timestamp)
|
||||
{
|
||||
storage.putLong("last_sync", timestamp);
|
||||
}
|
||||
|
||||
public boolean getShowArchived()
|
||||
{
|
||||
return storage.getBoolean("pref_show_archived", false);
|
||||
@@ -170,39 +156,6 @@ public class Preferences
|
||||
storage.putString("pref_snooze_interval", String.valueOf(interval));
|
||||
}
|
||||
|
||||
public String getSyncAddress()
|
||||
{
|
||||
return storage.getString("pref_sync_address", DEFAULT_SYNC_SERVER);
|
||||
}
|
||||
|
||||
public void setSyncAddress(String address)
|
||||
{
|
||||
storage.putString("pref_sync_address", address);
|
||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public String getSyncClientId()
|
||||
{
|
||||
String id = storage.getString("pref_sync_client_id", "");
|
||||
if (!id.isEmpty()) return id;
|
||||
|
||||
id = UUID.randomUUID().toString();
|
||||
storage.putString("pref_sync_client_id", id);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getSyncKey()
|
||||
{
|
||||
return storage.getString("pref_sync_key", "");
|
||||
}
|
||||
|
||||
public void setSyncKey(String key)
|
||||
{
|
||||
storage.putString("pref_sync_key", key);
|
||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public int getTheme()
|
||||
{
|
||||
return storage.getInt("pref_theme", ThemeSwitcher.THEME_AUTOMATIC);
|
||||
@@ -263,17 +216,6 @@ public class Preferences
|
||||
storage.putBoolean("pref_short_toggle", enabled);
|
||||
}
|
||||
|
||||
public boolean isSyncEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_feature_sync", false);
|
||||
}
|
||||
|
||||
public void setSyncEnabled(boolean isEnabled)
|
||||
{
|
||||
storage.putBoolean("pref_feature_sync", isEnabled);
|
||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public boolean isWidgetStackEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_feature_widget_stack", false);
|
||||
@@ -367,6 +309,26 @@ public class Preferences
|
||||
storage.putBoolean("pref_skip_enabled", value);
|
||||
}
|
||||
|
||||
public String getSyncBaseURL()
|
||||
{
|
||||
return storage.getString("pref_sync_base_url", "");
|
||||
}
|
||||
|
||||
public String getSyncKey()
|
||||
{
|
||||
return storage.getString("pref_sync_key", "");
|
||||
}
|
||||
|
||||
public void setSyncKey(String key)
|
||||
{
|
||||
storage.putString("pref_sync_key", key);
|
||||
}
|
||||
|
||||
public boolean isSyncEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_sync_enabled", false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return An integer representing the first day of the week. Sunday
|
||||
@@ -390,10 +352,6 @@ public class Preferences
|
||||
default void onNotificationsChanged()
|
||||
{
|
||||
}
|
||||
|
||||
default void onSyncFeatureChanged()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public interface Storage
|
||||
|
||||
@@ -109,37 +109,6 @@ public class PreferencesTest extends BaseUnitTest
|
||||
assertThat(prefs.getLastHintTimestamp(), equalTo(Timestamp.ZERO.plus(100)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSync() throws Exception
|
||||
{
|
||||
assertThat(prefs.getLastSync(), equalTo(0L));
|
||||
prefs.setLastSync(100);
|
||||
assertThat(prefs.getLastSync(), equalTo(100L));
|
||||
|
||||
assertThat(prefs.getSyncAddress(),
|
||||
equalTo(Preferences.DEFAULT_SYNC_SERVER));
|
||||
prefs.setSyncAddress("example");
|
||||
assertThat(prefs.getSyncAddress(), equalTo("example"));
|
||||
verify(listener).onSyncFeatureChanged();
|
||||
reset(listener);
|
||||
|
||||
assertThat(prefs.getSyncKey(), equalTo(""));
|
||||
prefs.setSyncKey("123");
|
||||
assertThat(prefs.getSyncKey(), equalTo("123"));
|
||||
verify(listener).onSyncFeatureChanged();
|
||||
reset(listener);
|
||||
|
||||
assertFalse(prefs.isSyncEnabled());
|
||||
prefs.setSyncEnabled(true);
|
||||
assertTrue(prefs.isSyncEnabled());
|
||||
verify(listener).onSyncFeatureChanged();
|
||||
reset(listener);
|
||||
|
||||
String id = prefs.getSyncClientId();
|
||||
assertFalse(id.isEmpty());
|
||||
assertThat(prefs.getSyncClientId(), equalTo(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTheme() throws Exception
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user