use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ModuleListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = getLayoutInflater().inflate(R.layout.fragment_module_list, container, false);
mToolbar = rootView.findViewById(R.id.toolbar);
CardView cardView = rootView.findViewById(R.id.cardView);
if (cardView != null) {
cardView.setCardBackgroundColor(Color.WHITE);
}
mRecyclerAdapter = new ModuleListRecyclerAdapter(mCourse, getDefaultSelectedId(), getContext(), getCanvasContext(), new ModuleAdapterToFragmentCallback() {
@Override
public void onRowClicked(ModuleObject moduleObject, ModuleItem moduleItem, int position, boolean isOpenDetail) {
if (moduleItem.getType() != null && moduleItem.getType().equals(ModuleObject.STATE.unlock_requirements.toString())) {
return;
}
// don't do anything with headers if the user selects it
if (moduleItem.getType() != null && (moduleItem.getType().equals(ModuleItem.TYPE.SubHeader.toString()))) {
return;
}
boolean isLocked = ModuleUtility.isGroupLocked(moduleObject);
if (isLocked) {
return;
}
// Remove all the subheaders and stuff.
ArrayList<ModuleObject> groups = mRecyclerAdapter.getGroups();
ArrayList<ArrayList<ModuleItem>> moduleItemsArray = new ArrayList<>();
for (int i = 0; i < groups.size(); i++) {
ArrayList<ModuleItem> moduleItems = mRecyclerAdapter.getItems(groups.get(i));
moduleItemsArray.add(moduleItems);
}
ModuleProgressionUtility.ModuleHelper moduleHelper = ModuleProgressionUtility.prepareModulesForCourseProgression(getContext(), moduleItem.getId(), groups, moduleItemsArray);
Navigation navigation = getNavigation();
if (navigation != null) {
Bundle bundle = CourseModuleProgressionFragment.createBundle(groups, moduleHelper.strippedModuleItems, mCourse, moduleHelper.newGroupPosition, moduleHelper.newChildPosition);
navigation.addFragment(FragUtils.getFrag(CourseModuleProgressionFragment.class, bundle));
}
}
@Override
public void onRefreshFinished() {
setRefreshing(false);
}
});
configureRecyclerView(rootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
return rootView;
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ModuleListRecyclerAdapter method getModuleItemsCallback.
private ModuleItemCallback getModuleItemsCallback(final ModuleObject moduleObject, final boolean isNotifyGroupChange) {
if (mModuleItemCallbacks.containsKey(moduleObject.getId())) {
return mModuleItemCallbacks.get(moduleObject.getId());
} else {
ModuleItemCallback moduleItemCallback = new ModuleItemCallback(moduleObject) {
private int checkMasteryPaths(int position, ModuleItem item) {
if (item.getMasteryPaths() != null && item.getMasteryPaths().isLocked()) {
// add another module item that says it's locked
ModuleItem masteryPathsLocked = new ModuleItem();
// set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
masteryPathsLocked.setId(UUID.randomUUID().getLeastSignificantBits());
masteryPathsLocked.setTitle(String.format(Locale.getDefault(), getContext().getString(R.string.locked_mastery_paths), item.getTitle()));
masteryPathsLocked.setType(ModuleItem.TYPE.Locked.toString());
masteryPathsLocked.setCompletionRequirement(null);
masteryPathsLocked.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), masteryPathsLocked);
} else if (item.getMasteryPaths() != null && !item.getMasteryPaths().isLocked() && item.getMasteryPaths().getSelectedSetId() == 0) {
// add another module item that says select to choose assignment group
// We only want to do this when we have a mastery paths object, it's unlocked, and the user hasn't already selected a set
ModuleItem masteryPathsSelect = new ModuleItem();
// set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
masteryPathsSelect.setId(UUID.randomUUID().getLeastSignificantBits());
masteryPathsSelect.setTitle(getContext().getString(R.string.choose_assignment_group));
masteryPathsSelect.setType(ModuleItem.TYPE.ChooseAssignmentGroup.toString());
masteryPathsSelect.setCompletionRequirement(null);
masteryPathsSelect.setPosition(position++);
// sort the mastery paths by position
ArrayList<AssignmentSet> assignmentSets = new ArrayList<>();
assignmentSets.addAll(Arrays.asList(item.getMasteryPaths().getAssignmentSets()));
Collections.sort(assignmentSets, new Comparator<AssignmentSet>() {
@Override
public int compare(AssignmentSet lh, AssignmentSet rh) {
if (lh != null && rh != null) {
if (lh.getPosition() < rh.getPosition()) {
return -1;
} else if (lh.getPosition() > rh.getPosition()) {
return 1;
}
}
return 0;
}
});
AssignmentSet[] set = new AssignmentSet[assignmentSets.size()];
assignmentSets.toArray(set);
item.getMasteryPaths().setAssignmentSets(set);
masteryPathsSelect.setMasteryPathsItemId(item.getId());
masteryPathsSelect.setMasteryPaths(item.getMasteryPaths());
addOrUpdateItem(this.getModuleObject(), masteryPathsSelect);
}
return position;
}
@Override
public void onResponse(@NonNull Response<List<ModuleItem>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
List<ModuleItem> moduleItems = response.body();
if (type == ApiType.API) {
int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
for (ModuleItem item : moduleItems) {
item.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), item);
position = checkMasteryPaths(position, item);
}
String nextItemsURL = linkHeaders.nextUrl;
if (nextItemsURL != null) {
ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
}
this.setIsFromNetwork(true);
expandGroup(this.getModuleObject(), isNotifyGroupChange);
} else if (type == ApiType.CACHE) {
int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
for (ModuleItem item : moduleItems) {
item.setPosition(position++);
addOrUpdateItem(this.getModuleObject(), item);
}
String nextItemsURL = linkHeaders.nextUrl;
if (nextItemsURL != null) {
ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
}
// Wait for the network to expand when there are no items
if (moduleItems.size() > 0) {
expandGroup(this.getModuleObject(), isNotifyGroupChange);
}
}
}
@Override
public void onFail(@Nullable Call<List<ModuleItem>> call, @NonNull Throwable error, @Nullable Response response) {
// Only expand if there was no cache result and no network. No connection empty cell will be displayed
if (response != null && response.code() == 504 && APIHelper.isCachedResponse(response) && getContext() != null && !Utils.isNetworkAvailable(getContext())) {
expandGroup(this.getModuleObject(), isNotifyGroupChange);
}
}
};
mModuleItemCallbacks.put(moduleObject.getId(), moduleItemCallback);
return moduleItemCallback;
}
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class CourseManager method getAllCourseStudents.
public static void getAllCourseStudents(final boolean forceNetwork, long courseId, StatusCallback<List<User>> callback) {
if (isTesting() || mTesting) {
// TODO...
} else {
final RestBuilder adapter = new RestBuilder(callback);
RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
StatusCallback<List<User>> depaginatedCallback = new ExhaustiveListCallback<User>(callback) {
@Override
public void getNextPage(@NonNull StatusCallback<List<User>> callback, @NonNull String nextUrl, boolean isCached) {
CourseAPI.getNextPageCourseStudents(forceNetwork, nextUrl, adapter, callback);
}
};
adapter.setStatusCallback(depaginatedCallback);
CourseAPI.getFirstPageCourseStudents(courseId, adapter, depaginatedCallback, params);
}
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ProfileUtilsTest method getUserInitials_string2.
@Test
public void getUserInitials_string2() throws Exception {
User user = new User();
user.setShortName("Billy Joel");
String testValue = ProfileUtils.getUserInitials(user.getShortName());
assertEquals("BJ", testValue);
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class CanvasContextTest method toAPIString_TestUsers.
@Test
public void toAPIString_TestUsers() {
User user = new User();
user.setId(1234);
assertEquals("/users/1234", user.toAPIString());
}
Aggregations