Search in sources :

Example 31 with FileFolder

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

the class FileFolderManager method getRootFolderForUser.

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

Example 32 with FileFolder

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

the class FileFolderManager method getAllFilesRoot.

public static void getAllFilesRoot(CanvasContext canvasContext, final boolean forceNetwork, final StatusCallback<List<FileFolder>> callback) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withCanvasContext(canvasContext).withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        FileFolderAPI.getRootFolderForContext(adapter, canvasContext, new StatusCallback<FileFolder>() {

            @Override
            public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                getAllFiles(response.body().getId(), forceNetwork, callback);
            }
        }, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ApiType(com.instructure.canvasapi2.utils.ApiType) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 33 with FileFolder

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

the class FileFolderManager method getFolder.

public static void getFolder(long folderId, boolean forceNetwork, StatusCallback<FileFolder> callback) {
    if (isTesting() || mTesting) {
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        FileFolderAPI.getFolder(folderId, adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 34 with FileFolder

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

the class BaseRouterActivity method handleSpecificFile.

private void handleSpecificFile(long courseId, String fileID) {
    final CanvasContext canvasContext = CanvasContext.getGenericContext(CanvasContext.Type.COURSE, courseId, "");
    Logger.d("handleSpecificFile()");
    FileFolderManager.getFileFolderFromURLAirwolf(ApiPrefs.getAirwolfDomain(), "files/" + fileID, new StatusCallback<FileFolder>() {

        @Override
        public void onResponse(@NonNull Response<FileFolder> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (type == ApiType.API) {
                FileFolder fileFolder = response.body();
                if (fileFolder == null || response.code() == 404) {
                    Toast.makeText(BaseRouterActivity.this, R.string.fileNoLongerExists, Toast.LENGTH_LONG).show();
                } else {
                    if (fileFolder.isLocked() || fileFolder.isLockedForUser()) {
                        Toast.makeText(BaseRouterActivity.this, String.format(getString(R.string.fileLocked), (fileFolder.getDisplayName() == null) ? getString(R.string.file) : fileFolder.getDisplayName()), Toast.LENGTH_LONG).show();
                    } else {
                        downloadMedia(BaseRouterActivity.this, fileFolder.getContentType(), fileFolder.getUrl(), fileFolder.getDisplayName());
                    }
                }
            }
        }

        @Override
        public void onFail(@Nullable Call<FileFolder> call, @NonNull Throwable error, @Nullable Response response) {
            if (response != null && response.code() == 404) {
                Toast.makeText(BaseRouterActivity.this, R.string.fileNoLongerExists, Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : Response(retrofit2.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FileFolder(com.instructure.canvasapi2.models.FileFolder) ApiType(com.instructure.canvasapi2.utils.ApiType) CanvasContext(com.instructure.canvasapi2.models.CanvasContext)

Example 35 with FileFolder

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

the class FileFolderTest method compareTo_FileAndFileReversed.

@Test
public void compareTo_FileAndFileReversed() {
    FileFolder file1 = new FileFolder();
    file1.setFullName("File 1");
    FileFolder file2 = new FileFolder();
    file2.setFullName("File 2");
    assertEquals(1, file2.compareTo(file1));
}
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