rewrite PropertiesDialog to not be a dialogfragment
This commit is contained in:
parent
faf721a9b1
commit
82018feee6
|
@ -390,8 +390,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PropertiesDialog dialog = PropertiesDialog.Companion.newInstance(item);
|
final Config config = Config.newInstance(getContext());
|
||||||
dialog.show(getFragmentManager(), "properties");
|
new PropertiesDialog(getContext(), item, config.getShowHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayRenameDialog() {
|
private void displayRenameDialog() {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package com.simplemobiletools.filemanager.dialogs
|
package com.simplemobiletools.filemanager.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.content.Context
|
||||||
import android.os.Bundle
|
|
||||||
import android.support.v4.app.DialogFragment
|
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.filemanager.Config
|
import com.simplemobiletools.filemanager.Config
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
|
@ -14,22 +13,19 @@ import kotlinx.android.synthetic.main.item_properties.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class PropertiesDialog : DialogFragment() {
|
class PropertiesDialog() {
|
||||||
companion object {
|
lateinit var mContext: Context
|
||||||
lateinit var mItem: FileDirItem
|
lateinit var mItem: FileDirItem
|
||||||
private var mFilesCnt: Int = 0
|
private var mCountHiddenItems = false // we always include the hidden item's size, counting items themselves is the optional thing
|
||||||
private var mShowHidden: Boolean = false
|
private var mFilesCnt = 0
|
||||||
|
|
||||||
fun newInstance(item: FileDirItem): PropertiesDialog {
|
constructor(context: Context, item: FileDirItem, countHiddenItems: Boolean = false) : this() {
|
||||||
mItem = item
|
mContext = context
|
||||||
mFilesCnt = 0
|
mItem = item
|
||||||
return PropertiesDialog()
|
mCountHiddenItems = countHiddenItems
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
||||||
val title = if (mItem.isDirectory) R.string.directory_properties else R.string.file_properties
|
val title = if (mItem.isDirectory) R.string.directory_properties else R.string.file_properties
|
||||||
val infoView = activity.layoutInflater.inflate(R.layout.item_properties, null)
|
val infoView = LayoutInflater.from(context).inflate(R.layout.item_properties, null)
|
||||||
|
|
||||||
infoView.apply {
|
infoView.apply {
|
||||||
properties_name.text = mItem.name
|
properties_name.text = mItem.name
|
||||||
|
@ -62,16 +58,17 @@ class PropertiesDialog : DialogFragment() {
|
||||||
properties_last_modified.text = formatLastModified(file.lastModified())
|
properties_last_modified.text = formatLastModified(file.lastModified())
|
||||||
}
|
}
|
||||||
|
|
||||||
return AlertDialog.Builder(context)
|
AlertDialog.Builder(context)
|
||||||
.setTitle(resources.getString(title))
|
.setTitle(context.resources.getString(title))
|
||||||
.setView(infoView)
|
.setView(infoView)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.create()
|
.create()
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItemSize(): String {
|
private fun getItemSize(): String {
|
||||||
if (mItem.isDirectory) {
|
if (mItem.isDirectory) {
|
||||||
mShowHidden = Config.newInstance(context).showHidden
|
mCountHiddenItems = Config.newInstance(mContext).showHidden
|
||||||
return getDirectorySize(File(mItem.path)).formatSize()
|
return getDirectorySize(File(mItem.path)).formatSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +90,7 @@ class PropertiesDialog : DialogFragment() {
|
||||||
size += getDirectorySize(files[i])
|
size += getDirectorySize(files[i])
|
||||||
} else {
|
} else {
|
||||||
size += files[i].length()
|
size += files[i].length()
|
||||||
if (!files[i].isHidden && !dir.isHidden || mShowHidden)
|
if (!files[i].isHidden && !dir.isHidden || mCountHiddenItems)
|
||||||
mFilesCnt++
|
mFilesCnt++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue