use of com.cpjd.roblu.tba.TBALoadEventsTask 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();
}
Aggregations