Search in sources :

Example 1 with Message

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

the class BaseParentActivity method handleError.

public void handleError(int code, String error) {
    if (code == 418) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        RevokedTokenResponse revokedTokenResponse = gson.fromJson(mJson, RevokedTokenResponse.class);
        showRevokedTokenDialog(revokedTokenResponse, this);
    }
    if (code == 403) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        BlockedStudentResponse blockedStudentResponse = gson.fromJson(mJson, BlockedStudentResponse.class);
        if (blockedStudentResponse.code.equals("studentBlocked")) {
            Prefs prefs = new Prefs(this, getString(R.string.app_name_parent));
            String parentId = prefs.load(Const.ID, "");
            // We want to refresh cache so the main activity can load quickly with accurate information
            UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {

                @Override
                public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (response.body() != null && !response.body().isEmpty()) {
                        // They have students that they are observing, take them to that activity
                        startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
                        overridePendingTransition(0, 0);
                        finish();
                    } else {
                        // Take the parent to the add user page.
                        FindSchoolActivity.Companion.createIntent(BaseParentActivity.this, true);
                        finish();
                    }
                }
            });
        }
    }
    if (code == 451) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        MismatchedRegionResponse mismatchedRegionResponse = gson.fromJson(mJson, MismatchedRegionResponse.class);
        showMismatchedRegionDialog(mismatchedRegionResponse.getStudentRegion(), this);
    }
}
Also used : BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Gson(com.google.gson.Gson) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) JsonElement(com.google.gson.JsonElement) ApiType(com.instructure.canvasapi2.utils.ApiType) List(java.util.List) JsonParser(com.google.gson.JsonParser)

Example 2 with Message

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

the class AskInstructorDialogStyled method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(getActivity().getString(R.string.instructor_question)).setPositiveButton(getActivity().getString(R.string.send), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (canClickSend) {
                if (message == null || message.getText().toString().trim().equals("")) {
                    Toast.makeText(getActivity(), getString(R.string.emptyMessage), Toast.LENGTH_SHORT).show();
                } else {
                    progressDialog = ProgressDialog.show(getActivity(), "", getActivity().getString(R.string.sending));
                    loadTeacherData();
                }
            }
        }
    });
    // Suppress lint warning about null parent when inflating layout
    @SuppressLint("InflateParams") final View view = LayoutInflater.from(getActivity()).inflate(R.layout.ask_instructor, null);
    courseSpinner = view.findViewById(R.id.courseSpinner);
    ArrayList<Course> loadingIndicator = new ArrayList<Course>();
    Course loading = new Course();
    loading.setName(getActivity().getString(R.string.loading));
    loadingIndicator.add(loading);
    courseAdapter = new CourseSpinnerAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item, loadingIndicator);
    // we haven't set an onItemSelectedListener, so selecting the item shouldn't do anything
    courseSpinner.setAdapter(courseAdapter);
    message = view.findViewById(R.id.message);
    builder.setView(view);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface worthless) {
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ThemePrefs.getBrandColor());
            ViewStyler.themeEditText(getContext(), (AppCompatEditText) message, ThemePrefs.getBrandColor());
        }
    });
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) AppCompatEditText(android.support.v7.widget.AppCompatEditText) SuppressLint(android.annotation.SuppressLint) Course(com.instructure.canvasapi2.models.Course) NonNull(android.support.annotation.NonNull)

Example 3 with Message

use of com.instructure.canvasapi2.models.Message 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 4 with Message

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

the class AddMessageFragment method getPresenterFactory.

@Override
protected PresenterFactory<AddMessagePresenter> getPresenterFactory() {
    Conversation conversation = getArguments().getParcelable(Const.CONVERSATION);
    ArrayList<BasicUser> participants = getArguments().getParcelableArrayList(KEY_PARTICIPANTS);
    ArrayList<Message> messages = getArguments().getParcelableArrayList(Const.MESSAGE);
    boolean isReply = getArguments().getBoolean(KEY_IS_REPLY, false);
    return new AddMessagePresenterFactory(conversation, participants, messages, isReply);
}
Also used : BasicUser(com.instructure.canvasapi2.models.BasicUser) Message(com.instructure.canvasapi2.models.Message) Conversation(com.instructure.canvasapi2.models.Conversation) AddMessagePresenterFactory(com.instructure.teacher.factory.AddMessagePresenterFactory)

Example 5 with Message

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

the class AddMessageFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_add_message, container, false);
    ButterKnife.bind(this, view);
    isNewMessage = getArguments().getBoolean(Const.COMPOSE_FRAGMENT);
    mIsPersonalMessage = getArguments().getBoolean(MESSAGE_STUDENTS_WHO_CONTEXT_IS_PERSONAL);
    mIsMessageStudentsWho = getArguments().getBoolean(MESSAGE_STUDENTS_WHO);
    if (savedInstanceState != null && !isNewMessage) {
    } else if (isNewMessage) {
        // composing a new message
        mSpinnerWrapper.setVisibility(View.VISIBLE);
        mRecipientWrapper.setVisibility(View.GONE);
        mSubject.setVisibility(View.GONE);
        mEditSubject.setVisibility(View.VISIBLE);
        mSendIndividualWrapper.setVisibility(View.VISIBLE);
        ViewStyler.themeSwitch(getContext(), mSendIndividualSwitch, ThemePrefs.getBrandColor());
        mSendIndividualSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                mSendIndividually = isChecked;
            }
        });
        if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_COURSE)) {
            mSelectedCourse = savedInstanceState.getParcelable(SELECTED_COURSE);
        }
    } else {
        mCurrentMessage = getArguments().getParcelable(Const.MESSAGE_TO_USER);
        ViewTreeObserver vto = mChipsTextView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                if (getPresenter().isReply()) {
                    if (mCurrentMessage != null) {
                        addInitialRecipients(mCurrentMessage.getParticipatingUserIds());
                    } else {
                        addInitialRecipients(getPresenter().getConversation().getAudience());
                    }
                } else if (mIsMessageStudentsWho) {
                    ArrayList<BasicUser> participants = getArguments().getParcelableArrayList(KEY_PARTICIPANTS);
                    List<Long> ids = new ArrayList<>();
                    if (participants != null) {
                        for (BasicUser user : participants) {
                            ids.add(user.getId());
                        }
                    }
                    addInitialRecipients(ids);
                }
                ViewTreeObserver obs = mChipsTextView.getViewTreeObserver();
                obs.removeOnGlobalLayoutListener(this);
            }
        });
    }
    return view;
}
Also used : BasicUser(com.instructure.canvasapi2.models.BasicUser) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) 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) ViewTreeObserver(android.view.ViewTreeObserver) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Aggregations

LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)59 Response (okhttp3.Response)57 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)28 ArrayList (java.util.ArrayList)27 Request (okhttp3.Request)27 List (java.util.List)22 Conversation (com.instructure.canvasapi2.models.Conversation)12 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 RestParams (com.instructure.canvasapi2.builders.RestParams)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)8 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)8 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)8 Submission (com.instructure.canvasapi2.models.Submission)7 Course (com.instructure.canvasapi2.models.Course)6 View (android.view.View)5 AdapterView (android.widget.AdapterView)5 TextView (android.widget.TextView)5 Assignment (com.instructure.canvasapi2.models.Assignment)5 CourseNickname (com.instructure.canvasapi2.models.CourseNickname)5 ImageView (android.widget.ImageView)4