Search in sources :

Example 1 with FileFolder

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

the class FileListRecyclerAdapterTest method testAreContentsTheSame_DifferentObjectSizes.

@Test
public void testAreContentsTheSame_DifferentObjectSizes() {
    FileFolder fileFolder1 = new FileFolder();
    fileFolder1.setDisplayName("fileFolder");
    fileFolder1.setSize(10);
    FileFolder fileFolder2 = new FileFolder();
    fileFolder2.setDisplayName("fileFolder");
    fileFolder2.setSize(100);
    assertFalse(mAdapter.getItemCallback().areContentsTheSame(fileFolder1, fileFolder2));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 2 with FileFolder

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

the class FileListRecyclerAdapterTest method testAreContentsTheSame_SameFolders.

@Test
public void testAreContentsTheSame_SameFolders() {
    FileFolder fileFolder = new FileFolder();
    fileFolder.setName("fileFolder");
    fileFolder.setSize(0);
    assertTrue(mAdapter.getItemCallback().areContentsTheSame(fileFolder, fileFolder));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 3 with FileFolder

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

the class FileListRecyclerAdapterTest method testAreContentsTheSame_DifferentFolderSizes.

@Test
public void testAreContentsTheSame_DifferentFolderSizes() {
    FileFolder fileFolder1 = new FileFolder();
    fileFolder1.setName("fileFolder");
    fileFolder1.setSize(10);
    FileFolder fileFolder2 = new FileFolder();
    fileFolder2.setName("fileFolder");
    fileFolder2.setSize(100);
    assertFalse(mAdapter.getItemCallback().areContentsTheSame(fileFolder1, fileFolder2));
}
Also used : FileFolder(com.instructure.canvasapi2.models.FileFolder) Test(org.junit.Test)

Example 4 with FileFolder

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

the class FileFolderAPI method uploadFileSynchronousNoRedirect.

@WorkerThread
public static /* Used to manually handle the last redirect */
RemoteFile uploadFileSynchronousNoRedirect(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    Headers headers = adapter.buildNoRedirects(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().headers();
    String redirect = headers.get("Location");
    String newFileUrl = redirect.split("/create_success")[0];
    // POST to the redirect... according to the docs we need to do this to finalize the file upload process
    RemoteFile newFile = adapter.build(FilesFoldersInterface.class, params).postNewlyCreatedFile(redirect).execute().body();
    // We weren't receiving a url in the response from the POST to the redirect - here we grab the full file info as a work around
    FileFolder fileFolder = FileFolderManager.getFileFolderFromURLSynchronous(newFileUrl);
    newFile.setUrl(fileFolder.getUrl());
    newFile.setThumbnailUrl(fileFolder.getThumbnailUrl());
    return newFile;
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) Headers(okhttp3.Headers) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RemoteFile(com.instructure.canvasapi2.models.RemoteFile) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 5 with FileFolder

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

the class FileFolderManager method getFileFolderFromURL.

public static void getFileFolderFromURL(String url, StatusCallback<FileFolder> callback) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withPerPageQueryParam(false).build();
        FileFolderAPI.getFileFolderFromURL(adapter, url, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

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