Search in sources :

Example 21 with Course

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

the class AddMessageFragment method onReadySetGo.

@Override
protected void onReadySetGo(AddMessagePresenter presenter) {
    setupToolbar();
    // Set conversation subject
    if (!isNewMessage && !mIsMessageStudentsWho) {
        mSubject.setText(presenter.getConversation().getSubject());
    } else if (mIsMessageStudentsWho) {
        if (mIsPersonalMessage) {
            mSubject.setVisibility(View.GONE);
            mEditSubject.setVisibility(View.VISIBLE);
            mEditSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        } else {
            mSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        }
    }
    // Set up recipients view
    mChipsTextView.setTokenizer(new Rfc822Tokenizer());
    if (mChipsAdapter == null) {
        mChipsAdapter = new RecipientAdapter(getContext());
    }
    if (mChipsTextView.getAdapter() == null) {
        mChipsTextView.setAdapter(mChipsAdapter);
    }
    if (getPresenter().getCourse().getId() != 0) {
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(getPresenter().getCourse());
    } else if (mSelectedCourse != null) {
        courseWasSelected();
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(mSelectedCourse);
    }
    ColorUtils.colorIt(ThemePrefs.getButtonColor(), mContactsButton);
    // don't show the contacts button if there is no selected course and there is no context_code from the conversation (shouldn't happen, but it does)
    if (mSelectedCourse == null && getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
        mContactsButton.setVisibility(View.INVISIBLE);
    }
    mContactsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CanvasContext canvasContext;
            if (getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
                // presenter doesn't know what the course is, use the mSelectedCourse instead
                canvasContext = mSelectedCourse;
            } else {
                canvasContext = getPresenter().getCourse();
            }
            RouteMatcher.route(getContext(), new Route(ChooseRecipientsFragment.class, canvasContext, ChooseRecipientsFragment.createBundle(canvasContext, getRecipientsFromRecipientEntries())));
        }
    });
    // Ensure attachments are up to date
    refreshAttachments();
    // get courses and groups if this is a new compose message
    if (isNewMessage) {
        getPresenter().getAllCoursesAndGroups(true);
    }
}
Also used : Rfc822Tokenizer(android.text.util.Rfc822Tokenizer) RecipientAdapter(com.instructure.teacher.adapters.RecipientAdapter) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) RecipientEditTextView(com.android.ex.chips.RecipientEditTextView) TextView(android.widget.TextView) AddMessageView(com.instructure.teacher.viewinterface.AddMessageView) AttachmentView(com.instructure.pandautils.views.AttachmentView) ScrollView(android.widget.ScrollView) Route(com.instructure.interactions.router.Route)

Example 22 with Course

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

the class OpenPollExpandableListFragment method configureViews.

@Override
public void configureViews(View rootView) {
    if (getArguments() != null) {
        ArrayList<Course> courseList = (ArrayList<Course>) getArguments().getSerializable(Constants.COURSES_LIST);
        if (courseList != null) {
            courseMap = createCourseMap(courseList);
        } else {
            courseMap = new HashMap<>();
        }
    } else {
        courseMap = new HashMap<>();
    }
    // set an animation for adding list items
    LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.list_layout_controller);
    getExpandableListView().setLayoutAnimation(controller);
    pollMap = new HashMap<>();
}
Also used : ArrayList(java.util.ArrayList) LayoutAnimationController(android.view.animation.LayoutAnimationController) Course(com.instructure.canvasapi2.models.Course)

Example 23 with Course

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

the class PollSessionListFragment method generateCSV.

private void generateCSV() {
    String csv = "";
    csv += "Poll Title, Poll Session, Course Name, Section Name, User Name, Answer, Date\n";
    for (int i = 0; i < getItemCount(); i++) {
        PollSession pollSession = getItem(i);
        if (pollSession.getPoll_submissions() != null) {
            for (PollSubmission pollSubmission : pollSession.getPoll_submissions()) {
                // now add all the necessary stuff to the csv string
                csv += poll.getQuestion() + ",";
                csv += pollSession.getId() + ",";
                csv += courseMap.get(pollSession.getCourse_id()).getName() + ",";
                csv += sectionMap.get(pollSession.getCourse_section_id()).getName() + ",";
                csv += pollSubmission.getUser_id() + ",";
                // of just an id
                if (pollChoiceMap != null && pollChoiceMap.containsKey(pollSubmission.getPoll_choice_id())) {
                    csv += pollChoiceMap.get(pollSubmission.getPoll_choice_id()).getText() + ",";
                } else {
                    csv += pollSubmission.getPoll_choice_id() + ",";
                }
                csv += pollSubmission.getCreated_at() + "\n";
            }
        } else {
            csv += poll.getQuestion() + ",";
            csv += pollSession.getId() + ",";
            csv += courseMap.get(pollSession.getCourse_id()).getName() + ",";
            csv += sectionMap.get(pollSession.getCourse_section_id()).getName() + ",";
            csv += "" + ",";
            csv += "" + ",";
            csv += pollSession.getCreated_at() + "\n";
        }
    }
    // check to make sure there is external storage
    String state = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        // it's not there, so the reset of this won't work. Let the user know.
        AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
        return;
    }
    File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), getString(R.string.generatedCSVFolderName));
    // Make sure the directory exists.
    boolean success = path.mkdirs();
    if (!success) {
        // return false)
        if (!path.isDirectory()) {
            // it's not a directory and wasn't created, so we need to return with an error
            AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
            return;
        }
    }
    Time now = new Time();
    now.setToNow();
    File file = new File(path, "csv_" + now.format3339(false) + ".csv");
    try {
        // write the string to a file
        FileWriter out = new FileWriter(file);
        out.write(csv);
        out.close();
    } catch (IOException e) {
        // Unable to create file
        AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
    }
    // file is generated, not share it
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    shareIntent.setType("text/csv");
    startActivity(Intent.createChooser(shareIntent, getString(R.string.shareCSV)));
}
Also used : PollSession(com.instructure.canvasapi2.models.PollSession) FileWriter(java.io.FileWriter) Time(android.text.format.Time) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) PollSubmission(com.instructure.canvasapi2.models.PollSubmission)

Example 24 with Course

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

the class QuestionListFragment method checkEnrollments.

// we need to know if the user is a teacher in any course
private void checkEnrollments(List<Course> courses) {
    for (Course course : courses) {
        if (course.isTeacher()) {
            hasTeacherEnrollment = true;
            // update the actionbar so the icon shows if we need it
            getActivity().invalidateOptionsMenu();
            return;
        }
    }
    hasTeacherEnrollment = false;
    // update the actionbar so the icon shows if we need it
    getActivity().invalidateOptionsMenu();
}
Also used : Course(com.instructure.canvasapi2.models.Course)

Example 25 with Course

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

the class PeopleListFragment method setupViews.

private void setupViews() {
    final CanvasContext canvasContext = getArguments().getParcelable(Const.CANVAS_CONTEXT);
    mToolbar.setTitle(R.string.tab_people);
    mToolbar.setSubtitle(canvasContext.getName());
    if (mToolbar.getMenu().size() == 0)
        mToolbar.inflateMenu(R.menu.menu_people_list);
    final SearchView searchView = (SearchView) mToolbar.getMenu().findItem(R.id.search).getActionView();
    MenuItemCompat.setOnActionExpandListener(mToolbar.getMenu().findItem(R.id.search), new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.GONE);
            mSwipeRefreshLayout.setEnabled(false);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(false);
            }
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.VISIBLE);
            mSwipeRefreshLayout.setEnabled(true);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(true);
            }
            getPresenter().refresh(false);
            return true;
        }
    });
    searchView.setOnQueryTextListener(this);
    if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
        mToolbar.getMenu().findItem(R.id.peopleFilter).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // let the user select the course/group they want to see
                PeopleListFilterDialog.getInstance(getActivity().getSupportFragmentManager(), getPresenter().getCanvasContextListIds(), canvasContext, true, new Function1<ArrayList<CanvasContext>, Unit>() {

                    @Override
                    public Unit invoke(ArrayList<CanvasContext> canvasContexts) {
                        mCanvasContextsSelected = new ArrayList<>();
                        mCanvasContextsSelected.addAll(canvasContexts);
                        getPresenter().setCanvasContextList(mCanvasContextsSelected);
                        setupTitle(canvasContexts);
                        return null;
                    }
                }).show(getActivity().getSupportFragmentManager(), PeopleListFilterDialog.class.getSimpleName());
                return false;
            }
        });
    }
    mClearFilterTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mPeopleFilter.setText(R.string.allPeople);
            getPresenter().clearCanvasContextList();
            mClearFilterTextView.setVisibility(View.GONE);
        }
    });
    setupTitle(getPresenter().getCanvasContextList());
    ViewStyler.themeToolbar(getActivity(), mToolbar, ColorKeeper.INSTANCE.getOrGenerateColor(canvasContext), Color.WHITE);
    ViewUtils.setupToolbarBackButton(mToolbar, this);
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) ArrayList(java.util.ArrayList) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) MenuItem(android.view.MenuItem) Unit(kotlin.Unit) SearchView(android.support.v7.widget.SearchView) EmptyPandaView(com.instructure.teacher.view.EmptyPandaView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PeopleListView(com.instructure.teacher.viewinterface.PeopleListView) SearchView(android.support.v7.widget.SearchView)

Aggregations

Course (com.instructure.canvasapi2.models.Course)106 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)39 Enrollment (com.instructure.canvasapi2.models.Enrollment)29 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)17 RestParams (com.instructure.canvasapi2.builders.RestParams)17 View (android.view.View)13 Bundle (android.os.Bundle)10 TextView (android.widget.TextView)10 NonNull (android.support.annotation.NonNull)8 AdapterView (android.widget.AdapterView)8 ModuleItem (com.instructure.canvasapi2.models.ModuleItem)8 ParentFragment (com.instructure.candroid.fragment.ParentFragment)7 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)7 ImageView (android.widget.ImageView)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 List (java.util.List)6 BindView (butterknife.BindView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 StatusCallback (com.instructure.canvasapi2.StatusCallback)4