Search in sources :

Example 6 with RCheckout

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

the class MyMatches method checkoutClicked.

// user tapped on a match, let's load the "jump to team" dialog
public void checkoutClicked(final View v) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // must be run on UI thread since it's a dialog and it's in a callback
            final RCheckout checkout = adapter.getCheckouts().get(rv.getChildAdapterPosition(v));
            final Dialog d = new Dialog(MyMatches.this);
            d.setTitle("Open team ");
            d.setContentView(R.layout.event_import_dialog);
            // load up a chooser with 6 teams into it (3 teammates, 3 opponents)
            final Spinner spinner = d.findViewById(R.id.type);
            String[] values = new String[6];
            for (int i = 0; i < values.length; i++) {
                if (i < 3)
                    values[i] = checkout.getTeam().getTabs().get(0).getTeammates().get(i).getNumber() + " (Teammate)";
                else
                    values[i] = checkout.getTeam().getTabs().get(0).getOpponents().get(i - 3).getNumber() + " (Opponent)";
            }
            TextView t = d.findViewById(R.id.spinner_tip);
            t.setText(R.string.team);
            ArrayAdapter<String> adp = new ArrayAdapter<>(MyMatches.this, 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(R.string.open);
            // launch teamviewer if the user selects a team and taps "open"
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // 0,1,2,3,4,5
                    int pos = spinner.getSelectedItemPosition();
                    int ID;
                    // select the right team to load, since first 3 teams are our teammates, and last 3 are our opponents, we have to choose the correct array to pull from
                    if (pos < 3)
                        ID = checkout.getTeam().getTabs().get(0).getTeammates().get(pos).getID();
                    else
                        ID = checkout.getTeam().getTabs().get(0).getOpponents().get(pos - 3).getID();
                    Intent intent = new Intent(MyMatches.this, TeamViewer.class);
                    intent.putExtra("teamID", ID);
                    intent.putExtra("eventID", eventID);
                    startActivity(intent);
                    d.dismiss();
                }
            });
            // sync animation with ui settings
            if (d.getWindow() != null)
                d.getWindow().getAttributes().windowAnimations = new IO(getApplicationContext()).loadSettings().getRui().getAnimation();
            // show the dialog
            d.show();
        }
    });
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Button(android.widget.Button) Dialog(android.app.Dialog) RCheckout(com.cpjd.roblu.models.RCheckout) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with RCheckout

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

the class BTServer method messageReceived.

@Override
public void messageReceived(String header, String message) {
    IO io = new IO(bluetooth.getActivity());
    switch(header) {
        case "SCOUTING_DATA":
            // Process scouting data
            try {
                JSONParser parser = new JSONParser();
                org.json.simple.JSONArray array = (org.json.simple.JSONArray) parser.parse(message);
                String[] received = new String[array.size()];
                for (int i = 0; i < array.size(); i++) received[i] = array.get(i).toString();
                syncHelper.unpackCheckouts(syncHelper.convertStringSerialToCloudCheckouts(received), null);
                Log.d("RBS", "Received " + array.size() + " checkouts from Roblu Scouter.");
            } catch (Exception e) {
                Log.d("RBS", "Failed to process checkouts received over Bluetooth: " + e.getMessage());
            }
            break;
        case "requestForm":
            Log.d("RBS", "Roblu Scouter requested form, responding with it.");
            try {
                bluetooth.send("FORM", mapper.writeValueAsString(io.loadForm(event.getID())));
            } catch (Exception e) {
                Log.d("RBS", "Failed to parse form as JSON.");
            }
            break;
        case "requestUI":
            Log.d("RBS", "Roblu Scouter requested ui, responding with it.");
            try {
                bluetooth.send("UI", mapper.writeValueAsString(io.loadSettings().getRui()));
            } catch (Exception e) {
                Log.d("RBS", "Failed to parse form as JSON.");
            }
            break;
        case "requestCheckouts":
            Log.d("RBS", "Roblu Scouter requested checkouts, responding with them.");
            // Get the timestamp
            long time = Long.parseLong(message.split(":")[1]);
            ArrayList<RCheckout> checkouts = syncHelper.generateCheckoutsFromEvent(io.loadTeams(event.getID()), time);
            try {
                bluetooth.send("CHECKOUTS", syncHelper.packCheckouts(checkouts));
            } catch (Exception e) {
                Log.d("RBS", "Failed to map checkouts to Bluetooth output stream. " + e.getMessage());
            }
            break;
        case "requestNumber":
            Log.d("RBS", "Roblu Scouter requested team number, responding with it.");
            bluetooth.send("NUMBER", String.valueOf(io.loadSettings().getTeamNumber()));
            break;
        case "requestEventName":
            Log.d("RBS", "Roblu Scouter requested event name, responding with it.");
            bluetooth.send("EVENT_NAME", event.getName());
            break;
        case "DONE":
            Log.d("RBS", "Roblu Scouter requested DONE. Confirming.");
            bluetooth.send("DONE", "noParams");
            pd.dismiss();
            bluetooth.disconnect();
            if (bluetooth.isEnabled()) {
                bluetooth.startServer();
            } else
                bluetooth.enable();
            break;
    }
}
Also used : IO(com.cpjd.roblu.io.IO) RCheckout(com.cpjd.roblu.models.RCheckout) JSONParser(org.json.simple.parser.JSONParser)

Example 8 with RCheckout

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

the class IO method loadPendingCheckouts.

/**
 * Loads all checkouts in the file system
 * @return Array of RCheckout object instances
 */
public RCheckout[] loadPendingCheckouts() {
    File[] files = getChildFiles(new File(context.getFilesDir(), PREFIX + File.separator + "pending" + File.separator));
    if (files == null || files.length == 0)
        return null;
    RCheckout[] checkouts = new RCheckout[files.length];
    for (int i = 0; i < checkouts.length; i++) {
        checkouts[i] = loadPendingCheckout(Integer.parseInt(files[i].getName().replace(".ser", "")));
    }
    return checkouts;
}
Also used : RCheckout(com.cpjd.roblu.models.RCheckout) File(java.io.File)

Example 9 with RCheckout

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

the class TeamsView method showTeamCreateDialog.

/**
 * Shows the team create dialog where the user can manually create a team
 */
private void showTeamCreateDialog() {
    if (eventDrawerManager.getEvent() == null)
        return;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    final AppCompatEditText input = new AppCompatEditText(this);
    Utils.setInputTextLayoutColor(settings.getRui().getAccent(), null, input);
    input.setHighlightColor(settings.getRui().getAccent());
    input.setHintTextColor(settings.getRui().getText());
    input.setTextColor(settings.getRui().getText());
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setHint("Team name");
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(30);
    input.setFilters(FilterArray);
    layout.addView(input);
    final AppCompatEditText input2 = new AppCompatEditText(this);
    Utils.setInputTextLayoutColor(settings.getRui().getAccent(), null, input2);
    input2.setHighlightColor(settings.getRui().getAccent());
    input2.setHintTextColor(settings.getRui().getText());
    input2.setTextColor(settings.getRui().getText());
    input2.setInputType(InputType.TYPE_CLASS_NUMBER);
    input2.setHint("Team number");
    InputFilter[] FilterArray2 = new InputFilter[1];
    FilterArray2[0] = new InputFilter.LengthFilter(6);
    input2.setFilters(FilterArray2);
    layout.addView(input2);
    builder.setView(layout);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (input2.getText().toString().equals(""))
                input2.setText("0");
            RTeam team = new RTeam(input.getText().toString(), Integer.parseInt(input2.getText().toString()), io.getNewTeamID(eventDrawerManager.getEvent().getID()));
            /*
                 * Package for cloud
                 */
            if (eventDrawerManager.getEvent() != null && eventDrawerManager.getEvent().isCloudEnabled()) {
                team.verify(io.loadForm(eventDrawerManager.getEvent().getID()));
                RCheckout checkout = new RCheckout(team);
                checkout.setStatus(0);
                io.savePendingCheckout(checkout);
            }
            io.saveTeam(eventDrawerManager.getEvent().getID(), team);
            executeLoadTeamsTask(lastFilter, true);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    TextView view = new TextView(this);
    view.setTextSize(Utils.DPToPX(getApplicationContext(), 5));
    view.setPadding(Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18));
    view.setText(R.string.create_team);
    view.setTextColor(settings.getRui().getText());
    AlertDialog dialog = builder.create();
    dialog.setCustomTitle(view);
    if (dialog.getWindow() != null) {
        dialog.getWindow().getAttributes().windowAnimations = settings.getRui().getAnimation();
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(settings.getRui().getBackground()));
    }
    dialog.show();
    dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(settings.getRui().getAccent());
    dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(settings.getRui().getAccent());
}
Also used : AlertDialog(android.app.AlertDialog) InputFilter(android.text.InputFilter) RTeam(com.cpjd.roblu.models.RTeam) DialogInterface(android.content.DialogInterface) AppCompatEditText(android.support.v7.widget.AppCompatEditText) ColorDrawable(android.graphics.drawable.ColorDrawable) RCheckout(com.cpjd.roblu.models.RCheckout) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 10 with RCheckout

use of com.cpjd.roblu.models.RCheckout 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)

Aggregations

RCheckout (com.cpjd.roblu.models.RCheckout)17 IO (com.cpjd.roblu.io.IO)8 RTeam (com.cpjd.roblu.models.RTeam)8 RTab (com.cpjd.roblu.models.RTab)6 RMetric (com.cpjd.roblu.models.metrics.RMetric)5 ArrayList (java.util.ArrayList)5 StrictMode (android.os.StrictMode)3 Request (com.cpjd.http.Request)3 CloudCheckout (com.cpjd.models.CloudCheckout)3 CloudCheckoutRequest (com.cpjd.requests.CloudCheckoutRequest)3 REvent (com.cpjd.roblu.models.REvent)3 RForm (com.cpjd.roblu.models.RForm)3 RSettings (com.cpjd.roblu.models.RSettings)3 RSyncSettings (com.cpjd.roblu.models.RSyncSettings)3 RFieldData (com.cpjd.roblu.models.metrics.RFieldData)3 SyncHelper (com.cpjd.roblu.sync.SyncHelper)3 Row (org.apache.poi.ss.usermodel.Row)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 TextView (android.widget.TextView)2 CloudTeam (com.cpjd.models.CloudTeam)2