use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class UserManager method getAllPeopleList.
public static void getAllPeopleList(final CanvasContext canvasContext, StatusCallback<List<User>> callback, boolean forceNetwork) {
if (isTesting() || mTesting) {
// TODO
} else {
final RestParams params = new RestParams.Builder().withCanvasContext(canvasContext).withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
// We don't want the canvas context on the paginated params
final RestParams paginatedParams = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
final RestBuilder adapter = new RestBuilder(callback);
StatusCallback<List<User>> depaginatedCallback = new ExhaustiveListCallback<User>(callback) {
@Override
public void getNextPage(@NonNull StatusCallback<List<User>> callback, @NonNull String nextUrl, boolean isCached) {
UserAPI.getPeopleList(adapter, paginatedParams, canvasContext.getId(), callback);
}
};
adapter.setStatusCallback(depaginatedCallback);
UserAPI.getPeopleList(adapter, params, canvasContext.getId(), depaginatedCallback);
}
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class UserManager method getFirstPagePeopleList.
public static void getFirstPagePeopleList(@NonNull CanvasContext canvasContext, UserAPI.ENROLLMENT_TYPE enrollmentType, boolean forceNetwork, @NonNull StatusCallback<List<User>> callback) {
if (isTesting() || mTesting) {
// TODO
} else {
final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).withCanvasContext(canvasContext).build();
final RestBuilder adapter = new RestBuilder(callback);
UserAPI.getFirstPagePeopleList(adapter, params, canvasContext.getId(), enrollmentType, callback);
}
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class AnnouncementManager_Test method getAnnouncements.
public static void getAnnouncements(CanvasContext canvasContext, StatusCallback<List<DiscussionTopicHeader>> callback) {
// TODO:
Response response = new Response.Builder().code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
List<DiscussionTopicHeader> items = new ArrayList<>();
retrofit2.Response<List<DiscussionTopicHeader>> response1 = retrofit2.Response.success(items, response);
callback.onResponse(response1, new LinkHeaders(), ApiType.CACHE);
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class OpenMediaAsyncTaskLoader method loadInBackground.
@Override
public LoadedMedia loadInBackground() {
LoadedMedia loadedMedia = new LoadedMedia();
if (this.isUseOutsideApps) {
loadedMedia.setUseOutsideApps(true);
}
if (this.isSubmission) {
loadedMedia.setIsSubmission(true);
}
final Context context = getContext();
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Const.IS_MEDIA_TYPE, true);
if (isHtmlFile() && canvasContext != null) {
File file = downloadFile(context, url, filename);
Bundle bundle = FileUploadUtils.createTaskLoaderBundle(canvasContext, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + Const.FILE_PROVIDER_AUTHORITY, file).toString(), filename, false);
loadedMedia.setBundle(bundle);
} else if (isHtmlFile() && canvasContext == null) {
// when the canvasContext is null we're routing from the teacher app, which just needs the url and title to get the html file
Bundle bundle = new Bundle();
bundle.putString(Const.INTERNAL_URL, url);
bundle.putString(Const.ACTION_BAR_TITLE, filename);
loadedMedia.setBundle(bundle);
} else if (Utils.isAmazonDevice()) {
attemptDownloadFile(context, intent, loadedMedia, url, filename);
} else {
loadedMedia.setHtmlFile(isHtmlFile());
Uri uri = attemptConnection(url);
if (uri != null) {
intent.setDataAndType(uri, mimeType);
loadedMedia.setIntent(intent);
Log.d(Const.OPEN_MEDIA_ASYNC_TASK_LOADER_LOG, "Intent can be handled: " + isIntentHandledByActivity(intent));
attemptDownloadFile(context, intent, loadedMedia, url, filename);
} else {
loadedMedia.setErrorMessage(R.string.noDataConnection);
}
}
} catch (MalformedURLException e) {
Log.e(Const.OPEN_MEDIA_ASYNC_TASK_LOADER_LOG, "MalformedURLException: " + e.toString());
} catch (IOException e) {
Log.e(Const.OPEN_MEDIA_ASYNC_TASK_LOADER_LOG, "IOException: " + e.toString());
loadedMedia.setErrorMessage(R.string.unexpectedErrorOpeningFile);
} catch (ActivityNotFoundException e) {
Log.e(Const.OPEN_MEDIA_ASYNC_TASK_LOADER_LOG, "ActivityNotFoundException: " + e.toString());
loadedMedia.setErrorMessage(R.string.noApps);
} catch (Exception e) {
Log.e(Const.OPEN_MEDIA_ASYNC_TASK_LOADER_LOG, "Exception: " + e.toString());
loadedMedia.setErrorMessage(R.string.unexpectedErrorOpeningFile);
}
return loadedMedia;
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class PeopleListFragment method getAdapter.
@Override
protected PeopleListRecyclerAdapter getAdapter() {
if (mAdapter == null) {
mAdapter = new PeopleListRecyclerAdapter(getContext(), getPresenter(), new AdapterToFragmentCallback<User>() {
@Override
public void onRowClicked(User user, int position) {
CanvasContext canvasContext = getArguments().getParcelable(Const.CANVAS_CONTEXT);
if (CanvasContextExtensions.isDesigner(canvasContext)) {
Toast.makeText(getContext(), R.string.errorIsDesigner, Toast.LENGTH_SHORT).show();
return;
}
Bundle bundle = StudentContextFragment.makeBundle(user.getId(), canvasContext.getId(), true);
RouteMatcher.route(getContext(), new Route(null, StudentContextFragment.class, canvasContext, bundle));
}
});
}
return mAdapter;
}
Aggregations