mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add download file to file service
This commit is contained in:
parent
762d1b6d4d
commit
72df6ddf82
@ -61,10 +61,10 @@ class DownloadRemoteFileOperation(
|
|||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||||
var result: RemoteOperationResult<Any>
|
var result: RemoteOperationResult<Any>
|
||||||
|
|
||||||
/// download will be performed to a temporal file, then moved to the final location
|
// download will be performed to a temporal file, then moved to the final location
|
||||||
val tmpFile = File(tmpPath)
|
val tmpFile = File(tmpPath)
|
||||||
|
|
||||||
/// perform the download
|
// perform the download
|
||||||
try {
|
try {
|
||||||
tmpFile.mkdirs()
|
tmpFile.mkdirs()
|
||||||
result = downloadFile(client, tmpFile)
|
result = downloadFile(client, tmpFile)
|
||||||
@ -145,15 +145,15 @@ class DownloadRemoteFileOperation(
|
|||||||
// TODO some kind of error control!
|
// TODO some kind of error control!
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) {
|
} else if (status != HttpConstants.HTTP_FORBIDDEN && status != HttpConstants.HTTP_SERVICE_UNAVAILABLE) {
|
||||||
client.exhaustResponse(getMethod.getResponseBodyAsStream())
|
client.exhaustResponse(getMethod.getResponseBodyAsStream())
|
||||||
} // else, body read by RemoteOperationResult constructor
|
} // else, body read by RemoteOperationResult constructor
|
||||||
|
|
||||||
result =
|
result =
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
RemoteOperationResult<Any>(RemoteOperationResult.ResultCode.OK)
|
RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
|
||||||
} else {
|
} else {
|
||||||
RemoteOperationResult<Any>(getMethod)
|
RemoteOperationResult(getMethod)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fos?.close()
|
fos?.close()
|
||||||
@ -181,9 +181,4 @@ class DownloadRemoteFileOperation(
|
|||||||
mCancellationRequested.set(true) // atomic set; there is no need of synchronizing it
|
mCancellationRequested.set(true) // atomic set; there is no need of synchronizing it
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val FORBIDDEN_ERROR = 403
|
|
||||||
private const val SERVICE_UNAVAILABLE_ERROR = 503
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,11 @@ interface FileService : Service {
|
|||||||
isChunkFolder: Boolean = false
|
isChunkFolder: Boolean = false
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
|
||||||
|
fun downloadFile(
|
||||||
|
remotePath: String,
|
||||||
|
localTempPath: String
|
||||||
|
): RemoteOperationResult<Any>
|
||||||
|
|
||||||
fun refreshFolder(
|
fun refreshFolder(
|
||||||
remotePath: String
|
remotePath: String
|
||||||
): RemoteOperationResult<ArrayList<RemoteFile>>
|
): RemoteOperationResult<ArrayList<RemoteFile>>
|
||||||
|
@ -27,12 +27,14 @@ import com.owncloud.android.lib.common.OwnCloudClient
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation
|
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation
|
||||||
|
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation
|
||||||
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation
|
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
|
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
|
||||||
import com.owncloud.android.lib.resources.files.RemoteFile
|
import com.owncloud.android.lib.resources.files.RemoteFile
|
||||||
import com.owncloud.android.lib.resources.files.services.FileService
|
import com.owncloud.android.lib.resources.files.services.FileService
|
||||||
|
|
||||||
class OCFileService(override val client: OwnCloudClient) : FileService {
|
class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||||
|
|
||||||
override fun checkPathExistence(
|
override fun checkPathExistence(
|
||||||
path: String,
|
path: String,
|
||||||
isUserLogged: Boolean
|
isUserLogged: Boolean
|
||||||
@ -56,6 +58,15 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
isChunksFolder = isChunkFolder
|
isChunksFolder = isChunkFolder
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
|
override fun downloadFile(
|
||||||
|
remotePath: String,
|
||||||
|
localTempPath: String
|
||||||
|
): RemoteOperationResult<Any> =
|
||||||
|
DownloadRemoteFileOperation(
|
||||||
|
remotePath = remotePath,
|
||||||
|
localFolderPath = localTempPath
|
||||||
|
).execute(client)
|
||||||
|
|
||||||
override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> =
|
override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> =
|
||||||
ReadRemoteFolderOperation(
|
ReadRemoteFolderOperation(
|
||||||
remotePath = remotePath
|
remotePath = remotePath
|
||||||
|
Loading…
x
Reference in New Issue
Block a user