Search in sources :

Example 1 with TutorialsRecyclerTouchHelper

use of com.cpjd.roblu.ui.tutorials.TutorialsRecyclerTouchHelper in project Roblu by wdavies973.

the class TBAEventSelector method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_apievent_select);
    teamNumber = new IO(getApplicationContext()).loadSettings().getTeamNumber();
    /*
         * Setup UI
         */
    // Setup
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Select an event");
    }
    // Progress bar
    bar = findViewById(R.id.progress_bar);
    bar.setVisibility(View.GONE);
    // Recycler view
    rv = findViewById(R.id.events_recycler);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    // Setup the tbaEventAdapter
    tbaEventAdapter = new TBAEventAdapter(this, this);
    rv.setAdapter(tbaEventAdapter);
    // Setup the gesture listener
    ItemTouchHelper.Callback callback = new TutorialsRecyclerTouchHelper();
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(rv);
    /*
         * Create the "My Events / All Events" chooser
         */
    Spinner showTeam = findViewById(R.id.show_team);
    ArrayAdapter<String> sAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, new String[] { "My events", "All events" });
    sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    showTeam.setAdapter(sAdapter);
    showTeam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
            onlyShowMyEvents = parent.getItemAtPosition(position).toString().equals("My events");
            rv.setVisibility(View.INVISIBLE);
            bar.setVisibility(View.VISIBLE);
            if (tbaEventAdapter.getEvents() != null)
                tbaEventAdapter.getEvents().clear();
            tbaEventAdapter.notifyDataSetChanged();
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.execute();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    // If no team number is found, default to "All events"
    if (new IO(getApplicationContext()).loadSettings().getTeamNumber() == 0)
        showTeam.setSelection(1);
    /*
         * Setup the years spinner
         */
    Spinner yearsSpinner = findViewById(R.id.spinner);
    selectedYear = Calendar.getInstance().get(Calendar.YEAR);
    String[] years = new String[selectedYear - 1991];
    for (int i = years.length - 1; i >= 0; i--) years[Math.abs(i - years.length + 1)] = String.valueOf(1992 + i);
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, years);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    yearsSpinner.setAdapter(adapter);
    yearsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            selectedYear = Integer.parseInt(adapterView.getItemAtPosition(i).toString());
            rv.setVisibility(View.INVISIBLE);
            bar.setVisibility(View.VISIBLE);
            if (tbaEventAdapter.getEvents() != null)
                tbaEventAdapter.getEvents().clear();
            tbaEventAdapter.notifyDataSetChanged();
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.execute();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    /*
         * Setup the search view
         */
    searchView = findViewById(R.id.search_view);
    searchView.setHintTextColor(Color.BLACK);
    searchView.setHint("Search events");
    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {

        @Override
        public void onSearchViewShown() {
        }

        @Override
        public void onSearchViewClosed() {
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.setEvents(events);
            task.execute();
        }
    });
    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchView.closeSearch();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.setEvents(events);
            task.setQuery(newText);
            task.execute();
            return true;
        }
    });
    // Sync UI with user preferences
    new UIHandler(this, toolbar).update();
}
Also used : TutorialsRecyclerTouchHelper(com.cpjd.roblu.ui.tutorials.TutorialsRecyclerTouchHelper) Spinner(android.widget.Spinner) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) TBALoadEventsTask(com.cpjd.roblu.tba.TBALoadEventsTask) Toolbar(android.support.v7.widget.Toolbar) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 IO (com.cpjd.roblu.io.IO)1 TBALoadEventsTask (com.cpjd.roblu.tba.TBALoadEventsTask)1 UIHandler (com.cpjd.roblu.ui.UIHandler)1 TutorialsRecyclerTouchHelper (com.cpjd.roblu.ui.tutorials.TutorialsRecyclerTouchHelper)1 MaterialSearchView (com.miguelcatalan.materialsearchview.MaterialSearchView)1