Make PropertiesDialog reusable for stuff other than files
This commit is contained in:
parent
571e8e3ef2
commit
7b890eae3e
2 changed files with 71 additions and 51 deletions
|
@ -0,0 +1,68 @@
|
|||
package com.simplemobiletools.commons.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import kotlinx.android.synthetic.main.dialog_properties.view.*
|
||||
import kotlinx.android.synthetic.main.item_property.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
abstract class BasePropertiesDialog(activity: Activity) {
|
||||
protected val mInflater: LayoutInflater
|
||||
protected val mPropertyView: ViewGroup
|
||||
protected val mResources: Resources
|
||||
protected val mActivity: Activity = activity
|
||||
protected val mDialogView: View
|
||||
|
||||
init {
|
||||
mInflater = LayoutInflater.from(activity)
|
||||
mResources = activity.resources
|
||||
mDialogView = mInflater.inflate(R.layout.dialog_properties, null)
|
||||
mPropertyView = mDialogView.properties_holder!!
|
||||
}
|
||||
|
||||
protected fun addProperty(labelId: Int, value: String?, viewId: Int = 0) {
|
||||
if (value == null) {
|
||||
return
|
||||
}
|
||||
|
||||
mInflater.inflate(R.layout.item_property, mPropertyView, false).apply {
|
||||
property_value.setTextColor(mActivity.getProperTextColor())
|
||||
property_label.setTextColor(mActivity.getProperTextColor())
|
||||
|
||||
property_label.text = mResources.getString(labelId)
|
||||
property_value.text = value
|
||||
mPropertyView.properties_holder.addView(this)
|
||||
|
||||
setOnLongClickListener {
|
||||
mActivity.copyToClipboard(property_value.value)
|
||||
true
|
||||
}
|
||||
|
||||
if (labelId == R.string.gps_coordinates) {
|
||||
setOnClickListener {
|
||||
mActivity.showLocationOnMap(value)
|
||||
}
|
||||
}
|
||||
|
||||
if (viewId != 0) {
|
||||
id = viewId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
package com.simplemobiletools.commons.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
@ -22,12 +19,7 @@ import kotlinx.android.synthetic.main.item_property.view.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class PropertiesDialog() {
|
||||
private lateinit var mInflater: LayoutInflater
|
||||
private lateinit var mPropertyView: ViewGroup
|
||||
private lateinit var mResources: Resources
|
||||
private lateinit var mActivity: Activity
|
||||
private lateinit var mDialogView: View
|
||||
class PropertiesDialog : BasePropertiesDialog {
|
||||
private var mCountHiddenItems = false
|
||||
|
||||
/**
|
||||
|
@ -37,18 +29,13 @@ class PropertiesDialog() {
|
|||
* @param path the file path
|
||||
* @param countHiddenItems toggle determining if we will count hidden files themselves and their sizes (reasonable only at directory properties)
|
||||
*/
|
||||
constructor(activity: Activity, path: String, countHiddenItems: Boolean = false) : this() {
|
||||
constructor(activity: Activity, path: String, countHiddenItems: Boolean = false) : super(activity) {
|
||||
if (!activity.getDoesFilePathExist(path) && !path.startsWith("content://")) {
|
||||
activity.toast(String.format(activity.getString(R.string.source_file_doesnt_exist), path))
|
||||
return
|
||||
}
|
||||
|
||||
mActivity = activity
|
||||
mInflater = LayoutInflater.from(activity)
|
||||
mResources = activity.resources
|
||||
mDialogView = mInflater.inflate(R.layout.dialog_properties, null)
|
||||
mCountHiddenItems = countHiddenItems
|
||||
mPropertyView = mDialogView.properties_holder!!
|
||||
addProperties(path)
|
||||
|
||||
val builder = activity.getAlertDialogBuilder()
|
||||
|
@ -215,13 +202,8 @@ class PropertiesDialog() {
|
|||
* @param path the file path
|
||||
* @param countHiddenItems toggle determining if we will count hidden files themselves and their sizes
|
||||
*/
|
||||
constructor(activity: Activity, paths: List<String>, countHiddenItems: Boolean = false) : this() {
|
||||
mActivity = activity
|
||||
mInflater = LayoutInflater.from(activity)
|
||||
mResources = activity.resources
|
||||
mDialogView = mInflater.inflate(R.layout.dialog_properties, null)
|
||||
constructor(activity: Activity, paths: List<String>, countHiddenItems: Boolean = false) : super(activity) {
|
||||
mCountHiddenItems = countHiddenItems
|
||||
mPropertyView = mDialogView.properties_holder
|
||||
|
||||
val fileDirItems = ArrayList<FileDirItem>(paths.size)
|
||||
paths.forEach {
|
||||
|
@ -340,34 +322,4 @@ class PropertiesDialog() {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun addProperty(labelId: Int, value: String?, viewId: Int = 0) {
|
||||
if (value == null) {
|
||||
return
|
||||
}
|
||||
|
||||
mInflater.inflate(R.layout.item_property, mPropertyView, false).apply {
|
||||
property_value.setTextColor(mActivity.getProperTextColor())
|
||||
property_label.setTextColor(mActivity.getProperTextColor())
|
||||
|
||||
property_label.text = mResources.getString(labelId)
|
||||
property_value.text = value
|
||||
mPropertyView.properties_holder.addView(this)
|
||||
|
||||
setOnLongClickListener {
|
||||
mActivity.copyToClipboard(property_value.value)
|
||||
true
|
||||
}
|
||||
|
||||
if (labelId == R.string.gps_coordinates) {
|
||||
setOnClickListener {
|
||||
mActivity.showLocationOnMap(value)
|
||||
}
|
||||
}
|
||||
|
||||
if (viewId != 0) {
|
||||
id = viewId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue