Search in sources :

Example 1 with EventWeekTab

use of com.thebluealliance.androidclient.models.EventWeekTab in project the-blue-alliance-android by the-blue-alliance.

the class EventTabSubscriberTest method testParsedData.

@Test
public void testParsedData() {
    int[] weeks = { 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 15, 21, 25, 28, 32, 37 };
    int[] sizes = { 2, 16, 13, 18, 20, 21, 18, 3, 9, 7, 10, 4, 2, 8, 13, 5 };
    String[] labels = { "Preseason Events", "Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6", "Week 7", "Championship Event", "May Offseason Events", "Jun Offseason Events", "Jul Offseason Events", "Aug Offseason Events", "Sep Offseason Events", "Oct Offseason Events", "Nov Offseason Events" };
    List<EventWeekTab> tabs = DatafeedTestDriver.getParsedData(mSubscriber, mEvents);
    assertEquals(tabs.size(), 16);
    for (int i = 0; i < tabs.size(); i++) {
        EventWeekTab tab = tabs.get(i);
        assertEquals(String.format("Tab %1$d week fail", i), weeks[i], tab.getWeek());
        assertEquals(String.format("Tab %1$d count fail", i), sizes[i], tab.getEventKeys().size());
        assertEquals(String.format("Tab %1$d label fail", i), labels[i], tab.getLabel());
    }
}
Also used : EventWeekTab(com.thebluealliance.androidclient.models.EventWeekTab) Test(org.junit.Test)

Example 2 with EventWeekTab

use of com.thebluealliance.androidclient.models.EventWeekTab in project the-blue-alliance-android by the-blue-alliance.

the class EventsByWeekFragment method getIndexForWeek.

/**
 * Finds the index in the adapter of the given week.
 * If the week is skipped over, return the next week (assumes sorted adapter items)
 *
 * @return Adapter index containing the week, -1 if not found
 */
private int getIndexForWeek(int week) {
    Preconditions.checkState(mViewPager.getAdapter() instanceof EventsByWeekFragmentPagerAdapter, "EventsByWeekFragment must use EventsByWeekFragmentPagerAdapter");
    List<EventWeekTab> tabs = ((EventsByWeekFragmentPagerAdapter) mViewPager.getAdapter()).getTabs();
    for (int i = 0; i < tabs.size(); i++) {
        if (tabs.get(i).getWeek() >= week) {
            return i;
        }
    }
    return -1;
}
Also used : EventsByWeekFragmentPagerAdapter(com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter) EventWeekTab(com.thebluealliance.androidclient.models.EventWeekTab) AndroidEntryPoint(dagger.hilt.android.AndroidEntryPoint)

Example 3 with EventWeekTab

use of com.thebluealliance.androidclient.models.EventWeekTab in project the-blue-alliance-android by the-blue-alliance.

the class EventTabSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    Collections.sort(mAPIData, mEventComparator);
    LinkedHashMap<String, EventWeekTab> eventTabs = new LinkedHashMap<>();
    for (Event event : mAPIData) {
        int eventWeek = event.getWeek() != null ? event.getWeek() : -1;
        String label = EventHelper.generateLabelForEvent(event);
        if (!eventTabs.containsKey(label)) {
            eventTabs.put(label, new EventWeekTab(label, eventWeek));
        }
        EventWeekTab tab = eventTabs.get(label);
        if (tab == null) {
            throw new RuntimeException("Expected to find event tab, but can't!");
        }
        tab.addEventKey(event.getKey());
    }
    for (Map.Entry<String, EventWeekTab> tab : eventTabs.entrySet()) {
        mDataToBind.add(tab.getValue());
    }
}
Also used : EventWeekTab(com.thebluealliance.androidclient.models.EventWeekTab) Event(com.thebluealliance.androidclient.models.Event) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

EventWeekTab (com.thebluealliance.androidclient.models.EventWeekTab)3 EventsByWeekFragmentPagerAdapter (com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter)1 Event (com.thebluealliance.androidclient.models.Event)1 AndroidEntryPoint (dagger.hilt.android.AndroidEntryPoint)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1