check if the destination has enough storage at copy/move

This commit is contained in:
tibbi 2019-08-01 22:18:12 +02:00
parent 75c9a88b24
commit 7d8b044a6c
3 changed files with 20 additions and 5 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.15.19'
propVersionName = '5.15.21'
kotlin_version = '1.3.41'
}

View file

@ -11,6 +11,7 @@ import android.os.Bundle
import android.provider.DocumentsContract
import android.view.MenuItem
import android.view.WindowManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.util.Pair
@ -322,10 +323,17 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
}
private fun startCopyMove(files: ArrayList<FileDirItem>, destinationPath: String, isCopyOperation: Boolean, copyPhotoVideoOnly: Boolean, copyHidden: Boolean) {
checkConflicts(files, destinationPath, 0, LinkedHashMap()) {
toast(if (isCopyOperation) R.string.copying else R.string.moving)
val pair = Pair(files, destinationPath)
CopyMoveTask(this, isCopyOperation, copyPhotoVideoOnly, it, copyMoveListener, copyHidden).execute(pair)
val availableSpace = destinationPath.getAvailableStorageB()
val sumToCopy = files.sumByLong { it.getProperSize(copyHidden) }
if (sumToCopy < availableSpace) {
checkConflicts(files, destinationPath, 0, LinkedHashMap()) {
toast(if (isCopyOperation) R.string.copying else R.string.moving)
val pair = Pair(files, destinationPath)
CopyMoveTask(this, isCopyOperation, copyPhotoVideoOnly, it, copyMoveListener, copyHidden).execute(pair)
}
} else {
val text = String.format(getString(R.string.no_space), sumToCopy.formatSize(), availableSpace.formatSize())
toast(text, Toast.LENGTH_LONG)
}
}

View file

@ -5,6 +5,7 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Point
import android.media.MediaMetadataRetriever
import android.os.StatFs
import android.text.Spannable
import android.text.SpannableString
import android.text.TextUtils
@ -200,6 +201,12 @@ fun String.getFileKey(): String {
return "${file.absolutePath}${file.lastModified()}"
}
fun String.getAvailableStorageB(): Long {
val stat = StatFs(this)
val bytesAvailable = stat.blockSizeLong * stat.availableBlocksLong
return bytesAvailable
}
// remove diacritics, for example č -> c
fun String.normalizeString() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(normalizeRegex, "")