Search in sources :

Example 1 with TeamTabAdapter

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

Aggregations

IntentFilter (android.content.IntentFilter)1 IO (com.cpjd.roblu.io.IO)1 RForm (com.cpjd.roblu.models.RForm)1 UIHandler (com.cpjd.roblu.ui.UIHandler)1 TeamTabAdapter (com.cpjd.roblu.ui.team.fragments.TeamTabAdapter)1