use of com.github.dedis.popstellar.ui.detail.event.election.ZoomOutTransformer in project popstellar by dedis.
the class ElectionSetupFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mSetupElectionFragBinding = ElectionSetupFragmentBinding.inflate(inflater, container, false);
mLaoDetailViewModel = LaoDetailActivity.obtainViewModel(requireActivity());
// Set the view for the date and time
setDateAndTimeView(mSetupElectionFragBinding.getRoot());
// Make the textWatcher listen to changes in the start and end date/time
addEndDateAndTimeListener(submitTextWatcher);
addStartDateAndTimeListener(submitTextWatcher);
cancelButton = mSetupElectionFragBinding.electionCancelButton;
submitButton = mSetupElectionFragBinding.electionSubmitButton;
electionNameText = mSetupElectionFragBinding.electionSetupName;
// Add text watchers on the fields that need to be filled
electionNameText.addTextChangedListener(submitTextWatcher);
// Set the text widget in layout to current LAO name
TextView laoNameTextView = mSetupElectionFragBinding.electionSetupLaoName;
laoNameTextView.setText(mLaoDetailViewModel.getCurrentLaoName().getValue());
// Set viewPager adapter
viewPagerAdapter = new ElectionSetupViewPagerAdapter(mLaoDetailViewModel);
// Set ViewPager
ViewPager2 viewPager2 = mSetupElectionFragBinding.electionSetupViewPager2;
viewPager2.setAdapter(viewPagerAdapter);
// Sets animation on swipe
viewPager2.setPageTransformer(new ZoomOutTransformer());
// This sets the indicator of which page we are on
CircleIndicator3 circleIndicator = mSetupElectionFragBinding.electionSetupSwipeIndicator;
circleIndicator.setViewPager(viewPager2);
// This observes if at least one of the question has the minimal information
viewPagerAdapter.isAnInputValid().observe(getViewLifecycleOwner(), aBoolean -> submitButton.setEnabled(aBoolean && isElectionLevelInputValid()));
Button addQuestion = mSetupElectionFragBinding.addQuestion;
addQuestion.setOnClickListener(v -> {
addQuestion.setEnabled(false);
viewPagerAdapter.addQuestion();
// This scales for a few dozens of questions but this is dangerous and greedy in
// resources
// TODO delete this and find a way to keep data on left swipe
viewPager2.setOffscreenPageLimit(viewPagerAdapter.getNumberOfQuestions());
// This swipes automatically to new question
viewPager2.setCurrentItem(viewPager2.getCurrentItem() + 1);
// Updates the number of circles in the indicator
circleIndicator.setViewPager(viewPager2);
addQuestion.setEnabled(true);
});
mSetupElectionFragBinding.setLifecycleOwner(getActivity());
return mSetupElectionFragBinding.getRoot();
}
use of com.github.dedis.popstellar.ui.detail.event.election.ZoomOutTransformer in project popstellar by dedis.
the class CastVoteFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
CastVoteFragmentBinding mCastVoteFragBinding = CastVoteFragmentBinding.inflate(inflater, container, false);
mLaoDetailViewModel = LaoDetailActivity.obtainViewModel(requireActivity());
TextView laoNameView = mCastVoteFragBinding.castVoteLaoName;
TextView electionNameView = mCastVoteFragBinding.castVoteElectionName;
// setUp the cast Vote button
voteButton = mCastVoteFragBinding.castVoteButton;
voteButton.setEnabled(false);
// Getting election
Election election = mLaoDetailViewModel.getCurrentElection();
// Setting the Lao Name
laoNameView.setText(mLaoDetailViewModel.getCurrentLaoName().getValue());
// Setting election name
electionNameView.setText(election.getName());
int numberOfQuestions = election.getElectionQuestions().size();
// Setting up the votes for the adapter
mLaoDetailViewModel.setCurrentElectionVotes(setEmptyVoteList(numberOfQuestions));
// Setting the viewPager and its adapter
ViewPager2 viewPager2 = mCastVoteFragBinding.castVotePager;
CastVoteViewPagerAdapter adapter = new CastVoteViewPagerAdapter(mLaoDetailViewModel, mCastVoteFragBinding);
viewPager2.setAdapter(adapter);
viewPager2.setPageTransformer(new ZoomOutTransformer());
// Setting the indicator for horizontal swipe
CircleIndicator3 circleIndicator = mCastVoteFragBinding.swipeIndicator;
circleIndicator.setViewPager(viewPager2);
voteButton.setOnClickListener(buttonListener);
return mCastVoteFragBinding.getRoot();
}
Aggregations