updating commons to 3.11.52

This commit is contained in:
tibbi 2018-02-16 18:30:21 +01:00
parent 1c02c8b16e
commit ad2c644f29
6 changed files with 25 additions and 54 deletions

View File

@ -45,7 +45,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.11.45'
implementation 'com.simplemobiletools:commons:3.11.52'
implementation files('../libs/RootTools.jar')

View File

@ -183,7 +183,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
selectedPositions.forEach { files.add(fileDirItems[it]) }
val firstFile = files[0]
val source = if (!firstFile.isDirectory) firstFile.path.substring(0, firstFile.path.length - firstFile.name.length) else firstFile.path
val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath()
FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) {
if (activity.isPathOnRoot(it)) {
copyRootItems(files, it)

View File

@ -9,17 +9,15 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
import java.io.File
class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
init {
val file = File(path)
val filename = path.getFilenameFromPath()
val indexOfDot = if (filename.contains('.') && file.isFile) filename.lastIndexOf(".") else filename.length
val indexOfDot = if (filename.contains('.') && !activity.getIsPathDirectory(path)) filename.lastIndexOf(".") else filename.length
val baseFilename = filename.substring(0, indexOfDot)
var realPath = file.parent.trimEnd('/')
var realPath = path.getParentPath()
view.apply {
file_name.setText(baseFilename)
@ -44,14 +42,14 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
when {
name.isEmpty() -> activity.toast(R.string.empty_name)
name.isAValidFilename() -> {
val newFile = File(realPath, "$name.zip")
if (newFile.exists()) {
val newPath = "$realPath/$name.zip"
if (activity.doesFilePathExist(newPath)) {
activity.toast(R.string.name_taken)
return@OnClickListener
}
dismiss()
callback(newFile.absolutePath)
callback(newPath)
}
else -> activity.toast(R.string.invalid_name)
}

View File

@ -25,18 +25,18 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
if (name.isEmpty()) {
activity.toast(R.string.empty_name)
} else if (name.isAValidFilename()) {
val file = File(path, name)
if (file.exists()) {
val newPath = "$path/$name"
if (activity.doesFilePathExist(newPath)) {
activity.toast(R.string.name_taken)
return@OnClickListener
}
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
createDirectory("$path/$name", this) {
createDirectory(newPath, this) {
callback(it)
}
} else {
createFile("$path/$name", this) {
createFile(newPath, this) {
callback(it)
}
}
@ -51,7 +51,7 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
when {
activity.needsStupidWritePermissions(this.path) -> activity.handleSAFDialog(path) {
val documentFile = activity.getDocumentFile(path)
val documentFile = activity.getDocumentFile(path.getParentPath())
if (documentFile == null) {
val error = String.format(activity.getString(R.string.could_not_create_folder), path)
activity.showErrorToast(error)
@ -72,14 +72,14 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
try {
if (activity.needsStupidWritePermissions(path)) {
activity.handleSAFDialog(path) {
val documentFile = activity.getDocumentFile(path)
val documentFile = activity.getDocumentFile(path.getParentPath())
if (documentFile == null) {
val error = String.format(activity.getString(R.string.could_not_create_file), path)
activity.showErrorToast(error)
callback(false)
return@handleSAFDialog
}
documentFile.createFile("", path.getFilenameFromPath())
documentFile.createFile(path.getMimeType(), path.getFilenameFromPath())
success(alertDialog)
}
} else if (File(path).createNewFile()) {

View File

@ -8,16 +8,15 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.R
import kotlinx.android.synthetic.main.dialog_save_as.view.*
import java.io.File
class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callback: (savePath: String) -> Unit) {
init {
if (path.isEmpty()) {
path = "${activity.internalStoragePath}/${System.currentTimeMillis()}.txt"
path = "${activity.internalStoragePath}/${activity.getCurrentFormattedDateTime()}.txt"
}
var realPath = File(path).parent.trimEnd('/')
var realPath = path.getParentPath()
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
save_as_path.text = activity.humanizePath(realPath)
@ -60,20 +59,21 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
return@setOnClickListener
}
val newFile = File(realPath, "$filename.$extension")
if (!newFile.name.isAValidFilename()) {
val newFilename = "$filename.$extension"
val newPath = "$realPath/$newFilename"
if (!newFilename.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
if (newFile.exists()) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name)
if (activity.doesFilePathExist(newPath)) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
ConfirmationDialog(activity, title) {
callback(newFile.absolutePath)
callback(newPath)
dismiss()
}
} else {
callback(newFile.absolutePath)
callback(newPath)
dismiss()
}
}

View File

@ -200,8 +200,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
continue
}
val children = getChildrenCount(file)
val size = if (file.isDirectory && context?.config?.sorting == SORT_BY_SIZE) getDirectorySize(file) else file.length()
val children = file.getDirectChildrenCount(showHidden)
val size = if (file.isDirectory && context?.config?.sorting == SORT_BY_SIZE) file.getProperSize(showHidden) else file.length()
val fileDirItem = FileDirItem(curPath, curName, file.isDirectory, children, size)
items.add(fileDirItem)
}
@ -209,33 +209,6 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
callback(path, items)
}
private fun getChildrenCount(file: File): Int {
val fileList: Array<out String>? = file.list() ?: return 0
if (file.isDirectory) {
return if (showHidden) {
fileList!!.size
} else {
fileList!!.count { fileName -> fileName[0] != '.' }
}
}
return 0
}
private fun getDirectorySize(directory: File): Long {
if (directory.exists()) {
val fileList = directory.listFiles() ?: return 0
return fileList.indices.map {
if (fileList[it].isDirectory) {
getDirectorySize(fileList[it])
} else {
fileList[it].length()
}
}.sum()
}
return 0
}
private fun itemClicked(item: FileDirItem) {
if (item.isDirectory) {
(activity as? MainActivity)?.apply {