Search in sources :

Example 11 with REvent

use of com.cpjd.roblu.models.REvent 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;
        }
    }
}
Also used : IO(com.cpjd.roblu.io.IO) REvent(com.cpjd.roblu.models.REvent) RSettings(com.cpjd.roblu.models.RSettings)

Example 12 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class EventEditor method createEvent.

/**
 * This method is more of a courtesy method to the source code reader,
 * an event will get created from EventEditor whenever this method is called, no exceptions.
 * @param form the form to save with the event
 */
private void createEvent(RForm form) {
    IO io = new IO(getApplicationContext());
    REvent event = new REvent(io.getNewEventID(), eventName.getText().toString());
    // we call this twice because the /event/ dir is required for the form to save
    io.saveEvent(event);
    io.saveForm(event.getID(), form);
    /*
         * We need to check if the user included any TBA information that we should include in this event creation
         */
    if (!editing && getIntent().getSerializableExtra("tbaEvent") != null) {
        ProgressDialog d = ProgressDialog.show(this, "Hold on tight!", "Generating team profiles from event...", true);
        d.setCancelable(false);
        event.setKey(((Event) getIntent().getSerializableExtra("tbaEvent")).key);
        io.saveEvent(event);
        UnpackTBAEvent unpackTBAEvent = new UnpackTBAEvent((Event) getIntent().getSerializableExtra("tbaEvent"), event.getID(), this, d);
        if (((Switch) findViewById(R.id.switch1)).isChecked())
            unpackTBAEvent.setRandomize(true);
        unpackTBAEvent.execute();
    } else /*
         * If we started the UnpackTask, then we have to wait to return, if not, return now
         */
    {
        io.saveEvent(event);
        Intent result = new Intent();
        result.putExtra("eventID", event.getID());
        setResult(Constants.NEW_EVENT_CREATED, result);
        finish();
    }
}
Also used : Switch(android.widget.Switch) IO(com.cpjd.roblu.io.IO) UnpackTBAEvent(com.cpjd.roblu.tba.UnpackTBAEvent) REvent(com.cpjd.roblu.models.REvent) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog)

Example 13 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class InitPacker method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    /*
         * Make sure this thread has network permissions
         */
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    Log.d("RBS", "Executing InitPacker task...");
    IO io = ioWeakReference.get();
    RSettings settings = io.loadSettings();
    RSyncSettings cloudSettings = io.loadCloudSettings();
    cloudSettings.setPurgeRequested(false);
    io.saveCloudSettings(cloudSettings);
    io.saveSettings(settings);
    Request r = new Request(settings.getServerIP());
    if (!r.ping()) {
        listener.statusUpdate("It appears as though the server is offline. Try again later.");
        return false;
    }
    /*
         * Load all teams from the event, also make sure that that the teams are verified
         */
    REvent event = io.loadEvent(eventID);
    event.setReadOnlyTeamNumber(-1);
    RForm form = io.loadForm(eventID);
    RTeam[] teams = io.loadTeams(eventID);
    if (event == null || form == null || teams == null || teams.length == 0) {
        Log.d("RBS", "Not enough data to warrant an event upload.");
        listener.statusUpdate("This event doesn't contain any teams or sufficient data to upload to the server. Create some teams!");
        return false;
    }
    // Generate the checkouts
    SyncHelper syncHelper = new SyncHelper(io, event, SyncHelper.MODES.NETWORK);
    ArrayList<RCheckout> checkouts = syncHelper.generateCheckoutsFromEvent(teams, -1);
    // Remove field data
    try {
        for (RCheckout checkout : checkouts) {
            for (RTab tab : checkout.getTeam().getTabs()) {
                for (RMetric metric : tab.getMetrics()) {
                    if (metric instanceof RFieldData) {
                        ((RFieldData) metric).setData(null);
                    }
                }
            }
        }
    } catch (Exception e) {
    // Doesn't matter
    }
    /*
         * Convert into JSON and upload
         */
    ObjectMapper mapper = new ObjectMapper();
    try {
        // serialization all the checkouts and pack them in an json array, this will be processed by the server
        String serializedCheckouts = syncHelper.packCheckouts(checkouts);
        String serializedForm = mapper.writeValueAsString(form);
        String serializedUI = mapper.writeValueAsString(settings.getRui());
        String eventName = event.getName();
        if (eventName == null)
            eventName = "";
        if (event.getKey() == null)
            event.setKey("");
        CloudCheckoutRequest ccr = new CloudCheckoutRequest(r, settings.getCode());
        Log.d("RBS", "Initializing init packer upload...");
        boolean success = ccr.init(settings.getTeamNumber(), eventName, serializedForm, serializedUI, serializedCheckouts, event.getKey());
        /*
             * Disable all other events with cloud syncing enabled
             */
        if (success) {
            REvent[] events = io.loadEvents();
            for (int i = 0; events != null && i < events.length; i++) {
                events[i].setCloudEnabled(events[i].getID() == eventID);
                io.saveEvent(events[i]);
            }
            cloudSettings.getCheckoutSyncIDs().clear();
            /*
                 * Add default sync ids
                 */
            for (RCheckout checkout : checkouts) {
                cloudSettings.getCheckoutSyncIDs().put(checkout.getID(), 0L);
            }
            io.saveCloudSettings(cloudSettings);
            io.saveSettings(settings);
        } else
            listener.statusUpdate("An error occurred. Event was not uploaded.");
        return success;
    } catch (Exception e) {
        Log.d("RBS", "An error occurred in InitPacker: " + e.getMessage());
        listener.statusUpdate("An error occurred. Event was not uploaded.");
        return false;
    } finally {
        /*
             * Set all images to null to return memory to normal
             */
        for (RCheckout checkout : checkouts) {
            for (RTab tab : checkout.getTeam().getTabs()) {
                for (RMetric metric : tab.getMetrics()) {
                    if (metric instanceof RGallery) {
                        ((RGallery) metric).setImages(null);
                    }
                }
            }
        }
    }
}
Also used : RTab(com.cpjd.roblu.models.RTab) RGallery(com.cpjd.roblu.models.metrics.RGallery) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RMetric(com.cpjd.roblu.models.metrics.RMetric) StrictMode(android.os.StrictMode) RForm(com.cpjd.roblu.models.RForm) REvent(com.cpjd.roblu.models.REvent) SyncHelper(com.cpjd.roblu.sync.SyncHelper) RCheckout(com.cpjd.roblu.models.RCheckout) RSyncSettings(com.cpjd.roblu.models.RSyncSettings) RSettings(com.cpjd.roblu.models.RSettings) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest) RTeam(com.cpjd.roblu.models.RTeam) IO(com.cpjd.roblu.io.IO) Request(com.cpjd.http.Request) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest)

Example 14 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class BTServer method run.

/**
 * Starts the sync task
 */
@Override
public void run() {
    /*
         * Load the active Bluetooth event
         */
    IO io = new IO(bluetooth.getActivity());
    REvent[] events = io.loadEvents();
    if (events == null || events.length == 0) {
        bluetooth.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(bluetooth.getActivity(), "No events found. Please create an event to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
            }
        });
        pd.dismiss();
        return;
    }
    for (REvent event : events) {
        if (event.isBluetoothEnabled()) {
            this.event = event;
            break;
        }
    }
    if (this.event == null) {
        bluetooth.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(bluetooth.getActivity(), "No active Bluetooth event found. Please enable Bluetooth in event settings to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
            }
        });
        pd.dismiss();
        return;
    }
    this.syncHelper = new SyncHelper(bluetooth.getActivity(), this.event, SyncHelper.MODES.BLUETOOTH);
    if (bluetooth.isEnabled()) {
        bluetooth.startServer();
    } else
        bluetooth.enable();
}
Also used : IO(com.cpjd.roblu.io.IO) REvent(com.cpjd.roblu.models.REvent) SyncHelper(com.cpjd.roblu.sync.SyncHelper)

Example 15 with REvent

use of com.cpjd.roblu.models.REvent 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.");
    }
}
Also used : StrictMode(android.os.StrictMode) TBA(com.cpjd.main.TBA) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) REvent(com.cpjd.roblu.models.REvent) Event(com.cpjd.models.Event) Row(org.apache.poi.ss.usermodel.Row) Match(com.cpjd.models.Match)

Aggregations

REvent (com.cpjd.roblu.models.REvent)15 IO (com.cpjd.roblu.io.IO)11 RTeam (com.cpjd.roblu.models.RTeam)5 ArrayList (java.util.ArrayList)5 StrictMode (android.os.StrictMode)4 RSettings (com.cpjd.roblu.models.RSettings)4 RTab (com.cpjd.roblu.models.RTab)4 RGallery (com.cpjd.roblu.models.metrics.RGallery)4 RMetric (com.cpjd.roblu.models.metrics.RMetric)4 View (android.view.View)3 TextView (android.widget.TextView)3 Request (com.cpjd.http.Request)3 CloudCheckoutRequest (com.cpjd.requests.CloudCheckoutRequest)3 RCheckout (com.cpjd.roblu.models.RCheckout)3 RForm (com.cpjd.roblu.models.RForm)3 RSyncSettings (com.cpjd.roblu.models.RSyncSettings)3 RUI (com.cpjd.roblu.models.RUI)3 SyncHelper (com.cpjd.roblu.sync.SyncHelper)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Dialog (android.app.Dialog)2