Search in sources :

Example 6 with RSettings

use of com.cpjd.roblu.models.RSettings 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 7 with RSettings

use of com.cpjd.roblu.models.RSettings 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 8 with RSettings

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

the class RUICategory method onBindView.

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    TextView titleView = view.findViewById(android.R.id.title);
    RSettings settings = new IO(view.getContext()).loadSettings();
    if (settings != null)
        titleView.setTextColor(settings.getRui().getAccent());
}
Also used : IO(com.cpjd.roblu.io.IO) TextView(android.widget.TextView) RSettings(com.cpjd.roblu.models.RSettings)

Aggregations

RSettings (com.cpjd.roblu.models.RSettings)8 IO (com.cpjd.roblu.io.IO)6 StrictMode (android.os.StrictMode)4 REvent (com.cpjd.roblu.models.REvent)4 RSyncSettings (com.cpjd.roblu.models.RSyncSettings)4 RUI (com.cpjd.roblu.models.RUI)4 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 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 TextView (android.widget.TextView)2 CloudCheckout (com.cpjd.models.CloudCheckout)2 CloudTeam (com.cpjd.models.CloudTeam)2 CloudTeamRequest (com.cpjd.requests.CloudTeamRequest)2 RTab (com.cpjd.roblu.models.RTab)2 RTeam (com.cpjd.roblu.models.RTeam)2 RGallery (com.cpjd.roblu.models.metrics.RGallery)2 RMetric (com.cpjd.roblu.models.metrics.RMetric)2 SyncHelper (com.cpjd.roblu.sync.SyncHelper)2