From 7bc23b8fbc45d0230cb9a2f9b3e74e8d48c69250 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 15 Feb 2018 14:52:33 +0100 Subject: [PATCH] update commons to 3.11.36 --- app/build.gradle | 2 +- .../activities/ReadTextActivity.kt | 3 +- .../filemanager/adapters/ItemsAdapter.kt | 8 +++--- .../dialogs/CreateNewItemDialog.kt | 28 +++++++++---------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 10974d23..e1783cac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.11.35' + implementation 'com.simplemobiletools:commons:3.11.36' implementation files('../libs/RootTools.jar') diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt index 4d644106..49a535a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt @@ -5,6 +5,7 @@ import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE +import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.dialogs.SaveAsDialog import com.simplemobiletools.filemanager.extensions.config @@ -50,7 +51,7 @@ class ReadTextActivity : SimpleActivity() { } SaveAsDialog(this, filePath) { - getFileOutputStream(File(it)) { + getFileOutputStream(FileDirItem(it, it.getFilenameFromPath())) { if (it != null) { it.bufferedWriter().use { it.write(read_text_view.text.toString()) } toast(R.string.file_saved) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 15a3e8d0..5a98e1ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -220,7 +220,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList(selectedPositions.size) val removeFiles = ArrayList(selectedPositions.size) - val SAFFile = File(fileDirItems[selectedPositions.first()].path) + val SAFPath = fileDirItems[selectedPositions.first()].path - activity.handleSAFDialog(SAFFile) { + activity.handleSAFDialog(SAFPath) { selectedPositions.sortedDescending().forEach { val file = fileDirItems[it] files.add(FileDirItem(file.path, file.name)) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt index 37485f18..ce265c02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt @@ -32,11 +32,11 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va } if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) { - createDirectory(file, this) { + createDirectory("$path/$name", this) { callback(it) } } else { - createFile(file, this) { + createFile("$path/$name", this) { callback(it) } } @@ -48,41 +48,41 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va } } - private fun createDirectory(file: File, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { + private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { when { - activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(file) { - val documentFile = activity.getFileDocument(file.absolutePath) + activity.needsStupidWritePermissions(this.path) -> activity.handleSAFDialog(path) { + val documentFile = activity.getFileDocument(path) if (documentFile == null) { - val error = String.format(activity.getString(R.string.could_not_create_folder), file.absolutePath) + val error = String.format(activity.getString(R.string.could_not_create_folder), path) activity.showErrorToast(error) callback(false) return@handleSAFDialog } - documentFile.createDirectory(file.name) + documentFile.createDirectory(path.getFilenameFromPath()) success(alertDialog) } - file.mkdirs() -> { + File(path).mkdirs() -> { success(alertDialog) } else -> callback(false) } } - private fun createFile(file: File, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { + private fun createFile(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { try { if (activity.needsStupidWritePermissions(path)) { - activity.handleSAFDialog(file) { - val documentFile = activity.getFileDocument(file.absolutePath) + activity.handleSAFDialog(path) { + val documentFile = activity.getFileDocument(path) if (documentFile == null) { - val error = String.format(activity.getString(R.string.could_not_create_file), file.absolutePath) + val error = String.format(activity.getString(R.string.could_not_create_file), path) activity.showErrorToast(error) callback(false) return@handleSAFDialog } - documentFile.createFile("", file.name) + documentFile.createFile("", path.getFilenameFromPath()) success(alertDialog) } - } else if (file.createNewFile()) { + } else if (File(path).createNewFile()) { success(alertDialog) } } catch (exception: IOException) {