use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class EventCreateMethodPicker method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event_picker);
/*
* Load dependencies
*/
rui = new IO(getApplicationContext()).loadSettings().getRui();
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setHomeAsUpIndicator(R.drawable.clear);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Create event");
getSupportActionBar().setSubtitle("Choose an option");
}
/*
* Bind choices to UI and setup an adapter
*/
ListView sharingView = findViewById(R.id.listView1);
List<Map<String, String>> data = new ArrayList<>();
for (int i = 0; i < items.length; i++) {
Map<String, String> datum = new HashMap<>(2);
datum.put("item", items[i]);
datum.put("description", sub_items[i]);
data.add(datum);
}
SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), data, android.R.layout.simple_list_item_2, new String[] { "item", "description" }, new int[] { android.R.id.text1, android.R.id.text2 }) {
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = view.findViewById(android.R.id.text1);
text1.setTextColor(rui.getText());
text1 = view.findViewById(android.R.id.text2);
text1.setTextColor(rui.getText());
return view;
}
};
sharingView.setAdapter(adapter);
sharingView.setOnItemClickListener(this);
/*
* sync general UI settings
*/
new UIHandler(this, toolbar).update();
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class EventCreateMethodPicker method onActivityResult.
/**
* Receives result data from child activities
* @param requestCode the request code of the child activities
* @param resultCode the result code of the child activity
* @param data any result data returned from the activity
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/*
* The user selected a backup file, let's attempt to import it here
*/
if (requestCode == Constants.FILE_CHOOSER) {
// this means the user didn't select a file, no point in returning an error message
if (data == null)
return;
try {
IO io = new IO(getApplicationContext());
RBackup backup = io.convertBackupFile(data.getData());
if (!backup.getFileVersion().equals(IO.PREFIX)) {
Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Invalid backup file. Backup was created with an older version of Roblu.", true, rui.getPrimaryColor());
return;
}
/*
* Create the event, we're not gonna use an AsyncTask because the user is just
* watching the event import anyway, and it will only freeze the UI for a couple hundred
* milliseconds.
*/
REvent event = backup.getEvent();
event.setCloudEnabled(false);
event.setID(io.getNewEventID());
io.saveEvent(event);
io.saveForm(event.getID(), backup.getForm());
if (backup.getTeams() != null) {
for (RTeam team : backup.getTeams()) {
for (RTab tab : team.getTabs()) {
for (RMetric metric : tab.getMetrics()) {
if (metric instanceof RGallery && ((RGallery) metric).getImages() != null) {
// Add images to the current gallery
for (int i = 0; i < ((RGallery) metric).getImages().size(); i++) {
((RGallery) metric).getPictureIDs().add(io.savePicture(event.getID(), ((RGallery) metric).getImages().get(i)));
}
((RGallery) metric).setImages(null);
}
}
}
io.saveTeam(event.getID(), team);
}
}
Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Successfully imported event from backup", false, rui.getPrimaryColor());
Intent intent = new Intent();
intent.putExtra("eventID", event.getID());
setResult(Constants.NEW_EVENT_CREATED, intent);
finish();
} catch (Exception e) {
Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Invalid backup file", true, rui.getPrimaryColor());
}
} else /*
* The user created an event manually with EventEditor, we actually don't need to do anything but auto-finish our class
* with a result code letting the TeamsView class now to refresh the event list
*/
if (resultCode == Constants.NEW_EVENT_CREATED) {
Bundle b = data.getExtras();
Intent intent = new Intent();
if (b != null)
intent.putExtras(b);
setResult(Constants.NEW_EVENT_CREATED, intent);
finish();
}
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class EventCreateMethodPicker method importRobluCloudEvent.
/**
* Imports an event from Roblu Cloud, given one exists
*
* @param teamNumber -1 to disable
*/
private void importRobluCloudEvent(int teamNumber) {
d = new ProgressDialog(EventCreateMethodPicker.this);
d.setTitle("Get ready!");
d.setMessage("Roblu is importing an event from Roblu Cloud...");
d.setCancelable(false);
d.show();
// Stop the background service so it won't interfere
IntentFilter serviceFilter = new IntentFilter();
serviceFilter.addAction(Constants.SERVICE_ID);
Intent serviceIntent = new Intent(this, Service.class);
stopService(serviceIntent);
EventDepacker dp = new EventDepacker(new IO(getApplicationContext()), teamNumber);
dp.setListener(this);
dp.start();
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class EventDrawerManager method loadEventsToDrawer.
/**
* Loads events from the file system into the event drawer.
* Note: loadEvents() must be called after the drawer UI is setup, it will insert
* REvents into the pre-created UI drawer
*/
public void loadEventsToDrawer() {
/*
* Load events
*/
// Delete the preview event, if necessary
new IO(activity).deleteEvent(-1);
REvent[] loaded = new IO(activity).loadEvents();
if (loaded == null) {
if (((AppCompatActivity) activity).getSupportActionBar() != null)
((AppCompatActivity) activity).getSupportActionBar().setSubtitle("No events");
return;
}
// Set loaded events to the managed array-list
events = new ArrayList<>(Arrays.asList(loaded));
// Sort descending by event ID, most recently created event will appear first
Collections.sort(events);
Collections.reverse(events);
// Load icons
Drawable folder, scout, options, pit;
folder = ContextCompat.getDrawable(activity, R.drawable.event);
scout = ContextCompat.getDrawable(activity, R.drawable.match);
options = ContextCompat.getDrawable(activity, R.drawable.settings_circle);
pit = ContextCompat.getDrawable(activity, R.drawable.pit);
// Set UI preferences to drawable icon
folder.mutate();
folder.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
scout.mutate();
scout.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
options.mutate();
options.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
pit.mutate();
pit.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
// Specify the list of items that have to be added to the drawer
ArrayList<IDrawerItem> items = new ArrayList<>();
if (events != null)
for (REvent e : events) {
items.add(new ExpandableDrawerItem().withTextColor(rui.getText()).withName(e.getName()).withTag(e.getID()).withArrowColor(rui.getText()).withIcon(folder).withIdentifier(Constants.HEADER).withSelectable(false).withSubItems(new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Scout").withLevel(2).withIcon(scout).withIdentifier(Constants.SCOUT).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("My matches").withLevel(2).withIcon(pit).withIdentifier(Constants.MY_MATCHES).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Settings").withLevel(2).withIcon(options).withIdentifier(Constants.EVENT_SETTINGS).withTag(e.getID())));
}
// Clear old events from the drawer
for (int i = 0; i < eventDrawer.getDrawerItems().size(); i++) {
long identifier = eventDrawer.getDrawerItems().get(i).getIdentifier();
if (identifier == Constants.HEADER || identifier == Constants.SCOUT || identifier == Constants.EVENT_SETTINGS || identifier == Constants.MY_MATCHES) {
eventDrawer.removeItemByPosition(i);
i = 0;
}
}
// Set defined list of items to drawer UI
for (int i = 0; i < items.size(); i++) eventDrawer.addItemAtPosition(items.get(i), i + 3);
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class EventDrawerManager method selectEvent.
/**
* Selects an event and flags the main activity to start loading
* teams and updating the UI appropriately
* @param ID the ID of the event to set as active
*/
public void selectEvent(int ID) {
if (events == null || events.size() == 0)
return;
for (REvent e : events) {
if (e.getID() == ID) {
event = e;
// Update the action bar title, it will get updated again when the teams are loaded by the LoadTeamsTask AsyncTask
if (((AppCompatActivity) activity).getSupportActionBar() != null) {
((AppCompatActivity) activity).getSupportActionBar().setTitle(event.getName());
((AppCompatActivity) activity).getSupportActionBar().setSubtitle("Teams");
}
// Save the event the user just selected to settings so Roblu can remember where they left off when the app is relaunched
RSettings settings = new IO(activity).loadSettings();
settings.setLastEventID(ID);
new IO(activity).saveSettings(settings);
// Tell the main activity to start loading the teams
// we'll provide a REvent reference for convenience, but TeamsView still has access to it with a getter
listener.eventSelected(event);
return;
}
}
}
Aggregations