mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
replace some functions with extension helpers
This commit is contained in:
@ -14,8 +14,9 @@ import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import kotlinx.android.synthetic.main.copy_item.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class CopyDialog(val activity: Activity, val files: List<File>, val copyListener: CopyTask.CopyListener, val listener: OnCopyListener) {
|
||||
class CopyDialog(val activity: Activity, val files: ArrayList<File>, val copyListener: CopyTask.CopyListener, val listener: OnCopyListener) {
|
||||
|
||||
init {
|
||||
val context = activity
|
||||
@ -82,21 +83,20 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
|
||||
|
||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
||||
context.toast(R.string.copying)
|
||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
|
||||
CopyTask(copyListener, context, false).execute(pair)
|
||||
dismiss()
|
||||
} else {
|
||||
if (context.isPathOnSD(sourcePath) || context.isPathOnSD(destinationPath)) {
|
||||
context.toast(R.string.moving)
|
||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
|
||||
CopyTask(copyListener, context, true).execute(pair)
|
||||
dismiss()
|
||||
} else {
|
||||
for (file in files) {
|
||||
val destination = File(destinationDir, file.name)
|
||||
file.renameTo(destination)
|
||||
context.rescanItem(file)
|
||||
context.rescanItem(destination)
|
||||
context.scanFiles(arrayListOf(file, destination)) {}
|
||||
}
|
||||
|
||||
context.toast(R.string.moving_success)
|
||||
|
@ -7,11 +7,7 @@ import android.view.View
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.filemanager.Config
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.extensions.isValidFilename
|
||||
import com.simplemobiletools.filemanager.extensions.value
|
||||
import com.simplemobiletools.filepicker.extensions.getFileDocument
|
||||
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import kotlinx.android.synthetic.main.create_new.view.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@ -32,7 +28,7 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
|
||||
val name = view.item_name.value
|
||||
if (name.isEmpty()) {
|
||||
context.toast(R.string.empty_name)
|
||||
} else if (name.isValidFilename()) {
|
||||
} else if (name.isAValidFilename()) {
|
||||
val file = File(path, name)
|
||||
if (file.exists()) {
|
||||
context.toast(R.string.name_taken)
|
||||
|
@ -6,12 +6,7 @@ import android.view.LayoutInflater
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.filemanager.Config
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.extensions.isValidFilename
|
||||
import com.simplemobiletools.filemanager.extensions.value
|
||||
import com.simplemobiletools.filepicker.extensions.getFileDocument
|
||||
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||
import com.simplemobiletools.filepicker.extensions.rescanItem
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||
import kotlinx.android.synthetic.main.rename_item.view.*
|
||||
import java.io.File
|
||||
@ -32,7 +27,7 @@ class RenameItemDialog(val context: Context, val path: String, val item: FileDir
|
||||
show()
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||
val newName = view.item_name.value
|
||||
if (newName.isValidFilename()) {
|
||||
if (newName.isAValidFilename()) {
|
||||
val currFile = File(path, item.name)
|
||||
val newFile = File(path, newName)
|
||||
|
||||
@ -63,8 +58,7 @@ class RenameItemDialog(val context: Context, val path: String, val item: FileDir
|
||||
}
|
||||
|
||||
private fun sendSuccess(currFile: File, newFile: File) {
|
||||
context.rescanItem(currFile)
|
||||
context.rescanItem(newFile)
|
||||
context.scanFiles(arrayListOf(currFile, newFile)) {}
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.simplemobiletools.filemanager.extensions
|
||||
|
||||
import android.text.format.DateFormat
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
|
||||
fun Long.formatSize(): String {
|
||||
if (this <= 0)
|
||||
@ -12,9 +10,3 @@ fun Long.formatSize(): String {
|
||||
val digitGroups = (Math.log10(toDouble()) / Math.log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.#").format(this / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
}
|
||||
|
||||
fun Long.formatLastModified(): String {
|
||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
||||
cal.timeInMillis = this
|
||||
return DateFormat.format("dd.MM.yyyy HH:mm", cal).toString()
|
||||
}
|
||||
|
Reference in New Issue
Block a user