Remember connection state (so you don't have to start a full node whenever you lost your WiFi connection)

This commit is contained in:
2017-05-07 13:39:30 +02:00
parent 5bc1bc2a47
commit 422c7ac803
9 changed files with 37 additions and 27 deletions

View File

@@ -26,6 +26,7 @@ public class Constants {
public static final String PREFERENCE_TRUSTED_NODE = "trusted_node";
public static final String PREFERENCE_SYNC_TIMEOUT = "sync_timeout";
public static final String PREFERENCE_SERVER_POW = "server_pow";
public static final String PREFERENCE_FULL_NODE = "full_node";
public static final String BITMESSAGE_URL_SCHEMA = "bitmessage:";
public static final Pattern BITMESSAGE_ADDRESS_PATTERN = Pattern.compile("\\bBM-[a-zA-Z0-9]+\\b");

View File

@@ -27,6 +27,7 @@ import ch.dissem.apps.abit.R;
import ch.dissem.apps.abit.listener.WifiReceiver;
import ch.dissem.apps.abit.notification.ErrorNotification;
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_FULL_NODE;
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_SYNC_TIMEOUT;
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_TRUSTED_NODE;
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_WIFI_ONLY;
@@ -54,7 +55,7 @@ public class Preferences {
int index = trustedNode.lastIndexOf(':');
trustedNode = trustedNode.substring(0, index);
}
return InetAddress.getByName(trustedNode);
return InetAddress.getByName(trustedNode);
}
public static int getTrustedNodePort(Context ctx) {
@@ -69,8 +70,8 @@ public class Preferences {
return Integer.parseInt(portString);
} catch (NumberFormatException e) {
new ErrorNotification(ctx)
.setError(R.string.error_invalid_sync_port, portString)
.show();
.setError(R.string.error_invalid_sync_port, portString)
.show();
}
}
return 8444;
@@ -95,4 +96,19 @@ public class Preferences {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
return preferences.getBoolean(PREFERENCE_WIFI_ONLY, true);
}
public static void setWifiOnly(Context ctx, boolean status) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
preferences.edit().putBoolean(PREFERENCE_WIFI_ONLY, status).apply();
}
public static boolean isFullNodeActive(Context ctx) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
return preferences.getBoolean(PREFERENCE_FULL_NODE, false);
}
public static void setFullNodeActive(Context ctx, boolean status) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
preferences.edit().putBoolean(PREFERENCE_FULL_NODE, status).apply();
}
}