Search in sources :

Example 1 with MessageData

use of com.google.samples.apps.iosched.messages.MessageData in project iosched by google.

the class MyIOAdapter method setItems.

void setItems(List<ScheduleItem> items) {
    List<Object> newData = new ArrayList<>();
    MessageData notSignedInCard = MessageCardHelper.notSignedInCard();
    notSignedInCard.setStartButtonClickListener(new OnClickListener() {

        @Override
        public void onClick(final View view) {
            WelcomeUtils.markHidePostOnboardingCard(mContext);
        }
    });
    notSignedInCard.setEndButtonClickListener(new OnClickListener() {

        @Override
        public void onClick(final View view) {
            WelcomeUtils.markHidePostOnboardingCard(mContext);
            ((MyIOActivity) mContext).signIn();
        }
    });
    MessageData signedInMessageCard = MessageCardHelper.signedInMessageCard();
    signedInMessageCard.setStartButtonClickListener(new OnClickListener() {

        @Override
        public void onClick(final View view) {
            WelcomeUtils.markHidePostOnboardingCard(mContext);
        }
    });
    if (WelcomeUtils.showPostOnboardingCard(mContext)) {
        if (AccountUtils.hasActiveAccount(mContext)) {
            newData.add(signedInMessageCard);
        } else {
            newData.add(notSignedInCard);
        }
    }
    int day = 0;
    if (items != null && !items.isEmpty()) {
        // Add the items to our list, interleaving separators as we go
        long separatorTime = DAY_SEPARATORS.get(day).mStartTime;
        for (ScheduleItem item : items) {
            if (item.startTime >= separatorTime) {
                // add the separator first
                newData.add(new SeparatorSpacer());
                newData.add(DAY_SEPARATORS.get(day));
                day++;
                if (day >= DAY_SEPARATORS.size()) {
                    // run the list to the end
                    separatorTime = Long.MAX_VALUE;
                } else {
                    separatorTime = DAY_SEPARATORS.get(day).mStartTime;
                }
            }
            // Add the item
            newData.add(item);
        }
    }
    // Add any remaining separators
    for (; day < DAY_SEPARATORS.size(); day++) {
        newData.add(new SeparatorSpacer());
        newData.add(DAY_SEPARATORS.get(day));
    }
    DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new MyIoDiff(mItems, newData));
    mItems.clear();
    mItems.addAll(newData);
    diff.dispatchUpdatesTo(this);
}
Also used : ScheduleItem(com.google.samples.apps.iosched.model.ScheduleItem) MessageData(com.google.samples.apps.iosched.messages.MessageData) ArrayList(java.util.ArrayList) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DiffUtil(android.support.v7.util.DiffUtil) OnClickListener(android.view.View.OnClickListener)

Aggregations

DiffUtil (android.support.v7.util.DiffUtil)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 TextView (android.widget.TextView)1 MessageData (com.google.samples.apps.iosched.messages.MessageData)1 ScheduleItem (com.google.samples.apps.iosched.model.ScheduleItem)1 ArrayList (java.util.ArrayList)1