use of com.github.dedis.popstellar.databinding.ElectionStartFragmentBinding in project popstellar by dedis.
the class ElectionStartFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ElectionStartFragmentBinding binding = ElectionStartFragmentBinding.inflate(inflater, container, false);
electionStart = binding.electionStart;
electionStatus = binding.electionStatus;
LaoDetailViewModel mLaoDetailViewModel = LaoDetailActivity.obtainViewModel(requireActivity());
Election election = mLaoDetailViewModel.getCurrentElection();
if (election == null) {
Log.e(TAG, "The current election of the LaoDetailViewModel is null");
return null;
}
String scheduledDate = dateFormat.format(new Date(election.getStartTimestampInMillis()));
String electionId = election.getId();
String instanceId = ElectInstance.generateConsensusId("election", electionId, "state");
binding.electionTitle.setText(getString(R.string.election_start_title, election.getName()));
electionStatus.setText(R.string.waiting_scheduled_time);
electionStart.setText(getString(R.string.election_scheduled, scheduledDate));
electionStart.setEnabled(false);
setupTimerUpdate(election);
setupButtonListeners(binding, mLaoDetailViewModel, electionId);
Lao lao = mLaoDetailViewModel.getCurrentLaoValue();
List<ConsensusNode> nodes = lao.getNodes();
ownNode = lao.getNode(mLaoDetailViewModel.getPublicKey());
if (ownNode == null) {
// Only possible if the user wasn't an acceptor, but shouldn't have access to this fragment
Log.e(TAG, "Couldn't find the Node with public key : " + mLaoDetailViewModel.getPublicKey());
throw new IllegalStateException("Only acceptors are allowed to access ElectionStartFragment");
}
NodesAcceptorAdapter adapter = new NodesAcceptorAdapter(nodes, ownNode, instanceId, getViewLifecycleOwner(), mLaoDetailViewModel);
GridView gridView = binding.nodesGrid;
gridView.setAdapter(adapter);
if (isElectionStartTimePassed(election)) {
updateStartAndStatus(nodes, election, instanceId);
}
mLaoDetailViewModel.getNodes().observe(getViewLifecycleOwner(), consensusNodes -> {
Log.d(TAG, "got an update for nodes : " + consensusNodes);
adapter.setList(consensusNodes);
if (isElectionStartTimePassed(election)) {
updateStartAndStatus(consensusNodes, election, instanceId);
}
});
binding.setLifecycleOwner(getViewLifecycleOwner());
return binding.getRoot();
}
Aggregations