Search in sources :

Example 46 with IO

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

the class EventEditor method createEvent.

/**
 * This method is more of a courtesy method to the source code reader,
 * an event will get created from EventEditor whenever this method is called, no exceptions.
 * @param form the form to save with the event
 */
private void createEvent(RForm form) {
    IO io = new IO(getApplicationContext());
    REvent event = new REvent(io.getNewEventID(), eventName.getText().toString());
    // we call this twice because the /event/ dir is required for the form to save
    io.saveEvent(event);
    io.saveForm(event.getID(), form);
    /*
         * We need to check if the user included any TBA information that we should include in this event creation
         */
    if (!editing && getIntent().getSerializableExtra("tbaEvent") != null) {
        ProgressDialog d = ProgressDialog.show(this, "Hold on tight!", "Generating team profiles from event...", true);
        d.setCancelable(false);
        event.setKey(((Event) getIntent().getSerializableExtra("tbaEvent")).key);
        io.saveEvent(event);
        UnpackTBAEvent unpackTBAEvent = new UnpackTBAEvent((Event) getIntent().getSerializableExtra("tbaEvent"), event.getID(), this, d);
        if (((Switch) findViewById(R.id.switch1)).isChecked())
            unpackTBAEvent.setRandomize(true);
        unpackTBAEvent.execute();
    } else /*
         * If we started the UnpackTask, then we have to wait to return, if not, return now
         */
    {
        io.saveEvent(event);
        Intent result = new Intent();
        result.putExtra("eventID", event.getID());
        setResult(Constants.NEW_EVENT_CREATED, result);
        finish();
    }
}
Also used : Switch(android.widget.Switch) IO(com.cpjd.roblu.io.IO) UnpackTBAEvent(com.cpjd.roblu.tba.UnpackTBAEvent) REvent(com.cpjd.roblu.models.REvent) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog)

Example 47 with IO

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

the class FormViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_form);
    /*
		 * Load dependencies
		 */
    /*
         Stores the user's UI preferences
        */
    RUI rui = new IO(getApplicationContext()).loadSettings().getRui();
    /*
		 * Setup UI
		 */
    // Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Form editor");
        if (getIntent().getBooleanExtra("master", false))
            getSupportActionBar().setSubtitle("Master form");
    }
    // Bottom bar - selector that lets the user switch between PIT and MATCH forms
    BottomBar bBar = findViewById(R.id.bottomBar);
    bBar.setOnTabSelectListener(this);
    BottomBarTab tab = bBar.getTabAtPosition(0);
    BottomBarTab tab2 = bBar.getTabAtPosition(1);
    tab.setBarColorWhenSelected(rui.getPrimaryColor());
    tab2.setBarColorWhenSelected(rui.getPrimaryColor());
    bBar.selectTabAtPosition(0);
    // Add the "New metric" button
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(this);
    // Recycler view setup
    RecyclerView rv = findViewById(R.id.movie_recycler_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    metricsAdapter = new FormRecyclerAdapter(this, this);
    rv.setAdapter(metricsAdapter);
    // Gesture helper
    ItemTouchHelper.Callback callback = new FormRecyclerTouchHelper(metricsAdapter);
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(rv);
    /*
         * Check to see if we received a form from a different class or
         * if we need to create a new one
         */
    if (getIntent().getSerializableExtra("form") != null) {
        form = (RForm) getIntent().getSerializableExtra("form");
    } else {
        RTextfield name = new RTextfield(0, "Team name", false, true, "");
        RTextfield number = new RTextfield(1, "Team number", true, true, "");
        ArrayList<RMetric> pit = new ArrayList<>();
        pit.add(name);
        pit.add(number);
        form = new RForm(pit, new ArrayList<RMetric>());
    }
    loadViews(true, 0);
    new UIHandler(this, toolbar, fab).update();
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RUI(com.cpjd.roblu.models.RUI) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) BottomBar(com.roughike.bottombar.BottomBar) RForm(com.cpjd.roblu.models.RForm) BottomBarTab(com.roughike.bottombar.BottomBarTab) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 48 with IO

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

the class TBAEventSelector method tbaEventSelected.

/**
 * The user selected an event from the downloaded events, what happens next is we need to create a sort of
 * "partial REvent" and pass it to the EventEditor class so the user can decide which form they want, etc.
 * @param v the view that was tapped
 */
@Override
public void tbaEventSelected(View v) {
    /*
         * Force close the keyboard, Android doesn't always automatically do this
         */
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
    // Get the event reference from the UI
    Event event = tbaEventAdapter.getEvents().get(rv.getChildLayoutPosition(v));
    Utils.showSnackbar(findViewById(R.id.activity_apievent_select), getApplicationContext(), "Downloading event...", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
    Log.d("RBS", "Importing event with key: " + event.key);
    /*
         * Import the event specifically, eventDownloaded(Event event) will receive the result of this
         * task execution
         */
    new ImportEvent(this, event.key).start();
}
Also used : IO(com.cpjd.roblu.io.IO) ImportEvent(com.cpjd.roblu.tba.ImportEvent) Event(com.cpjd.models.Event) InputMethodManager(android.view.inputmethod.InputMethodManager) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) ImportEvent(com.cpjd.roblu.tba.ImportEvent)

Example 49 with IO

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

the class TeamViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_team_viewer);
    // load the checkout that the user requested
    int teamID = getIntent().getIntExtra("teamID", 0);
    event = new IO(getApplicationContext()).loadEvent(getIntent().getIntExtra("eventID", 0));
    team = new IO(getApplicationContext()).loadTeam(event.getID(), teamID);
    /*
         Flag that determines if any of this team information should be editable. Team information
         should be read only if it's loaded from the "checkouts" list
         */
    editable = getIntent().getBooleanExtra("editable", true);
    /*
         * Optional parameter for choosing a page to go to
         */
    String requestedMatch = getIntent().getStringExtra("match");
    if (requestedMatch != null) {
        for (int i = 0; i < team.getTabs().size(); i++) {
            if (team.getTabs().get(i).getTitle().equalsIgnoreCase(requestedMatch)) {
                team.setPage(i + 1);
                break;
            }
        }
    }
    /*
         * What's the RForm reference for? It's used for verifying that a local checkout's form is matched with the Roblu Master form.
         * However, with update 4.0.0, we're not actually going to force a sync on the client if a form isn't available. Instead, all
         * incoming Checkouts will be re-verified by Roblu Master, so if the form can't be loaded here, no biggy.
         */
    RForm form = new IO(getApplicationContext()).loadForm(event.getID());
    if (form == null)
        Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), this, "Form could not by synced with server. Local form may contain discrepancies.", true, 0);
    else {
        // verify the form
        team.verify(form);
        if (editable)
            new IO(this).saveTeam(event.getID(), team);
    // else Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Read only mode is enabled", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
    }
    /*
         * Setup UI
         */
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    rui = new IO(getApplicationContext()).loadSettings().getRui();
    tabLayout = findViewById(R.id.tab_layout);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    getSupportActionBar().setTitle(team.getName());
    getSupportActionBar().setSubtitle("#" + String.valueOf(team.getNumber()));
    tabAdapter = new TeamTabAdapter(getSupportFragmentManager(), event, form, getApplicationContext(), editable);
    pager = findViewById(R.id.pager);
    pager.addOnPageChangeListener(this);
    pager.setAdapter(tabAdapter);
    pager.setCurrentItem(team.getPage());
    onPageSelected(team.getPage());
    tabLayout.setupWithViewPager(pager);
    tabLayout.setBackgroundColor(rui.getPrimaryColor());
    tabLayout.setSelectedTabIndicatorColor(rui.getAccent());
    tabLayout.setTabTextColors(RUI.darker(rui.getText(), 0.95f), rui.getText());
    new UIHandler(this, toolbar).update();
    if (team.getPage() > 1)
        onPageSelected(team.getPage());
    /*
         * Attach to background service
         */
    serviceFilter = new IntentFilter();
    serviceFilter.addAction(Constants.SERVICE_ID);
}
Also used : TeamTabAdapter(com.cpjd.roblu.ui.team.fragments.TeamTabAdapter) IntentFilter(android.content.IntentFilter) RForm(com.cpjd.roblu.models.RForm) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO)

Example 50 with IO

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

the class TeamViewer method showPopup.

/**
 * Displays a match popup menu with various actions.
 *
 * "Mark as won"
 * "Open on TBA"
 * "Delete match"
 */
private void showPopup() {
    View menuItemView = findViewById(R.id.match_settings);
    final PopupMenu popup = new PopupMenu(TeamViewer.this, menuItemView);
    MenuInflater inflate = popup.getMenuInflater();
    inflate.inflate(R.menu.match_options, popup.getMenu());
    final PopupMenu.OnMenuItemClickListener popupListener = new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.match_page) {
                if (event.getKey() == null || event.getKey().equals("")) {
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "No event key found. Set it in event settings.", true, 0);
                    return false;
                }
                if (pager.getCurrentItem() == 0)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Overview can't be opened on TBA.", true, 0);
                else if (pager.getCurrentItem() == 1)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "PIT can't be opened on TBA.", true, 0);
                else if (pager.getCurrentItem() == 2)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Predictions can't be opened on TBA.", true, 0);
                else {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("https://www.thebluealliance.com/match/" + event.getKey() + "_" + Utils.guessMatchKey(team.getTabs().get(pager.getCurrentItem() - 1).getTitle())));
                    startActivity(i);
                    popup.dismiss();
                }
                return true;
            }
            if (item.getItemId() == R.id.delete_match) {
                if (!editable)
                    return true;
                if (pager.getCurrentItem() == 0)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Overview can't be deleted", true, 0);
                else if (pager.getCurrentItem() == 1)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "PIT can't be deleted", true, 0);
                else if (pager.getCurrentItem() == 2)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Predictions can't be deleted", true, 0);
                else {
                    int pos = pager.getCurrentItem() - 1;
                    String title = team.getTabs().get(pos).getTitle();
                    tabAdapter.deleteTab(pos);
                    pager.setCurrentItem(pos);
                    popup.dismiss();
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), title + " was successfully deleted.", false, rui.getPrimaryColor());
                    new IO(getApplicationContext()).saveTeam(event.getID(), team);
                }
                return true;
            }
            if (item.getItemId() == R.id.won) {
                if (!editable)
                    return true;
                if (pager.getCurrentItem() == 0)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Overview can't be marked as won", true, 0);
                else if (pager.getCurrentItem() == 1)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "PIT can't be marked as won", true, 0);
                else if (pager.getCurrentItem() == 2)
                    Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Predictions can't be marked as won", true, 0);
                else {
                    String title = team.getTabs().get(pager.getCurrentItem() - 1).getTitle();
                    boolean won = tabAdapter.markWon(pager.getCurrentItem() - 1);
                    if (won)
                        Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), title + " marked as won.", false, rui.getPrimaryColor());
                    else
                        Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), title + " marked as lost.", false, rui.getPrimaryColor());
                    popup.dismiss();
                    new IO(getApplicationContext()).saveTeam(event.getID(), team);
                }
            }
            return true;
        }
    };
    popup.setOnMenuItemClickListener(popupListener);
    if (pager.getCurrentItem() > 2) {
        boolean won;
        if (!editable)
            won = team.getTabs().get(pager.getCurrentItem()).isWon();
        else
            won = team.getTabs().get(pager.getCurrentItem() - 1).isWon();
        if (won && pager.getCurrentItem() > 2)
            popup.getMenu().getItem(0).setTitle("Mark as lost");
    }
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) IO(com.cpjd.roblu.io.IO) MenuItem(android.view.MenuItem) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) PopupMenu(android.support.v7.widget.PopupMenu)

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