use of com.google.samples.apps.iosched.model.ScheduleItem in project iosched by google.
the class OutputMockData method generateScheduleItemCode.
/**
* This generates code, as a String, to create an {@link ArrayList} of {@link ScheduleItem}s
* with the same data as {@code items}. This can be used to easily create schedule items with
* mock data in integration tests (in mockdata package), by logging the output of this method in
* {@link com.google.samples.apps.iosched.myschedule.MyScheduleModel
* .LoadScheduleDataListener#onDataLoaded(ArrayList)}
* and copying the logged string into a method that returns a {@link ArrayList<ScheduleItem>} in
* a class in {@link com.google.samples.apps.iosched.mockdata}.
*/
public static String generateScheduleItemCode(ArrayList<ScheduleItem> items) {
String output = "";
output += "ArrayList<ScheduleItem> newItems = new ArrayList<ScheduleItem>()";
output += NEWLINE;
for (int i = 0; i < items.size(); i++) {
ScheduleItem item = items.get(i);
String newItem = "newItem" + i;
output += "ScheduleItem " + newItem + " = new ScheduleItem()";
output += NEWLINE;
output += newItem + ".type = " + item.type;
output += NEWLINE;
output += newItem + ".sessionType = " + item.sessionType;
output += NEWLINE;
if (!TextUtils.isEmpty(item.mainTag)) {
output += newItem + ".mainTag = " + QUOTE + item.mainTag + QUOTE;
output += NEWLINE;
}
output += newItem + ".startTime = " + item.startTime + LONG;
output += NEWLINE;
output += newItem + ".endTime = " + item.endTime + LONG;
output += NEWLINE;
if (item.numOfSessions != 0) {
output += newItem + ".numOfSessions = " + item.numOfSessions;
output += NEWLINE;
}
if (!TextUtils.isEmpty(item.sessionId)) {
output += newItem + ".sessionId = " + QUOTE + item.sessionId + QUOTE;
output += NEWLINE;
}
output += newItem + ".title = " + QUOTE + item.title + QUOTE;
output += NEWLINE;
output += newItem + ".subtitle = " + QUOTE + item.subtitle + QUOTE;
output += NEWLINE;
output += newItem + ".room = " + QUOTE + item.room + QUOTE;
output += NEWLINE;
output += newItem + ".hasGivenFeedback = " + item.hasGivenFeedback;
output += NEWLINE;
if (!TextUtils.isEmpty(item.backgroundImageUrl)) {
output += newItem + ".backgroundImageUrl = " + QUOTE + item.backgroundImageUrl + QUOTE;
output += NEWLINE;
}
if (item.backgroundColor != 0) {
output += newItem + ".backgroundColor = " + item.backgroundColor;
output += NEWLINE;
}
if (item.flags != 0) {
output += newItem + ".flags = " + item.flags;
output += NEWLINE;
}
output += "newItems.add(" + newItem + ")";
output += NEWLINE;
}
output += "return newItems";
output += NEWLINE;
return output;
}
use of com.google.samples.apps.iosched.model.ScheduleItem in project iosched by google.
the class TestScheduleHelperAction method check.
private boolean check(String testDescription, ArrayList<ScheduleItem> actual, ScheduleItem[] expected) {
out.append("testing " + testDescription + "...");
boolean equal = true;
if (actual.size() != expected.length) {
equal = false;
} else {
int i = 0;
for (ScheduleItem item : actual) {
if (!item.title.equals(expected[i].title) || item.startTime != expected[i].startTime || item.endTime != expected[i].endTime || (item.flags & ScheduleItem.FLAG_CONFLICTS_WITH_PREVIOUS) != (expected[i].flags & ScheduleItem.FLAG_CONFLICTS_WITH_PREVIOUS)) {
equal = false;
break;
}
i++;
}
}
if (!equal) {
out.append("ERROR!:\n");
out.append(" expected\n");
for (ScheduleItem item : expected) {
out.append(" " + format(item) + "\n");
}
out.append(" actual\n");
for (ScheduleItem item : actual) {
out.append(" " + format(item) + "\n");
}
} else {
out.append("OK\n");
}
return equal;
}
use of com.google.samples.apps.iosched.model.ScheduleItem in project iosched by google.
the class MyScheduleDayAdapter method updateItems.
public void updateItems(List<ScheduleItem> items) {
mItems.clear();
if (items != null) {
for (ScheduleItem item : items) {
LOGD(TAG, "Adding schedule item: " + item + " start=" + new Date(item.startTime));
mItems.add((ScheduleItem) item.clone());
}
}
notifyObservers();
}
use of com.google.samples.apps.iosched.model.ScheduleItem in project iosched by google.
the class MyScheduleDayAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (mImageLoader == null) {
mImageLoader = new ImageLoader(mContext);
}
ViewHolder holder;
// Create a new view if it is not ready yet.
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.my_schedule_item, parent, false);
holder = new ViewHolder();
holder.startTime = (TextView) view.findViewById(R.id.start_time);
holder.more = (TextView) view.findViewById(R.id.more);
holder.icon = (ImageView) view.findViewById(R.id.icon);
holder.title = (TextView) view.findViewById(R.id.slot_title);
holder.description = (TextView) view.findViewById(R.id.slot_description);
holder.browse = (TextView) view.findViewById(R.id.browse_sessions);
holder.feedback = (Button) view.findViewById(R.id.give_feedback_button);
holder.separator = view.findViewById(R.id.separator);
holder.touchArea = view.findViewById(R.id.touch_area);
holder.live = view.findViewById(R.id.live_now_badge);
view.setTag(holder);
// Typeface
mLUtils.setMediumTypeface(holder.startTime);
mLUtils.setMediumTypeface(holder.browse);
mLUtils.setMediumTypeface(holder.title);
adjustForRtl(holder);
} else {
holder = (ViewHolder) view.getTag();
// Clear event listeners
clearClickable(view);
clearClickable(holder.startTime);
clearClickable(holder.touchArea);
//Make sure it doesn't retain conflict coloring
holder.description.setTextColor(mHourColorDefault);
}
if (position < 0 || position >= mItems.size()) {
LOGE(TAG, "Invalid view position passed to MyScheduleDayAdapter: " + position);
return view;
}
final ScheduleItem item = mItems.get(position);
ScheduleItem nextItem = position < mItems.size() - 1 ? mItems.get(position + 1) : null;
long now = TimeUtils.getCurrentTime(view.getContext());
boolean isNowPlaying = item.startTime <= now && now <= item.endTime && item.type == ScheduleItem.SESSION;
boolean isPastDuringConference = item.endTime <= now && now < Config.CONFERENCE_END_MILLIS;
if (isPastDuringConference) {
view.setBackgroundColor(mColorBackgroundPast);
holder.startTime.setTextColor(mHourColorPast);
holder.title.setTextColor(mTitleColorPast);
holder.description.setVisibility(View.GONE);
holder.icon.setColorFilter(mIconColorPast);
} else {
view.setBackgroundColor(mColorBackgroundDefault);
holder.startTime.setTextColor(mHourColorDefault);
holder.title.setTextColor(mTitleColorDefault);
holder.description.setVisibility(View.VISIBLE);
holder.icon.setColorFilter(mIconColorDefault);
}
holder.startTime.setText(TimeUtils.formatShortTime(mContext, new Date(item.startTime)));
// show or hide the "LIVE NOW" badge
holder.live.setVisibility(0 != (item.flags & ScheduleItem.FLAG_HAS_LIVESTREAM) && isNowPlaying ? View.VISIBLE : View.GONE);
holder.touchArea.setTag(R.id.myschedule_uri_tagkey, null);
if (item.type == ScheduleItem.FREE) {
holder.startTime.setVisibility(View.VISIBLE);
holder.more.setVisibility(View.GONE);
holder.icon.setImageResource(R.drawable.ic_browse);
holder.feedback.setVisibility(View.GONE);
holder.title.setVisibility(View.GONE);
holder.browse.setVisibility(View.VISIBLE);
setUriClickable(view, ScheduleContract.Sessions.buildUnscheduledSessionsInInterval(item.startTime, item.endTime));
holder.description.setVisibility(View.GONE);
} else if (item.type == ScheduleItem.BREAK) {
holder.startTime.setVisibility(View.VISIBLE);
holder.more.setVisibility(View.GONE);
holder.feedback.setVisibility(View.GONE);
holder.title.setVisibility(View.VISIBLE);
holder.title.setText(item.title);
holder.icon.setImageResource(UIUtils.getBreakIcon(item.title));
holder.browse.setVisibility(View.GONE);
holder.description.setText(formatDescription(item));
} else if (item.type == ScheduleItem.SESSION) {
if (holder.feedback != null) {
boolean showFeedbackButton = !item.hasGivenFeedback;
// conference too.
if (showFeedbackButton) {
if (item.endTime > now) {
// Session hasn't finished yet, don't show button.
showFeedbackButton = false;
}
}
holder.feedback.setVisibility(showFeedbackButton ? View.VISIBLE : View.GONE);
holder.feedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(MyScheduleModel.SESSION_ID_KEY, item.sessionId);
bundle.putString(MyScheduleModel.SESSION_TITLE_KEY, item.title);
mListener.onUserAction(MyScheduleUserActionEnum.FEEDBACK, bundle);
Intent feedbackIntent = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(item.sessionId), mContext, SessionFeedbackActivity.class);
mContext.startActivity(feedbackIntent);
}
});
}
holder.title.setVisibility(View.VISIBLE);
holder.title.setText(item.title);
holder.more.setVisibility(item.isKeynote() ? View.GONE : View.VISIBLE);
holder.browse.setVisibility(View.GONE);
holder.icon.setImageResource(UIUtils.getSessionIcon(item.sessionType));
final Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(item.sessionId);
if (0 != (item.flags & ScheduleItem.FLAG_CONFLICTS_WITH_PREVIOUS)) {
holder.startTime.setVisibility(View.GONE);
holder.description.setTextColor(mColorConflict);
setUriClickable(holder.touchArea, sessionUri);
} else {
holder.startTime.setVisibility(View.VISIBLE);
setUriClickable(holder.startTime, ScheduleContract.Sessions.buildUnscheduledSessionsInInterval(item.startTime, item.endTime));
// Padding fix needed for KitKat (padding gets removed by setting the background)
holder.startTime.setPadding((int) mContext.getResources().getDimension(R.dimen.keyline_2), 0, (int) mContext.getResources().getDimension(R.dimen.keyline_2), 0);
setUriClickable(holder.touchArea, sessionUri);
if (0 != (item.flags & ScheduleItem.FLAG_CONFLICTS_WITH_NEXT)) {
holder.description.setTextColor(mColorConflict);
}
}
holder.description.setText(formatDescription(item));
} else {
LOGE(TAG, "Invalid item type in MyScheduleDayAdapter: " + item.type);
}
holder.separator.setVisibility(nextItem == null || 0 != (item.flags & ScheduleItem.FLAG_CONFLICTS_WITH_NEXT) ? View.GONE : View.VISIBLE);
if (position == 0) {
// First item
view.setPadding(0, mListSpacing, 0, 0);
} else if (nextItem == null) {
// Last item
view.setPadding(0, 0, 0, mListSpacing);
} else {
view.setPadding(0, 0, 0, 0);
}
return view;
}
Aggregations