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 propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1 propVersionCode = 1
propVersionName = '2.24.6' propVersionName = '2.25.0'
kotlin_version = '1.1.3-2' kotlin_version = '1.1.3-2'
support_libs = '25.3.1' support_libs = '25.3.1'
} }

View file

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