public int compare(Event event1, Event event2) { Date d1 = event1.getStartDate(); Date d2 = event2.getStartDate(); if (d1.after(d2)) { return 1; } else if (d1.before(d2)) { return -1; } return 0; }
/** * Creates the event. * * @param event the event * @param category_ids the category_ids * @return the long */ public long createEvent(Event event, long[] category_ids) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_EVENT_TITLE, event.getTitle()); values.put(KEY_EVENT_STARTDATE, event.getStartDate()); values.put(KEY_EVENT_ENDDATE, event.getEndDate()); values.put(KEY_EVENT_STARTTIME, event.getStartTime()); values.put(KEY_EVENT_ENDTIME, event.getEndTime()); values.put(KEY_EVENT_DESCRIPTION, event.getDescription()); values.put(KEY_EVENT_REPEAT, event.getRepeat()); // insert row long event_id = db.insert(TABLE_EVENT, null, values); // assigning categories to events for (long category_id : category_ids) { createEventCategory(event_id, category_id); } // for logging // Log.e("createEvent", event.toString()); // db.close(); return event_id; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.post, parent, false); mViewHolder = new ViewHolder(); mViewHolder.thumbnail = (ImageView) convertView.findViewById(R.id.post_thumbnail); mViewHolder.author = (TextView) convertView.findViewById(R.id.post_author); mViewHolder.title = (TextView) convertView.findViewById(R.id.post_title); mViewHolder.date = (TextView) convertView.findViewById(R.id.post_date); convertView.setTag(mViewHolder); } else { mViewHolder = (ViewHolder) convertView.getTag(); } mPost = mPosts.get(position); /*if (mPost.getThumbnail() != null) { */ /*new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { URL url = new URL(mPost.getThumbnail()); mBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream()); } catch (MalformedURLException e) { } catch (IOException e) { } return null; } }.execute();*/ /* mViewHolder.thumbnail.setImageBitmap(mBitmap); } Picasso.with(mActivity) .load(mPost.getThumbnail()) .into(mViewHolder.thumbnail); */ mViewHolder.date.setText(mPost.getStartDate() + " to " + mPost.getEndDate()); mViewHolder.title.setText(mPost.getNameTitle() + ""); mViewHolder.author.setText(mPost.getDescription()); // mViewHolder.date.setText(mPost.getStartDateString()); return convertView; }
/** * Update event. * * @param event the event * @return the int */ public int updateEvent(Event event) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_EVENT_TITLE, event.getTitle()); values.put(KEY_EVENT_STARTDATE, event.getStartDate()); values.put(KEY_EVENT_ENDDATE, event.getEndDate()); values.put(KEY_EVENT_STARTTIME, event.getStartTime()); values.put(KEY_EVENT_ENDTIME, event.getEndTime()); values.put(KEY_EVENT_DESCRIPTION, event.getDescription()); values.put(KEY_EVENT_REPEAT, event.getRepeat()); // updating row return db.update( TABLE_EVENT, values, KEY_ID + " = ?", new String[] {String.valueOf(event.getId())}); }
/** * Check conflictin update events. * * @param newEvent the new event * @return true, if successful * @throws ParseException the parse exception */ @SuppressLint("LongLogTag") public boolean checkConflictinUpdateEvents(Event newEvent) throws ParseException { SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm"); String sTime = newEvent.getStartTime(); String sDate = newEvent.getStartDate(); String eTime = newEvent.getEndTime(); String eDate = newEvent.getEndDate(); Date parsedStartTime = timeFormat.parse(sTime); Timestamp newStartTime = new Timestamp(parsedStartTime.getTime()); Date parsedEndTime = timeFormat.parse(eTime); Timestamp newEndTime = new Timestamp(parsedEndTime.getTime()); if (sDate.equalsIgnoreCase(eDate)) { if (newStartTime.after(newEndTime)) { Log.e("Illogiacl Update", "StartTime is greater then EndTime"); return false; } } List<Event> allEvents = getEvent(sDate, eDate); for (Event prevEvent : allEvents) { Log.d( "Event: " + prevEvent.getTitle(), "" + prevEvent.getId() + " " + prevEvent.getDescription()); Date parsedPreviousStartTime = timeFormat.parse(prevEvent.getStartTime()); Timestamp previousStartTime = new Timestamp(parsedPreviousStartTime.getTime()); Date parsedPreviousEndTime = timeFormat.parse(prevEvent.getEndTime()); Timestamp previousEndTime = new Timestamp(parsedPreviousEndTime.getTime()); if (newStartTime.after(previousStartTime) && newStartTime.before(previousEndTime) || newEndTime.after(previousStartTime) && newEndTime.before(previousEndTime) || previousStartTime.after(newStartTime) && previousStartTime.before(newEndTime) || previousEndTime.after(newStartTime) && previousEndTime.before(newEndTime)) { if (newEvent.getId() != prevEvent.getId()) { Log.e("Conflict with existent event", "Can't update this event"); return false; } } } return true; }
public EventListByDateAdapter(Context c, String startDate, String endDate) { eContext = c; this.startDate = startDate; this.endDate = endDate; // this.ctg = ctg; // db = new MySQLiteHelper(eContext); // Getting all Events Log.d("Get Events", "Getting All Events"); dayEvents = new ArrayList<Event>(); try { stDate = dateFormat.parse(startDate); eDate = dateFormat.parse(endDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Getting all Events Log.d("Get Events", "Getting All Events"); allEvents = SimpleCalendarView.db.getAllEvents(); for (Event event : allEvents) { Date eventStartDate = new Date(); // Date eventEndDate = new Date(); try { eventStartDate = dateFormat.parse(event.getStartDate()); // eventEndDate = dateFormat.parse(event.getEndDate()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (((eventStartDate.compareTo(stDate) >= 0) && (eventStartDate.compareTo(eDate) <= 0))) { dayEvents.add(event); Log.d( "Event:" + event.getTitle(), "ID:" + event.getId() + "Description:" + event.getDescription()); } } }