use of com.thebluealliance.androidclient.listitems.TeamListElement in project the-blue-alliance-android by the-blue-alliance.
the class TeamRendererTest method testNullRenderFromKey.
@Test
public void testNullRenderFromKey() {
when(mDatafeed.fetchTeam(TEAM_KEY)).thenReturn(Observable.just(null));
TeamListElement element = mRenderer.renderFromKey(TEAM_KEY, ModelType.TEAM, null);
assertNull(element);
}
use of com.thebluealliance.androidclient.listitems.TeamListElement in project the-blue-alliance-android by the-blue-alliance.
the class TeamRendererTest method testRenderFromModelBasic.
@Test
public void testRenderFromModelBasic() {
TeamListElement element = mRenderer.renderFromModel(mTeam, TeamRenderer.RENDER_BASIC);
assertTeamElement(element, false);
}
use of com.thebluealliance.androidclient.listitems.TeamListElement in project the-blue-alliance-android by the-blue-alliance.
the class TeamRendererTest method testRenderFromKey.
@Test
public void testRenderFromKey() {
when(mDatafeed.fetchTeam(TEAM_KEY)).thenReturn(Observable.just(mTeam));
TeamListElement element = mRenderer.renderFromKey(TEAM_KEY, ModelType.TEAM, null);
assertTeamElement(element, false);
}
use of com.thebluealliance.androidclient.listitems.TeamListElement in project the-blue-alliance-android by the-blue-alliance.
the class TeamRendererTest method testRenderFromModelDetails.
@Test
public void testRenderFromModelDetails() {
TeamListElement element = mRenderer.renderFromModel(mTeam, TeamRenderer.RENDER_DETAILS_BUTTON);
assertTeamElement(element, true);
}
use of com.thebluealliance.androidclient.listitems.TeamListElement 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);
}
});
}
Aggregations