extracting method
This commit is contained in:
parent
01510bc8aa
commit
d8b0753796
|
@ -22,6 +22,20 @@ public class ConnectionStatus {
|
|||
@NotNull
|
||||
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 {
|
||||
NOT_CONNECTED,
|
||||
LOADING,
|
||||
|
|
|
@ -25,20 +25,7 @@ public abstract class BaseConfigField {
|
|||
}
|
||||
|
||||
protected void requestInitialValue(final Field 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
ConnectionStatus.INSTANCE.executeOnceConnected(() -> processInitialValue(field));
|
||||
}
|
||||
|
||||
private void processInitialValue(Field field) {
|
||||
|
|
Loading…
Reference in New Issue