|
@@ -55,39 +55,39 @@ class CopyFileViewModel(applicationContext: Context,
|
|
fun copyFile(applicationContext: Context) {
|
|
fun copyFile(applicationContext: Context) {
|
|
if (!info.shouldCopyFile) {
|
|
if (!info.shouldCopyFile) {
|
|
onCopySuccess()
|
|
onCopySuccess()
|
|
- } else {
|
|
|
|
- val source = if (!info.filePath.isNullOrEmpty()) {
|
|
|
|
- FilePathSource(info.filePath!!)
|
|
|
|
- } else if (info.isActionView && null != info.uri) {
|
|
|
|
- FileUriSource(applicationContext, info.uri)
|
|
|
|
- } else {
|
|
|
|
- null
|
|
|
|
- }
|
|
|
|
- srcFilePath = source?.getFilePath()
|
|
|
|
-
|
|
|
|
- if (isSrcFileEqualsDstFile()) {
|
|
|
|
- onCopySuccess()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- val fullFileSize = Math.max(1, source?.getFileSize() ?: 1)
|
|
|
|
- val task = CopyFileTask()
|
|
|
|
- task.setCopyMode(CopyFileTask.Mode.CREATE_NEW_FILE)
|
|
|
|
- task.setTargetFolder(FileUtil.getKdanPDFReaderFolder())
|
|
|
|
- dstFilePath = task.generateUniqueFilePath(source)
|
|
|
|
-
|
|
|
|
- copyFileDisposable = task.copyFile(source)
|
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
- .subscribe({
|
|
|
|
- val progress = Math.min(100, (it * 100.0 / fullFileSize).toInt())
|
|
|
|
- onCopyProgressUpdate(progress)
|
|
|
|
- }, {
|
|
|
|
- onCopyFailed(it)
|
|
|
|
- }, {
|
|
|
|
- onCopySuccess()
|
|
|
|
- })
|
|
|
|
|
|
+ val source = if (!info.filePath.isNullOrEmpty()) {
|
|
|
|
+ FilePathSource(info.filePath!!)
|
|
|
|
+ } else if (info.isActionView && null != info.uri) {
|
|
|
|
+ FileUriSource(applicationContext, info.uri)
|
|
|
|
+ } else {
|
|
|
|
+ null
|
|
|
|
+ }
|
|
|
|
+ srcFilePath = source?.getFilePath()
|
|
|
|
+ if (isSrcFileEqualsDstFile()) {
|
|
|
|
+ onCopySuccess()
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ val fullFileSize = Math.max(1, source?.getFileSize() ?: 1)
|
|
|
|
+ val task = CopyFileTask()
|
|
|
|
+ task.setCopyMode(CopyFileTask.Mode.CREATE_NEW_FILE)
|
|
|
|
+ task.setTargetFolder(FileUtil.getKdanPDFReaderFolder())
|
|
|
|
+ dstFilePath = task.generateUniqueFilePath(source)
|
|
|
|
+
|
|
|
|
+ copyFileDisposable = task.copyFile(source)
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
+ .subscribe({
|
|
|
|
+ val progress = Math.min(100, (it * 100.0 / fullFileSize).toInt())
|
|
|
|
+ onCopyProgressUpdate(progress)
|
|
|
|
+ }, {
|
|
|
|
+ onCopyFailed(it)
|
|
|
|
+ }, {
|
|
|
|
+ onCopySuccess()
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
// check the destination path is the same with the source path or not
|
|
// check the destination path is the same with the source path or not
|