Search in sources :

Example 36 with IO

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

the class TeamsView method showFilterDialog.

/**
 * Displays the filter dialog and refreshes the team's list when the user selects the
 * desired filter method
 */
private void showFilterDialog() {
    if (eventDrawerManager.getEvent() == null)
        return;
    final Dialog d = new Dialog(this);
    d.setContentView(R.layout.dialog_sort);
    TextView view = d.findViewById(R.id.sort_title);
    view.setTextColor(settings.getRui().getText());
    RadioGroup group = d.findViewById(R.id.filter_group);
    for (int i = 0; i < group.getChildCount(); i++) {
        AppCompatRadioButton rb = (AppCompatRadioButton) group.getChildAt(i);
        if (i == lastFilter)
            rb.setChecked(true);
        rb.setTextColor(settings.getRui().getText());
        final int i2 = i;
        rb.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (i2 == 3) {
                    Intent intent = new Intent(TeamsView.this, CustomSort.class);
                    intent.putExtra("eventID", eventDrawerManager.getEvent().getID());
                    startActivityForResult(intent, Constants.GENERAL);
                    d.dismiss();
                    return;
                }
                eventDrawerManager.getEvent().setLastFilter(i2);
                io.saveEvent(eventDrawerManager.getEvent());
                lastFilter = i2;
                executeLoadTeamsTask(lastFilter, false);
                d.dismiss();
                settings.setLastFilter(lastFilter);
                new IO(getApplicationContext()).saveSettings(settings);
            }
        });
    }
    if (d.getWindow() != null) {
        d.getWindow().setBackgroundDrawable(new ColorDrawable(settings.getRui().getBackground()));
        d.getWindow().getAttributes().windowAnimations = settings.getRui().getAnimation();
    }
    d.show();
}
Also used : AppCompatRadioButton(android.support.v7.widget.AppCompatRadioButton) RadioGroup(android.widget.RadioGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) CustomSort(com.cpjd.roblu.ui.teamsSorting.CustomSort) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) IO(com.cpjd.roblu.io.IO) TextView(android.widget.TextView) Intent(android.content.Intent) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 37 with IO

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

the class TeamsView method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_teams_view);
    io = new IO(getApplicationContext());
    // Initialize startup requirements
    // sets width for UI, needed for RMetricToUI
    Utils.initWidth(this);
    if (IO.init(getApplicationContext())) {
        // checks if we need to show startup dialog
        startActivity(new Intent(this, SetupActivity.class));
        finish();
        return;
    }
    // setup TBA api vars
    TBA.setID("Roblu", "Scouting-App", "v3");
    settings = io.loadSettings();
    /*
         * Setup UI
         */
    // Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle("Roblu");
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    }
    // Progress bar, also make sure to hide it
    bar = findViewById(R.id.progress_bar);
    bar.setVisibility(View.GONE);
    // Recycler View, UI front-end to teams array
    rv = findViewById(R.id.teams_recycler);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    // Setup the team adapter
    adapter = new TeamsRecyclerAdapter(this, this);
    rv.setAdapter(adapter);
    // Setup the UI gestures manager and link to recycler view
    ItemTouchHelper.Callback callback = new TeamsRecyclerTouchHelper(adapter);
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(rv);
    // Search view
    searchView = findViewById(R.id.search_view);
    searchView.setHintTextColor(Color.BLACK);
    searchView.setHint("Name, number, or match");
    // Search button
    searchButton = findViewById(R.id.fab);
    searchButton.setOnClickListener(this);
    searchButton.setOnLongClickListener(this);
    // Link the search button appearance to the scrolling behavior of the recycler view
    rv.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0 && searchButton.isShown())
                searchButton.hide();
            if (dy < 0 && !searchButton.isShown())
                searchButton.show();
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE)
                searchButton.show();
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
    // If the user closes the search bar, refresh the teams view with all the original items
    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {

        @Override
        public void onSearchViewShown() {
        }

        @Override
        public void onSearchViewClosed() {
            executeLoadTeamsTask(lastFilter, false);
            searchButton.setVisibility(FloatingActionButton.VISIBLE);
        }
    });
    // Listen for text in the search view, if text is found, complete teh search
    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchView.closeSearch();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            lastQuery = newText;
            if (lastFilter == SORT_TYPE.CUSTOM_SORT)
                executeLoadTeamsTask(SORT_TYPE.CUSTOM_SORT, false);
            else
                executeLoadTeamsTask(SORT_TYPE.SEARCH, false);
            return true;
        }
    });
    // Make general changes to UI, keep it synced with RUI
    new UIHandler(this, toolbar, searchButton, true).update();
    // Reload last filter, custom sort, and query
    lastFilter = settings.getLastFilter();
    // custom sort or search can't be loaded at startup because lastQuery and lastCustomSortFilter aren't saved
    if (lastFilter == SORT_TYPE.CUSTOM_SORT || lastFilter == SORT_TYPE.SEARCH)
        lastFilter = SORT_TYPE.NUMERICAL;
    /*
         * Setup events drawer and load events to it
         */
    eventDrawerManager = new EventDrawerManager(this, toolbar, this);
    eventDrawerManager.selectEvent(settings.getLastEventID());
    // Check to see if the background service is running, if it isn't, start it
    serviceFilter = new IntentFilter();
    serviceFilter.addAction(Constants.SERVICE_ID);
    Log.d("RBS", "Is service running: " + Utils.isMyServiceRunning(getApplicationContext()));
    if (!Utils.isMyServiceRunning(getApplicationContext())) {
        Intent serviceIntent = new Intent(this, Service.class);
        startService(serviceIntent);
    }
    /*
         * Display update messages
         *
         */
    if (settings.getUpdateLevel() != Constants.VERSION) {
        settings.setUpdateLevel(Constants.VERSION);
        AlertDialog.Builder builder = new AlertDialog.Builder(TeamsView.this).setTitle("Changelist for Version 4.4.5").setMessage(Constants.UPDATE_MESSAGE).setPositiveButton("Rock on", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        AlertDialog dialog = builder.create();
        if (dialog.getWindow() != null) {
            dialog.getWindow().getAttributes().windowAnimations = settings.getRui().getDialogDirection();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(settings.getRui().getBackground()));
        }
        dialog.show();
        dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(settings.getRui().getAccent());
        io.saveSettings(settings);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EventDrawerManager(com.cpjd.roblu.ui.events.EventDrawerManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) SetupActivity(com.cpjd.roblu.ui.setup.SetupActivity) Toolbar(android.support.v7.widget.Toolbar) IntentFilter(android.content.IntentFilter) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent) ColorDrawable(android.graphics.drawable.ColorDrawable) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 38 with IO

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

the class CustomSort method onCreate.

@Override
public void onCreate(Bundle saveInstanceState) {
    super.onCreate(saveInstanceState);
    setContentView(R.layout.activity_customsort);
    /*
         * Load the form and remove the team NAME and NUMBER metrics (since the user can sort by
         * this already without using CustomSort). Good news is that we know the form will ALWAYS
         * keep the team NAME and NUMBER as ID 0 and 1 respectively.
         */
    RForm form = new IO(getApplicationContext()).loadForm(getIntent().getIntExtra("eventID", 0));
    for (int i = 0; i < form.getPit().size(); i++) {
        if (form.getPit().get(i).getID() == 0 || form.getPit().get(i).getID() == 1 || form.getPit().get(i) instanceof RDivider || form.getPit().get(i) instanceof RFieldDiagram) {
            form.getPit().remove(i);
            i--;
        }
    }
    // Remove dividers - they are useless for sorting
    for (int i = 0; i < form.getMatch().size(); i++) {
        if (form.getMatch().get(i) instanceof RDivider || form.getMatch().get(i) instanceof RFieldDiagram) {
            form.getMatch().remove(i);
            i--;
        }
    }
    /*
         * Setup UI
         */
    // Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle("Custom sort");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    // Setup tabs
    TabLayout tabLayout = findViewById(R.id.tab_layout);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setBackgroundColor(new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
    // Setup the adapter - the back-end to the UI (manages all the MetricFragments)
    MetricSortAdapter adapter = new MetricSortAdapter(getSupportFragmentManager(), form, getIntent().getIntExtra("eventID", 0));
    ViewPager pager = findViewById(R.id.pager);
    pager.addOnPageChangeListener(this);
    pager.setAdapter(adapter);
    tabLayout.setupWithViewPager(pager);
    // Sync UI with user preferences
    new UIHandler(this, toolbar).update();
}
Also used : RDivider(com.cpjd.roblu.models.metrics.RDivider) RForm(com.cpjd.roblu.models.RForm) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) TabLayout(android.support.design.widget.TabLayout) RFieldDiagram(com.cpjd.roblu.models.metrics.RFieldDiagram) ViewPager(android.support.v4.view.ViewPager) Toolbar(android.support.v7.widget.Toolbar)

Example 39 with IO

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

the class MetricSortFragment method metricSelected.

/**
 * This method is called when the user taps on a metric
 *
 * @param v the View that the user tapped on (used for inferring the RMetric object)
 */
@Override
public void metricSelected(View v) {
    final int position = rv.getChildLayoutPosition(v);
    if (metrics.get(position) instanceof RFieldData) {
        final Dialog d = new Dialog(getActivity());
        d.setTitle("Select sub metric");
        d.setContentView(R.layout.submetric_import);
        final Spinner spinner = d.findViewById(R.id.type);
        // Attempt to load a team to get a list of values
        int id = 0;
        IO io = new IO(getActivity());
        RTeam team;
        do {
            team = io.loadTeam(eventID, id);
            id++;
        } while (team == null && id < 100);
        RFieldData fieldData = null;
        try {
            mainLoop: for (RTab tab : team.getTabs()) {
                if (tab.getTitle().equalsIgnoreCase("PIT") || tab.getTitle().equalsIgnoreCase("PREDICTIONS"))
                    continue;
                for (RMetric metric2 : tab.getMetrics()) {
                    if (metric2 instanceof RFieldData && metrics.get(position).getID() == metric2.getID() && ((RFieldData) metric2).getData() != null && ((RFieldData) metric2).getData().size() >= 1) {
                        fieldData = (RFieldData) metric2;
                        break mainLoop;
                    }
                }
            }
        } catch (Exception e) {
        // }
        }
        if (fieldData == null)
            return;
        final String[] values = Utils.depackFieldData(fieldData);
        if (values == null) {
            Toast.makeText(getActivity(), "Error occurred while loading metrics.", Toast.LENGTH_LONG).show();
            return;
        }
        ArrayAdapter<String> adp = new ArrayAdapter<>(getActivity(), 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.select);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent result = new Intent();
                result.putExtra("sortToken", TeamMetricProcessor.PROCESS_METHOD.MATCHES + ":" + metrics.get(position).getID() + ":" + values[spinner.getSelectedItemPosition()]);
                getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
                getActivity().finish();
                d.dismiss();
            }
        });
        if (d.getWindow() != null)
            d.getWindow().getAttributes().windowAnimations = new IO(getActivity()).loadSettings().getRui().getAnimation();
        d.show();
        return;
    } else // User selected the "In Match" option, now we have to display a list of all the matches within the event
    if (processMethod == TeamMetricProcessor.PROCESS_METHOD.OTHER && metrics.get(position).getID() == TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH) {
        final Dialog d = new Dialog(getActivity());
        d.setTitle("Select match");
        d.setContentView(R.layout.event_import_dialog);
        final Spinner spinner = d.findViewById(R.id.type);
        TextView t = d.findViewById(R.id.spinner_tip);
        t.setText(R.string.match);
        final String[] values = Utils.getMatchTitlesWithinEvent(getContext(), eventID);
        if (values == null) {
            Toast.makeText(getActivity(), "Error occurred while loading matches. Do any matches exist?", Toast.LENGTH_LONG).show();
            return;
        }
        ArrayAdapter<String> adp = new ArrayAdapter<>(getActivity(), 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.select);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent result = new Intent();
                result.putExtra("sortToken", TeamMetricProcessor.PROCESS_METHOD.OTHER + ":" + TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH + ":" + values[spinner.getSelectedItemPosition()]);
                getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
                getActivity().finish();
                d.dismiss();
            }
        });
        if (d.getWindow() != null)
            d.getWindow().getAttributes().windowAnimations = new IO(getActivity()).loadSettings().getRui().getAnimation();
        d.show();
        return;
    }
    String sortToken = processMethod + ":" + metrics.get(position).getID();
    Intent result = new Intent();
    result.putExtra("sortToken", sortToken);
    if (getActivity() != null) {
        getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
        getActivity().finish();
    }
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) Intent(android.content.Intent) RMetric(com.cpjd.roblu.models.metrics.RMetric) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Button(android.widget.Button) Dialog(android.app.Dialog) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 40 with IO

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

the class UIHandler method updateMenu.

public void updateMenu() {
    rui = new IO(activity).loadSettings().getRui();
    // Update icon colors
    for (int i = 0; i < menu.size(); i++) {
        Drawable d = menu.getItem(i).getIcon();
        d.mutate();
        d.setColorFilter(rui.getButtons(), PorterDuff.Mode.SRC_IN);
    }
}
Also used : IO(com.cpjd.roblu.io.IO) Drawable(android.graphics.drawable.Drawable)

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