inflate all property items as needed

This commit is contained in:
tibbi 2016-10-16 21:13:48 +02:00
parent b4f22ae877
commit 2b726248de
3 changed files with 57 additions and 152 deletions

View File

@ -1,21 +1,27 @@
package com.simplemobiletools.filemanager.dialogs
import android.content.Context
import android.content.res.Resources
import android.support.v7.app.AlertDialog
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.formatSize
import com.simplemobiletools.filepicker.models.FileDirItem
import kotlinx.android.synthetic.main.item_properties.view.*
import kotlinx.android.synthetic.main.property_item.view.*
import java.io.File
import java.util.*
class PropertiesDialog() {
lateinit var mContext: Context
lateinit var mItem: FileDirItem
lateinit var mInflater: LayoutInflater
lateinit var mPropertyView: ViewGroup
lateinit var mResources: Resources
private var mCountHiddenItems = false
private var mFilesCnt = 0
@ -23,49 +29,44 @@ class PropertiesDialog() {
mContext = context
mItem = item
mCountHiddenItems = countHiddenItems
val title = if (mItem.isDirectory) R.string.directory_properties else R.string.file_properties
val infoView = LayoutInflater.from(context).inflate(R.layout.item_properties, null)
infoView.apply {
properties_name.text = mItem.name
properties_path.text = mItem.path
properties_size.text = getItemSize()
if (mItem.isDirectory) {
properties_files_count_label.visibility = View.VISIBLE
properties_files_count.visibility = View.VISIBLE
properties_files_count.text = mFilesCnt.toString()
} else if (mItem.isImage()) {
properties_resolution_label.visibility = View.VISIBLE
properties_resolution.visibility = View.VISIBLE
properties_resolution.text = mItem.getImageResolution()
} else if (mItem.isAudio()) {
properties_duration_label.visibility = View.VISIBLE
properties_duration.visibility = View.VISIBLE
properties_duration.text = mItem.getDuration()
} else if (mItem.isVideo()) {
properties_duration_label.visibility = View.VISIBLE
properties_duration.visibility = View.VISIBLE
properties_duration.text = mItem.getDuration()
properties_resolution_label.visibility = View.VISIBLE
properties_resolution.visibility = View.VISIBLE
properties_resolution.text = mItem.getVideoResolution()
}
mInflater = LayoutInflater.from(context)
mResources = mContext.resources
val file = File(mItem.path)
properties_last_modified.text = formatLastModified(file.lastModified())
val title = if (mItem.isDirectory) R.string.directory_properties else R.string.file_properties
mPropertyView = mInflater.inflate(R.layout.item_properties, null) as ViewGroup
addProperty(R.string.name, mItem.name)
addProperty(R.string.path, mItem.path)
addProperty(R.string.size, getItemSize())
addProperty(R.string.last_modified, formatLastModified(file.lastModified()))
if (mItem.isDirectory) {
addProperty(R.string.files_count, mFilesCnt.toString())
} else if (mItem.isImage()) {
addProperty(R.string.resolution, mItem.getImageResolution())
} else if (mItem.isAudio()) {
addProperty(R.string.duration, mItem.getDuration())
} else if (mItem.isVideo()) {
addProperty(R.string.duration, mItem.getDuration())
addProperty(R.string.resolution, mItem.getVideoResolution())
}
AlertDialog.Builder(context)
.setTitle(context.resources.getString(title))
.setView(infoView)
.setTitle(mResources.getString(title))
.setView(mPropertyView)
.setPositiveButton(R.string.ok, null)
.create()
.show()
}
private fun addProperty(labelId: Int, value: String) {
val view = mInflater.inflate(R.layout.property_item, mPropertyView, false)
view.property_label.text = mResources.getString(labelId)
view.property_value.text = value
mPropertyView.properties_holder.addView(view)
}
private fun getItemSize(): String {
if (mItem.isDirectory) {
mCountHiddenItems = Config.newInstance(mContext).showHidden
@ -82,8 +83,8 @@ class PropertiesDialog() {
}
private fun getDirectorySize(dir: File): Long {
var size = 0L
if (dir.exists()) {
var size: Long = 0
val files = dir.listFiles()
for (i in files.indices) {
if (files[i].isDirectory) {
@ -93,8 +94,7 @@ class PropertiesDialog() {
size += files[i].length()
}
}
}
return size
}
return 0
}
}

View File

@ -9,121 +9,4 @@
android:paddingRight="@dimen/smtfp_activity_margin"
android:paddingTop="@dimen/smtfp_activity_margin">
<TextView
android:id="@+id/properties_name_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/name"
android:textSize="@dimen/smtfp_details_text_size"/>
<TextView
android:id="@+id/properties_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/properties_path_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/path"
android:textSize="@dimen/smtfp_details_text_size"/>
<TextView
android:id="@+id/properties_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/properties_size_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/size"
android:textSize="@dimen/smtfp_details_text_size"/>
<TextView
android:id="@+id/properties_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/properties_last_modified_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/last_modified"
android:textSize="@dimen/smtfp_details_text_size"/>
<TextView
android:id="@+id/properties_last_modified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"/>
<TextView
android:id="@+id/properties_files_count_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/files_count"
android:textSize="@dimen/smtfp_details_text_size"
android:visibility="gone"/>
<TextView
android:id="@+id/properties_files_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"
android:visibility="gone"/>
<TextView
android:id="@+id/properties_resolution_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/resolution"
android:textSize="@dimen/smtfp_details_text_size"
android:visibility="gone"/>
<TextView
android:id="@+id/properties_resolution"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"
android:visibility="gone"/>
<TextView
android:id="@+id/properties_duration_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:text="@string/duration"
android:textSize="@dimen/smtfp_details_text_size"
android:visibility="gone"/>
<TextView
android:id="@+id/properties_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"
android:textColor="@android:color/black"
android:visibility="gone"/>
</LinearLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/property_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smtfp_activity_margin"
android:textSize="@dimen/smtfp_details_text_size"/>
<TextView
android:id="@+id/property_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/smtfp_small_margin"
android:paddingRight="@dimen/smtfp_small_margin"/>
</LinearLayout>