Search in sources :

Example 76 with CanvasContext

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);
    }
}
Also used : User(com.instructure.canvasapi2.models.User) RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 77 with CanvasContext

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);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 78 with CanvasContext

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);
}
Also used : Response(okhttp3.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) List(java.util.List) ArrayList(java.util.ArrayList)

Example 79 with CanvasContext

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;
}
Also used : Context(android.content.Context) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) MalformedURLException(java.net.MalformedURLException) ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Uri(android.net.Uri) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 80 with CanvasContext

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;
}
Also used : User(com.instructure.canvasapi2.models.User) Bundle(android.os.Bundle) AdapterToFragmentCallback(com.instructure.teacher.interfaces.AdapterToFragmentCallback) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) StudentContextFragment(com.instructure.teacher.adapters.StudentContextFragment) PeopleListRecyclerAdapter(com.instructure.teacher.adapters.PeopleListRecyclerAdapter) Route(com.instructure.interactions.router.Route)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)60 RestParams (com.instructure.canvasapi2.builders.RestParams)55 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)19 StatusCallback (com.instructure.canvasapi2.StatusCallback)8 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)7 List (java.util.List)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)6 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)5 FileFolder (com.instructure.canvasapi2.models.FileFolder)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 NonNull (android.support.annotation.NonNull)4 View (android.view.View)4 TextView (android.widget.TextView)4 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)4 Bundle (android.os.Bundle)3 ImageView (android.widget.ImageView)3 BindView (butterknife.BindView)3 Course (com.instructure.canvasapi2.models.Course)3