cache the documentFile at copying files too

This commit is contained in:
tibbi 2017-08-05 18:14:21 +02:00
parent 9396f006bd
commit e72127713d
2 changed files with 12 additions and 4 deletions

View file

@ -29,7 +29,7 @@ ext {
propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '2.24.6'
propVersionName = '2.25.0'
kotlin_version = '1.1.3-2'
support_libs = '25.3.1'
}

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.commons.asynctasks
import android.os.AsyncTask
import android.support.v4.provider.DocumentFile
import android.support.v4.util.Pair
import android.util.Log
import com.simplemobiletools.commons.activities.BaseSimpleActivity
@ -14,6 +15,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
private val TAG = CopyMoveTask::class.java.simpleName
private var mListener: WeakReference<CopyMoveListener>? = null
private var mMovedFiles: ArrayList<File> = ArrayList()
private var mDocument: DocumentFile? = null
lateinit var mFiles: ArrayList<File>
init {
@ -99,9 +101,15 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
var out: OutputStream? = null
try {
if (activity.needsStupidWritePermissions(destination.absolutePath)) {
var document = activity.getFileDocument(destination.parent) ?: return
document = document.createFile("", destination.name)
out = activity.contentResolver.openOutputStream(document.uri)
if (mDocument == null) {
mDocument = activity.getFileDocument(destination.parent)
}
if (mDocument == null)
return
val newDocument = mDocument!!.createFile("", destination.name)
out = activity.contentResolver.openOutputStream(newDocument!!.uri)
} else {
out = FileOutputStream(destination)
}