public boolean asyncMkDir(Dentry dentry, final IMkDirListener listener) { if (dentry == null || dentry.type == Dentry.MORE || dentry.type == Dentry.FILE || dentry.type == Dentry.VIDEO || dentry.type == Dentry.BUCKET) { return false; } final String path = dentry.path; DirCreateTask task = new DirCreateTask( getFileType(), getBucket(), path, dentry.attribute, new DirCreateTask.IListener() { @Override public void onSuccess(final DirCreateTask.CmdTaskRsp result) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onMkDirSuccess(path, result.accessUrl); } }); } @Override public void onFailure(final int ret, final String msg) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onMkDirFailure(path, ret, msg); } }); } }); task.setAuth(getSign()); return BizService.getInstance().sendCommand(task); }
public boolean asyncStat(Dentry dentry, final IStatListener listener) { if (dentry == null || dentry.type == Dentry.MORE) { return false; } final String path = dentry.path; ObjectStatTask task = new ObjectStatTask( getFileType(), getBucket(), path, dentry.type, new ObjectStatTask.IListener() { @Override public void onSuccess(ObjectStatTask.CmdTaskRsp result) { final Dentry dentry = result.inode; mMainHandler.post( new Runnable() { @Override public void run() { listener.onStatSuccess(path, dentry); } }); } @Override public void onFailure(final int ret, final String msg) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onStatFailure(path, ret, msg); } }); } }); task.setAuth(getSign()); return BizService.getInstance().sendCommand(task); };
public boolean cancelUploadTask() { Log.i(TAG, "cancelUploadTask upload task " + mUploadTask.getTaskId()); return BizService.getInstance().cancel(mUploadTask); }
public boolean resumeUploadTask() { Log.i(TAG, "resumeUploadTask upload task " + mUploadTask.getTaskId()); return BizService.getInstance().resume(mUploadTask); }
public boolean pauseUploadTask() { Log.i(TAG, "pauseUploadTask upload task " + mUploadTask.getTaskId()); return BizService.getInstance().pause(mUploadTask); }
public boolean clear() { Log.i(TAG, "clear upload task"); return BizService.getInstance().uploadManagerClear(getFileType()); }
public boolean asyncUploadFile( String srcPath, final Dentry destDentry, Object externData, final IUploadListener listener) { if (destDentry == null || destDentry.type == Dentry.MORE || destDentry.type == Dentry.DIR || destDentry.type == Dentry.BUCKET) { return false; } mbUploading = true; final String destPath = destDentry.path; final String attribute = destDentry.attribute; IUploadTaskListener taskListener = new IUploadTaskListener() { @Override public void onUploadSucceed(FileInfo info) { final Dentry dentry = new Dentry() .setPath(destPath) .setType(destDentry.type) .setAttribute(attribute) .setAccessUrl(info.url); mMainHandler.post( new Runnable() { @Override public void run() { listener.onUploadSucceed(dentry); mbUploading = false; } }); } @Override public void onUploadStateChange(final ITask.TaskState taskState) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onUploadStateChange(taskState); if (taskState == ITask.TaskState.CANCEL) { mbUploading = false; } } }); } @Override public void onUploadProgress(final long totalSize, final long sendSize) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onUploadProgress(totalSize, sendSize); } }); } @Override public void onUploadFailed(final int ret, final String msg) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onUploadFailed(ret, msg); mbUploading = false; } }); } }; UploadTask task = null; if (destDentry.type == Dentry.FILE) { task = new FileUploadTask(getBucket(), srcPath, destPath, attribute, taskListener); } else if (destDentry.type == Dentry.VIDEO) { VideoAttr videoAttr = (VideoAttr) externData; task = new VideoUploadTask(getBucket(), srcPath, destPath, attribute, videoAttr, taskListener); } if (task == null) { return false; } int taskId = task.getTaskId(); task.setAuth(getSign()); if (!BizService.getInstance().upload(task)) { mbUploading = false; return false; } Log.i(TAG, "begin upload taskId " + taskId + " " + srcPath + " to " + destPath); mUploadTask = task; return true; }
public boolean asyncListDir( final Dentry dentry, boolean enablePrefix, final IListDirListener listener) { if (dentry == null || dentry.type == Dentry.FILE || dentry.type == Dentry.VIDEO) { return false; } String content = ""; boolean bOrder = getOrder(); boolean bPrefix = enablePrefix; if (dentry.type == Dentry.MORE) { // 拉取上一页是保存的状态信息 bOrder = ((DentryMore) dentry).order; bPrefix = ((DentryMore) dentry).prefix; content = ((DentryMore) dentry).content; } enablePrefix = bPrefix; final boolean order = bOrder; final boolean prefix = bPrefix; final String path = dentry.path; DirListTask task = new DirListTask( getFileType(), getBucket(), path, getPageSize(), getListPattern(), order, content, new DirListTask.IListener() { @Override public void onSuccess(DirListTask.CmdTaskRsp result) { final ArrayList<Dentry> dirList = result.inodes; if (result.hasMore) { // 保存当前页的状态信息 DentryMore entry = null; String content = result.content; entry = new DentryMore(Dentry.MORE) .setOrder(order) .setPrefix(prefix) .setContent(content); entry.setPath(path).setName("更多..."); dirList.add(entry); } mMainHandler.post( new Runnable() { @Override public void run() { listener.onListDirSuccess(path, dirList); } }); } @Override public void onFailure(final int ret, final String msg) { mMainHandler.post( new Runnable() { @Override public void run() { listener.onListDirFailure(path, ret, msg); } }); } }); if (enablePrefix) { task.setPrefixSearch(true); } task.setAuth(getSign()); return BizService.getInstance().sendCommand(task); }