Search in sources :

Example 6 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class Utils method launchEventPicker.

/**
 * For certain things, the user may need to select an event from a list of locally stored event,
 * this method does just that! The EventSelectListener method will trigger when an event is successfully
 * selected.
 * @param context context reference
 * @param listener listener to respond to events
 * @return true if some events exist
 */
public static boolean launchEventPicker(Context context, final EventDrawerManager.EventSelectListener listener) {
    final Dialog d = new Dialog(context);
    d.setTitle("Pick event:");
    d.setContentView(R.layout.event_import_dialog);
    final Spinner spinner = d.findViewById(R.id.type);
    String[] values;
    final REvent[] events = new IO(context).loadEvents();
    if (events == null || events.length == 0)
        return false;
    values = new String[events.length];
    for (int i = 0; i < values.length; i++) {
        values[i] = events[i].getName();
    }
    ArrayAdapter<String> adp = new ArrayAdapter<>(context, 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.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            listener.eventSelected(events[spinner.getSelectedItemPosition()]);
            d.dismiss();
        }
    });
    if (d.getWindow() != null)
        d.getWindow().getAttributes().windowAnimations = new IO(context).loadSettings().getRui().getAnimation();
    d.show();
    return true;
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) Button(android.widget.Button) Dialog(android.app.Dialog) REvent(com.cpjd.roblu.models.REvent) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class IO method createPreview.

/*
     * Preview event methods
     *
     * Simplifies preview code by just creating and temporary event for viewing a form
     */
public void createPreview(RForm form) {
    REvent event = new REvent(-1, "Preview event");
    RTeam team = new RTeam("Previewing form", 0, -1);
    team.setPage(-1);
    team.verify(form);
    saveEvent(event);
    saveTeam(event.getID(), team);
    saveForm(event.getID(), form);
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) REvent(com.cpjd.roblu.models.REvent)

Example 8 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class IO method loadEvents.

/**
 * Loads all events in the /events/ dir
 * @return array of REvents found on the system
 */
public REvent[] loadEvents() {
    File[] files = getChildFiles(new File(context.getFilesDir(), PREFIX + File.separator + "events" + File.separator));
    if (files == null || files.length == 0)
        return null;
    REvent[] events = new REvent[files.length];
    for (int i = 0; i < events.length; i++) {
        events[i] = loadEvent(Integer.parseInt(files[i].getName()));
    }
    return events;
}
Also used : REvent(com.cpjd.roblu.models.REvent) File(java.io.File)

Example 9 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class EventCreateMethodPicker method onActivityResult.

/**
 * Receives result data from child activities
 * @param requestCode the request code of the child activities
 * @param resultCode the result code of the child activity
 * @param data any result data returned from the activity
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    /*
         * The user selected a backup file, let's attempt to import it here
         */
    if (requestCode == Constants.FILE_CHOOSER) {
        // this means the user didn't select a file, no point in returning an error message
        if (data == null)
            return;
        try {
            IO io = new IO(getApplicationContext());
            RBackup backup = io.convertBackupFile(data.getData());
            if (!backup.getFileVersion().equals(IO.PREFIX)) {
                Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Invalid backup file. Backup was created with an older version of Roblu.", true, rui.getPrimaryColor());
                return;
            }
            /*
                 * Create the event, we're not gonna use an AsyncTask because the user is just
                 * watching the event import anyway, and it will only freeze the UI for a couple hundred
                 * milliseconds.
                 */
            REvent event = backup.getEvent();
            event.setCloudEnabled(false);
            event.setID(io.getNewEventID());
            io.saveEvent(event);
            io.saveForm(event.getID(), backup.getForm());
            if (backup.getTeams() != null) {
                for (RTeam team : backup.getTeams()) {
                    for (RTab tab : team.getTabs()) {
                        for (RMetric metric : tab.getMetrics()) {
                            if (metric instanceof RGallery && ((RGallery) metric).getImages() != null) {
                                // Add images to the current gallery
                                for (int i = 0; i < ((RGallery) metric).getImages().size(); i++) {
                                    ((RGallery) metric).getPictureIDs().add(io.savePicture(event.getID(), ((RGallery) metric).getImages().get(i)));
                                }
                                ((RGallery) metric).setImages(null);
                            }
                        }
                    }
                    io.saveTeam(event.getID(), team);
                }
            }
            Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Successfully imported event from backup", false, rui.getPrimaryColor());
            Intent intent = new Intent();
            intent.putExtra("eventID", event.getID());
            setResult(Constants.NEW_EVENT_CREATED, intent);
            finish();
        } catch (Exception e) {
            Utils.showSnackbar(findViewById(R.id.activity_create_event_picker), getApplicationContext(), "Invalid backup file", true, rui.getPrimaryColor());
        }
    } else /*
         * The user created an event manually with EventEditor, we actually don't need to do anything but auto-finish our class
         * with a result code letting the TeamsView class now to refresh the event list
         */
    if (resultCode == Constants.NEW_EVENT_CREATED) {
        Bundle b = data.getExtras();
        Intent intent = new Intent();
        if (b != null)
            intent.putExtras(b);
        setResult(Constants.NEW_EVENT_CREATED, intent);
        finish();
    }
}
Also used : RBackup(com.cpjd.roblu.models.RBackup) RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) RGallery(com.cpjd.roblu.models.metrics.RGallery) IO(com.cpjd.roblu.io.IO) Bundle(android.os.Bundle) REvent(com.cpjd.roblu.models.REvent) Intent(android.content.Intent) RMetric(com.cpjd.roblu.models.metrics.RMetric)

Example 10 with REvent

use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.

the class EventDrawerManager method loadEventsToDrawer.

/**
 * Loads events from the file system into the event drawer.
 * Note: loadEvents() must be called after the drawer UI is setup, it will insert
 * REvents into the pre-created UI drawer
 */
public void loadEventsToDrawer() {
    /*
         * Load events
         */
    // Delete the preview event, if necessary
    new IO(activity).deleteEvent(-1);
    REvent[] loaded = new IO(activity).loadEvents();
    if (loaded == null) {
        if (((AppCompatActivity) activity).getSupportActionBar() != null)
            ((AppCompatActivity) activity).getSupportActionBar().setSubtitle("No events");
        return;
    }
    // Set loaded events to the managed array-list
    events = new ArrayList<>(Arrays.asList(loaded));
    // Sort descending by event ID, most recently created event will appear first
    Collections.sort(events);
    Collections.reverse(events);
    // Load icons
    Drawable folder, scout, options, pit;
    folder = ContextCompat.getDrawable(activity, R.drawable.event);
    scout = ContextCompat.getDrawable(activity, R.drawable.match);
    options = ContextCompat.getDrawable(activity, R.drawable.settings_circle);
    pit = ContextCompat.getDrawable(activity, R.drawable.pit);
    // Set UI preferences to drawable icon
    folder.mutate();
    folder.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    scout.mutate();
    scout.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    options.mutate();
    options.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    pit.mutate();
    pit.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    // Specify the list of items that have to be added to the drawer
    ArrayList<IDrawerItem> items = new ArrayList<>();
    if (events != null)
        for (REvent e : events) {
            items.add(new ExpandableDrawerItem().withTextColor(rui.getText()).withName(e.getName()).withTag(e.getID()).withArrowColor(rui.getText()).withIcon(folder).withIdentifier(Constants.HEADER).withSelectable(false).withSubItems(new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Scout").withLevel(2).withIcon(scout).withIdentifier(Constants.SCOUT).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("My matches").withLevel(2).withIcon(pit).withIdentifier(Constants.MY_MATCHES).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Settings").withLevel(2).withIcon(options).withIdentifier(Constants.EVENT_SETTINGS).withTag(e.getID())));
        }
    // Clear old events from the drawer
    for (int i = 0; i < eventDrawer.getDrawerItems().size(); i++) {
        long identifier = eventDrawer.getDrawerItems().get(i).getIdentifier();
        if (identifier == Constants.HEADER || identifier == Constants.SCOUT || identifier == Constants.EVENT_SETTINGS || identifier == Constants.MY_MATCHES) {
            eventDrawer.removeItemByPosition(i);
            i = 0;
        }
    }
    // Set defined list of items to drawer UI
    for (int i = 0; i < items.size(); i++) eventDrawer.addItemAtPosition(items.get(i), i + 3);
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) IO(com.cpjd.roblu.io.IO) AppCompatActivity(android.support.v7.app.AppCompatActivity) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) REvent(com.cpjd.roblu.models.REvent) ExpandableDrawerItem(com.mikepenz.materialdrawer.model.ExpandableDrawerItem)

Aggregations

REvent (com.cpjd.roblu.models.REvent)15 IO (com.cpjd.roblu.io.IO)11 RTeam (com.cpjd.roblu.models.RTeam)5 ArrayList (java.util.ArrayList)5 StrictMode (android.os.StrictMode)4 RSettings (com.cpjd.roblu.models.RSettings)4 RTab (com.cpjd.roblu.models.RTab)4 RGallery (com.cpjd.roblu.models.metrics.RGallery)4 RMetric (com.cpjd.roblu.models.metrics.RMetric)4 View (android.view.View)3 TextView (android.widget.TextView)3 Request (com.cpjd.http.Request)3 CloudCheckoutRequest (com.cpjd.requests.CloudCheckoutRequest)3 RCheckout (com.cpjd.roblu.models.RCheckout)3 RForm (com.cpjd.roblu.models.RForm)3 RSyncSettings (com.cpjd.roblu.models.RSyncSettings)3 RUI (com.cpjd.roblu.models.RUI)3 SyncHelper (com.cpjd.roblu.sync.SyncHelper)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Dialog (android.app.Dialog)2