use of com.cpjd.roblu.ui.events.EventDrawerManager in project Roblu by wdavies973.
the class TeamsView method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teams_view);
io = new IO(getApplicationContext());
// Initialize startup requirements
// sets width for UI, needed for RMetricToUI
Utils.initWidth(this);
if (IO.init(getApplicationContext())) {
// checks if we need to show startup dialog
startActivity(new Intent(this, SetupActivity.class));
finish();
return;
}
// setup TBA api vars
TBA.setID("Roblu", "Scouting-App", "v3");
settings = io.loadSettings();
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("Roblu");
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
// Progress bar, also make sure to hide it
bar = findViewById(R.id.progress_bar);
bar.setVisibility(View.GONE);
// Recycler View, UI front-end to teams array
rv = findViewById(R.id.teams_recycler);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rv.setLayoutManager(linearLayoutManager);
((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
// Setup the team adapter
adapter = new TeamsRecyclerAdapter(this, this);
rv.setAdapter(adapter);
// Setup the UI gestures manager and link to recycler view
ItemTouchHelper.Callback callback = new TeamsRecyclerTouchHelper(adapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(rv);
// Search view
searchView = findViewById(R.id.search_view);
searchView.setHintTextColor(Color.BLACK);
searchView.setHint("Name, number, or match");
// Search button
searchButton = findViewById(R.id.fab);
searchButton.setOnClickListener(this);
searchButton.setOnLongClickListener(this);
// Link the search button appearance to the scrolling behavior of the recycler view
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0 && searchButton.isShown())
searchButton.hide();
if (dy < 0 && !searchButton.isShown())
searchButton.show();
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE)
searchButton.show();
super.onScrollStateChanged(recyclerView, newState);
}
});
// If the user closes the search bar, refresh the teams view with all the original items
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
}
@Override
public void onSearchViewClosed() {
executeLoadTeamsTask(lastFilter, false);
searchButton.setVisibility(FloatingActionButton.VISIBLE);
}
});
// Listen for text in the search view, if text is found, complete teh search
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
searchView.closeSearch();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
lastQuery = newText;
if (lastFilter == SORT_TYPE.CUSTOM_SORT)
executeLoadTeamsTask(SORT_TYPE.CUSTOM_SORT, false);
else
executeLoadTeamsTask(SORT_TYPE.SEARCH, false);
return true;
}
});
// Make general changes to UI, keep it synced with RUI
new UIHandler(this, toolbar, searchButton, true).update();
// Reload last filter, custom sort, and query
lastFilter = settings.getLastFilter();
// custom sort or search can't be loaded at startup because lastQuery and lastCustomSortFilter aren't saved
if (lastFilter == SORT_TYPE.CUSTOM_SORT || lastFilter == SORT_TYPE.SEARCH)
lastFilter = SORT_TYPE.NUMERICAL;
/*
* Setup events drawer and load events to it
*/
eventDrawerManager = new EventDrawerManager(this, toolbar, this);
eventDrawerManager.selectEvent(settings.getLastEventID());
// Check to see if the background service is running, if it isn't, start it
serviceFilter = new IntentFilter();
serviceFilter.addAction(Constants.SERVICE_ID);
Log.d("RBS", "Is service running: " + Utils.isMyServiceRunning(getApplicationContext()));
if (!Utils.isMyServiceRunning(getApplicationContext())) {
Intent serviceIntent = new Intent(this, Service.class);
startService(serviceIntent);
}
/*
* Display update messages
*
*/
if (settings.getUpdateLevel() != Constants.VERSION) {
settings.setUpdateLevel(Constants.VERSION);
AlertDialog.Builder builder = new AlertDialog.Builder(TeamsView.this).setTitle("Changelist for Version 4.4.5").setMessage(Constants.UPDATE_MESSAGE).setPositiveButton("Rock on", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
if (dialog.getWindow() != null) {
dialog.getWindow().getAttributes().windowAnimations = settings.getRui().getDialogDirection();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(settings.getRui().getBackground()));
}
dialog.show();
dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(settings.getRui().getAccent());
io.saveSettings(settings);
}
}
Aggregations