use of com.github.dedis.popstellar.model.objects.ElectInstance.State in project popstellar by dedis.
the class NodesAcceptorAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ConsensusNodeLayoutBinding binding;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
binding = ConsensusNodeLayoutBinding.inflate(inflater);
} else {
binding = DataBindingUtil.getBinding(convertView);
}
if (binding == null) {
throw new IllegalStateException("Binding could not be find in the view");
}
ConsensusNode node = getItem(position);
Optional<ElectInstance> lastElectInstance = node.getLastElectInstance(instanceId);
State state = node.getState(instanceId);
boolean alreadyAccepted = lastElectInstance.map(ElectInstance::getMessageId).map(ownNode.getAcceptedMessageIds()::contains).orElse(false);
String text = "";
switch(state) {
case FAILED:
text = "Start Failed\n";
break;
case STARTING:
text = "Approve Start by\n";
break;
case WAITING:
text = "Waiting\n";
break;
case ACCEPTED:
text = "Started by\n";
}
text += node.getPublicKey().getEncoded();
binding.nodeButton.setText(text);
binding.nodeButton.setEnabled(state == State.STARTING && !alreadyAccepted);
lastElectInstance.ifPresent(electInstance -> binding.nodeButton.setOnClickListener(clicked -> laoDetailViewModel.sendConsensusElectAccept(electInstance, true)));
binding.setLifecycleOwner(lifecycleOwner);
binding.executePendingBindings();
return binding.getRoot();
}
use of com.github.dedis.popstellar.model.objects.ElectInstance.State in project popstellar by dedis.
the class ElectionStartFragment method updateStartAndStatus.
private void updateStartAndStatus(List<ConsensusNode> nodes, Election election, String instanceId) {
boolean isAnyElectInstanceAccepted = nodes.stream().map(node -> node.getLastElectInstance(instanceId)).filter(Optional::isPresent).map(Optional::get).map(ElectInstance::getState).anyMatch(State.ACCEPTED::equals);
if (isAnyElectInstanceAccepted) {
// assuming the election start time was updated from scheduled to real start time
String startedDate = dateFormat.format(new Date(election.getStartTimestampInMillis()));
electionStatus.setText(R.string.started);
electionStart.setText(getString(R.string.election_started_at, startedDate));
electionStart.setEnabled(false);
} else {
State ownState = ownNode.getState(instanceId);
boolean canClick = ownState == State.WAITING || ownState == State.FAILED;
electionStart.setEnabled(canClick);
}
}
Aggregations