11package com.simplemobiletools.filemanager.dialogs
22
33import android.content.Context
4+ import android.content.res.Resources
45import android.support.v7.app.AlertDialog
56import android.text.format.DateFormat
67import android.view.LayoutInflater
7- import android.view.View
8+ import android.view.ViewGroup
89import com.simplemobiletools.filemanager.Config
910import com.simplemobiletools.filemanager.R
1011import com.simplemobiletools.filemanager.extensions.formatSize
1112import com.simplemobiletools.filepicker.models.FileDirItem
1213import kotlinx.android.synthetic.main.item_properties.view.*
14+ import kotlinx.android.synthetic.main.property_item.view.*
1315import java.io.File
1416import java.util.*
1517
1618class PropertiesDialog () {
1719 lateinit var mContext: Context
1820 lateinit var mItem: FileDirItem
21+ lateinit var mInflater: LayoutInflater
22+ lateinit var mPropertyView: ViewGroup
23+ lateinit var mResources: Resources
24+
1925 private var mCountHiddenItems = false
2026 private var mFilesCnt = 0
2127
2228 constructor (context: Context , item: FileDirItem , countHiddenItems: Boolean = false ) : this () {
2329 mContext = context
2430 mItem = item
2531 mCountHiddenItems = countHiddenItems
32+ mInflater = LayoutInflater .from(context)
33+ mResources = mContext.resources
2634
35+ val file = File (mItem.path)
2736 val title = if (mItem.isDirectory) R .string.directory_properties else R .string.file_properties
28- val infoView = LayoutInflater .from(context).inflate(R .layout.item_properties, null )
29-
30- infoView.apply {
31- properties_name.text = mItem.name
32- properties_path.text = mItem.path
33- properties_size.text = getItemSize()
37+ mPropertyView = mInflater.inflate(R .layout.item_properties, null ) as ViewGroup
3438
35- if (mItem.isDirectory) {
36- properties_files_count_label.visibility = View .VISIBLE
37- properties_files_count.visibility = View .VISIBLE
38- properties_files_count.text = mFilesCnt.toString()
39- } else if (mItem.isImage()) {
40- properties_resolution_label.visibility = View .VISIBLE
41- properties_resolution.visibility = View .VISIBLE
42- properties_resolution.text = mItem.getImageResolution()
43- } else if (mItem.isAudio()) {
44- properties_duration_label.visibility = View .VISIBLE
45- properties_duration.visibility = View .VISIBLE
46- properties_duration.text = mItem.getDuration()
47- } else if (mItem.isVideo()) {
48- properties_duration_label.visibility = View .VISIBLE
49- properties_duration.visibility = View .VISIBLE
50- properties_duration.text = mItem.getDuration()
51-
52- properties_resolution_label.visibility = View .VISIBLE
53- properties_resolution.visibility = View .VISIBLE
54- properties_resolution.text = mItem.getVideoResolution()
55- }
39+ addProperty(R .string.name, mItem.name)
40+ addProperty(R .string.path, mItem.path)
41+ addProperty(R .string.size, getItemSize())
42+ addProperty(R .string.last_modified, formatLastModified(file.lastModified()))
5643
57- val file = File (mItem.path)
58- properties_last_modified.text = formatLastModified(file.lastModified())
44+ if (mItem.isDirectory) {
45+ addProperty(R .string.files_count, mFilesCnt.toString())
46+ } else if (mItem.isImage()) {
47+ addProperty(R .string.resolution, mItem.getImageResolution())
48+ } else if (mItem.isAudio()) {
49+ addProperty(R .string.duration, mItem.getDuration())
50+ } else if (mItem.isVideo()) {
51+ addProperty(R .string.duration, mItem.getDuration())
52+ addProperty(R .string.resolution, mItem.getVideoResolution())
5953 }
6054
6155 AlertDialog .Builder (context)
62- .setTitle(context.resources .getString(title))
63- .setView(infoView )
56+ .setTitle(mResources .getString(title))
57+ .setView(mPropertyView )
6458 .setPositiveButton(R .string.ok, null )
6559 .create()
6660 .show()
6761 }
6862
63+ private fun addProperty (labelId : Int , value : String ) {
64+ val view = mInflater.inflate(R .layout.property_item, mPropertyView, false )
65+ view.property_label.text = mResources.getString(labelId)
66+ view.property_value.text = value
67+ mPropertyView.properties_holder.addView(view)
68+ }
69+
6970 private fun getItemSize (): String {
7071 if (mItem.isDirectory) {
7172 mCountHiddenItems = Config .newInstance(mContext).showHidden
@@ -82,8 +83,8 @@ class PropertiesDialog() {
8283 }
8384
8485 private fun getDirectorySize (dir : File ): Long {
86+ var size = 0L
8587 if (dir.exists()) {
86- var size: Long = 0
8788 val files = dir.listFiles()
8889 for (i in files.indices) {
8990 if (files[i].isDirectory) {
@@ -93,8 +94,7 @@ class PropertiesDialog() {
9394 size + = files[i].length()
9495 }
9596 }
96- return size
9797 }
98- return 0
98+ return size
9999 }
100100}
0 commit comments