Search in sources :

Example 26 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class FileDetailsFragment method setUpCallback.

public void setUpCallback() {
    fileFolderCanvasCallback = new StatusCallback<FileFolder>() {

        @Override
        public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            // set up everything else now, we should have a file
            file = response.body();
            if (file != null) {
                if (file.getLockInfo() != null) {
                    // file is locked
                    icon.setImageResource(R.drawable.vd_lock);
                    openButton.setVisibility(View.GONE);
                    downloadButton.setVisibility(View.GONE);
                    fileTypeTextView.setVisibility(View.INVISIBLE);
                    String lockedMessage = "";
                    if (file.getLockInfo().getLockedModuleName() != null) {
                        lockedMessage = "<p>" + String.format(getActivity().getString(R.string.lockedFileDesc), "<b>" + file.getLockInfo().getLockedModuleName() + "</b>") + "</p>";
                    }
                    if (file.getLockInfo().getModulePrerequisiteNames().size() > 0) {
                        // we only want to add this text if there are module completion requirements
                        lockedMessage += getActivity().getString(R.string.mustComplete) + "<br>";
                        // textViews can't display <ul> and <li> tags, so we need to use "&#8226; " instead
                        for (int i = 0; i < file.getLockInfo().getModulePrerequisiteNames().size(); i++) {
                            // "&#8226; "
                            lockedMessage += "&#8226; " + file.getLockInfo().getModulePrerequisiteNames().get(i);
                        }
                        lockedMessage += "<br><br>";
                    }
                    // check to see if there is an unlocked date
                    if (file.getLockInfo().getUnlockAt() != null && file.getLockInfo().getUnlockAt().after(new Date())) {
                        lockedMessage += DateHelper.createPrefixedDateTimeString(getContext(), getActivity().getString(R.string.unlockedAt) + "<br>&#8226; ", file.getLockInfo().getUnlockAt());
                    }
                    fileNameTextView.setText(StringUtilities.simplifyHTML(Html.fromHtml(lockedMessage)));
                } else {
                    setupTextViews();
                    setupClickListeners();
                    // if the file has a thumbnail then show it. Make it a little bigger since the thumbnail size is pretty small
                    if (!TextUtils.isEmpty(file.getThumbnailUrl())) {
                        int dp = (int) ViewUtils.convertDipsToPixels(150, getActivity());
                        Picasso.with(getActivity()).load(file.getThumbnailUrl()).resize(dp, dp).centerInside().into(icon);
                    }
                }
                setPageViewReady();
            }
            toolbar.setTitle(title());
        }
    };
    markReadCanvasCallback = new StatusCallback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
        }
    };
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) ApiType(com.instructure.canvasapi2.utils.ApiType) Date(java.util.Date) ResponseBody(okhttp3.ResponseBody)

Example 27 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class LinkHeadersTest method toString_TestPrev.

@Test
public void toString_TestPrev() throws Exception {
    LinkHeaders linkHeaders = generateLinkHeaders();
    String testVal = linkHeaders.toString();
    String[] testValArray = testVal.split("\n");
    assertEquals("PREV:  prevUrl", testValArray[0]);
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Test(org.junit.Test)

Example 28 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class LinkHeadersTest method toString_TestNext.

@Test
public void toString_TestNext() throws Exception {
    LinkHeaders linkHeaders = generateLinkHeaders();
    String testVal = linkHeaders.toString();
    String[] testValArray = testVal.split("\n");
    assertEquals("NEXT:  nextUrl", testValArray[1]);
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Test(org.junit.Test)

Example 29 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class LinkHeadersTest method generateLinkHeaders.

private LinkHeaders generateLinkHeaders() {
    LinkHeaders linkHeaders = new LinkHeaders();
    linkHeaders.prevUrl = "prevUrl";
    linkHeaders.nextUrl = "nextUrl";
    linkHeaders.lastUrl = "lastUrl";
    linkHeaders.firstUrl = "firstUrl";
    return linkHeaders;
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders)

Example 30 with LinkHeaders

use of com.instructure.canvasapi2.utils.LinkHeaders in project instructure-android by instructure.

the class AssignmentManager_Test method getAssignmentGroupsWithAssignments.

public static void getAssignmentGroupsWithAssignments(long courseId, StatusCallback<List<AssignmentGroup>> callback) {
    // TODO:
    Response httpResponse = new Response.Builder().request(new Request.Builder().url("https://test.com").build()).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<AssignmentGroup> assignments = new ArrayList<>();
    retrofit2.Response<List<AssignmentGroup>> response = retrofit2.Response.success(assignments, httpResponse);
    callback.onResponse(response, new LinkHeaders(), ApiType.CACHE);
}
Also used : Response(okhttp3.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Request(okhttp3.Request) AssignmentGroup(com.instructure.canvasapi2.models.AssignmentGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)87 Response (okhttp3.Response)57 ArrayList (java.util.ArrayList)31 Request (okhttp3.Request)27 List (java.util.List)25 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)24 ApiType (com.instructure.canvasapi2.utils.ApiType)23 Response (retrofit2.Response)15 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)13 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)12 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 Conversation (com.instructure.canvasapi2.models.Conversation)9 NonNull (android.support.annotation.NonNull)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)8 StatusCallback (com.instructure.canvasapi2.StatusCallback)7 FileFolder (com.instructure.canvasapi2.models.FileFolder)6 Submission (com.instructure.canvasapi2.models.Submission)6 Assignment (com.instructure.canvasapi2.models.Assignment)5 CourseNickname (com.instructure.canvasapi2.models.CourseNickname)5 ResponseBody (okhttp3.ResponseBody)5