Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 9502c1d2 authored by solokot's avatar solokot Committed by GitHub
Browse files

Merge pull request #42 from SimpleMobileTools/master

upd
parents 81f08325 34e26214
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@
buildscript {
    ext {
        propCompileSdkVersion = 28
        propBuildToolsVersion = "28.0.2"
        propBuildToolsVersion = "28.0.3"
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '4.7.2'
        kotlin_version = '1.2.61'
        propVersionName = '4.8.0'
        kotlin_version = '1.2.71'
        support_libs = '27.1.1'
    }

@@ -18,7 +18,7 @@ buildscript {
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+30 −18
Original line number Diff line number Diff line
@@ -255,6 +255,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {

        handleSAFDialog(destination) {
            copyMoveCallback = callback
            var fileCountToCopy = fileDirItems.size
            if (isCopyOperation) {
                startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
            } else {
@@ -263,12 +264,22 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
                        startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
                    }
                } else {
                    try {
                        checkConflicts(fileDirItems, destination, 0, LinkedHashMap()) {
                            toast(R.string.moving)
                            val updatedFiles = ArrayList<FileDirItem>(fileDirItems.size * 2)
                    try {
                            val destinationFolder = File(destination)
                            for (oldFileDirItem in fileDirItems) {
                                val newFile = File(destinationFolder, oldFileDirItem.name)
                                if (newFile.exists()) {
                                    if (getConflictResolution(it, newFile.absolutePath) == CONFLICT_SKIP) {
                                        fileCountToCopy--
                                    } else {
                                        // this file is guaranteed to be on the internal storage, so just delete it this way
                                        newFile.delete()
                                    }
                                }

                                if (!newFile.exists() && File(oldFileDirItem.path).renameTo(newFile)) {
                                    if (!baseConfig.keepLastModified) {
                                        newFile.setLastModified(System.currentTimeMillis())
@@ -278,14 +289,15 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
                            }

                            val updatedPaths = updatedFiles.map { it.path } as ArrayList<String>
                            if (updatedPaths.isEmpty()) {
                                copyMoveListener.copySucceeded(false, fileCountToCopy == 0, destination)
                            } else {
                                rescanPaths(updatedPaths) {
                                    runOnUiThread {
                                copyMoveListener.copySucceeded(false, fileDirItems.size == updatedFiles.size, destination)
                                        copyMoveListener.copySucceeded(false, fileCountToCopy <= updatedPaths.size, destination)
                                    }
                                }
                            }

                        if (updatedPaths.isEmpty()) {
                            copyMoveListener.copySucceeded(false, false, destination)
                        }
                    } catch (e: Exception) {
                        showErrorToast(e)
+3 −16
Original line number Diff line number Diff line
@@ -13,10 +13,7 @@ import android.support.v4.util.Pair
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.interfaces.CopyMoveListener
import com.simplemobiletools.commons.models.FileDirItem
import java.io.File
@@ -70,7 +67,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
            val newPath = "$mDestinationPath/${file.name}"
            val fileExists = if (newPath.startsWith(OTG_PATH)) activity.getOTGFastDocumentFile(newPath)?.exists()
                    ?: false else File(newPath).exists()
            if (getConflictResolution(newPath) != CONFLICT_SKIP || !fileExists) {
            if (getConflictResolution(conflictResolutions, newPath) != CONFLICT_SKIP || !fileExists) {
                mMaxSize += (file.size / 1000).toInt()
            }
        }
@@ -85,7 +82,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
                val newPath = "$mDestinationPath/${file.name}"
                val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), file.isDirectory)
                if (activity.getDoesFilePathExist(newPath)) {
                    val resolution = getConflictResolution(newPath)
                    val resolution = getConflictResolution(conflictResolutions, newPath)
                    if (resolution == CONFLICT_SKIP) {
                        mFileCountToCopy--
                        continue
@@ -151,16 +148,6 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        }, PROGRESS_RECHECK_INTERVAL)
    }

    private fun getConflictResolution(path: String): Int {
        return if (conflictResolutions.size == 1 && conflictResolutions.containsKey("")) {
            conflictResolutions[""]!!
        } else if (conflictResolutions.containsKey(path)) {
            conflictResolutions[path]!!
        } else {
            CONFLICT_SKIP
        }
    }

    private fun copy(source: FileDirItem, destination: FileDirItem) {
        if (source.isDirectory) {
            copyDirectory(source, destination.path)
+3 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_message.view.*

// similar fo ConfirmationDialog, but has a callback for negative button too
class ConfirmationAdvancedDialog(activity: Activity, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
                                 negative: Int, val callback: (result: Boolean) -> Unit) {
    var dialog: AlertDialog
@@ -15,8 +16,8 @@ class ConfirmationAdvancedDialog(activity: Activity, message: String = "", messa
        view.message.text = if (message.isEmpty()) activity.resources.getString(messageId) else message

        dialog = AlertDialog.Builder(activity)
                .setPositiveButton(positive, { dialog, which -> positivePressed() })
                .setNegativeButton(negative, { dialog, which -> negativePressed() })
                .setPositiveButton(positive) { dialog, which -> positivePressed() }
                .setNegativeButton(negative) { dialog, which -> negativePressed() }
                .create().apply {
                    activity.setupDialogStuff(view, this)
                }
+9 −6
Original line number Diff line number Diff line
@@ -630,8 +630,7 @@ fun BaseSimpleActivity.getFileOutputStream(fileDirItem: FileDirItem, allowCreati
            }

            if (document == null) {
                val error = String.format(getString(R.string.could_not_create_file), fileDirItem.path)
                showErrorToast(error)
                showFileCreateError(fileDirItem.path)
                callback(null)
                return@handleSAFDialog
            }
@@ -648,8 +647,7 @@ fun BaseSimpleActivity.getFileOutputStream(fileDirItem: FileDirItem, allowCreati
                    callback(null)
                }
            } else {
                val error = String.format(getString(R.string.could_not_create_file), fileDirItem.path)
                showErrorToast(error)
                showFileCreateError(fileDirItem.path)
                callback(null)
            }
        }
@@ -667,6 +665,12 @@ fun BaseSimpleActivity.getFileOutputStream(fileDirItem: FileDirItem, allowCreati
    }
}

fun BaseSimpleActivity.showFileCreateError(path: String) {
    val error = String.format(getString(R.string.could_not_create_file), path)
    baseConfig.treeUri = ""
    showErrorToast(error)
}

fun BaseSimpleActivity.getFileOutputStreamSync(path: String, mimeType: String, parentDocumentFile: DocumentFile? = null): OutputStream? {
    val targetFile = File(path)

@@ -682,8 +686,7 @@ fun BaseSimpleActivity.getFileOutputStreamSync(path: String, mimeType: String, p
        }

        if (documentFile == null) {
            val error = String.format(getString(R.string.could_not_create_file), targetFile.parent)
            showErrorToast(error)
            showFileCreateError(targetFile.parent)
            return null
        }

Loading