use of com.github.dedis.popstellar.databinding.ConsensusNodeLayoutBinding 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();
}
Aggregations