Search in sources :

Example 1 with AssignmentGroup

use of com.instructure.canvasapi.model.AssignmentGroup in project instructure-android by instructure.

the class AssignmentGroupUnitTest method testAssignmentGroup.

@Test
public void testAssignmentGroup() {
    String assignmentGroupJSON = "[\n" + "{\n" + "\"group_weight\": 0,\n" + "\"id\": 534101,\n" + "\"name\": \"Extra Credit\",\n" + "\"position\": 1,\n" + "\"rules\": {}\n" + "},\n" + "{\n" + "\"group_weight\": 0,\n" + "\"id\": 534100,\n" + "\"name\": \"Assignments\",\n" + "\"position\": 2,\n" + "\"rules\": {}\n" + "}\n" + "]";
    Gson gson = CanvasRestAdapter.getGSONParser();
    AssignmentGroup[] assignmentGroup = gson.fromJson(assignmentGroupJSON, AssignmentGroup[].class);
    assertNotNull(assignmentGroup);
    assertEquals(2, assignmentGroup.length);
    assertNotNull(assignmentGroup[0].getName());
    assertNotNull(assignmentGroup[1].getName());
    assertTrue(assignmentGroup[0].getId() > 0);
    assertTrue(assignmentGroup[1].getId() > 0);
}
Also used : AssignmentGroup(com.instructure.canvasapi.model.AssignmentGroup) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 2 with AssignmentGroup

use of com.instructure.canvasapi.model.AssignmentGroup in project instructure-android by instructure.

the class EditAssignmentDialog method populateViewData.

private void populateViewData() {
    if (assignment.isUseRubricForGrading()) {
        useRubricForGrading.setChecked(true);
    } else {
        useRubricForGrading.setChecked(false);
    }
    if (assignmentTitleCache != null) {
        assignmentTitleET.setText(assignmentTitleCache);
    } else {
        assignmentTitleET.setText(assignment.getName());
    }
    if (isNotifyUsers) {
        notifyUsers.setChecked(true);
    }
    if (isMuted) {
        mutedCheckBox.setChecked(true);
    } else {
        mutedCheckBox.setChecked(false);
    }
    if (dueDateCache != null) {
        dueDateDT.setDate(dueDateCache);
    } else {
        dueDateDT.setDate(assignment.getDueDate());
    }
    if (pointsPossibleCache != null) {
        pointsPossibleET.setText(pointsPossibleCache);
    } else {
        pointsPossibleET.setText(String.valueOf(assignment.getPointsPossible()));
    }
    // We are unable to set points possible on a quiz
    if (assignment.getTurnInType() == Assignment.TURN_IN_TYPE.QUIZ) {
        pointsPossibleET.setEnabled(false);
    }
    int currentIndex = 0;
    // Set up assignmentGroupSpinner adapter
    ArrayAdapter<String> assignmentGroupSpinnerArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.generic_spinner_textview);
    for (int i = 0; i < assignmentGroups.length; i++) {
        AssignmentGroup currentAssignmentGroup = assignmentGroups[i];
        if (currentAssignmentGroup.getId() == assignment.getAssignmentGroupId()) {
            currentIndex = i;
        }
        assignmentGroupSpinnerArrayAdapter.add(currentAssignmentGroup.getName());
    }
    assignmentGroupSpinner.setAdapter(assignmentGroupSpinnerArrayAdapter);
    assignmentGroupSpinner.setSelection(currentIndex, true);
    // Set up gradingTypeSpinner adapter
    currentIndex = 0;
    ArrayAdapter<String> gradingTypeSpinnerArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.generic_spinner_textview);
    for (int i = 0; i < Assignment.GRADING_TYPE.values().length; i++) {
        Assignment.GRADING_TYPE currentGradingType = Assignment.GRADING_TYPE.values()[i];
        if (currentGradingType == assignment.getGradingType()) {
            currentIndex = i;
        }
        gradingTypeSpinnerArrayAdapter.add(Assignment.gradingTypeToPrettyPrintString(currentGradingType, getActivity()));
    }
    gradingTypeSpinner.setAdapter(gradingTypeSpinnerArrayAdapter);
    gradingTypeSpinner.setSelection(currentIndex, true);
    // Set the Type spinner adapter
    if (assignmentTurnInType != Assignment.TURN_IN_TYPE.DISCUSSION && assignmentTurnInType != Assignment.TURN_IN_TYPE.QUIZ && assignmentTurnInType != Assignment.TURN_IN_TYPE.EXTERNAL_TOOL) {
        currentIndex = 0;
        ArrayAdapter<String> submissionTypeSelectedAdapter = new ArrayAdapter<String>(getActivity(), R.layout.generic_spinner_textview);
        for (int i = 0; i < TURN_IN_TYPES_ALLOWED.length; i++) {
            Assignment.TURN_IN_TYPE turnInType = TURN_IN_TYPES_ALLOWED[i];
            if (turnInType == assignmentTurnInType) {
                currentIndex = i;
            }
            submissionTypeSelectedAdapter.add(Assignment.turnInTypeToPrettyPrintString(turnInType, getActivity()));
        }
        turnInTypeSpinner.setAdapter(submissionTypeSelectedAdapter);
        turnInTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                Assignment.TURN_IN_TYPE turnInType = Assignment.stringToTurnInType((String) adapterView.getItemAtPosition(i), getActivity());
                if (turnInType == Assignment.TURN_IN_TYPE.ONLINE) {
                    allOnlineSubmissionTypes.setVisibility(View.VISIBLE);
                    onlineEntriesText.setVisibility(View.VISIBLE);
                } else {
                    allOnlineSubmissionTypes.setVisibility(View.GONE);
                    onlineEntriesText.setVisibility(View.GONE);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
        turnInTypeSpinner.setSelection(currentIndex, true);
    } else {
        turnInTypeWrapper.setVisibility(View.GONE);
        onlineEntriesText.setVisibility(View.GONE);
    }
    checkedSubmissionTypes = (ArrayList) assignment.getSubmissionTypes();
    // Populate Online Submission options
    submissionTypesArrayList.clear();
    allOnlineSubmissionTypes.removeAllViews();
    for (int i = 0; i < Assignment.ONLINE_SUBMISSIONS.length; i++) {
        final Assignment.SUBMISSION_TYPE currentSubmissionType = Assignment.ONLINE_SUBMISSIONS[i];
        final CheckBox submissionTypeCheckBox = new CheckBox(getActivity());
        submissionTypeCheckBox.setTextColor(getResources().getColor(R.color.sg_darkText));
        submissionTypeCheckBox.setTag(currentSubmissionType);
        submissionTypeCheckBox.setText(Assignment.submissionTypeToPrettyPrintString(currentSubmissionType, getActivity()));
        if ((checkedSubmissionTypes.contains(currentSubmissionType) && (!checkedSubmissionTypesCache.containsKey(currentSubmissionType) || (checkedSubmissionTypesCache.containsKey(currentSubmissionType)) && checkedSubmissionTypesCache.get(currentSubmissionType).equals(true))) || (checkedSubmissionTypesCache.containsKey(currentSubmissionType) && checkedSubmissionTypesCache.get(currentSubmissionType).equals(true))) {
            submissionTypeCheckBox.setChecked(true);
        }
        submissionTypeCheckBox.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        submissionTypeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    checkedSubmissionTypesCache.put(currentSubmissionType, true);
                } else {
                    checkedSubmissionTypesCache.put(currentSubmissionType, false);
                }
                if (checkedSubmissionTypes.contains(currentSubmissionType) && checkedSubmissionTypesCache.containsKey(currentSubmissionType) && checkedSubmissionTypesCache.get(currentSubmissionType).equals(true)) {
                    checkedSubmissionTypesCache.remove(currentSubmissionType);
                }
            }
        });
        submissionTypesArrayList.add(submissionTypeCheckBox);
        allOnlineSubmissionTypes.addView(submissionTypeCheckBox);
    }
}
Also used : AssignmentGroup(com.instructure.canvasapi.model.AssignmentGroup) HelveticaTextView(com.instructure.speedgrader.views.HelveticaTextView) View(android.view.View) AdapterView(android.widget.AdapterView) DateTextView(com.instructure.speedgrader.views.DateTextView) Assignment(com.instructure.canvasapi.model.Assignment) CheckBox(android.widget.CheckBox) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) CompoundButton(android.widget.CompoundButton)

Example 3 with AssignmentGroup

use of com.instructure.canvasapi.model.AssignmentGroup in project instructure-android by instructure.

the class AssignmentGroupListRecyclerAdapter method populateAdapter.

private void populateAdapter(List<Assignment> assignments, List<AssignmentGroup> assignmentGroups) {
    // wait for all api calls to return
    if (assignmentGroups.size() == 0 || assignments.size() == 0) {
        return;
    }
    for (Assignment assignment : assignments) {
        // put the mAssignments into assignment groups
        AssignmentGroup assignmentGroup = mAssignmentGroupsHash.get(assignment.getAssignmentGroupId());
        if (assignmentGroup != null) {
            addOrUpdateItem(assignmentGroup, assignment);
        }
    }
    if (isAssignmentsLoaded && isGroupsLoaded) {
        mAdapterToFragmentCallback.onRefreshFinished();
        setAllPagesLoaded(true);
    }
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment) AssignmentGroup(com.instructure.canvasapi.model.AssignmentGroup)

Example 4 with AssignmentGroup

use of com.instructure.canvasapi.model.AssignmentGroup in project instructure-android by instructure.

the class EditAssignmentDialog method saveData.

public void saveData() {
    // disable save, show our progress
    disableSave();
    String editedAssignmentTitle = assignmentTitleET.getText().toString();
    Date editedDueAt = dueDateDT.getDate();
    boolean shouldNotifyUsers = notifyUsers.isChecked();
    Double editedPointsPossible = Double.parseDouble(pointsPossibleET.getText().toString());
    String editedAssignmentGroupString = (String) assignmentGroupSpinner.getSelectedItem();
    Long editedAssignmentGroup = null;
    for (AssignmentGroup group : assignmentGroups) {
        if (editedAssignmentGroupString.equals(group.getName())) {
            editedAssignmentGroup = group.getId();
            break;
        }
    }
    Assignment.GRADING_TYPE editedGradingType = Assignment.getGradingTypeFromString((String) gradingTypeSpinner.getSelectedItem(), getActivity());
    Assignment.SUBMISSION_TYPE[] editedSubmissionTypes;
    Assignment.TURN_IN_TYPE editedTurnInType = Assignment.stringToTurnInType((String) turnInTypeSpinner.getSelectedItem(), getActivity());
    if (editedTurnInType == Assignment.TURN_IN_TYPE.ONLINE) {
        ArrayList<Assignment.SUBMISSION_TYPE> newSubmissionTypes = new ArrayList<Assignment.SUBMISSION_TYPE>();
        for (CheckBox checkbox : submissionTypesArrayList) {
            if (checkbox.isChecked()) {
                newSubmissionTypes.add((Assignment.SUBMISSION_TYPE) checkbox.getTag());
            }
        }
        editedSubmissionTypes = newSubmissionTypes.toArray(new Assignment.SUBMISSION_TYPE[newSubmissionTypes.size()]);
    } else if (editedTurnInType == Assignment.TURN_IN_TYPE.ON_PAPER) {
        editedSubmissionTypes = new Assignment.SUBMISSION_TYPE[1];
        editedSubmissionTypes[0] = Assignment.SUBMISSION_TYPE.ON_PAPER;
    } else if (editedTurnInType == Assignment.TURN_IN_TYPE.NONE) {
        editedSubmissionTypes = new Assignment.SUBMISSION_TYPE[1];
        editedSubmissionTypes[0] = Assignment.SUBMISSION_TYPE.NONE;
    } else {
        editedSubmissionTypes = null;
    }
    assignment.setName(editedAssignmentTitle);
    assignment.setAssignmentGroupId(editedAssignmentGroup);
    if (editedSubmissionTypes != null) {
        assignment.setSubmissionTypes(editedSubmissionTypes);
    }
    assignment.setPointsPossible(editedPointsPossible);
    assignment.setGradingType(editedGradingType);
    assignment.setDueDate(editedDueAt);
    assignment.setMuted(mutedCheckBox.isChecked());
    AssignmentAPI.editAssignment(assignment, shouldNotifyUsers, assignmentCanvasCallback);
}
Also used : AssignmentGroup(com.instructure.canvasapi.model.AssignmentGroup) ArrayList(java.util.ArrayList) Date(java.util.Date) Assignment(com.instructure.canvasapi.model.Assignment) CheckBox(android.widget.CheckBox)

Example 5 with AssignmentGroup

use of com.instructure.canvasapi.model.AssignmentGroup in project instructure-android by instructure.

the class AssignmentListFragment method loadSavedInstanceState.

public void loadSavedInstanceState(Bundle savedInstanceState) {
    this.mAssignments = (ArrayList) savedInstanceState.getSerializable(Const.ASSIGNMENTS);
    // get all AssignmentGroups from parcelable array
    Parcelable[] assignmentGroupParcels = savedInstanceState.getParcelableArray(Const.assignmentGroups);
    if (assignmentGroupParcels != null) {
        this.mAssignmentGroups = new AssignmentGroup[assignmentGroupParcels.length];
        // array and cast each item into a AssignmentGroup to rebuild our arrray
        for (int i = 0; i < assignmentGroupParcels.length; i++) {
            this.mAssignmentGroups[i] = (AssignmentGroup) assignmentGroupParcels[i];
        }
        for (AssignmentGroup assignmentGroup : this.mAssignmentGroups) {
            mAssignmentGroupsHash.put(assignmentGroup.getId(), assignmentGroup);
        }
    }
    this.mSections = (ArrayList) savedInstanceState.getSerializable(Const.sections);
}
Also used : AssignmentGroup(com.instructure.canvasapi.model.AssignmentGroup) Parcelable(android.os.Parcelable)

Aggregations

AssignmentGroup (com.instructure.canvasapi.model.AssignmentGroup)5 Assignment (com.instructure.canvasapi.model.Assignment)3 CheckBox (android.widget.CheckBox)2 Parcelable (android.os.Parcelable)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 CompoundButton (android.widget.CompoundButton)1 Gson (com.google.gson.Gson)1 DateTextView (com.instructure.speedgrader.views.DateTextView)1 HelveticaTextView (com.instructure.speedgrader.views.HelveticaTextView)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1