Search in sources :

Example 1 with Event

use of com.github.dedis.popstellar.model.objects.event.Event in project popstellar by dedis.

the class EventExpandableListViewAdapter method getChildView.

/**
 * Gets a View that displays the data for the given child within the given group.
 *
 * @param groupPosition the position of the group that contains the child
 * @param childPosition the position of the child (for which the View is returned) within the
 *     group
 * @param isLastChild Whether the child is the last child within the group
 * @param convertView the old view to reuse, if possible. You should check that this view is
 *     non-null and of an appropriate type before using. If it is not possible to convert this
 *     view to display the correct data, this method can create a new view. It is not guaranteed
 *     that the convertView will have been previously created by {@link #getChildView(int, int,
 *     boolean, View, ViewGroup)}.
 * @param parent the parent that this view will eventually be attached to
 * @return the View corresponding to the child at the specified position
 */
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    Event event = ((Event) getChild(groupPosition, childPosition));
    EventLayoutBinding layoutEventBinding;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        layoutEventBinding = EventLayoutBinding.inflate(inflater, parent, false);
    } else {
        layoutEventBinding = DataBindingUtil.getBinding(convertView);
    }
    layoutEventBinding.setEvent(event);
    EventCategory category = (EventCategory) getGroup(groupPosition);
    switch(event.getType()) {
        case ELECTION:
            return setupElectionElement((Election) event, category, layoutEventBinding);
        case ROLL_CALL:
            return setupRollCallElement((RollCall) event, layoutEventBinding);
        default:
            layoutEventBinding.setLifecycleOwner(lifecycleOwner);
            layoutEventBinding.executePendingBindings();
            return layoutEventBinding.getRoot();
    }
}
Also used : EventCategory(com.github.dedis.popstellar.model.objects.event.EventCategory) LayoutInflater(android.view.LayoutInflater) Event(com.github.dedis.popstellar.model.objects.event.Event) EventLayoutBinding(com.github.dedis.popstellar.databinding.EventLayoutBinding) RollCallEventLayoutBinding(com.github.dedis.popstellar.databinding.RollCallEventLayoutBinding)

Example 2 with Event

use of com.github.dedis.popstellar.model.objects.event.Event in project popstellar by dedis.

the class LaoDetailFragment method setupEventListUpdates.

private void setupEventListUpdates() {
    mLaoDetailViewModel.getLaoEvents().observe(requireActivity(), events -> {
        Log.d(TAG, "Got an event list update");
        for (Event event : events) {
            if (event.getType() == EventType.ROLL_CALL) {
                Log.d(TAG, ((RollCall) event).getDescription());
            }
        }
        mEventListViewEventAdapter.replaceList(events);
    });
}
Also used : Event(com.github.dedis.popstellar.model.objects.event.Event)

Example 3 with Event

use of com.github.dedis.popstellar.model.objects.event.Event in project popstellar by dedis.

the class EventExpandableListViewAdapter method getGroupView.

/**
 * Gets a View that displays the given group. This View is only for the group--the Views for the
 * group's children will be fetched using {@link #getChildView(int, int, boolean, View,
 * ViewGroup)}.
 *
 * @param groupPosition the position of the group for which the View is returned
 * @param isExpanded whether the group is expanded or collapsed
 * @param convertView the old view to reuse, if possible. You should check that this view is
 *     non-null and of an appropriate type before using. If it is not possible to convert this
 *     view to display the correct data, this method can create a new view. It is not guaranteed
 *     that the convertView will have been previously created by {@link #getGroupView(int,
 *     boolean, View, ViewGroup)}.
 * @param parent the parent that this view will eventually be attached to
 * @return the View corresponding to the group at the specified position
 */
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    EventCategory eventCategory = (EventCategory) getGroup(groupPosition);
    EventCategoryLayoutBinding binding;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        binding = EventCategoryLayoutBinding.inflate(inflater, parent, false);
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }
    binding.setCategoryName(eventCategory.name());
    Context context = parent.getContext();
    AddEventListener addEventOnClickListener = () -> {
        Builder builder = new Builder(context);
        builder.setTitle("Select Event Type");
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, android.R.layout.select_dialog_singlechoice);
        arrayAdapter.add("Roll-Call Event");
        arrayAdapter.add("Election Event");
        builder.setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
        builder.setAdapter(arrayAdapter, ((dialog, which) -> {
            dialog.dismiss();
            viewModel.chooseEventType(EventType.values()[which]);
        }));
        builder.show();
    };
    binding.setIsFutureCategory(eventCategory.equals(FUTURE));
    binding.setViewmodel(viewModel);
    binding.setLifecycleOwner(lifecycleOwner);
    binding.setAddEventListener(addEventOnClickListener);
    binding.executePendingBindings();
    binding.addFutureEventButton.setFocusable(false);
    return binding.getRoot();
}
Also used : Context(android.content.Context) Builder(android.app.AlertDialog.Builder) Context(android.content.Context) R(com.github.dedis.popstellar.R) EventType(com.github.dedis.popstellar.model.objects.event.EventType) EventState(com.github.dedis.popstellar.model.objects.event.EventState) Date(java.util.Date) EventCategory(com.github.dedis.popstellar.model.objects.event.EventCategory) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter) CLOSED(com.github.dedis.popstellar.model.objects.event.EventState.CLOSED) ArrayList(java.util.ArrayList) FUTURE(com.github.dedis.popstellar.model.objects.event.EventCategory.FUTURE) LifecycleOwner(androidx.lifecycle.LifecycleOwner) Locale(java.util.Locale) View(android.view.View) DataBindingUtil(androidx.databinding.DataBindingUtil) Election(com.github.dedis.popstellar.model.objects.Election) LayoutInflater(android.view.LayoutInflater) Event(com.github.dedis.popstellar.model.objects.event.Event) EventLayoutBinding(com.github.dedis.popstellar.databinding.EventLayoutBinding) EventCategoryLayoutBinding(com.github.dedis.popstellar.databinding.EventCategoryLayoutBinding) Instant(java.time.Instant) ViewGroup(android.view.ViewGroup) ArrayAdapter(android.widget.ArrayAdapter) LaoDetailViewModel(com.github.dedis.popstellar.ui.detail.LaoDetailViewModel) List(java.util.List) RESULTS_READY(com.github.dedis.popstellar.model.objects.event.EventState.RESULTS_READY) ElectionDisplayLayoutBinding(com.github.dedis.popstellar.databinding.ElectionDisplayLayoutBinding) RollCall(com.github.dedis.popstellar.model.objects.RollCall) RollCallEventLayoutBinding(com.github.dedis.popstellar.databinding.RollCallEventLayoutBinding) PRESENT(com.github.dedis.popstellar.model.objects.event.EventCategory.PRESENT) PAST(com.github.dedis.popstellar.model.objects.event.EventCategory.PAST) Collections(java.util.Collections) EventCategory(com.github.dedis.popstellar.model.objects.event.EventCategory) EventCategoryLayoutBinding(com.github.dedis.popstellar.databinding.EventCategoryLayoutBinding) LayoutInflater(android.view.LayoutInflater) Builder(android.app.AlertDialog.Builder) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with Event

use of com.github.dedis.popstellar.model.objects.event.Event in project popstellar by dedis.

the class EventExpandableListViewAdapter method putEventsInMap.

/**
 * A helper method that places the events in the correct key-value pair according to their times
 *
 * @param events
 */
private void putEventsInMap(List<Event> events) {
    Collections.sort(events);
    this.eventsMap.get(PAST).clear();
    this.eventsMap.get(FUTURE).clear();
    this.eventsMap.get(PRESENT).clear();
    long now = Instant.now().getEpochSecond();
    for (Event event : events) {
        if (event.getEndTimestamp() <= now) {
            eventsMap.get(PAST).add(event);
        } else if (event.getStartTimestamp() > now) {
            eventsMap.get(FUTURE).add(event);
        } else {
            eventsMap.get(PRESENT).add(event);
        }
    }
}
Also used : Event(com.github.dedis.popstellar.model.objects.event.Event)

Aggregations

Event (com.github.dedis.popstellar.model.objects.event.Event)4 LayoutInflater (android.view.LayoutInflater)2 EventLayoutBinding (com.github.dedis.popstellar.databinding.EventLayoutBinding)2 RollCallEventLayoutBinding (com.github.dedis.popstellar.databinding.RollCallEventLayoutBinding)2 EventCategory (com.github.dedis.popstellar.model.objects.event.EventCategory)2 Builder (android.app.AlertDialog.Builder)1 Context (android.content.Context)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1 BaseExpandableListAdapter (android.widget.BaseExpandableListAdapter)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 LifecycleOwner (androidx.lifecycle.LifecycleOwner)1 R (com.github.dedis.popstellar.R)1 ElectionDisplayLayoutBinding (com.github.dedis.popstellar.databinding.ElectionDisplayLayoutBinding)1 EventCategoryLayoutBinding (com.github.dedis.popstellar.databinding.EventCategoryLayoutBinding)1 Election (com.github.dedis.popstellar.model.objects.Election)1 RollCall (com.github.dedis.popstellar.model.objects.RollCall)1 FUTURE (com.github.dedis.popstellar.model.objects.event.EventCategory.FUTURE)1 PAST (com.github.dedis.popstellar.model.objects.event.EventCategory.PAST)1