couple copy/move improvements
This commit is contained in:
parent
fc3c416758
commit
db42b53658
7 changed files with 23 additions and 19 deletions
|
@ -6,7 +6,7 @@ buildscript {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '3.11.46'
|
||||
propVersionName = '3.11.47'
|
||||
kotlin_version = '1.2.21'
|
||||
support_libs = '27.0.2'
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ open class BaseSimpleActivity : AppCompatActivity() {
|
|||
newFile.setLastModified(System.currentTimeMillis())
|
||||
}
|
||||
updateInMediaStore(oldFileDirItem.path, newFile.absolutePath)
|
||||
updatedFiles.add(newFile.toFileDirItem())
|
||||
updatedFiles.add(newFile.toFileDirItem(applicationContext))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
private val PROGRESS_RECHECK_INTERVAL = 500L
|
||||
|
||||
private var mListener: WeakReference<CopyMoveListener>? = null
|
||||
private var mMovedFiles = ArrayList<FileDirItem>()
|
||||
private var mTransferredFiles = ArrayList<FileDirItem>()
|
||||
private var mDocuments = LinkedHashMap<String, DocumentFile?>()
|
||||
private var mFiles = ArrayList<FileDirItem>()
|
||||
private var mFileCountToCopy = 0
|
||||
|
@ -76,7 +76,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
for (file in mFiles) {
|
||||
try {
|
||||
val newPath = "${pair.second!!.path}/${file.name}"
|
||||
val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath())
|
||||
val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), file.isDirectory)
|
||||
if (activity.doesFilePathExist(newPath)) {
|
||||
val resolution = getConflictResolution(newPath)
|
||||
if (resolution == CONFLICT_SKIP) {
|
||||
|
@ -96,7 +96,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
}
|
||||
|
||||
if (!copyOnly) {
|
||||
activity.deleteFiles(mMovedFiles) {}
|
||||
activity.deleteFiles(mTransferredFiles) {}
|
||||
}
|
||||
|
||||
val paths = mFiles.map { it.path } as ArrayList<String>
|
||||
|
@ -110,7 +110,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
val listener = mListener?.get() ?: return
|
||||
|
||||
if (success) {
|
||||
listener.copySucceeded(copyOnly, mMovedFiles.size >= mFileCountToCopy)
|
||||
listener.copySucceeded(copyOnly, mTransferredFiles.size >= mFileCountToCopy)
|
||||
} else {
|
||||
listener.copyFailed()
|
||||
}
|
||||
|
@ -172,10 +172,10 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
}
|
||||
|
||||
if (activity.isPathOnOTG(source.path)) {
|
||||
val children = activity.getSomeDocumentFile(source.path)?.listFiles() ?: return
|
||||
val children = activity.getDocumentFile(source.path)?.listFiles() ?: return
|
||||
for (child in children) {
|
||||
val newPath = "$destinationPath/${child.name}"
|
||||
if (activity.getFastDocumentFile(newPath)?.exists() == true) {
|
||||
if (activity.doesFilePathExist(newPath)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -184,18 +184,21 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
val newFileDirItem = FileDirItem(newPath, child.name, child.isDirectory)
|
||||
copy(oldFileDirItem, newFileDirItem)
|
||||
}
|
||||
mTransferredFiles.add(source)
|
||||
} else {
|
||||
val children = File(source.path).list()
|
||||
for (child in children) {
|
||||
val newFile = File(destinationPath, child)
|
||||
if (newFile.exists()) {
|
||||
val newPath = "$destinationPath/$child"
|
||||
if (activity.doesFilePathExist(newPath)) {
|
||||
continue
|
||||
}
|
||||
|
||||
val oldFile = File(source.path, child)
|
||||
copy(oldFile.toFileDirItem(), newFile.toFileDirItem())
|
||||
val oldFileDirItem = oldFile.toFileDirItem(activity.applicationContext)
|
||||
val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), oldFile.isDirectory)
|
||||
copy(oldFileDirItem, newFileDirItem)
|
||||
}
|
||||
mMovedFiles.add(source)
|
||||
mTransferredFiles.add(source)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +237,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
|
|||
mCurrentProgress += copiedSize
|
||||
|
||||
if (source.size == copiedSize) {
|
||||
mMovedFiles.add(source)
|
||||
mTransferredFiles.add(source)
|
||||
if (activity.baseConfig.keepLastModified) {
|
||||
copyOldLastModified(source.path, destination.path)
|
||||
} else {
|
||||
|
|
|
@ -332,7 +332,7 @@ fun BaseSimpleActivity.deleteFolderBg(fileDirItem: FileDirItem, deleteMediaOnly:
|
|||
val filesList = (filesArr as Array).toList()
|
||||
val files = filesList.filter { !deleteMediaOnly || it.isImageVideoGif() }
|
||||
for (file in files) {
|
||||
deleteFileBg(file.toFileDirItem(), false) { }
|
||||
deleteFileBg(file.toFileDirItem(applicationContext), false) { }
|
||||
}
|
||||
|
||||
if (folder.listFiles()?.isEmpty() == true) {
|
||||
|
@ -589,12 +589,12 @@ fun Activity.handleAppPasswordProtection(callback: (success: Boolean) -> Unit) {
|
|||
}
|
||||
|
||||
fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean {
|
||||
if (File(directory).exists()) {
|
||||
if (doesFilePathExist(directory)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (needsStupidWritePermissions(directory)) {
|
||||
val documentFile = getDocumentFile(directory) ?: return false
|
||||
val documentFile = getDocumentFile(directory.getParentPath()) ?: return false
|
||||
val newDir = documentFile.createDirectory(directory.getFilenameFromPath())
|
||||
return newDir != null
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.commons.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Point
|
||||
|
@ -150,4 +151,4 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int {
|
|||
return count
|
||||
}
|
||||
|
||||
fun File.toFileDirItem() = FileDirItem(absolutePath, name, isDirectory, 0, 0L)
|
||||
fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, absolutePath.getIsDirectory(context), 0, 0L)
|
||||
|
|
|
@ -128,7 +128,7 @@ fun String.getParentPath() = substring(0, length - getFilenameFromPath().length)
|
|||
|
||||
fun String.getIsDirectory(context: Context): Boolean {
|
||||
return if (context.isPathOnOTG(this)) {
|
||||
context.getSomeDocumentFile(this)?.isDirectory ?: false
|
||||
context.getFastDocumentFile(this)?.isDirectory ?: false
|
||||
} else {
|
||||
File(this).isDirectory
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ data class FileDirItem(val path: String, val name: String = "", var isDirectory:
|
|||
|
||||
fun getProperSize(context: Context, countHidden: Boolean): Long {
|
||||
return if (context.isPathOnOTG(path)) {
|
||||
context.getSomeDocumentFile(path)?.getItemSize(countHidden) ?: 0
|
||||
context.getDocumentFile(path)?.getItemSize(countHidden) ?: 0
|
||||
} else {
|
||||
File(path).getProperSize(countHidden)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue