Bläddra i källkod

Refactor: rearrange code

cooperku_kdanmobile 5 år sedan
förälder
incheckning
b4b4bfc9c3
1 ändrade filer med 31 tillägg och 31 borttagningar
  1. 31 31
      src/main/java/com/kdanmobile/reader/copyfile/CopyFileViewModel.kt

+ 31 - 31
src/main/java/com/kdanmobile/reader/copyfile/CopyFileViewModel.kt

@@ -55,39 +55,39 @@ class CopyFileViewModel(applicationContext: Context,
     fun copyFile(applicationContext: Context) {
         if (!info.shouldCopyFile) {
             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