Search in sources :

Example 16 with Event

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

the class MyTbaModelRendererTest method testRenderEvent.

@Test
public void testRenderEvent() {
    Event event = ModelMaker.getModel(Event.class, EVENT_KEY);
    when(mDatafeed.fetchEvent(EVENT_KEY)).thenReturn(Observable.just(event));
    mRenderer.renderFromKey(EVENT_KEY, ModelType.EVENT, null);
    verify(mEventRenderer).renderFromModel(event, true);
}
Also used : Event(com.thebluealliance.androidclient.models.Event) Test(org.junit.Test)

Example 17 with Event

use of com.thebluealliance.androidclient.models.Event 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 18 with Event

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

the class TeamAtEventActivity method onEventSelected.

private void onEventSelected(int position) {
    if (position == mCurrentSelectedEventPosition) {
        return;
    }
    if (position < 0 || position >= mEventsParticipated.size()) {
        return;
    }
    mCurrentSelectedEventPosition = position;
    updateEventSelector(mCurrentSelectedEventPosition);
    Event newEvent = mEventsParticipated.get(mCurrentSelectedEventPosition);
    if (mEventKey.equals(newEvent.getKey())) {
        return;
    }
    mEventKey = newEvent.getKey();
    mAdapter.updateEvent(mEventKey);
    mAdapter.notifyDataSetChanged();
    String eventTeamKey = EventTeamHelper.generateKey(mEventKey, mTeamKey);
    setModelKey(eventTeamKey, ModelType.EVENTTEAM);
    setBeamUri(String.format(NfcUris.URI_TEAM_AT_EVENT, mEventKey, mTeamKey));
    setShareUri(String.format(ShareUris.URI_TEAM_AT_EVENT, TeamHelper.getTeamNumber(mTeamKey), EventHelper.getYear(mEventKey), mEventKey));
}
Also used : Event(com.thebluealliance.androidclient.models.Event) TeamAvatarUpdateEvent(com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)

Example 19 with Event

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

the class TeamAtEventActivity method makeDialogForEventSelection.

private Dialog makeDialogForEventSelection(@StringRes int titleResId, ImmutableList<Event> eventsParticipated) {
    String[] events = new String[eventsParticipated.size()];
    for (int i = 0; i < eventsParticipated.size(); i++) {
        Event event = eventsParticipated.get(i);
        events[i] = event.getYear() + " " + event.getShortName();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(titleResId));
    builder.setItems(events, (dialog, which) -> onEventSelected(which));
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) TaskStackBuilder(androidx.core.app.TaskStackBuilder) Event(com.thebluealliance.androidclient.models.Event) TeamAvatarUpdateEvent(com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent) AndroidEntryPoint(dagger.hilt.android.AndroidEntryPoint)

Example 20 with Event

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

the class EventHelper method renderEventListForDistrict.

public static void renderEventListForDistrict(Context context, List<Event> events, List<Object> output) {
    Collections.sort(events, new EventSortByDateComparator());
    String lastHeader = null, currentHeader;
    for (Event event : events) {
        currentHeader = weekLabelFromNum(event.getYear(), event.getWeek());
        if (!currentHeader.equals(lastHeader)) {
            String headerTitle = context.getString(R.string.week_events_header, currentHeader);
            output.add(new ListSectionHeaderViewModel(headerTitle));
        }
        output.add(event.renderToViewModel(context, Event.RENDER_BASIC));
        if (event.isHappeningNow()) {
            // send out that there are live matches happening for other things to pick up
            TbaLogger.d("Sending live event broadcast: " + event.getKey());
            EventBus.getDefault().post(new LiveEventUpdateEvent(event));
        }
        lastHeader = currentHeader;
    }
}
Also used : ListSectionHeaderViewModel(com.thebluealliance.androidclient.viewmodels.ListSectionHeaderViewModel) LiveEventUpdateEvent(com.thebluealliance.androidclient.eventbus.LiveEventUpdateEvent) Event(com.thebluealliance.androidclient.models.Event) LiveEventUpdateEvent(com.thebluealliance.androidclient.eventbus.LiveEventUpdateEvent) EventSortByDateComparator(com.thebluealliance.androidclient.comparators.EventSortByDateComparator)

Aggregations

Event (com.thebluealliance.androidclient.models.Event)35 Test (org.junit.Test)8 Team (com.thebluealliance.androidclient.models.Team)6 ArrayList (java.util.ArrayList)5 District (com.thebluealliance.androidclient.models.District)4 Date (java.util.Date)4 JsonObject (com.google.gson.JsonObject)3 TeamAvatarUpdateEvent (com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)3 Match (com.thebluealliance.androidclient.models.Match)3 EventRenderer (com.thebluealliance.androidclient.renderers.EventRenderer)3 Before (org.junit.Before)3 Cursor (android.database.Cursor)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 JsonElement (com.google.gson.JsonElement)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 LiveEventUpdateEvent (com.thebluealliance.androidclient.eventbus.LiveEventUpdateEvent)2 ListGroup (com.thebluealliance.androidclient.listitems.ListGroup)2 DistrictPointBreakdown (com.thebluealliance.androidclient.models.DistrictPointBreakdown)2