Skip to content

Commit 2b72624

Browse files
committed
inflate all property items as needed
1 parent b4f22ae commit 2b72624

File tree

3 files changed

+57
-152
lines changed

3 files changed

+57
-152
lines changed
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,72 @@
11
package com.simplemobiletools.filemanager.dialogs
22

33
import android.content.Context
4+
import android.content.res.Resources
45
import android.support.v7.app.AlertDialog
56
import android.text.format.DateFormat
67
import android.view.LayoutInflater
7-
import android.view.View
8+
import android.view.ViewGroup
89
import com.simplemobiletools.filemanager.Config
910
import com.simplemobiletools.filemanager.R
1011
import com.simplemobiletools.filemanager.extensions.formatSize
1112
import com.simplemobiletools.filepicker.models.FileDirItem
1213
import kotlinx.android.synthetic.main.item_properties.view.*
14+
import kotlinx.android.synthetic.main.property_item.view.*
1315
import java.io.File
1416
import java.util.*
1517

1618
class 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
}

app/src/main/res/layout/item_properties.xml

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -9,121 +9,4 @@
99
android:paddingRight="@dimen/smtfp_activity_margin"
1010
android:paddingTop="@dimen/smtfp_activity_margin">
1111

12-
<TextView
13-
android:id="@+id/properties_name_label"
14-
android:layout_width="match_parent"
15-
android:layout_height="wrap_content"
16-
android:text="@string/name"
17-
android:textSize="@dimen/smtfp_details_text_size"/>
18-
19-
<TextView
20-
android:id="@+id/properties_name"
21-
android:layout_width="match_parent"
22-
android:layout_height="wrap_content"
23-
android:paddingLeft="@dimen/smtfp_small_margin"
24-
android:paddingRight="@dimen/smtfp_small_margin"
25-
android:textColor="@android:color/black"/>
26-
27-
<TextView
28-
android:id="@+id/properties_path_label"
29-
android:layout_width="match_parent"
30-
android:layout_height="wrap_content"
31-
android:layout_marginTop="@dimen/smtfp_activity_margin"
32-
android:text="@string/path"
33-
android:textSize="@dimen/smtfp_details_text_size"/>
34-
35-
<TextView
36-
android:id="@+id/properties_path"
37-
android:layout_width="match_parent"
38-
android:layout_height="wrap_content"
39-
android:paddingLeft="@dimen/smtfp_small_margin"
40-
android:paddingRight="@dimen/smtfp_small_margin"
41-
android:textColor="@android:color/black"/>
42-
43-
<TextView
44-
android:id="@+id/properties_size_label"
45-
android:layout_width="match_parent"
46-
android:layout_height="wrap_content"
47-
android:layout_marginTop="@dimen/smtfp_activity_margin"
48-
android:text="@string/size"
49-
android:textSize="@dimen/smtfp_details_text_size"/>
50-
51-
<TextView
52-
android:id="@+id/properties_size"
53-
android:layout_width="match_parent"
54-
android:layout_height="wrap_content"
55-
android:paddingLeft="@dimen/smtfp_small_margin"
56-
android:paddingRight="@dimen/smtfp_small_margin"
57-
android:textColor="@android:color/black"/>
58-
59-
<TextView
60-
android:id="@+id/properties_last_modified_label"
61-
android:layout_width="match_parent"
62-
android:layout_height="wrap_content"
63-
android:layout_marginTop="@dimen/smtfp_activity_margin"
64-
android:text="@string/last_modified"
65-
android:textSize="@dimen/smtfp_details_text_size"/>
66-
67-
<TextView
68-
android:id="@+id/properties_last_modified"
69-
android:layout_width="match_parent"
70-
android:layout_height="wrap_content"
71-
android:paddingLeft="@dimen/smtfp_small_margin"
72-
android:paddingRight="@dimen/smtfp_small_margin"
73-
android:textColor="@android:color/black"/>
74-
75-
<TextView
76-
android:id="@+id/properties_files_count_label"
77-
android:layout_width="match_parent"
78-
android:layout_height="wrap_content"
79-
android:layout_marginTop="@dimen/smtfp_activity_margin"
80-
android:text="@string/files_count"
81-
android:textSize="@dimen/smtfp_details_text_size"
82-
android:visibility="gone"/>
83-
84-
<TextView
85-
android:id="@+id/properties_files_count"
86-
android:layout_width="match_parent"
87-
android:layout_height="wrap_content"
88-
android:paddingLeft="@dimen/smtfp_small_margin"
89-
android:paddingRight="@dimen/smtfp_small_margin"
90-
android:textColor="@android:color/black"
91-
android:visibility="gone"/>
92-
93-
<TextView
94-
android:id="@+id/properties_resolution_label"
95-
android:layout_width="match_parent"
96-
android:layout_height="wrap_content"
97-
android:layout_marginTop="@dimen/smtfp_activity_margin"
98-
android:text="@string/resolution"
99-
android:textSize="@dimen/smtfp_details_text_size"
100-
android:visibility="gone"/>
101-
102-
<TextView
103-
android:id="@+id/properties_resolution"
104-
android:layout_width="match_parent"
105-
android:layout_height="wrap_content"
106-
android:paddingLeft="@dimen/smtfp_small_margin"
107-
android:paddingRight="@dimen/smtfp_small_margin"
108-
android:textColor="@android:color/black"
109-
android:visibility="gone"/>
110-
111-
<TextView
112-
android:id="@+id/properties_duration_label"
113-
android:layout_width="match_parent"
114-
android:layout_height="wrap_content"
115-
android:layout_marginTop="@dimen/smtfp_activity_margin"
116-
android:text="@string/duration"
117-
android:textSize="@dimen/smtfp_details_text_size"
118-
android:visibility="gone"/>
119-
120-
<TextView
121-
android:id="@+id/properties_duration"
122-
android:layout_width="match_parent"
123-
android:layout_height="wrap_content"
124-
android:paddingLeft="@dimen/smtfp_small_margin"
125-
android:paddingRight="@dimen/smtfp_small_margin"
126-
android:textColor="@android:color/black"
127-
android:visibility="gone"/>
128-
12912
</LinearLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:orientation="vertical">
7+
8+
<TextView
9+
android:id="@+id/property_label"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:layout_marginTop="@dimen/smtfp_activity_margin"
13+
android:textSize="@dimen/smtfp_details_text_size"/>
14+
15+
<TextView
16+
android:id="@+id/property_value"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:paddingLeft="@dimen/smtfp_small_margin"
20+
android:paddingRight="@dimen/smtfp_small_margin"/>
21+
22+
</LinearLayout>

0 commit comments

Comments
 (0)