@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View layout = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_dialog_edit, null, false); if (event != null) { initViews(layout); } builder .setTitle( event == null ? getString(R.string.dialog_event_change_title) : event.getSubjects().getTitle()) .setCancelable(false) .setView(layout) .setPositiveButton( R.string.dialog_event_change_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { event.setType(typeEdit.getText().toString()); event.setLecturer(lecturerEdit.getText().toString()); event.setRoom(roomEdit.getText().toString()); try { Calendar date = Calendar.getInstance(); date.setTime(dateFormat.parse(dateEdit.getText().toString())); int month = date.get(Calendar.MONTH); int day = date.get(Calendar.DAY_OF_MONTH); int year = date.get(Calendar.YEAR); Calendar start = Calendar.getInstance(); start.setTime(timeFormat.parse(startEdit.getText().toString())); start.set(year, month, day); Calendar end = Calendar.getInstance(); end.setTime(timeFormat.parse(endEdit.getText().toString())); end.set(year, month, day); event.setStart(start.getTime()); event.setEnd(end.getTime()); } catch (Exception e) { Log.e(getClass().getSimpleName(), e.toString()); } finally { ((TimetableApplication) getActivity().getApplication()).updateEvent(event); if (getActivity() instanceof TimetableActivity) { ((TimetableActivity) getActivity()).updateList(); } dialog.dismiss(); } } }) .setNegativeButton( R.string.dialog_event_change_discard, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alertDialog = builder.create(); return alertDialog; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; int type = getItemViewType(position); if (convertView == null) { holder = new ViewHolder(); switch (type) { case TYPE_ITEM: convertView = mInflater.inflate(R.layout.fragment_subject_item, null); holder.titleView = (TextView) convertView.findViewById(R.id.text_subject_item_title); holder.dateView = (TextView) convertView.findViewById(R.id.text_subject_item_time); holder.roomView = (TextView) convertView.findViewById(R.id.text_subject_item_room); if (position % 2 == 0) { convertView.setBackgroundColor( context.getResources().getColor(R.color.abs__background_holo_dark)); } else { convertView.setBackgroundColor( context.getResources().getColor(R.color.abs__background_holo_light)); } break; case TYPE_SEPARATOR: convertView = mInflater.inflate(R.layout.fragment_subject_separator, null); holder.separatorView = (TextView) convertView.findViewById(R.id.text_subject_separator); break; } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (type == TYPE_ITEM) { final Events item = mData.get(position); if (item != null) { if (selection == item.getId()) { convertView.setBackgroundResource(R.drawable.abs__list_activated_holo); int padding = context.getResources().getDimensionPixelSize(R.dimen.default_list_padding); convertView.setPadding(padding, padding, padding, padding); } else { convertView.setBackgroundResource(android.R.color.transparent); } try { holder.titleView.setText(item.getSubjects().getTitle()); } catch (Exception e) { Log.e(TAG, item.getSubjectId() + " " + item.getSubjects()); HashMap<String, String> extraData = new HashMap<String, String>(); extraData.put("subjectsid", String.valueOf(item.getSubjectId())); extraData.put("subjects", String.valueOf(item.getSubjects())); BugSenseHandler.sendExceptionMap(extraData, e); } holder.roomView.setText(item.getRoom()); holder.dateView.setText(df.format(item.getStart()) + " - " + df.format(item.getEnd())); } } else { try { Calendar nextSeperatorDate = Calendar.getInstance(); nextSeperatorDate.setTime(fullDateFormat.parse(getSeperatorItem(position))); long dateDiff = daysDiff(Calendar.getInstance(), nextSeperatorDate); if (dateDiff == 0) { holder.separatorView.setText(context.getString(R.string.text_today)); } else if (dateDiff == 1) { holder.separatorView.setText(context.getString(R.string.text_tomorrow)); } else if (dateDiff == -1) { holder.separatorView.setText(context.getString(R.string.text_yesterday)); } else if (dateDiff == -2) { holder.separatorView.setText(context.getString(R.string.text_twoago)); } else { holder.separatorView.setText(getSeperatorItem(position)); } } catch (Exception e) { holder.separatorView.setText(getSeperatorItem(position)); BugSenseHandler.sendException(e); } } return convertView; }