Search in sources :

Example 1 with ZoomOutTransformer

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();
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) CircleIndicator3(me.relex.circleindicator.CircleIndicator3) Button(android.widget.Button) ZoomOutTransformer(com.github.dedis.popstellar.ui.detail.event.election.ZoomOutTransformer) TextView(android.widget.TextView) ElectionSetupViewPagerAdapter(com.github.dedis.popstellar.ui.detail.event.election.adapters.ElectionSetupViewPagerAdapter) Nullable(androidx.annotation.Nullable)

Example 2 with ZoomOutTransformer

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();
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) CircleIndicator3(me.relex.circleindicator.CircleIndicator3) CastVoteViewPagerAdapter(com.github.dedis.popstellar.ui.detail.event.election.adapters.CastVoteViewPagerAdapter) ZoomOutTransformer(com.github.dedis.popstellar.ui.detail.event.election.ZoomOutTransformer) CastVoteFragmentBinding(com.github.dedis.popstellar.databinding.CastVoteFragmentBinding) TextView(android.widget.TextView) Election(com.github.dedis.popstellar.model.objects.Election) AndroidEntryPoint(dagger.hilt.android.AndroidEntryPoint)

Aggregations

TextView (android.widget.TextView)2 ViewPager2 (androidx.viewpager2.widget.ViewPager2)2 ZoomOutTransformer (com.github.dedis.popstellar.ui.detail.event.election.ZoomOutTransformer)2 CircleIndicator3 (me.relex.circleindicator.CircleIndicator3)2 Button (android.widget.Button)1 Nullable (androidx.annotation.Nullable)1 CastVoteFragmentBinding (com.github.dedis.popstellar.databinding.CastVoteFragmentBinding)1 Election (com.github.dedis.popstellar.model.objects.Election)1 CastVoteViewPagerAdapter (com.github.dedis.popstellar.ui.detail.event.election.adapters.CastVoteViewPagerAdapter)1 ElectionSetupViewPagerAdapter (com.github.dedis.popstellar.ui.detail.event.election.adapters.ElectionSetupViewPagerAdapter)1 AndroidEntryPoint (dagger.hilt.android.AndroidEntryPoint)1