Search in sources :

Example 1 with REvent

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

the class Overview method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.overview_tab, container, false);
    Bundle bundle = this.getArguments();
    layout = view.findViewById(R.id.overview_layout);
    REvent event = (REvent) getArguments().getSerializable("event");
    RTeam team = new IO(getActivity()).loadTeam(event.getID(), TeamViewer.team.getID());
    rMetricToUI = new RMetricToUI(getActivity(), new IO(getActivity()).loadSettings().getRui(), true);
    try {
        /*
         * Do statistics generation, this will generate graphs for certain metrics
         */
        // Stores pie chart values, with the sub linked hash map <item,occurrences>, this will need to be processed later into a percent
        LinkedHashMap<String, LinkedHashMap<String, Double>> pieValues = new LinkedHashMap<>();
        // Stores line chart values, with the sub linked hash map <matchName,value>
        LinkedHashMap<String, LinkedHashMap<String, Double>> lineValues = new LinkedHashMap<>();
        // This isn't directly related, more of a side project
        ArrayList<RGallery> galleries = new ArrayList<>();
        for (RTab tab : team.getTabs()) {
            // Rule out disallowed tabs
            if (tab.getTitle().equalsIgnoreCase("PIT"))
                continue;
            // Start processing metrics
            for (RMetric metric : tab.getMetrics()) {
                if (metric instanceof RGallery) {
                    galleries.add((RGallery) metric);
                }
                if (!metric.isModified())
                    continue;
                // Pie graph metrics, scan these here
                if (metric instanceof RBoolean) {
                    LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    String key = ((RBoolean) metric).isValue() ? "Yes" : "No";
                    if (temp.get(key) == null)
                        temp.put(key, 1.0);
                    else
                        temp.put(key, temp.get(key) + 1);
                    pieValues.put(metric.getTitle(), temp);
                } else if (metric instanceof RCheckbox) {
                    if (((RCheckbox) metric).getValues() != null) {
                        for (Object key : ((RCheckbox) metric).getValues().keySet()) {
                            LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                            if (temp == null)
                                temp = new LinkedHashMap<>();
                            if (temp.get(key.toString()) == null)
                                temp.put(key.toString(), 1.0);
                            else
                                temp.put(key.toString(), temp.get(key.toString()) + 1);
                            pieValues.put(metric.getTitle(), temp);
                        }
                    }
                } else if (metric instanceof RChooser) {
                    LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    if (temp.get(metric.toString()) == null)
                        temp.put(metric.toString(), 1.0);
                    else
                        temp.put(metric.toString(), temp.get(metric.toString()) + 1);
                    pieValues.put(metric.getTitle(), temp);
                } else // Line chart metrics
                if (metric instanceof RCounter || metric instanceof RSlider || metric instanceof RStopwatch || metric instanceof RCalculation) {
                    LinkedHashMap<String, Double> temp = lineValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    temp.put(tab.getTitle(), Double.parseDouble(metric.toString()));
                    lineValues.put(metric.getTitle(), temp);
                }
            }
        }
        // Add the divider metrics by position, -1 if no metric after it, or at the end
        ArrayList<RDivider> addedDividers = new ArrayList<>();
        /*
         * Add the charts!
         */
        for (Object key : lineValues.keySet()) {
            if (lineValues.get(key.toString()).size() >= 2) {
                loop: for (RTab tab : team.getTabs()) {
                    for (int i = 0; i < tab.getMetrics().size(); i++) {
                        if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
                            // See if there is a RDivider hiding above this metric
                            for (int j = i; j >= 0; j--) {
                                if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
                                    layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
                                    addedDividers.add((RDivider) tab.getMetrics().get(j));
                                    break loop;
                                }
                            }
                        }
                    }
                }
                layout.addView(rMetricToUI.generateLineChart(key.toString(), lineValues.get(key.toString())));
            }
        }
        // Process the pie charts
        for (Object key : pieValues.keySet()) {
            if (pieValues.get(key.toString()).size() <= 1)
                continue;
            int metricID = 0;
            loop: for (RTab tab : team.getTabs()) {
                for (int i = 0; i < tab.getMetrics().size(); i++) {
                    if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
                        metricID = tab.getMetrics().get(i).getID();
                        // See if there is a RDivider hiding above this metric
                        for (int j = i; j >= 0; j--) {
                            if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
                                layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
                                addedDividers.add((RDivider) tab.getMetrics().get(j));
                                break loop;
                            }
                        }
                    }
                }
            }
            for (Object key2 : pieValues.get(key.toString()).keySet()) {
                if (numModified(team.getTabs(), metricID) != 0)
                    pieValues.get(key.toString()).put(key2.toString(), pieValues.get(key.toString()).get(key2.toString()) / (double) numModified(team.getTabs(), metricID));
            }
            layout.addView(rMetricToUI.generatePieChart(key.toString(), pieValues.get(key.toString())));
        }
        /*
         * Find the image with the most entropy, and add
         * it as the "featured" image
         */
        galleryLoop: for (int j = galleries.size() - 1; j >= 0; j--) {
            if (galleries.get(j).getImages() != null && galleries.get(j).getImages().size() > 0) {
                for (int i = galleries.get(j).getImages().size() - 1; i >= 0; i--) {
                    try {
                        layout.addView(rMetricToUI.getImageView("Featured image", BitmapFactory.decodeByteArray(galleries.get(j).getImages().get(i), 0, galleries.get(j).getImages().get(i).length)));
                        break galleryLoop;
                    } catch (Exception e) {
                        Log.d("RBS", "Failed to load featured image: " + e.getMessage());
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.d("RBS", "Failed to generate graphs for this team profile.");
    }
    /*
         * Attempt to download TBA info for this team
         */
    if (!team.hasTBAInfo()) {
        if (event.getKey() != null && event.getKey().length() >= 4)
            new TBATeamInfoTask(view.getContext(), team.getNumber(), event.getKey().substring(0, 4), this);
    } else {
        // TBA info card
        layout.addView(rMetricToUI.getInfoField("TBA.com information", TeamViewer.team.getTbaInfo(), TeamViewer.team.getWebsite(), TeamViewer.team.getNumber()), 0);
        if (TeamViewer.team.getImage() != null) {
            // Image view
            Bitmap bitmap = BitmapFactory.decodeByteArray(TeamViewer.team.getImage(), 0, TeamViewer.team.getImage().length);
            layout.addView(rMetricToUI.getImageView("Robot", bitmap));
        }
    }
    /*
         * Add UI cards to the layout
         */
    // "Other" card
    layout.addView(rMetricToUI.getInfoField("Other", "Last edited: " + Utils.convertTime(team.getLastEdit()) + "\nSize on disk: " + new IO(view.getContext()).getTeamSize(bundle.getInt("eventID"), team.getID()) + " KB", "", 0));
    return view;
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RDivider(com.cpjd.roblu.models.metrics.RDivider) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTab(com.cpjd.roblu.models.RTab) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) LinkedHashMap(java.util.LinkedHashMap) Bitmap(android.graphics.Bitmap) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) REvent(com.cpjd.roblu.models.REvent) TBATeamInfoTask(com.cpjd.roblu.ui.team.TBATeamInfoTask) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTeam(com.cpjd.roblu.models.RTeam) Bundle(android.os.Bundle) IO(com.cpjd.roblu.io.IO) View(android.view.View) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCounter(com.cpjd.roblu.models.metrics.RCounter) RMetricToUI(com.cpjd.roblu.ui.forms.RMetricToUI)

Example 2 with REvent

use of com.cpjd.roblu.models.REvent 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();
}
Also used : UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) RUI(com.cpjd.roblu.models.RUI) RelativeLayout(android.widget.RelativeLayout) UnpackTBAEvent(com.cpjd.roblu.tba.UnpackTBAEvent) REvent(com.cpjd.roblu.models.REvent) Event(com.cpjd.models.Event) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with REvent

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

the class EventDepacker method run.

@Override
public void run() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    Log.d("RBS", "Executing EventDepacker task...");
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    RSettings settings = io.loadSettings();
    RSyncSettings cloudSettings = io.loadCloudSettings();
    cloudSettings.setTeamSyncID(0);
    cloudSettings.getCheckoutSyncIDs().clear();
    cloudSettings.setPurgeRequested(false);
    io.saveCloudSettings(cloudSettings);
    Request r = new Request(settings.getServerIP());
    CloudTeamRequest ctr = new CloudTeamRequest(r, settings.getCode());
    if (teamNumber != -1) {
        ctr.setCode("");
        ctr.setTeamNumber(teamNumber);
    }
    CloudCheckoutRequest ccr = new CloudCheckoutRequest(r, settings.getCode());
    if (teamNumber != -1) {
        ccr.setTeamCode("");
        ccr.setTeamNumber(teamNumber);
    }
    if (teamNumber == -1 && (settings.getCode() == null || settings.getCode().equals(""))) {
        if (listener != null)
            listener.errorOccurred("No team code found in settings. Unable to import event.");
        return;
    }
    // Ping
    if (!r.ping()) {
        if (listener != null)
            listener.errorOccurred("It appears as though the server is offline. Try again later.");
        return;
    }
    if (!ctr.isActive()) {
        if (listener != null)
            listener.errorOccurred("No event found on Roblu Cloud.");
        return;
    }
    /*
         * Download everything
         *
         */
    CloudTeam team = ctr.getTeam(-1);
    REvent event;
    try {
        // Create a new event
        event = new REvent(io.getNewEventID(), team.getActiveEventName());
        event.setKey(team.getTbaKey());
        // should be -1 if cloud is not enabled
        event.setReadOnlyTeamNumber(teamNumber);
        event.setID(io.getNewEventID());
        event.setCloudEnabled(true);
        io.saveEvent(event);
        settings.setTeamNumber((int) team.getNumber());
        settings.setRui(mapper.readValue(team.getUi(), RUI.class));
        io.saveSettings(settings);
        RForm form = mapper.readValue(team.getForm(), RForm.class);
        io.saveForm(event.getID(), form);
    } catch (Exception e) {
        Log.d("RBS", "Failed to download event");
        listener.errorOccurred("Failed to import Roblu Cloud event.");
        return;
    }
    /*
         * Un-package checkouts into a teams array
         */
    ArrayList<RCheckout> checkouts = new ArrayList<>();
    try {
        CloudCheckout[] pulledCheckouts = ccr.pullCheckouts(null, true);
        for (CloudCheckout s : pulledCheckouts) checkouts.add(mapper.readValue(s.getContent(), RCheckout.class));
    } catch (IOException e) {
        Log.d("RBS", "Failed to de-package checkouts.");
        listener.errorOccurred("Failed to import Roblu Cloud event.");
        return;
    }
    /*
         * Start sorting the checkouts into teams
         */
    ArrayList<RTeam> teams = new ArrayList<>();
    for (RCheckout checkout : checkouts) {
        // First, check if the team has already been created
        boolean found = false;
        for (RTeam t : teams) {
            if (t.getID() == checkout.getTeam().getID()) {
                // Add the checkout information to the team
                t.getTabs().addAll(checkout.getTeam().getTabs());
                found = true;
                break;
            }
            t.setLastEdit(checkout.getTime());
        }
        // If not found, create a new team
        if (!found) {
            RTeam newTeam = new RTeam(checkout.getTeam().getName(), checkout.getTeam().getNumber(), checkout.getTeam().getID());
            newTeam.setTabs(new ArrayList<RTab>());
            newTeam.getTabs().addAll(checkout.getTeam().getTabs());
            teams.add(newTeam);
        }
    }
    Log.d("RBS", "Created " + teams.size() + " teams");
    /*
         * Unpack images
         */
    for (RCheckout checkout : checkouts) {
        for (RTab tab : checkout.getTeam().getTabs()) {
            for (RMetric metric : tab.getMetrics()) {
                if (metric instanceof RGallery) {
                    for (int i = 0; ((RGallery) metric).getImages() != null && i < ((RGallery) metric).getImages().size(); i++) {
                        int picID = io.savePicture(event.getID(), ((RGallery) metric).getImages().get(i));
                        if (picID != -1) {
                            ((RGallery) metric).setPictureIDs(new ArrayList<Integer>());
                            ((RGallery) metric).getPictureIDs().add(picID);
                        }
                    }
                    if (((RGallery) metric).getImages() != null)
                        ((RGallery) metric).getImages().clear();
                }
            }
        }
    }
    /*
         * Save teams
         * -Teams don't need to be verified since the form has also been pulled from the server
         */
    for (RTeam t : teams) {
        Collections.sort(t.getTabs());
        io.saveTeam(event.getID(), t);
    }
    // Remove all the other synced events
    REvent[] events = io.loadEvents();
    for (int i = 0; events != null && i < events.length; i++) {
        events[i].setCloudEnabled(events[i].getID() == event.getID());
        io.saveEvent(events[i]);
    }
    /*
         * Add default sync ids
         */
    for (RCheckout checkout : checkouts) {
        cloudSettings.getCheckoutSyncIDs().put(checkout.getID(), 0L);
    }
    io.saveCloudSettings(cloudSettings);
    if (listener != null) {
        listener.success(event);
    }
}
Also used : RTab(com.cpjd.roblu.models.RTab) RGallery(com.cpjd.roblu.models.metrics.RGallery) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) StrictMode(android.os.StrictMode) RForm(com.cpjd.roblu.models.RForm) CloudTeamRequest(com.cpjd.requests.CloudTeamRequest) REvent(com.cpjd.roblu.models.REvent) CloudTeam(com.cpjd.models.CloudTeam) RCheckout(com.cpjd.roblu.models.RCheckout) RSyncSettings(com.cpjd.roblu.models.RSyncSettings) CloudCheckout(com.cpjd.models.CloudCheckout) RSettings(com.cpjd.roblu.models.RSettings) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest) RTeam(com.cpjd.roblu.models.RTeam) RUI(com.cpjd.roblu.models.RUI) Request(com.cpjd.http.Request) CloudTeamRequest(com.cpjd.requests.CloudTeamRequest) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest) IOException(java.io.IOException) IOException(java.io.IOException)

Example 4 with REvent

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

the class Service method loop.

/**
 * This is the main background service looper, this should perform any necessary
 * Roblu Cloud sync operations
 */
public void loop() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    if (!Utils.hasInternetConnection(getApplicationContext())) {
        Log.d("RBS", "No internet connection detected. Ending loop() early.");
        return;
    }
    /*
         * Create all the utilities we need for this loop
         */
    IO io = new IO(getApplicationContext());
    RSettings settings = io.loadSettings();
    RSyncSettings cloudSettings = io.loadCloudSettings();
    Request r = new Request(settings.getServerIP());
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    CloudTeamRequest teamRequest = new CloudTeamRequest(r, settings.getCode());
    CloudCheckoutRequest checkoutRequest = new CloudCheckoutRequest(r, settings.getCode());
    boolean result = r.ping();
    if (result)
        Utils.requestServerHealthRefresh(getApplicationContext(), "online");
    else
        Utils.requestServerHealthRefresh(getApplicationContext(), "offline");
    if (!result) {
        Log.d("RBS", "Roblu server is down. Unable to connect.");
        return;
    }
    // Load the active event
    REvent[] events = io.loadEvents();
    REvent activeEvent = null;
    for (int i = 0; events != null && events.length > 0 && i < events.length; i++) {
        if (events[i].isCloudEnabled()) {
            activeEvent = events[i];
            break;
        }
    }
    if (activeEvent != null && activeEvent.getReadOnlyTeamNumber() != -1) {
        teamRequest.setTeamNumber(activeEvent.getReadOnlyTeamNumber());
        teamRequest.setCode("");
        checkoutRequest.setTeamNumber(activeEvent.getReadOnlyTeamNumber());
        checkoutRequest.setTeamCode("");
    }
    /*
         * Check if a purge is requested
         */
    if (cloudSettings.isPurgeRequested() && checkoutRequest.purge()) {
        cloudSettings.setPurgeRequested(false);
        cloudSettings.setTeamSyncID(0);
        cloudSettings.getCheckoutSyncIDs().clear();
        Log.d("RBS", "Event successfully purged from Roblu Cloud.");
        io.saveCloudSettings(cloudSettings);
        Notify.notifyNoAction(getApplicationContext(), "Event purged", "Active event successfully removed from Roblu Cloud.");
        return;
    }
    if (activeEvent == null)
        return;
    // Create the sync helper
    SyncHelper syncHelper = new SyncHelper(getApplicationContext(), activeEvent, SyncHelper.MODES.NETWORK);
    RForm form = io.loadForm(activeEvent.getID());
    /*
         * Check to see if the form was modified and needs to be uploaded
         */
    if (form.isUploadRequired()) {
        try {
            teamRequest.pushForm(mapper.writeValueAsString(form));
            form.setUploadRequired(false);
            io.saveForm(activeEvent.getID(), form);
            Notify.notifyNoAction(getApplicationContext(), "Form uploaded", "Successfully uploaded RForm to the server.");
            Log.d("RBS-Service", "Successfully uploaded RForm to the server.");
        } catch (Exception e) {
            Log.d("RBS-Service", "Failed to complete an upload required request for RForm.");
        }
    }
    /*
         * Check to see if the UI model should be uploaded
         */
    if (settings.getRui().isUploadRequired()) {
        try {
            teamRequest.pushUI(mapper.writeValueAsString(settings.getRui()));
            settings.getRui().setUploadRequired(false);
            io.saveSettings(settings);
            Log.d("RBS-Service", "Successfully uploaded RUI to the server.");
        } catch (Exception e) {
            Log.d("RBS-Service", "Failed to complete an upload required request for RUI.");
        }
    }
    /*
         * Check for cloud team updates
         */
    try {
        CloudTeam t = teamRequest.getTeam(cloudSettings.getTeamSyncID());
        if (t != null) {
            /*
                 * If a different master app overwrites the cloud app with a different event, run this check to prevent conflicts
                 * from happening.
                 */
            if (t.getActiveEventName() != null && !t.getActiveEventName().equals("") && activeEvent.getName() != null && !t.getActiveEventName().equals(activeEvent.getName())) {
                activeEvent.setCloudEnabled(false);
                cloudSettings.getCheckoutSyncIDs().clear();
                io.saveCloudSettings(cloudSettings);
                io.saveEvent(activeEvent);
                return;
            }
            // Merge RForm
            form = mapper.readValue(t.getForm(), RForm.class);
            form.setUploadRequired(false);
            io.saveForm(activeEvent.getID(), form);
            // Merge RUI
            RUI rui = mapper.readValue(t.getUi(), RUI.class);
            rui.setUploadRequired(false);
            settings.setRui(rui);
            // make sure to refresh this
            settings = io.loadSettings();
            io.saveSettings(settings);
            // Update the sync ID
            cloudSettings.setTeamSyncID((int) t.getSyncID());
            io.saveCloudSettings(cloudSettings);
            Log.d("RBS-Service", "Successfully pulled team data from the server.");
        }
    } catch (Exception e) {
        Log.d("RBS-Service", "Failed to pull team data from the server: " + e.getMessage());
    }
    /*
         *
         * Alright, into the belly of the beast.
         * This code will check for completed checkouts on the server and merge them with the local repository.
         * Shall we begin?
         *
         */
    try {
        CloudCheckout[] checkouts = checkoutRequest.pullCompletedCheckouts(syncHelper.packSyncIDs(cloudSettings.getCheckoutSyncIDs()));
        syncHelper.unpackCheckouts(checkouts, cloudSettings);
        io.saveCloudSettings(cloudSettings);
    } catch (Exception e) {
        Log.d("RBS-Service", "An error occurred while fetching completed checkouts. " + e.getMessage());
    }
    /*
         * Next, uploading everything from /pending/
         */
    try {
        Log.d("RBS-Service", "Checking for any checkouts to upload...");
        ArrayList<RCheckout> checkouts = new ArrayList<>(Arrays.asList(io.loadPendingCheckouts()));
        boolean wasSuccess = checkoutRequest.pushCheckouts(syncHelper.packCheckouts(checkouts));
        if (wasSuccess) {
            for (RCheckout checkout : checkouts) {
                io.deletePendingCheckout(checkout.getID());
            }
            Notify.notifyNoAction(getApplicationContext(), "Uploaded new checkouts", "Uploaded " + checkouts.size() + " new checkout(s).");
        }
        Log.d("RBS-Service", "Uploaded " + checkouts.size() + " checkouts.");
    } catch (Exception e) {
        Log.d("RBS-Service", "An error occurred while attempting to push /pending/ checkouts: " + e.getMessage());
    }
    io.saveCloudSettings(cloudSettings);
    Log.d("RBS-Service", "Sleeping Roblu background service for 10 seconds...");
}
Also used : IO(com.cpjd.roblu.io.IO) RUI(com.cpjd.roblu.models.RUI) Request(com.cpjd.http.Request) CloudTeamRequest(com.cpjd.requests.CloudTeamRequest) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest) ArrayList(java.util.ArrayList) StrictMode(android.os.StrictMode) RForm(com.cpjd.roblu.models.RForm) CloudTeamRequest(com.cpjd.requests.CloudTeamRequest) REvent(com.cpjd.roblu.models.REvent) SyncHelper(com.cpjd.roblu.sync.SyncHelper) CloudTeam(com.cpjd.models.CloudTeam) RCheckout(com.cpjd.roblu.models.RCheckout) RSyncSettings(com.cpjd.roblu.models.RSyncSettings) CloudCheckout(com.cpjd.models.CloudCheckout) RSettings(com.cpjd.roblu.models.RSettings) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CloudCheckoutRequest(com.cpjd.requests.CloudCheckoutRequest)

Example 5 with REvent

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

the class Utils method launchEventPickerWithExcludedEvent.

/**
 * For certain things, the user may need to select an event from a list of locally stored event,
 * this method does just that! The EventSelectListener method will trigger when an event is successfully
 * selected.
 * @param context context reference
 * @param listener listener to respond to events
 * @return true if some events exist
 */
public static boolean launchEventPickerWithExcludedEvent(Context context, int eventIDExcluded, final EventDrawerManager.EventSelectListener listener) {
    final Dialog d = new Dialog(context);
    d.setTitle("Pick event:");
    d.setContentView(R.layout.event_import_dialog);
    final Spinner spinner = d.findViewById(R.id.type);
    String[] values;
    final REvent[] events = new IO(context).loadEvents();
    if (events == null || events.length == 0)
        return false;
    final ArrayList<REvent> eventArrayList = new ArrayList<>();
    for (REvent event : events) {
        if (event.getID() != eventIDExcluded)
            eventArrayList.add(event);
    }
    values = new String[eventArrayList.size()];
    for (int i = 0; i < values.length; i++) {
        values[i] = eventArrayList.get(i).getName();
    }
    ArrayAdapter<String> adp = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, values);
    adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adp);
    Button button = d.findViewById(R.id.button7);
    button.setText("Select");
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            listener.eventSelected(eventArrayList.get(spinner.getSelectedItemPosition()));
            d.dismiss();
        }
    });
    if (d.getWindow() != null)
        d.getWindow().getAttributes().windowAnimations = new IO(context).loadSettings().getRui().getAnimation();
    d.show();
    return true;
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) Button(android.widget.Button) Dialog(android.app.Dialog) REvent(com.cpjd.roblu.models.REvent) ArrayAdapter(android.widget.ArrayAdapter)

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