Search in sources :

Example 51 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class Match method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.match_tab, container, false);
    layout = view.findViewById(R.id.match_layout);
    Bundle bundle = this.getArguments();
    event = (REvent) bundle.getSerializable("event");
    form = (RForm) bundle.getSerializable("form");
    position = bundle.getInt("position") - 1;
    editable = bundle.getBoolean("editable");
    if (!editable)
        position++;
    // This is used for generating the metric cards, note the "event.getID() == -1", this flags it as editable if previewing,
    // instead of editable being true, because editable is used as a flag for several other UI things
    els = new RMetricToUI(getActivity(), new IO(getActivity()).loadSettings().getRui(), editable || event.getID() == -1);
    els.setListener(this);
    load();
    return view;
}
Also used : Bundle(android.os.Bundle) IO(com.cpjd.roblu.io.IO) RMetricToUI(com.cpjd.roblu.ui.forms.RMetricToUI)

Example 52 with IO

use of com.cpjd.roblu.io.IO 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 53 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class MyMatches method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setup ui stuff
    setContentView(R.layout.mymatches);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // access the eventID, if no eventID is passed in to this class, the app will crash
    eventID = getIntent().getIntExtra("eventID", 0);
    // load the number from settings
    int number = new IO(getApplicationContext()).loadSettings().getTeamNumber();
    if (number == 0) {
        // the user hasn't changed their number yet, and since no team is #0, we have to stop the activity
        Toast.makeText(getApplicationContext(), "No team number found. Set it in settings.", Toast.LENGTH_LONG).show();
        setResult(Constants.CANCELLED);
        finish();
        return;
    }
    /*
         * we have a reference to the team's number but not the team'd ID (we need the team's ID to load).
         *
         * so the problem here is that there is a potential for the user to have created multiple teams with
         * their own team number (not likely, but possible). Currently, this code will just load the first
         * team that matches our number that it comes across, but you could modify this code to do a "smart select"
         * that looks of data contained within each team (num of matches, size, last edit, etc.). for now, the first
         * team we come across should be fine and work 99% of the time
         */
    RTeam[] local = new IO(getApplicationContext()).loadTeams(eventID);
    RTeam myTeam = null;
    for (RTeam team : local) {
        // search through locally stored teams until we find one that matches our number
        if (team.getNumber() == number) {
            myTeam = team;
            break;
        }
    }
    if (myTeam == null) {
        // team will be null if it was not contained in the event, if no team, force close this activity
        Toast.makeText(getApplicationContext(), "Your team is missing from event, please add it", Toast.LENGTH_LONG).show();
        setResult(Constants.CANCELLED);
        finish();
        return;
    }
    if (myTeam.getTabs() == null || myTeam.getTabs().size() <= 2) {
        // we found a team, but it doesn't contain any matches, so we can't load "my matches", force close
        Toast.makeText(getApplicationContext(), "Team does not contain any match data, please add some.", Toast.LENGTH_LONG).show();
        setResult(Constants.CANCELLED);
        finish();
        return;
    }
    // for more on verification, visit the RTeam class, basically, to be safe, we want to sync the form and the team before we play around with any of them
    myTeam.verify(new IO(getApplicationContext()).loadForm(eventID));
    // next, we need to split apart the RTab array within our team, we want one RCheckout model per match
    // we'll use this array for storing info, one RChecklist per match
    ArrayList<RCheckout> toSave = new ArrayList<>();
    for (int i = 0; i < myTeam.getTabs().size(); i++) {
        // we don't care about pit or predictions tabs, so skip them since they are always at index 0 & 1
        if (i < 2)
            continue;
        // create a new team with only one tab, wrap it in a checkout, and add it to our array
        RTeam team = new RTeam(myTeam.getName(), myTeam.getNumber(), myTeam.getID());
        team.addTab(myTeam.getTabs().get(i));
        toSave.add(new RCheckout(team));
    }
    // next, we need to look through our local teams list again and search for other teams in the same match as us, then we can add them to the either the teammates or opponents array
    for (RCheckout checkout : toSave) {
        ArrayList<RTeam> teammates = new ArrayList<>();
        ArrayList<RTeam> opponents = new ArrayList<>();
        for (RTeam team : local) {
            for (RTab tab : team.getTabs()) {
                if (tab.getTitle().equalsIgnoreCase(checkout.getTeam().getTabs().get(0).getTitle())) {
                    if (checkout.getTeam().getTabs().get(0).isRedAlliance() == tab.isRedAlliance())
                        teammates.add(team);
                    else
                        opponents.add(team);
                }
            }
        }
        checkout.getTeam().getTabs().get(0).setTeammates(teammates);
        checkout.getTeam().getTabs().get(0).setOpponents(opponents);
    }
    // we've got everything we need, let's load it into the UI
    rv = findViewById(R.id.recycler);
    // manages the layout loading
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    adapter = new CheckoutsViewAdapter(getApplicationContext(), new IO(getApplicationContext()).loadSettings());
    adapter.setCheckouts(toSave);
    adapter.setListener(this);
    rv.setAdapter(adapter);
    // prevents a weird rendering issues
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    // don't forget to sync our activity ui with the RUI settings
    new UIHandler(this, toolbar).update();
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) RTeam(com.cpjd.roblu.models.RTeam) UIHandler(com.cpjd.roblu.ui.UIHandler) RTab(com.cpjd.roblu.models.RTab) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RCheckout(com.cpjd.roblu.models.RCheckout) Toolbar(android.support.v7.widget.Toolbar)

Example 54 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class AdvSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set layout, ui attributes
    setContentView(R.layout.activity_settings);
    setTitle("Settings");
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Load settings
    settings = new IO(getApplicationContext()).loadSettings();
    // Replace the view with the preference fragment, the preference fragment manages all the setting changes and whatnot
    getFragmentManager().beginTransaction().replace(R.id.blankFragment, new SettingsFragment()).commit();
    // UIHandler updates our activity to match what's set in RUI
    new UIHandler(this, (Toolbar) findViewById(R.id.toolbar)).update();
}
Also used : UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) Toolbar(android.support.v7.widget.Toolbar)

Example 55 with IO

use of com.cpjd.roblu.io.IO 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

IO (com.cpjd.roblu.io.IO)59 TextView (android.widget.TextView)18 Intent (android.content.Intent)15 View (android.view.View)14 ArrayList (java.util.ArrayList)13 REvent (com.cpjd.roblu.models.REvent)11 Toolbar (android.support.v7.widget.Toolbar)10 RForm (com.cpjd.roblu.models.RForm)10 RTeam (com.cpjd.roblu.models.RTeam)10 RUI (com.cpjd.roblu.models.RUI)10 RCheckout (com.cpjd.roblu.models.RCheckout)8 RTab (com.cpjd.roblu.models.RTab)8 RMetric (com.cpjd.roblu.models.metrics.RMetric)8 UIHandler (com.cpjd.roblu.ui.UIHandler)8 RecyclerView (android.support.v7.widget.RecyclerView)7 Dialog (android.app.Dialog)6 Bundle (android.os.Bundle)6 Button (android.widget.Button)6 RSettings (com.cpjd.roblu.models.RSettings)6 AlertDialog (android.app.AlertDialog)5