Search in sources :

Example 16 with FileFolder

use of com.instructure.canvasapi2.models.FileFolder 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 17 with FileFolder

use of com.instructure.canvasapi2.models.FileFolder in project instructure-android by instructure.

the class FileFolderTest method compareTo_FileAndFolder.

@Test
public void compareTo_FileAndFolder() {
    FileFolder folder = new FileFolder();
    folder.setFullName("fileFolder");
    FileFolder file = new FileFolder();
    file.setDisplayName("fileFolder");
    assertEquals(1, file.compareTo(folder));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 18 with FileFolder

use of com.instructure.canvasapi2.models.FileFolder in project instructure-android by instructure.

the class FileFolderTest method compareTo_FileAndFile.

@Test
public void compareTo_FileAndFile() {
    FileFolder file1 = new FileFolder();
    file1.setFullName("File 1");
    FileFolder file2 = new FileFolder();
    file2.setFullName("File 2");
    assertEquals(-1, file1.compareTo(file2));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 19 with FileFolder

use of com.instructure.canvasapi2.models.FileFolder in project instructure-android by instructure.

the class FileFolderTest method compareTo_FolderAndFolder.

@Test
public void compareTo_FolderAndFolder() {
    FileFolder folder1 = new FileFolder();
    folder1.setFullName("Folder 1");
    FileFolder folder2 = new FileFolder();
    folder2.setFullName("Folder 2");
    assertEquals(-1, folder1.compareTo(folder2));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 20 with FileFolder

use of com.instructure.canvasapi2.models.FileFolder in project instructure-android by instructure.

the class FileFolderTest method compareTo_FolderAndFolderReversed.

@Test
public void compareTo_FolderAndFolderReversed() {
    FileFolder folder1 = new FileFolder();
    folder1.setFullName("Folder 1");
    FileFolder folder2 = new FileFolder();
    folder2.setFullName("Folder 2");
    assertEquals(1, folder2.compareTo(folder1));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)21 RestParams (com.instructure.canvasapi2.builders.RestParams)21 FileFolder (com.instructure.canvasapi2.models.FileFolder)21 Test (org.junit.Test)12 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 StatusCallback (com.instructure.canvasapi2.StatusCallback)3 NonNull (android.support.annotation.NonNull)2 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 WorkerThread (android.support.annotation.WorkerThread)1 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)1 RemoteFile (com.instructure.canvasapi2.models.RemoteFile)1 Date (java.util.Date)1 Headers (okhttp3.Headers)1 RequestBody (okhttp3.RequestBody)1 ResponseBody (okhttp3.ResponseBody)1 Response (retrofit2.Response)1