extracting method
This commit is contained in:
parent
01510bc8aa
commit
d8b0753796
|
@ -22,6 +22,20 @@ public class ConnectionStatus {
|
||||||
@NotNull
|
@NotNull
|
||||||
private Value value = Value.NOT_CONNECTED;
|
private Value value = Value.NOT_CONNECTED;
|
||||||
|
|
||||||
|
public void executeOnceConnected(Runnable r) {
|
||||||
|
/*
|
||||||
|
* This would request initial value
|
||||||
|
*/
|
||||||
|
if (isConnected()) {
|
||||||
|
r.run();
|
||||||
|
} else {
|
||||||
|
addListener(isConnected -> {
|
||||||
|
if (getValue() == Value.CONNECTED)
|
||||||
|
r.run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum Value {
|
public enum Value {
|
||||||
NOT_CONNECTED,
|
NOT_CONNECTED,
|
||||||
LOADING,
|
LOADING,
|
||||||
|
|
|
@ -25,20 +25,7 @@ public abstract class BaseConfigField {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void requestInitialValue(final Field field) {
|
protected void requestInitialValue(final Field field) {
|
||||||
/**
|
ConnectionStatus.INSTANCE.executeOnceConnected(() -> processInitialValue(field));
|
||||||
* This would request initial value
|
|
||||||
*/
|
|
||||||
if (ConnectionStatus.INSTANCE.isConnected()) {
|
|
||||||
processInitialValue(field);
|
|
||||||
} else {
|
|
||||||
ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onConnectionStatus(boolean isConnected) {
|
|
||||||
if (ConnectionStatus.INSTANCE.getValue() == ConnectionStatus.Value.CONNECTED)
|
|
||||||
processInitialValue(field);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processInitialValue(Field field) {
|
private void processInitialValue(Field field) {
|
||||||
|
|
Loading…
Reference in New Issue