use of com.cpjd.models.Event in project Roblu by wdavies973.
the class EventEditor method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* Load dependencies
*/
editing = getIntent().getBooleanExtra("editing", false);
RUI rui = new IO(getApplicationContext()).loadSettings().getRui();
// decide whether to use create event or edit event UI scheme
if (editing)
setContentView(R.layout.activity_edit_event);
else
setContentView(R.layout.activity_create_event);
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setHomeAsUpIndicator(R.drawable.clear);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (editing)
getSupportActionBar().setTitle("Edit event");
else
getSupportActionBar().setTitle("Create event");
}
// event name
eventName = findViewById(R.id.event_create_name_edit);
/*
* Bind user color preferences to the UI elements
*/
Utils.setInputTextLayoutColor(rui.getAccent(), (TextInputLayout) findViewById(R.id.name_wrapper), (AppCompatEditText) findViewById(R.id.event_create_name_edit));
/*
* Setup editing/non-editing UI specifics
*/
if (!editing) {
TextView t = findViewById(R.id.event_create_form_label);
t.setTextColor(rui.getAccent());
if (getIntent().getSerializableExtra("tbaEvent") != null) {
/*
* This item will be set if this activity is called form the TBAEventSelector activity, all it's saying is that
* all the data within this Event model should be included when creating the REvent
*/
Event event = (Event) getIntent().getSerializableExtra("tbaEvent");
eventName.setText(event.name);
findViewById(R.id.switch1).setVisibility(View.VISIBLE);
}
} else {
RelativeLayout layout = findViewById(R.id.create_layout);
for (int i = 0; i < layout.getChildCount(); i++) {
if (layout.getChildAt(i).getId() == R.id.form_type || layout.getChildAt(i).getId() == R.id.event_create_form_label) {
layout.removeViewAt(i);
i = 0;
}
}
tbaKeyText = findViewById(R.id.key_edit);
tbaKeyText.setText(getIntent().getStringExtra("key"));
eventName.setText(getIntent().getStringExtra("name"));
}
// General UI syncing
new UIHandler(this, toolbar).update();
}
use of com.cpjd.models.Event in project Roblu by wdavies973.
the class ImportEvent method run.
@Override
public void run() {
/*
* Make sure this thread has network permissions
*/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
// set what should be included in the event download
Settings.defaults();
// notify the listener of the downloaded event
Event e = new TBA().getEvent(this.key);
if (e != null)
listener.eventDownloaded(e);
else
listener.errorOccurred("No event found with key: " + this.key + ".");
try {
join();
} catch (InterruptedException error) {
Log.d("RBS", "Failed to stop ImportEvent thread.");
}
}
use of com.cpjd.models.Event in project Roblu by wdavies973.
the class TBAEventSelector method tbaEventSelected.
/**
* The user selected an event from the downloaded events, what happens next is we need to create a sort of
* "partial REvent" and pass it to the EventEditor class so the user can decide which form they want, etc.
* @param v the view that was tapped
*/
@Override
public void tbaEventSelected(View v) {
/*
* Force close the keyboard, Android doesn't always automatically do this
*/
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
// Get the event reference from the UI
Event event = tbaEventAdapter.getEvents().get(rv.getChildLayoutPosition(v));
Utils.showSnackbar(findViewById(R.id.activity_apievent_select), getApplicationContext(), "Downloading event...", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
Log.d("RBS", "Importing event with key: " + event.key);
/*
* Import the event specifically, eventDownloaded(Event event) will receive the result of this
* task execution
*/
new ImportEvent(this, event.key).start();
}
use of com.cpjd.models.Event in project Roblu by wdavies973.
the class TBALoadEventsTask method doInBackground.
/**
* Executes the task
* @param params no parameters should all be set by the getters and setters for the LoadEventsTask variables
* @return null (listener will receive the data)
*/
@Override
protected Void doInBackground(Void... params) {
if (events == null)
events = new ArrayList<>();
/*
* We need to make sure that this thread has access to the internet
*/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
/*
* This disables any sub-data returned with the events, we only want the event data!
* Downloading sub-teams for each event would take a while.
*/
Settings.disableAll();
/*
* Now let's use the AMAZING TBA-API features to download the events, you
* should check out the TBA-API developer, he's great.
*/
if (events == null || events.size() == 0) {
try {
Event[] events;
if (onlyShowMyEvents)
events = new TBA().getTeamEvents(teamNumber, year, false);
else
events = new TBA().getEvents(year, false);
/*
* Clean up the downloaded data a bit
*/
for (Event e : events) {
while (e.name.startsWith(" ")) e.name = e.name.substring(1);
e.start_date = Integer.parseInt(e.start_date.split("-")[1]) + "/" + Integer.parseInt(e.start_date.split("-")[2]) + "/" + e.start_date.split("-")[0];
}
this.events = new ArrayList<>();
Collections.addAll(this.events, events);
listener.eventListDownloaded(this.events);
} catch (Exception e) {
e.printStackTrace();
if (onlyShowMyEvents && teamNumber == 0)
listener.errorOccurred("Error occurred downloading events list. Is your team number properly defined in Roblu settings?");
else
listener.errorOccurred("An error occurred while accessing TheBlueAlliance.com");
}
}
/*
* Now, perform searching if necessary
*/
if (!query.equals("")) {
for (Event e : this.events) {
/*
* Because of the janky API sort method, relevance can NEVER be zero (otherwise the event will get sorted by date),
* so make sure that zero is not possible!
*/
e.relevance = -1;
/*
* It's tempting to use if statements here, don't! They are INDIVIDUAL search criteria scores
*/
if (e.name.toLowerCase().equals(query))
e.relevance += 5;
if (e.name.toLowerCase().contains(query))
e.relevance += 2;
if (Utils.contains(e.name.toLowerCase(), query))
e.relevance += 4;
if (e.start_date.toLowerCase().contains(query))
e.relevance += 2;
if (e.start_date.toLowerCase().equals(query))
e.relevance += 5;
if (Utils.contains(e.start_date.toLowerCase(), query))
e.relevance += 4;
if (e.location.toLowerCase().equals(query))
e.relevance += 5;
if (e.location.toLowerCase().contains(query))
e.relevance += 2;
if (Utils.contains(e.location.toLowerCase(), query))
e.relevance += 4;
}
Collections.sort(this.events);
Collections.reverse(this.events);
} else /*
* Sort by date!
*/
{
// make sure to reset old relevance (from past searches)
for (Event e : this.events) e.relevance = 0;
Collections.sort(this.events);
}
return null;
}
use of com.cpjd.models.Event in project Roblu by wdavies973.
the class OurMatches method generateSheet.
@Override
public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] teams, ArrayList<RCheckout> checkouts) {
if (event.getKey() == null || event.getKey().equalsIgnoreCase("") || io.loadSettings().getTeamNumber() == 0)
return;
int teamNumber = io.loadSettings().getTeamNumber();
// Allow this thread to access the internet
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
XSSFCellStyle blue = setCellStyle(BorderStyle.THIN, IndexedColors.CORNFLOWER_BLUE, IndexedColors.BLACK, false);
XSSFCellStyle red = setCellStyle(BorderStyle.THIN, IndexedColors.CORAL, IndexedColors.BLACK, false);
/*
* Create header row
*/
Row one = createRow(sheet, 0);
setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, true);
createCell(one, 0, "Match#");
setStyle(blue);
createCell(one, 1, "Team1");
createCell(one, 2, "Team2");
createCell(one, 3, "Team3");
setStyle(red);
createCell(one, 4, "Team4");
createCell(one, 5, "Team5");
createCell(one, 6, "Team6");
// Determine event year
Settings.disableAll();
Settings.GET_EVENT_MATCHES = true;
try {
Event tbaEvent = new TBA().getEvent(event.getKey());
for (Match m : tbaEvent.matches) {
if (m.doesMatchContainTeam(teamNumber) > 0) {
Row row = createRow(sheet);
setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, true);
createCell(row, 0, String.valueOf(m.match_number));
setStyle(blue);
createCell(row, 1, m.blueTeams[0].replace("frc", ""));
createCell(row, 2, m.blueTeams[1].replace("frc", ""));
createCell(row, 3, m.blueTeams[2].replace("frc", ""));
setStyle(red);
createCell(row, 4, m.redTeams[0].replace("frc", ""));
createCell(row, 5, m.redTeams[1].replace("frc", ""));
createCell(row, 6, m.redTeams[2].replace("frc", ""));
}
}
} catch (Exception e) {
Row r = createRow(sheet);
createCell(r, 0, "Failed to pull data from TheBlueAlliance.com.");
}
}
Aggregations