Search in sources :

Example 21 with UIHandler

use of com.cpjd.roblu.ui.UIHandler 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 22 with UIHandler

use of com.cpjd.roblu.ui.UIHandler 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 23 with UIHandler

use of com.cpjd.roblu.ui.UIHandler 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 24 with UIHandler

use of com.cpjd.roblu.ui.UIHandler in project Roblu by wdavies973.

the class AdvSettings method onCreateOptionsMenu.

// load in the bug report button, and make it match the ui settings
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.settings_actionbar, menu);
    new UIHandler(this, menu).updateMenu();
    return true;
}
Also used : UIHandler(com.cpjd.roblu.ui.UIHandler)

Example 25 with UIHandler

use of com.cpjd.roblu.ui.UIHandler 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)

Aggregations

UIHandler (com.cpjd.roblu.ui.UIHandler)26 Toolbar (android.support.v7.widget.Toolbar)14 IO (com.cpjd.roblu.io.IO)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)5 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 MenuInflater (android.view.MenuInflater)4 RForm (com.cpjd.roblu.models.RForm)4 ArrayList (java.util.ArrayList)4 RecyclerView (android.support.v7.widget.RecyclerView)3 IntentFilter (android.content.IntentFilter)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 SimpleAdapter (android.widget.SimpleAdapter)2 TextView (android.widget.TextView)2 RUI (com.cpjd.roblu.models.RUI)2 MaterialSearchView (com.miguelcatalan.materialsearchview.MaterialSearchView)2 HashMap (java.util.HashMap)2 AlertDialog (android.app.AlertDialog)1