Search in sources :

Example 1 with ListViewAdapter

use of com.thebluealliance.androidclient.adapters.ListViewAdapter in project the-blue-alliance-android by the-blue-alliance.

the class FirebaseTickerFragment method createFilterListAdapter.

private ListViewAdapter createFilterListAdapter(Set<String> enabledNotifications) {
    List<ListItem> listItems = new ArrayList<>();
    // Start with all notifications enabled
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_upcoming_match, "Upcoming Matches", NotificationTypes.UPCOMING_MATCH, true));
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_match_results, "Match Results", NotificationTypes.MATCH_SCORE, true));
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_schedule_updated, "Schedule Updated", NotificationTypes.SCHEDULE_UPDATED, true));
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_competition_level_starting, "Competition Level Starting", NotificationTypes.LEVEL_STARTING, true));
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_alliance_selections, "Alliance Selections", NotificationTypes.ALLIANCE_SELECTION, true));
    listItems.add(new GamedayTickerFilterCheckbox(R.layout.list_item_checkbox_awards_posted, "Awards Posted", NotificationTypes.AWARDS, true));
    // Initialize the preferences to their appropriate value
    if (enabledNotifications != null) {
        for (ListItem item : listItems) {
            GamedayTickerFilterCheckbox checkbox = (GamedayTickerFilterCheckbox) item;
            if (!enabledNotifications.contains(checkbox.getKey())) {
                checkbox.setChecked(false);
            }
        }
    }
    return new ListViewAdapter(getActivity(), listItems);
}
Also used : ListViewAdapter(com.thebluealliance.androidclient.adapters.ListViewAdapter) ArrayList(java.util.ArrayList) ListItem(com.thebluealliance.androidclient.listitems.ListItem) GamedayTickerFilterCheckbox(com.thebluealliance.androidclient.listitems.gameday.GamedayTickerFilterCheckbox)

Example 2 with ListViewAdapter

use of com.thebluealliance.androidclient.adapters.ListViewAdapter in project the-blue-alliance-android by the-blue-alliance.

the class EventStatsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Setup views & listeners
    View view = inflater.inflate(R.layout.fragment_event_stats, null);
    mBinder.setRootView(view);
    mListView = (ListView) view.findViewById(R.id.list);
    mRadioGroup = (RadioGroup) view.findViewById(R.id.stats_type_selector);
    ProgressBar mProgressBar = (ProgressBar) view.findViewById(R.id.progress);
    // Or get data if viewing fragment for the first time.
    if (mAdapter != null) {
        mListView.setAdapter(mAdapter);
        mListView.onRestoreInstanceState(mListState);
        mRadioGroup.restoreHierarchyState(mRadioState);
        mProgressBar.setVisibility(View.GONE);
    }
    mBinder.setNoDataView((NoDataView) view.findViewById(R.id.no_data));
    mListView.setOnItemClickListener((adapterView, view1, position, id) -> {
        if (!(adapterView.getAdapter() instanceof ListViewAdapter) || position >= adapterView.getAdapter().getCount() || !(((ListViewAdapter) adapterView.getAdapter()).getItem(position) instanceof ListElement)) {
            TbaLogger.d("Can't open stat item");
            return;
        }
        String teamKey = ((ListElement) ((ListViewAdapter) adapterView.getAdapter()).getItem(position)).getKey();
        if (TeamHelper.validateTeamKey(teamKey) ^ TeamHelper.validateMultiTeamKey(teamKey)) {
            teamKey = TeamHelper.baseTeamKey(teamKey);
            startActivity(TeamAtEventActivity.newInstance(getActivity(), mEventKey, teamKey));
        }
    });
    return view;
}
Also used : ListViewAdapter(com.thebluealliance.androidclient.adapters.ListViewAdapter) ListElement(com.thebluealliance.androidclient.listitems.ListElement) NoDataView(com.thebluealliance.androidclient.views.NoDataView) View(android.view.View) ListView(android.widget.ListView) ProgressBar(android.widget.ProgressBar)

Example 3 with ListViewAdapter

use of com.thebluealliance.androidclient.adapters.ListViewAdapter 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 4 with ListViewAdapter

use of com.thebluealliance.androidclient.adapters.ListViewAdapter in project the-blue-alliance-android by the-blue-alliance.

the class EventClickListener method onItemClick.

/**
 * When called from a ListView, assume {@code mKey} is a team key
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (!(parent.getAdapter() instanceof ListViewAdapter)) {
        // safety check. Shouldn't ever be tripped unless someone messed up in code somewhere
        TbaLogger.w("Someone done goofed. A ListView adapter doesn't extend ListViewAdapter. Try again...");
        return;
    }
    Object item = ((ListViewAdapter) parent.getAdapter()).getItem(position);
    if (item != null && item instanceof ListElement) {
        // only open up the view event activity if the user actually clicks on a ListElement
        // (as opposed to something inheriting from ListHeader, which shouldn't do anything on user click
        Intent intent;
        String eventKey = ((ListElement) item).getKey();
        if (mKey == null || mKey.isEmpty()) {
            // no team is selected, go to the event details
            intent = ViewEventActivity.newInstance(context, eventKey);
            AnalyticsHelper.sendClickUpdate(context, "event_click", eventKey, "");
        } else {
            // team is selected, open up the results for that specific team at the event
            intent = TeamAtEventActivity.newInstance(context, eventKey, mKey);
            AnalyticsHelper.sendClickUpdate(context, "team@event_click", EventTeamHelper.generateKey(eventKey, mKey), "");
        }
        context.startActivity(intent);
    } else {
        TbaLogger.d("ListHeader clicked. Ignore...");
    }
}
Also used : ListViewAdapter(com.thebluealliance.androidclient.adapters.ListViewAdapter) ListElement(com.thebluealliance.androidclient.listitems.ListElement) Intent(android.content.Intent)

Aggregations

ListViewAdapter (com.thebluealliance.androidclient.adapters.ListViewAdapter)4 ListElement (com.thebluealliance.androidclient.listitems.ListElement)3 ListItem (com.thebluealliance.androidclient.listitems.ListItem)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 View (android.view.View)1 ListView (android.widget.ListView)1 ProgressBar (android.widget.ProgressBar)1 EmptyListElement (com.thebluealliance.androidclient.listitems.EmptyListElement)1 EventListElement (com.thebluealliance.androidclient.listitems.EventListElement)1 SearchResultsHeaderListElement (com.thebluealliance.androidclient.listitems.SearchResultsHeaderListElement)1 TeamListElement (com.thebluealliance.androidclient.listitems.TeamListElement)1 GamedayTickerFilterCheckbox (com.thebluealliance.androidclient.listitems.gameday.GamedayTickerFilterCheckbox)1 Event (com.thebluealliance.androidclient.models.Event)1 Team (com.thebluealliance.androidclient.models.Team)1 EventRenderer (com.thebluealliance.androidclient.renderers.EventRenderer)1 TeamRenderer (com.thebluealliance.androidclient.renderers.TeamRenderer)1 NoDataView (com.thebluealliance.androidclient.views.NoDataView)1