Search in sources :

Example 6 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class CompactCalendarHelper method getDayEventWithMultipleEventsPerDay.

public static List<Events> getDayEventWithMultipleEventsPerDay(int start, int days, long timeStamp) {
    Calendar currentCalender = Calendar.getInstance(Locale.getDefault());
    List<Events> events = new ArrayList<>();
    for (int i = start; i < days; i++) {
        setDateTime(timeStamp, currentCalender, i);
        List<Event> eventsList = Arrays.asList(new Event(Color.BLUE, currentCalender.getTimeInMillis()), new Event(Color.RED, currentCalender.getTimeInMillis() + 3600 * 1000), new Event(Color.RED, currentCalender.getTimeInMillis() + (3600 * 2) * 1000), new Event(Color.RED, currentCalender.getTimeInMillis() + (3600 * 3) * 1000));
        Events eventsObject = new Events(currentCalender.getTimeInMillis(), eventsList);
        events.add(eventsObject);
    }
    return events;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Event(com.github.sundeepk.compactcalendarview.domain.Event)

Example 7 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItRemovesEvents.

@Test
public void testItRemovesEvents() {
    //Sun, 01 Feb 2015 00:00:00 GMT
    List<Event> events = getSingleEvents(0, 30, 1422748800000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    underTest.removeEvent(events.get(0));
    underTest.removeEvent(events.get(1));
    underTest.removeEvent(events.get(5));
    underTest.removeEvent(events.get(20));
    List<Event> expectedEvents = getSingleEvents(0, 28, 1422748800000L);
    expectedEvents.remove(events.get(0));
    expectedEvents.remove(events.get(1));
    expectedEvents.remove(events.get(5));
    expectedEvents.remove(events.get(20));
    for (Event e : expectedEvents) {
        List<Event> actualEvents = underTest.getEventsFor(e.getTimeInMillis());
        Assert.assertEquals(1, actualEvents.size());
        Assert.assertEquals(e, actualEvents.get(0));
    }
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 8 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItAddsAndGetsEvents.

@Test
public void testItAddsAndGetsEvents() {
    //Sun, 01 Feb 2015 00:00:00 GMT
    List<Event> events = getSingleEvents(0, 30, 1422748800000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    events = getSingleEvents(0, 28, 1422748800000L);
    List<Event> actualEvents = underTest.getEventsFor(1422748800000L);
    Assert.assertEquals(events.get(0), actualEvents.get(0));
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 9 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItGetsEventsForMonth.

@Test
public void testItGetsEventsForMonth() {
    //Sun, 07 Jun 2015 18:20:51 GMT
    //get 30 events in total
    List<Event> events = getSingleEvents(0, 30, 1433701251000L);
    //Wed, 06 Jul 2016 13:37:32 GMT
    List<Event> events2 = getSingleEvents(0, 30, 1467812256000L);
    //give a random ordering to elements
    Collections.shuffle(events, new Random());
    Collections.shuffle(events2, new Random());
    for (Event event : events) {
        underTest.addEvent(event);
    }
    for (Event event : events2) {
        underTest.addEvent(event);
    }
    //Sun, 07 Jun 2015 18:20:51 GMT
    List<Event> calendarDayEvents = underTest.getEventsForMonth(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    assertNotNull(calendarDayEvents);
    //Assert 6th item since it will represent Sun, 07 Jun 2015 which is the day that we queried for
    //Check that events are sorted as expected
    assertEquals(getSingleEvents(0, 30, 1433701251000L), calendarDayEvents);
}
Also used : Random(java.util.Random) Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 10 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItUpdatesEvents.

@Test
public void testItUpdatesEvents() {
    //Sun, 07 Jun 2015 18:20:51 GMT
    //get 30 events in total
    List<Event> events = getSingleEvents(0, 30, 1433701251000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    //Sun, 07 Jun 2015 18:20:51 GMT
    List<Event> calendarDayEvents = underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    assertNotNull(calendarDayEvents);
    //Assert 6th item since it will represent Sun, 07 Jun 2015 which is the day that we queried for
    assertEquals(events.get(6), calendarDayEvents.get(0));
    //Add a random event Sun, 07 Jun 2015 21:24:21 GMT
    Event updateItem = new Event(Color.GREEN, 1433712261000L);
    calendarDayEvents.add(updateItem);
    //Query again Sun, 07 Jun 2015 18:20:51 GMT to make sure list is updated
    List<Event> calendarDayEvents2 = underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    assertTrue(calendarDayEvents2.contains(updateItem));
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Aggregations

Event (com.github.sundeepk.compactcalendarview.domain.Event)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 MotionEvent (android.view.MotionEvent)5 Calendar (java.util.Calendar)5 Date (java.util.Date)3 List (java.util.List)3 Paint (android.graphics.Paint)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 CompactCalendarHelper.getMultipleEventsForEachDayAsMap (com.github.sundeepk.compactcalendarview.CompactCalendarHelper.getMultipleEventsForEachDayAsMap)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Random (java.util.Random)1 TimeZone (java.util.TimeZone)1