updating rename dialog

This commit is contained in:
tibbi 2017-03-11 11:15:23 +01:00
parent dd9c6266db
commit 179763ebe6
4 changed files with 19 additions and 27 deletions

View file

@ -22,6 +22,7 @@ import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.dialogs.CopyDialog
import com.simplemobiletools.filemanager.dialogs.RenameItemDialog
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.list_item.view.*
import java.io.File
import java.util.*
@ -30,7 +31,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: List<FileDirItem>,
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
val config = Config.newInstance(activity)
val config = activity.config
companion object {
var actMode: ActionMode? = null
@ -96,12 +97,10 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: List<FileDirItem>,
}
private fun displayRenameDialog() {
RenameItemDialog(activity, getSelectedMedia()[0], object : RenameItemDialog.OnRenameItemListener {
override fun onSuccess() {
listener?.refreshItems()
actMode?.finish()
}
})
RenameItemDialog(activity, getSelectedMedia()[0]) {
listener?.refreshItems()
actMode?.finish()
}
}
private fun showProperties() {

View file

@ -4,9 +4,9 @@ import android.support.v4.util.Pair
import android.support.v7.app.AlertDialog
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.copy_item.view.*
import java.io.File
import java.util.*
@ -20,7 +20,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val c
var destinationPath = ""
view.source.text = "${context.humanizePath(sourcePath)}/"
val config = Config.newInstance(context)
val config = context.config
/*view.destination.setOnClickListener {
FilePickerDialog(activity, destinationPath, false, config.showHidden, object : FilePickerDialog.OnFilePickerListener {
override fun onFail(error: FilePickerDialog.FilePickerResult) {

View file

@ -1,33 +1,29 @@
package com.simplemobiletools.filemanager.dialogs
import android.content.Context
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.WindowManager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.rename_item.view.*
import java.io.File
class RenameItemDialog(val context: Context, val item: FileDirItem, val listener: OnRenameItemListener) {
class RenameItemDialog(val activity: Activity, val item: FileDirItem, val callback: () -> Unit) {
init {
val view = LayoutInflater.from(context).inflate(R.layout.rename_item, null)
val view = activity.layoutInflater.inflate(R.layout.rename_item, null)
view.item_name.setText(item.name)
val path = File(item.path).parent
AlertDialog.Builder(context)
.setTitle(context.resources.getString(R.string.rename_item))
.setView(view)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.rename_item)
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
setCanceledOnTouchOutside(true)
show()
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val newName = view.item_name.value
if (!newName.isAValidFilename()) {
@ -44,7 +40,7 @@ class RenameItemDialog(val context: Context, val item: FileDirItem, val listener
}
if (context.needsStupidWritePermissions(path)) {
val document = context.getFileDocument(currFile.absolutePath, Config.newInstance(context).treeUri) ?: return@setOnClickListener
val document = context.getFileDocument(currFile.absolutePath, context.config.treeUri) ?: return@setOnClickListener
if (document.canWrite())
document.renameTo(newName)
sendSuccess(newFile)
@ -62,11 +58,7 @@ class RenameItemDialog(val context: Context, val item: FileDirItem, val listener
}
private fun sendSuccess(newFile: File) {
context.scanFiles(arrayListOf(newFile)) {}
listener.onSuccess()
}
interface OnRenameItemListener {
fun onSuccess()
activity.scanFiles(arrayListOf(newFile)) {}
callback.invoke()
}
}

View file

@ -22,6 +22,7 @@ import com.simplemobiletools.filemanager.SCROLL_STATE
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.items_fragment.*
import java.io.File
import java.util.*
@ -42,7 +43,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mConfig = Config.newInstance(context)
mConfig = context.config
mShowHidden = mConfig.showHidden
mItems = ArrayList<FileDirItem>()
mToBeDeleted = ArrayList<String>()