add the camera model fetcher at string extensions too

This commit is contained in:
tibbi 2017-10-18 20:39:29 +02:00
parent ebd9bb5585
commit e6dfe99cd8
2 changed files with 20 additions and 13 deletions

View file

@ -126,21 +126,20 @@ class PropertiesDialog() {
private fun addExifProperties(path: String) {
val exif = ExifInterface(path)
val dateTaken = path.getFileExifDateTaken()
val dateTaken = path.getExifDateTaken(exif)
if (dateTaken.isNotEmpty()) {
addProperty(R.string.date_taken, dateTaken)
}
exif.getAttribute(ExifInterface.TAG_MAKE).let {
if (it?.isNotEmpty() == true) {
val model = exif.getAttribute(ExifInterface.TAG_MODEL)
addProperty(R.string.camera, "$it $model")
}
val cameraModel = path.getExifCameraModel(exif)
if (cameraModel.isNotEmpty()) {
addProperty(R.string.camera, cameraModel)
}
val exifString = path.getFileExifProperties()
if (exifString.isNotEmpty())
addProperty(R.string.exif, exifString.trim())
val exifString = path.getExifProperties(exif)
if (exifString.isNotEmpty()) {
addProperty(R.string.exif, exifString)
}
}
private fun isSameParent(files: List<File>): Boolean {

View file

@ -45,8 +45,7 @@ fun String.isAudioFast() = audioExtensions.any { endsWith(it, true) }
fun String.areDigitsOnly() = matches(Regex("[0-9]+"))
fun String.getFileExifProperties(): String {
val exif = ExifInterface(this)
fun String.getExifProperties(exif: ExifInterface): String {
var exifString = ""
exif.getAttribute(ExifInterface.TAG_F_NUMBER).let {
if (it?.isNotEmpty() == true) {
@ -79,8 +78,7 @@ fun String.getFileExifProperties(): String {
return exifString.trim()
}
fun String.getFileExifDateTaken(): String {
val exif = ExifInterface(this)
fun String.getExifDateTaken(exif: ExifInterface): String {
exif.getAttribute(ExifInterface.TAG_DATETIME).let {
if (it?.isNotEmpty() == true) {
try {
@ -93,6 +91,16 @@ fun String.getFileExifDateTaken(): String {
return ""
}
fun String.getExifCameraModel(exif: ExifInterface): String {
exif.getAttribute(ExifInterface.TAG_MAKE).let {
if (it?.isNotEmpty() == true) {
val model = exif.getAttribute(ExifInterface.TAG_MODEL)
return "$it $model".trim()
}
}
return ""
}
fun String.getMimeTypeFromPath(): String {
val typesMap = HashMap<String, String>().apply {
put("323", "text/h323")