Search in sources :

Example 1 with EventLayoutBinding

use of com.github.dedis.popstellar.databinding.EventLayoutBinding 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)

Aggregations

LayoutInflater (android.view.LayoutInflater)1 EventLayoutBinding (com.github.dedis.popstellar.databinding.EventLayoutBinding)1 RollCallEventLayoutBinding (com.github.dedis.popstellar.databinding.RollCallEventLayoutBinding)1 Event (com.github.dedis.popstellar.model.objects.event.Event)1 EventCategory (com.github.dedis.popstellar.model.objects.event.EventCategory)1