Search in sources :

Example 1 with ToDo

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

the class CalendarListRecyclerAdapter method getExtraData.

/**
 * A small helper method used to create a data list for use in getView for the calendar grid
 * used to determine when dates have events and how many.
 */
private void getExtraData() {
    HashMap<String, Object> hashMap = mAdapterToCalendarCallback.getExtraCalendarData();
    ArrayList<EventData> eventList = new ArrayList<>();
    // flush mAllEvents
    HashSet<ScheduleItem> hs = new HashSet<>();
    hs.addAll(mAllEvents);
    mAllEvents.clear();
    mAllEvents.addAll(hs);
    // todo optimize
    for (ScheduleItem s : mAllEvents) {
        Date d = s.getStartAt();
        DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
        int dateCount = countDateInEvents(d);
        if (dateCount == 1) {
            // ExtraData(date, number of events)
            eventList.add(new EventData(dateTime, EventData.EventCount.MIN));
        } else if (dateCount >= 2 && dateCount <= 5) {
            eventList.add(new EventData(dateTime, EventData.EventCount.MID));
        } else {
            eventList.add(new EventData(dateTime, EventData.EventCount.MAX));
        }
    }
    hashMap.put(Const.EVENT_LIST, eventList);
    mAdapterToCalendarCallback.refreshCalendarFragment();
    refreshListView();
    mAdapterToCalendarCallback.hidePandaLoading();
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) ArrayList(java.util.ArrayList) EventData(com.instructure.candroid.model.EventData) Date(java.util.Date) DateTime(hirondelle.date4j.DateTime) HashSet(java.util.HashSet)

Example 2 with ToDo

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

the class TodoListRecyclerAdapter method populateAdapter.

private void populateAdapter() {
    if (mTodoList == null || mCourseMap == null || mGroupMap == null) {
        return;
    }
    List<ToDo> todos = ToDoManager.mergeToDoUpcoming(mTodoList, null);
    // Now populate the todoList and upcomingList with the course information
    for (ToDo toDo : todos) {
        ToDo.setContextInfo(toDo, mCourseMap, mGroupMap);
        if (toDo.getCanvasContext() != null)
            addOrUpdateItem(DateHelper.getCleanDate(toDo.getComparisonDate().getTime()), toDo);
    }
    mAdapterToFragmentCallback.onRefreshFinished();
    setAllPagesLoaded(true);
    // Reset the lists
    mTodoList = null;
    mCourseMap = null;
    mGroupMap = null;
    onCallbackFinished(ApiType.API);
}
Also used : ToDo(com.instructure.canvasapi2.models.ToDo)

Example 3 with ToDo

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

the class SubmissionDetailsFragment method setupListeners.

private void setupListeners() {
    if (addSubmission != null) {
        addSubmission.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO  Open Submission view, "Go To Discussion" or "Go To Quiz"
                if (// Allow the user to go to the discussion.
                assignment.getDiscussionTopicHeader() != null && assignment.getDiscussionTopicHeader().getId() > 0 && assignment.getCourseId() > 0) {
                    String url = DiscussionTopic.getDiscussionURL(ApiPrefs.getProtocol(), ApiPrefs.getDomain(), assignment.getCourseId(), assignment.getDiscussionTopicHeader().getId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getQuizId() > 0) {
                    String url = getQuizURL(getActivity(), assignment.getCourseId(), assignment.getQuizId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getTurnInType() == Assignment.TURN_IN_TYPE.EXTERNAL_TOOL) {
                    // TODO stream doesn't pass the LTI url. Grab it now if we need it
                    String authenticationURL = assignment.getUrl();
                    if (authenticationURL == null || authenticationURL.equalsIgnoreCase("null")) {
                        // get the assignment
                        AssignmentManager.getAssignment(assignment.getId(), course.getId(), true, canvasCallbackAssignment);
                        return;
                    } else {
                        SubmissionManager.getLtiFromAuthenticationUrl(assignment.getUrl(), canvasCallbackLTITool, true);
                    }
                } else {
                    if (!APIHelper.hasNetworkConnection()) {
                        Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // open add submission view
                    // start it for xml so we can update the results if we need to. Need to call it on the parent fragment
                    // and it will call onActivityResult in the current child fragment.
                    Navigation navigation = getNavigation();
                    if (navigation != null) {
                        Bundle bundle = AddSubmissionFragment.createBundle((Course) getCanvasContext(), assignment, isOnlineTextAllowed, isUrlEntryAllowed, isFileEntryAllowed, isMediaRecording);
                        navigation.addFragment(FragUtils.getFrag(AddSubmissionFragment.class, bundle));
                    }
                }
            }
        });
    }
    // Handle pressing of the send button.
    if (submitComment != null) {
        submitComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // try to submit the comment
                if (!APIHelper.hasNetworkConnection()) {
                    Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                    return;
                }
                sendMessage(assignment.getId());
            }
        });
        mediaComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                ListView listView = new ListView(getActivity());
                AttachmentAdapter adapter = new AttachmentAdapter(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.discussion_attachments));
                listView.setAdapter(adapter);
                listView.setDivider(null);
                listView.setPadding((int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 16));
                final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.commentUpload).setView(listView).create();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        switch(position) {
                            case 0:
                                // Use File Upload Dialog
                                showUploadFileDialog();
                                dialog.dismiss();
                                break;
                            case 1:
                                if (message.getText().toString().trim().length() != 0 || attachmentIds.size() > 0) {
                                    Toast.makeText(getContext(), R.string.unableToUploadMediaComment, Toast.LENGTH_SHORT).show();
                                } else {
                                    // Use Notorious
                                    Intent intent = NotoriousMediaUploadPicker.createIntentForSubmissionComment(getContext(), assignment);
                                    assignmentFragment.get().startActivityForResult(intent, RequestCodes.NOTORIOUS_REQUEST);
                                    dialog.dismiss();
                                }
                                break;
                            default:
                                break;
                        }
                    }
                });
                dialog.show();
            }
        });
    }
    // Handle if they hit the send button in landscape mode.
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            // Try to send the message.
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendMessage(assignment.getId());
                // Hide keyboard
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    if (listView != null) {
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
                Submission submission = (Submission) adapter.getAdapter().getItem(position);
                // it has the details that we need
                if (submission.getSubmissionComments().size() == 0) {
                    if (submission.getSubmissionType().equals("online_upload") || submission.getSubmissionType().equals("media_recording")) {
                        if (submission.getAttachments().size() == 1) {
                            // makes more sense to open the file since they should already have it on their device
                            if (submission.getAttachments().get(0).getContentType().contains("pdf")) {
                                startActivity(StudentSubmissionActivity.createIntent(getActivity(), course, assignment, new GradeableStudentSubmission(new StudentAssignee(ApiPrefs.getUser(), ApiPrefs.getUser().getId(), ApiPrefs.getUser().getName()), null, false)));
                            } else {
                                openMedia(submission.getAttachments().get(0).getContentType(), submission.getAttachments().get(0).getUrl(), submission.getAttachments().get(0).getFilename());
                            }
                        } else if (submission.getMediaComment() != null) {
                            MediaComment mediaComment = submission.getMediaComment();
                            openMedia(mediaComment.getContentType(), mediaComment.getUrl(), mediaComment.get_fileName());
                        } else {
                            // show a list dialog of the files to download.
                            showFileList(submission.getAttachments());
                        }
                    } else if (submission.getSubmissionType().equals("online_text_entry")) {
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = InternalWebviewFragment.Companion.createBundleHTML(getCanvasContext(), submission.getBody());
                            navigation.addFragment(FragUtils.getFrag(InternalWebviewFragment.class, bundle));
                        }
                    } else if (submission.getSubmissionType().equals("online_url")) {
                        // Take the user to viewing the online url submission. If the image hasn't processed yet they'll see a toast and it
                        // will match what the web does - show the url and say it might be different from when they submitted.
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = SubmissionViewOnlineURLFragment.createBundle(getCanvasContext(), submission);
                            navigation.addFragment(FragUtils.getFrag(SubmissionViewOnlineURLFragment.class, bundle));
                        }
                        if (submission.getAttachments().size() == 0) {
                            // the server hasn't processed the image for the submitted url yet, show a crouton and reload
                            showToast(R.string.itemStillProcessing);
                            loadData(assignment.getId(), false, false);
                        }
                    }
                }
            }
        });
    }
    addComment.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!APIHelper.hasNetworkConnection()) {
                Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                return;
            }
            // Only show the header if it hasn't been added prior.
            if (listView.getHeaderViewsCount() == 1) {
                listView.addHeaderView(composeHeaderView, null, false);
            }
            // add the compose header (the comment box)
            composeHeaderView.setVisibility(View.VISIBLE);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) StudentAssignee(com.instructure.canvasapi2.models.StudentAssignee) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) TextView(android.widget.TextView) Course(com.instructure.canvasapi2.models.Course) MediaComment(com.instructure.canvasapi2.models.MediaComment) Navigation(com.instructure.interactions.Navigation) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) Bundle(android.os.Bundle) Intent(android.content.Intent) 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) InternalWebViewActivity(com.instructure.candroid.activity.InternalWebViewActivity) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 4 with ToDo

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

the class ToDoListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = getLayoutInflater().inflate(R.layout.fragment_list_todo, container, false);
    mToolbar = mRootView.findViewById(R.id.toolbar);
    mAdapterToFragmentCallback = new NotificationAdapterToFragmentCallback<ToDo>() {

        @Override
        public void onRowClicked(ToDo todo, int position, boolean isOpenDetail) {
            mRecyclerAdapter.setSelectedPosition(position);
            onRowClick(todo);
        }

        @Override
        public void onRefreshFinished() {
            setRefreshing(false);
            mEditOptions.setVisibility(View.GONE);
        }

        @Override
        public void onShowEditView(boolean isVisible) {
            mEditOptions.setVisibility(isVisible ? View.VISIBLE : View.GONE);
        }

        @Override
        public void onShowErrorCrouton(int message) {
        // do nothing
        }
    };
    mRecyclerAdapter = new TodoListRecyclerAdapter(getContext(), getCanvasContext(), mAdapterToFragmentCallback);
    configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    PandaRecyclerView pandaRecyclerView = mRootView.findViewById(R.id.listView);
    pandaRecyclerView.setSelectionEnabled(false);
    configureViews(mRootView);
    return mRootView;
}
Also used : ToDo(com.instructure.canvasapi2.models.ToDo) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) TodoListRecyclerAdapter(com.instructure.candroid.adapter.TodoListRecyclerAdapter)

Example 5 with ToDo

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

the class TodoListRecyclerAdapterTest method testAreContentsTheSame_DifferentTitleFromSchedule.

@Test
public void testAreContentsTheSame_DifferentTitleFromSchedule() {
    ToDo item = new ToDo();
    ScheduleItem scheduleItem = new ScheduleItem();
    scheduleItem.setTitle("item");
    item.setScheduleItem(scheduleItem);
    ToDo item1 = new ToDo();
    ScheduleItem scheduleItem1 = new ScheduleItem();
    scheduleItem1.setTitle("item1");
    item1.setScheduleItem(scheduleItem1);
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(item, item1));
}
Also used : ToDo(com.instructure.canvasapi2.models.ToDo) ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Test(org.junit.Test)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)158 RestParams (com.instructure.canvasapi2.builders.RestParams)141 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)51 Response (okhttp3.Response)47 List (java.util.List)43 ArrayList (java.util.ArrayList)36 Request (okhttp3.Request)26 StatusCallback (com.instructure.canvasapi2.StatusCallback)21 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)20 NonNull (android.support.annotation.NonNull)19 Conversation (com.instructure.canvasapi2.models.Conversation)10 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)8 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)8 ToDo (com.instructure.canvasapi2.models.ToDo)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)7 Assignment (com.instructure.canvasapi2.models.Assignment)6 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)6 FileFolder (com.instructure.canvasapi2.models.FileFolder)6 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)6 Course (com.instructure.canvasapi2.models.Course)5