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);
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations