Search in sources :

Example 21 with ListItem

use of com.thebluealliance.androidclient.listitems.ListItem in project the-blue-alliance-android by the-blue-alliance.

the class MyTbaModelRendererTest method testNullTeam.

@Test
public void testNullTeam() {
    when(mDatafeed.fetchTeam(TEAM_KEY)).thenReturn(Observable.just(null));
    ListItem item = mRenderer.renderFromKey(TEAM_KEY, ModelType.TEAM, null);
    assertNotNull(item);
    assertTrue(item instanceof ModelListElement);
    assertEquals(((ModelListElement) item).getText(), "frc1124");
    assertEquals(((ModelListElement) item).getKey(), TEAM_KEY);
    assertEquals(((ModelListElement) item).getType(), ModelType.TEAM);
}
Also used : ModelListElement(com.thebluealliance.androidclient.listitems.ModelListElement) ListItem(com.thebluealliance.androidclient.listitems.ListItem) Test(org.junit.Test)

Example 22 with ListItem

use of com.thebluealliance.androidclient.listitems.ListItem in project the-blue-alliance-android by the-blue-alliance.

the class MyTbaModelRendererTest method testNullEvent.

@Test
public void testNullEvent() {
    when(mDatafeed.fetchEvent(EVENT_KEY)).thenReturn(Observable.just(null));
    ListItem item = mRenderer.renderFromKey(EVENT_KEY, ModelType.EVENT, null);
    verifyZeroInteractions(mEventRenderer);
    assertNotNull(item);
    assertTrue(item instanceof ModelListElement);
    assertEquals(((ModelListElement) item).getText(), "2015cthar");
    assertEquals(((ModelListElement) item).getKey(), EVENT_KEY);
    assertEquals(((ModelListElement) item).getType(), ModelType.EVENT);
}
Also used : ModelListElement(com.thebluealliance.androidclient.listitems.ModelListElement) ListItem(com.thebluealliance.androidclient.listitems.ListItem) Test(org.junit.Test)

Example 23 with ListItem

use of com.thebluealliance.androidclient.listitems.ListItem in project the-blue-alliance-android by the-blue-alliance.

the class AwardRendererTest method testRenderTeamCarded.

@Test
public void testRenderTeamCarded() {
    Award award = ModelMaker.getModel(Award.class, AWARD_TEAM);
    ListItem rendered = mRenderer.renderFromModel(award, new AwardRenderer.RenderArgs(new HashMap<>(), null));
    assertNotNull(rendered);
    assertTrue(rendered instanceof CardedAwardListElement);
}
Also used : CardedAwardListElement(com.thebluealliance.androidclient.listitems.CardedAwardListElement) HashMap(java.util.HashMap) Award(com.thebluealliance.androidclient.models.Award) ListItem(com.thebluealliance.androidclient.listitems.ListItem) Test(org.junit.Test)

Example 24 with ListItem

use of com.thebluealliance.androidclient.listitems.ListItem in project the-blue-alliance-android by the-blue-alliance.

the class SearchResultsActivity method updateQuery.

private void updateQuery(final String query) {
    currentQuery = query;
    String preparedQuery = Utilities.getPreparedQueryForSearch(query);
    ArrayList<ListItem> listItems = new ArrayList<>();
    // Teams
    Cursor teamQueryResults = mDb.getMatchesForTeamQuery(preparedQuery);
    if (teamQueryResults != null && teamQueryResults.moveToFirst()) {
        teamQueryResults.moveToPosition(-1);
        teamsHeader = new SearchResultsHeaderListElement(getString(R.string.teams_header));
        if (teamQueryResults.getCount() > MAX_RESULTS_PER_CATEGORY) {
            teamsHeader.showMoreButton(true);
            teamsHeader.setMoreCount(teamQueryResults.getCount() - MAX_RESULTS_PER_CATEGORY);
        } else {
            teamsHeader.showMoreButton(false);
        }
        listItems.add(teamsHeader);
        TeamRenderer teamRenderer = new TeamRenderer(null);
        while (teamQueryResults.moveToNext()) {
            // Limit ourselves to a certain number of teams
            if (teamQueryResults.getPosition() >= MAX_RESULTS_PER_CATEGORY) {
                break;
            }
            String key = teamQueryResults.getString(teamQueryResults.getColumnIndex("_id"));
            Team team = mDb.getTeamsTable().get(key);
            if (team == null) {
                // Don't display models that don't exist anymore and delete them from search indexes
                team = new Team();
                team.setKey(key);
                mDb.getTeamsTable().deleteSearchIndex(team);
                continue;
            }
            listItems.add(teamRenderer.renderFromModel(team, TeamRenderer.RENDER_BASIC));
            TbaLogger.d("titles: " + teamQueryResults.getString(teamQueryResults.getColumnIndex(Database.SearchTeam.TITLES)));
        }
        teamQueryResults.close();
    } else {
        teamsHeader = new SearchResultsHeaderListElement(getString(R.string.teams_header));
        teamsHeader.showMoreButton(false);
        listItems.add(teamsHeader);
        listItems.add(new EmptyListElement(getString(R.string.no_teams_found)));
    }
    // Events
    Cursor eventQueryResults = mDb.getMatchesForEventQuery(preparedQuery);
    if (eventQueryResults != null && eventQueryResults.moveToFirst()) {
        eventQueryResults.moveToPosition(-1);
        eventsHeader = new SearchResultsHeaderListElement(getString(R.string.events_header));
        if (eventQueryResults.getCount() > MAX_RESULTS_PER_CATEGORY) {
            eventsHeader.showMoreButton(true);
            eventsHeader.setMoreCount(eventQueryResults.getCount() - MAX_RESULTS_PER_CATEGORY);
        } else {
            eventsHeader.showMoreButton(false);
        }
        listItems.add(eventsHeader);
        EventRenderer eventRenderer = new EventRenderer(null);
        while (eventQueryResults.moveToNext()) {
            // Limit ourselves to a certain number of events
            if (eventQueryResults.getPosition() >= MAX_RESULTS_PER_CATEGORY) {
                break;
            }
            String key = eventQueryResults.getString(eventQueryResults.getColumnIndex("_id"));
            Event event = mDb.getEventsTable().get(key);
            if (event == null) {
                // Don't display models that don't exist anymore and delete them from search indexes
                event = new Event();
                event.setKey(key);
                mDb.getEventsTable().deleteSearchIndex(event);
                continue;
            }
            listItems.add(eventRenderer.renderFromModel(event, false));
        }
        eventQueryResults.close();
    } else {
        eventsHeader = new SearchResultsHeaderListElement(getString(R.string.events_header));
        eventsHeader.showMoreButton(false);
        listItems.add(eventsHeader);
        listItems.add(new EmptyListElement(getString(R.string.no_events_found)));
    }
    ListViewAdapter adapter = new ListViewAdapter(this, listItems);
    resultsList.setAdapter(adapter);
    resultsList.setOnItemClickListener((adapterView, view, position, id) -> {
        ListViewAdapter adapter1 = (ListViewAdapter) adapterView.getAdapter();
        ListItem clickedItem = adapter1.getItem(position);
        if (clickedItem instanceof TeamListElement) {
            String teamKey = ((ListElement) clickedItem).getKey();
            startActivity(ViewTeamActivity.newInstance(SearchResultsActivity.this, teamKey));
        } else if (clickedItem instanceof EventListElement) {
            String eventKey = ((ListElement) clickedItem).getKey();
            startActivity(ViewEventActivity.newInstance(SearchResultsActivity.this, eventKey));
        } else if (clickedItem == teamsHeader) {
            if (teamsHeader.isShowingMoreButton()) {
                startActivity(MoreSearchResultsActivity.newInstance(SearchResultsActivity.this, MoreSearchResultsActivity.TEAM_RESULTS, query));
            }
        } else if (clickedItem == eventsHeader) {
            if (eventsHeader.isShowingMoreButton()) {
                startActivity(MoreSearchResultsActivity.newInstance(SearchResultsActivity.this, MoreSearchResultsActivity.EVENT_RESULTS, query));
            }
        } else {
            searchView.setVisibility(View.INVISIBLE);
            searchView.setVisibility(View.VISIBLE);
        }
    });
}
Also used : EventListElement(com.thebluealliance.androidclient.listitems.EventListElement) EventRenderer(com.thebluealliance.androidclient.renderers.EventRenderer) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) TeamListElement(com.thebluealliance.androidclient.listitems.TeamListElement) EmptyListElement(com.thebluealliance.androidclient.listitems.EmptyListElement) ListViewAdapter(com.thebluealliance.androidclient.adapters.ListViewAdapter) SearchResultsHeaderListElement(com.thebluealliance.androidclient.listitems.SearchResultsHeaderListElement) TeamRenderer(com.thebluealliance.androidclient.renderers.TeamRenderer) EventListElement(com.thebluealliance.androidclient.listitems.EventListElement) SearchResultsHeaderListElement(com.thebluealliance.androidclient.listitems.SearchResultsHeaderListElement) ListElement(com.thebluealliance.androidclient.listitems.ListElement) EmptyListElement(com.thebluealliance.androidclient.listitems.EmptyListElement) TeamListElement(com.thebluealliance.androidclient.listitems.TeamListElement) Event(com.thebluealliance.androidclient.models.Event) Team(com.thebluealliance.androidclient.models.Team) ListItem(com.thebluealliance.androidclient.listitems.ListItem)

Example 25 with ListItem

use of com.thebluealliance.androidclient.listitems.ListItem in project the-blue-alliance-android by the-blue-alliance.

the class SubscriptionListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    Collections.sort(mAPIData, mComparator);
    int lastModel = -1;
    for (int i = 0; i < mAPIData.size(); i++) {
        Subscription subscription = mAPIData.get(i);
        ListItem item = mRenderer.renderFromKey(subscription.getModelKey(), subscription.getModelType(), null);
        if (item != null) {
            if (lastModel != subscription.getModelEnum()) {
                mDataToBind.add(new EventTypeHeader(subscription.getModelType().getTitle()));
            }
            mDataToBind.add(item);
        }
        lastModel = subscription.getModelEnum();
    }
}
Also used : ListItem(com.thebluealliance.androidclient.listitems.ListItem) EventTypeHeader(com.thebluealliance.androidclient.listitems.EventTypeHeader) Subscription(com.thebluealliance.androidclient.models.Subscription)

Aggregations

ListItem (com.thebluealliance.androidclient.listitems.ListItem)26 Test (org.junit.Test)18 ModelListElement (com.thebluealliance.androidclient.listitems.ModelListElement)6 CardedAwardListElement (com.thebluealliance.androidclient.listitems.CardedAwardListElement)5 Award (com.thebluealliance.androidclient.models.Award)3 Team (com.thebluealliance.androidclient.models.Team)3 ListViewAdapter (com.thebluealliance.androidclient.adapters.ListViewAdapter)2 DistrictTeamListElement (com.thebluealliance.androidclient.listitems.DistrictTeamListElement)2 EventTypeHeader (com.thebluealliance.androidclient.listitems.EventTypeHeader)2 LabelValueListItem (com.thebluealliance.androidclient.listitems.LabelValueListItem)2 Event (com.thebluealliance.androidclient.models.Event)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Cursor (android.database.Cursor)1 JsonObject (com.google.gson.JsonObject)1 EventAwardsEvent (com.thebluealliance.androidclient.eventbus.EventAwardsEvent)1 RenderableModel (com.thebluealliance.androidclient.interfaces.RenderableModel)1 ContributorListElement (com.thebluealliance.androidclient.listitems.ContributorListElement)1 DividerListItem (com.thebluealliance.androidclient.listitems.DividerListItem)1 EmptyListElement (com.thebluealliance.androidclient.listitems.EmptyListElement)1