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);
}
Aggregations