use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class CalendarChooserDialogStyled method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
User mUser = ApiPrefs.getUser();
Bundle args = getArguments();
if (args != null) {
mSelectedIds = args.getStringArrayList(Const.CALENDAR_DIALOG_FILTER_PREFS);
mAllContextIDs = (HashMap<String, String>) args.getSerializable(Const.CALENDAR_DIALOG_CONTEXT_IDS);
mAllContextCourseCodes = (List<String>) args.getSerializable(Const.CALENDAR_DIALOG_CONTEXT_COURSE_IDS);
mIsFirstShow = args.getBoolean(Const.IS_FIRST_SHOW);
if (mAllContextIDs == null) {
mAllContextIDs = new LinkedHashMap<>();
}
if (mAllContextCourseCodes == null) {
mAllContextCourseCodes = new ArrayList<>();
}
if (mSelectedIds.size() == 0) {
mSelectedIds.add(mUser.getContextId());
}
initCheckedItemsArray();
}
}
use of com.instructure.canvasapi2.models.User 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;
}
use of com.instructure.canvasapi2.models.User 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)));
}
use of com.instructure.canvasapi2.models.User 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();
}
use of com.instructure.canvasapi2.models.User 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);
}
Aggregations