From 82018feee6f3829513e3d7d0b62b9701ff595261 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Oct 2016 19:56:55 +0200 Subject: [PATCH] rewrite PropertiesDialog to not be a dialogfragment --- .../filemanager/fragments/ItemsFragment.java | 4 +- .../filemanager/dialogs/PropertiesDialog.kt | 37 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index df8c4994..37bddab9 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -390,8 +390,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment if (item == null) return; - PropertiesDialog dialog = PropertiesDialog.Companion.newInstance(item); - dialog.show(getFragmentManager(), "properties"); + final Config config = Config.newInstance(getContext()); + new PropertiesDialog(getContext(), item, config.getShowHidden()); } private void displayRenameDialog() { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt index b7d8c57e..8e89172b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt @@ -1,10 +1,9 @@ package com.simplemobiletools.filemanager.dialogs -import android.app.Dialog -import android.os.Bundle -import android.support.v4.app.DialogFragment +import android.content.Context import android.support.v7.app.AlertDialog import android.text.format.DateFormat +import android.view.LayoutInflater import android.view.View import com.simplemobiletools.filemanager.Config import com.simplemobiletools.filemanager.R @@ -14,22 +13,19 @@ import kotlinx.android.synthetic.main.item_properties.view.* import java.io.File import java.util.* -class PropertiesDialog : DialogFragment() { - companion object { - lateinit var mItem: FileDirItem - private var mFilesCnt: Int = 0 - private var mShowHidden: Boolean = false +class PropertiesDialog() { + lateinit var mContext: Context + lateinit var mItem: FileDirItem + private var mCountHiddenItems = false // we always include the hidden item's size, counting items themselves is the optional thing + private var mFilesCnt = 0 - fun newInstance(item: FileDirItem): PropertiesDialog { - mItem = item - mFilesCnt = 0 - return PropertiesDialog() - } - } + constructor(context: Context, item: FileDirItem, countHiddenItems: Boolean = false) : this() { + mContext = context + mItem = item + mCountHiddenItems = countHiddenItems - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 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 { properties_name.text = mItem.name @@ -62,16 +58,17 @@ class PropertiesDialog : DialogFragment() { properties_last_modified.text = formatLastModified(file.lastModified()) } - return AlertDialog.Builder(context) - .setTitle(resources.getString(title)) + AlertDialog.Builder(context) + .setTitle(context.resources.getString(title)) .setView(infoView) .setPositiveButton(R.string.ok, null) .create() + .show() } private fun getItemSize(): String { if (mItem.isDirectory) { - mShowHidden = Config.newInstance(context).showHidden + mCountHiddenItems = Config.newInstance(mContext).showHidden return getDirectorySize(File(mItem.path)).formatSize() } @@ -93,7 +90,7 @@ class PropertiesDialog : DialogFragment() { size += getDirectorySize(files[i]) } else { size += files[i].length() - if (!files[i].isHidden && !dir.isHidden || mShowHidden) + if (!files[i].isHidden && !dir.isHidden || mCountHiddenItems) mFilesCnt++ } }