Search in sources :

Example 41 with Assignment

use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.

the class SubmissionDetailsFragment method showFileList.

/**
 * this will display a dialog list of the attachments for the assignment. Tapping on one will open it.
 *
 * @param attachments
 */
private void showFileList(ArrayList<Attachment> attachments) {
    // create a new dialog
    Dialog dlg = new Dialog(getActivity());
    LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // inflate the view
    View v = li.inflate(R.layout.dialog_listview, null, false);
    dlg.setContentView(v);
    ListView lv = (ListView) v.findViewById(R.id.listview);
    // create the adapter
    SubmissionFileAdapter fileAdapter = new SubmissionFileAdapter(getActivity(), R.layout.listview_item_row_attachedfiles, attachments);
    dlg.setTitle(getString(R.string.myFiles));
    lv.setAdapter(fileAdapter);
    // when they tap an item, open it
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            Attachment attachment = (Attachment) adapter.getAdapter().getItem(position);
            // If this is a pdf, we want to make sure we disable annotations/etc
            if (attachment.getContentType().contains("pdf")) {
                openMedia(true, attachment.getContentType(), attachment.getUrl(), attachment.getFilename());
            } else {
                openMedia(attachment.getContentType(), attachment.getUrl(), attachment.getFilename());
            }
        }
    });
    dlg.show();
}
Also used : ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) UploadFilesDialog(com.instructure.pandautils.dialogs.UploadFilesDialog) LayoutInflater(android.view.LayoutInflater) Attachment(com.instructure.canvasapi2.models.Attachment) ImageView(android.widget.ImageView) AttachmentView(com.instructure.candroid.view.AttachmentView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) BeforePageView(com.instructure.canvasapi2.utils.pageview.BeforePageView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) TextView(android.widget.TextView) ListView(android.widget.ListView) Paint(android.graphics.Paint)

Example 42 with Assignment

use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.

the class SubmissionDetailsFragment method setupCallbacks.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setupCallbacks() {
    notoriousConfigCallback = new StatusCallback<NotoriousConfig>() {

        @Override
        public void onResponse(@NonNull Response<NotoriousConfig> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            NotoriousConfig notoriousConfig = response.body();
            if (notoriousConfig.isEnabled()) {
                mediaComment.setEnabled(true);
            }
        }
    };
    // We use a NoNetworkErrorDelegate because sometimes old submissions are deleted.
    // We don't want to display unnecessary croutons.
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            if (response.body() != null) {
                populateAdapter(response.body());
            }
        }
    };
    canvasCallbackMessage = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            // See if it was successful.
            Submission submission = response.body();
            if (submission != null) {
                SubmissionComment comment = submission.getSubmissionComments().get(submission.getSubmissionComments().size() - 1);
                // Our list is a list of Submission, so add the comment to a SubmissionGrade object
                Submission newSub = new Submission();
                ArrayList<SubmissionComment> comments = new ArrayList<>();
                comments.add(comment);
                newSub.setSubmittedAt(comment.getCreatedAt());
                newSub.setSubmissionComments(comments);
                adapter.subList.add(0, newSub);
                message.setText("");
            } else {
                showToast(R.string.errorPostingComment);
            }
            adapter.notifyDataSetChanged();
            // Close the keyboard
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
            // Enable the send message button again
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }

        @Override
        public void onFail(@Nullable Call<Submission> call, @NonNull Throwable error, @Nullable Response response) {
            // Enable the send message button again if there was an Error
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }
    };
    canvasCallbackLTITool = new StatusCallback<LTITool>() {

        @Override
        public void onResponse(@NonNull Response<LTITool> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            LTITool ltiTool = response.body();
            String url = ltiTool.getUrl();
            // Append platform for quizzes 2 lti tool
            Uri uri = Uri.parse(url).buildUpon().appendQueryParameter("platform", "android").build();
            // Do NOT authenticate or the LTI tool won't load.
            InternalWebviewFragment.Companion.loadInternalWebView(getActivity(), ((Navigation) getActivity()), InternalWebviewFragment.Companion.createBundle(getCanvasContext(), uri.toString(), ltiTool.getName(), false, false, true, assignment.getUrl()));
        }

        @Override
        public void onFail(@Nullable Call<LTITool> call, @NonNull Throwable error, @Nullable Response response) {
            // If it wasn't a network Error, then the LTI tool must be expired or invalid.
            if (APIHelper.hasNetworkConnection() && (response == null || (response != null && response.code() != 504))) {
                showToast(R.string.invalidExternal);
            }
        }
    };
    canvasCallbackAssignment = new StatusCallback<Assignment>() {

        @Override
        public void onResponse(@NonNull Response<Assignment> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Assignment newAssignment = response.body();
            String authenticationURL;
            if (newAssignment == null) {
                authenticationURL = null;
            } else {
                authenticationURL = newAssignment.getUrl();
            }
            // Now get the LTITool
            // This API call handles url being null
            SubmissionManager.getLtiFromAuthenticationUrl(authenticationURL, canvasCallbackLTITool, true);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) SubmissionComment(com.instructure.canvasapi2.models.SubmissionComment) Assignment(com.instructure.canvasapi2.models.Assignment) ApiType(com.instructure.canvasapi2.utils.ApiType) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Response(retrofit2.Response) NotoriousConfig(com.instructure.canvasapi2.models.NotoriousConfig)

Example 43 with Assignment

use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.

the class ToDoListFragment method onRowClick.

private void onRowClick(ToDo toDo) {
    if (toDo == null) {
        return;
    }
    Bundle bundle = new Bundle();
    bundle.putParcelable(Const.SELECTED_ITEM, toDo);
    Navigation navigation = getNavigation();
    if (navigation != null) {
        if (toDo.getAssignment() != null) {
            // Launch assignment details fragment.
            navigation.addFragment(FragUtils.getFrag(AssignmentFragment.class, createBundle(toDo.getCanvasContext(), toDo.getAssignment())));
        } else if (toDo.getScheduleItem() != null) {
            // It's a Calendar event from the Upcoming API.
            ScheduleItem scheduleItem = toDo.getScheduleItem();
            String actionBarTitle = "";
            if (scheduleItem.getContextType() == CanvasContext.Type.COURSE) {
                actionBarTitle = toDo.getCanvasContext().getName();
            } else if (scheduleItem.getContextType() == CanvasContext.Type.USER) {
                actionBarTitle = getContext().getString(R.string.PersonalCalendar);
            }
            navigation.addFragment(FragUtils.getFrag(CalendarEventFragment.class, createBundle(toDo.getCanvasContext(), actionBarTitle, toDo.getScheduleItem())));
        }
    }
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Navigation(com.instructure.interactions.Navigation) Bundle(android.os.Bundle)

Example 44 with Assignment

use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.

the class AssignmentDateListRecyclerAdapterTest method testAreContentsTheSame_oneNullDueDate.

@Test
public void testAreContentsTheSame_oneNullDueDate() {
    Assignment assignmentDueDate = new Assignment();
    assignmentDueDate.setName("Assign1");
    assignmentDueDate.setDueAt(APIHelper.dateToString(new Date()));
    Assignment assignment1 = new Assignment();
    assignment1.setName("Assign1");
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignment1));
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignment1, assignmentDueDate));
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignmentDueDate));
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Date(java.util.Date) Test(org.junit.Test)

Example 45 with Assignment

use of com.instructure.canvasapi2.models.Assignment in project instructure-android by instructure.

the class AssignmentGroupListRecyclerAdapterTest method testAreContentsTheSame_oneNullDueDate.

@Test
public void testAreContentsTheSame_oneNullDueDate() {
    Assignment assignmentDueDate = new Assignment();
    assignmentDueDate.setName("Assign1");
    assignmentDueDate.setDueAt(APIHelper.dateToString(new Date()));
    Assignment assignment1 = new Assignment();
    assignment1.setName("Assign1");
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignment1));
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(assignment1, assignmentDueDate));
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(assignmentDueDate, assignmentDueDate));
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Assignment (com.instructure.canvasapi2.models.Assignment)62 Test (org.junit.Test)46 Submission (com.instructure.canvasapi2.models.Submission)25 Date (java.util.Date)18 ArrayList (java.util.ArrayList)15 View (android.view.View)10 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)10 Course (com.instructure.canvasapi2.models.Course)9 RestParams (com.instructure.canvasapi2.builders.RestParams)7 Bundle (android.os.Bundle)6 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 Navigation (com.instructure.interactions.Navigation)5 DrawableRes (android.support.annotation.DrawableRes)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 Request (okhttp3.Request)4 Response (okhttp3.Response)4 Paint (android.graphics.Paint)3 Drawable (android.graphics.drawable.Drawable)3