From e72127713dca6f78c4eb4588fd7398d4d4a4a012 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 5 Aug 2017 18:14:21 +0200 Subject: [PATCH] cache the documentFile at copying files too --- build.gradle | 2 +- .../commons/asynctasks/CopyMoveTask.kt | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 35e09b69a..326398c36 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt index 4235f8c83..af7e5fa74 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt @@ -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? = null private var mMovedFiles: ArrayList = ArrayList() + private var mDocument: DocumentFile? = null lateinit var mFiles: ArrayList 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) }