Search in sources :

Example 16 with RForm

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

the class EventMergeTask method run.

@Override
public void run() {
    try {
        // Load teams for each event
        RTeam[] localTeams = io.loadTeams(localEventID);
        RTeam[] targetTeams = io.loadTeams(targetEventID);
        RForm localForm = io.loadForm(localEventID);
        RForm targetForm = io.loadForm(targetEventID);
        for (RTeam team : localTeams) team.verify(localForm);
        for (RTeam team : targetTeams) team.verify(targetForm);
        // Start merging
        for (RTeam local : localTeams) {
            // Find the team
            for (RTeam target : targetTeams) {
                if (local.getNumber() == target.getNumber()) {
                    for (RTab localTab : local.getTabs()) {
                        // Find tab
                        for (RTab targetTab : target.getTabs()) {
                            if (targetTab.getTitle().equalsIgnoreCase(localTab.getTitle())) {
                                // Match found, start merging metrics
                                for (RMetric localMetric : localTab.getMetrics()) {
                                    // Find metric
                                    for (RMetric targetMetric : targetTab.getMetrics()) {
                                        /*
                                         * Okay, the forms might be different, so we need to run some checks before we override the localMetric:
                                         * -Same instanceof type (obviously)
                                         * -Same title (within reason, do a little trimming, and ignore caps)
                                         * -ID - ID should not be considered, they might not be equal
                                         *
                                         * If we find a good candidate for the metric, override the local. Conditions
                                         * -Target is not modified: do nothing
                                         * -Target is modified: overwrite if local not modified
                                         * -Both modified: Compare team last edit time stamp
                                         */
                                        if ((localMetric.getClass().equals(targetMetric.getClass())) && localMetric.getTitle().toLowerCase().replaceAll(" ", "").equals(targetMetric.getTitle().toLowerCase().replaceAll(" ", ""))) {
                                            if (localMetric instanceof RGallery) {
                                                // Just add the images
                                                if (((RGallery) localMetric).getPictureIDs() == null)
                                                    ((RGallery) localMetric).setPictureIDs(new ArrayList<Integer>());
                                                if (((RGallery) localMetric).getImages() != null) {
                                                    // Add images to the current gallery
                                                    for (int i = 0; i < ((RGallery) targetMetric).getImages().size(); i++) {
                                                        ((RGallery) localMetric).getPictureIDs().add(io.savePicture(localEventID, ((RGallery) targetMetric).getImages().get(i)));
                                                    }
                                                }
                                                // Don't forget to clear the pictures from memory after they've been merged
                                                ((RGallery) targetMetric).setImages(null);
                                                local.setLastEdit(target.getLastEdit());
                                            } else // Alright, looks like we can do the checks now
                                            if (targetMetric.isModified() && !localMetric.isModified()) {
                                                int tabIndex = local.getTabs().indexOf(localTab);
                                                int metricIndex = local.getTabs().get(tabIndex).getMetrics().indexOf(localMetric);
                                                local.getTabs().get(tabIndex).getMetrics().set(metricIndex, targetMetric);
                                                local.setLastEdit(target.getLastEdit());
                                            } else if (targetMetric.isModified() && localMetric.isModified() && target.getLastEdit() > local.getLastEdit()) {
                                                int tabIndex = local.getTabs().indexOf(localTab);
                                                int metricIndex = local.getTabs().get(tabIndex).getMetrics().indexOf(localMetric);
                                                local.getTabs().get(tabIndex).getMetrics().set(metricIndex, targetMetric);
                                                local.setLastEdit(target.getLastEdit());
                                            }
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            io.saveTeam(localEventID, local);
        }
        listener.success();
    } catch (Exception e) {
        Log.d("RBS", "Error occurred in EventMergeTask: " + e.getMessage());
        listener.error();
    }
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) RGallery(com.cpjd.roblu.models.metrics.RGallery) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric)

Example 17 with RForm

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

the class Utils method createEmpty.

/**
 * Creates an empty form for an event (not technically empty).
 *
 * Makes sure that nothing is null and that we have the required
 * team name and team number fields
 * @return creates an empty RForm
 */
public static RForm createEmpty() {
    ArrayList<RMetric> pit = new ArrayList<>();
    ArrayList<RMetric> matches = new ArrayList<>();
    RTextfield name = new RTextfield(0, "Team name", false, true, "");
    RTextfield number = new RTextfield(1, "Team number", true, true, "");
    pit.add(name);
    pit.add(number);
    return new RForm(pit, matches);
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric)

Example 18 with RForm

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

the class IO method duplicateEvent.

/**
 * Duplicates an event. The EVENT MUST BE RELOADED, never ever return the REvent
 * reference.
 * @param event the REvent to duplicate
 * @param keepScoutingData true if scouting data should be preserved
 * @return reference to the duplicated event
 */
public REvent duplicateEvent(REvent event, boolean keepScoutingData) {
    int newID = getNewEventID();
    // New name
    event.setName("Copy of " + event.getName());
    // Set teams
    RTeam[] teams = loadTeams(event.getID());
    // Set forms
    RForm form = loadForm(event.getID());
    event.setID(newID);
    saveEvent(event);
    saveForm(newID, form);
    RTeam temp;
    for (int i = 0; teams != null && i < teams.length; i++) {
        temp = teams[i];
        if (!keepScoutingData)
            temp.setTabs(null);
        temp.setPage(1);
        saveTeam(newID, temp);
    }
    return event;
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam)

Aggregations

RForm (com.cpjd.roblu.models.RForm)18 IO (com.cpjd.roblu.io.IO)10 RTeam (com.cpjd.roblu.models.RTeam)9 ArrayList (java.util.ArrayList)9 RMetric (com.cpjd.roblu.models.metrics.RMetric)7 RTab (com.cpjd.roblu.models.RTab)6 RGallery (com.cpjd.roblu.models.metrics.RGallery)4 RTextfield (com.cpjd.roblu.models.metrics.RTextfield)4 UIHandler (com.cpjd.roblu.ui.UIHandler)4 StrictMode (android.os.StrictMode)3 Toolbar (android.support.v7.widget.Toolbar)3 Request (com.cpjd.http.Request)3 CloudCheckoutRequest (com.cpjd.requests.CloudCheckoutRequest)3 RCheckout (com.cpjd.roblu.models.RCheckout)3 REvent (com.cpjd.roblu.models.REvent)3 RSettings (com.cpjd.roblu.models.RSettings)3 RSyncSettings (com.cpjd.roblu.models.RSyncSettings)3 RUI (com.cpjd.roblu.models.RUI)3 IOException (java.io.IOException)3 CloudCheckout (com.cpjd.models.CloudCheckout)2