use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class AssignmentListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.assignment_list_layout, container, false);
mToolbar = mRootView.findViewById(R.id.toolbar);
setUpCallbacks();
mAdapterToAssignmentsCallback = new AdapterToAssignmentsCallback() {
@Override
public void setTermSpinnerState(boolean isEnabled) {
mTermSpinner.setEnabled(isEnabled);
if (mTermAdapter != null) {
if (isEnabled) {
mTermAdapter.setIsLoading(false);
} else {
mTermAdapter.setIsLoading(true);
}
mTermAdapter.notifyDataSetChanged();
}
}
@Override
public void onRowClicked(Assignment assignment, int position, boolean isOpenDetail) {
Navigation navigation = getNavigation();
if (navigation != null) {
Bundle bundle = AssignmentFragment.Companion.createBundle((Course) getCanvasContext(), assignment);
navigation.addFragment(FragUtils.getFrag(AssignmentFragment.class, bundle));
}
}
@Override
public void onRefreshFinished() {
setRefreshing(false);
}
};
// Just load the AssignmentGroup list in the case that its a Group
mRecyclerAdapter = new AssignmentDateListRecyclerAdapter(getContext(), getCanvasContext(), mGradingPeriodsCallback, mAdapterToAssignmentsCallback);
configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
mTermSpinner = mRootView.findViewById(R.id.termSpinner);
mTermSpinnerLayout = mRootView.findViewById(R.id.termSpinnerLayout);
AppBarLayout appBarLayout = mRootView.findViewById(R.id.appbar);
View shadow = mRootView.findViewById(R.id.shadow);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
shadow.setVisibility(View.GONE);
} else {
shadow.setVisibility(View.VISIBLE);
}
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
// workaround for Toolbar not showing with swipe to refresh
if (i == 0) {
setRefreshingEnabled(true);
} else {
setRefreshingEnabled(false);
}
}
});
return mRootView;
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class ComposeNewDiscussionFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
applyTheme();
if (isAnnouncement) {
threaded.setVisibility(View.GONE);
publish.setVisibility(View.GONE);
} else {
threaded.setVisibility(View.VISIBLE);
publish.setVisibility(View.VISIBLE);
}
if (getCanvasContext() instanceof Course) {
Course course = (Course) getCanvasContext();
if (((course.isStudent() && !course.isTeacher()))) {
// Students cannot post draft discussions.
// We force it checked for when the api call is made and hide the option.
publish.setChecked(true);
publish.setVisibility(View.GONE);
}
} else if (getCanvasContext() instanceof Group) {
// Always publish for groups
publish.setChecked(true);
publish.setVisibility(View.GONE);
}
setUpCallback();
if (discussionTopicHeader != null) {
populateViewsWithData();
} else {
// clear out views
initViews();
}
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class CanvasContextSpinnerAdapter method newAdapterInstance.
public static CanvasContextSpinnerAdapter newAdapterInstance(Context context, List<Course> courses, List<Group> groups) {
ArrayList<CanvasContext> canvasContexts = new ArrayList<>();
Course courseSeparator = new Course();
courseSeparator.setName(context.getString(R.string.courses));
courseSeparator.setId(COURSE_SEPARATOR);
canvasContexts.add(courseSeparator);
canvasContexts.addAll(courses);
if (groups.size() > 0) {
Course groupSeparator = new Course();
groupSeparator.setName(context.getString(R.string.assignee_type_groups));
groupSeparator.setId(GROUP_SEPARATOR);
canvasContexts.add(groupSeparator);
canvasContexts.addAll(groups);
}
return new CanvasContextSpinnerAdapter(context, canvasContexts);
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class AddMessageFragment method addCoursesAndGroups.
@Override
public void addCoursesAndGroups(ArrayList<Course> courses, ArrayList<Group> groups) {
final CanvasContextSpinnerAdapter adapter = CanvasContextSpinnerAdapter.newAdapterInstance(getContext(), courses, groups);
mCourseSpinner.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.spinner_item_nothing_selected, getContext()));
if (mSelectedCourse != null) {
// prevent listener from firing the when selection is placed
mCourseSpinner.setOnItemSelectedListener(null);
// + 1 is for the nothingSelected position
mCourseSpinner.setSelection(adapter.getPosition(mSelectedCourse) + 1, false);
courseWasSelected();
}
mCourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != 0) {
// position zero is nothingSelected prompt
// -1 to account for nothingSelected item
CanvasContext canvasContext = adapter.getItem(position - 1);
if (mSelectedCourse == null || mSelectedCourse.getId() != canvasContext.getId()) {
mChipsTextView.removeAllRecipientEntry();
mSelectedCourse = canvasContext;
courseWasSelected();
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.
the class PollSessionListFragment method setupCallbacks.
@Override
public void setupCallbacks() {
pollSessionCallback = new StatusCallback<PollSessionResponse>() {
@Override
public void onResponse(@NonNull Response<PollSessionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollSession> pollSessions = response.body().getPollSessions();
sessionNextUrl = linkHeaders.nextUrl;
if (pollSessions != null) {
for (PollSession pollSession : pollSessions) {
addItem(pollSession);
SectionManager.getSection(pollSession.getCourse_id(), pollSession.getCourse_section_id(), sectionCallback, true);
}
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
sectionCallback = new StatusCallback<Section>() {
@Override
public void onResponse(@NonNull Response<Section> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
sectionMap.put(response.body().getId(), response.body());
notifyDataSetChanged();
}
};
pollChoiceCallback = new StatusCallback<PollChoiceResponse>() {
@Override
public void onResponse(@NonNull Response<PollChoiceResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (getActivity() == null || type.isCache())
return;
List<PollChoice> pollChoices = response.body().getPollChoices();
if (pollChoices != null) {
pollChoiceArrayList.addAll(pollChoices);
}
// or generate the CSV, depending on which action they selected
if (!StatusCallback.moreCallsExist(linkHeaders)) {
if (fromGenerateCSV) {
// generate a map from the array list of poll choices
for (PollChoice choice : pollChoiceArrayList) {
pollChoiceMap.put(choice.getId(), choice);
}
generateCSV();
} else {
AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
// populate the current data with the bundle
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.POLL_BUNDLE, poll);
bundle.putParcelableArrayList(Constants.POLL_CHOICES, pollChoiceArrayList);
addQuestionFragment.setArguments(bundle);
((FragmentManagerActivity) getActivity()).swapFragments(addQuestionFragment, AddQuestionFragment.class.getSimpleName(), R.anim.slide_in_from_bottom, 0, 0, R.anim.slide_out_to_bottom);
}
} else {
// otherwise, get the next group of poll choices.
PollsManager.getNextPagePollChoices(linkHeaders.nextUrl, pollChoiceCallback, false);
}
}
@Override
public void onFinished(ApiType type) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}
};
responseCanvasCallback = new StatusCallback<ResponseBody>() {
@Override
public void onFail(@Nullable Call<ResponseBody> call, @NonNull Throwable error, @Nullable Response response) {
AppMsg.makeText(getActivity(), getString(R.string.errorDeletingPollSession), AppMsg.STYLE_ERROR).show();
// we didn't actually delete anything, but we removed the item from the list to make the animation smoother, so now
// lets get the poll sessions again
reloadData();
}
};
}
Aggregations