move the Last modified date and time formatting to an extension
This commit is contained in:
parent
7571ffc124
commit
5cbc13885a
|
@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.dialogs
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.text.format.DateFormat
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.simplemobiletools.filemanager.Config
|
import com.simplemobiletools.filemanager.Config
|
||||||
|
@ -12,7 +11,6 @@ import com.simplemobiletools.filemanager.extensions.*
|
||||||
import kotlinx.android.synthetic.main.item_properties.view.*
|
import kotlinx.android.synthetic.main.item_properties.view.*
|
||||||
import kotlinx.android.synthetic.main.property_item.view.*
|
import kotlinx.android.synthetic.main.property_item.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class PropertiesDialog() {
|
class PropertiesDialog() {
|
||||||
lateinit var mContext: Context
|
lateinit var mContext: Context
|
||||||
|
@ -36,7 +34,7 @@ class PropertiesDialog() {
|
||||||
addProperty(R.string.name, file.name)
|
addProperty(R.string.name, file.name)
|
||||||
addProperty(R.string.path, file.parent)
|
addProperty(R.string.path, file.parent)
|
||||||
addProperty(R.string.size, getItemSize(file))
|
addProperty(R.string.size, getItemSize(file))
|
||||||
addProperty(R.string.last_modified, formatLastModified(file.lastModified()))
|
addProperty(R.string.last_modified, file.lastModified().formatLastModified())
|
||||||
|
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
addProperty(R.string.files_count, mFilesCnt.toString())
|
addProperty(R.string.files_count, mFilesCnt.toString())
|
||||||
|
@ -73,12 +71,6 @@ class PropertiesDialog() {
|
||||||
return file.length().formatSize()
|
return file.length().formatSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatLastModified(ts: Long): String {
|
|
||||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
|
||||||
cal.timeInMillis = ts
|
|
||||||
return DateFormat.format("dd.MM.yyyy HH:mm", cal).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDirectorySize(dir: File): Long {
|
private fun getDirectorySize(dir: File): Long {
|
||||||
var size = 0L
|
var size = 0L
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.simplemobiletools.filemanager.extensions
|
package com.simplemobiletools.filemanager.extensions
|
||||||
|
|
||||||
|
import android.text.format.DateFormat
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun Long.formatSize(): String {
|
fun Long.formatSize(): String {
|
||||||
if (this <= 0)
|
if (this <= 0)
|
||||||
|
@ -10,3 +12,9 @@ fun Long.formatSize(): String {
|
||||||
val digitGroups = (Math.log10(toDouble()) / Math.log10(1024.0)).toInt()
|
val digitGroups = (Math.log10(toDouble()) / Math.log10(1024.0)).toInt()
|
||||||
return DecimalFormat("#,##0.#").format(this / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
|
return DecimalFormat("#,##0.#").format(this / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Long.formatLastModified(): String {
|
||||||
|
val cal = Calendar.getInstance(Locale.ENGLISH)
|
||||||
|
cal.timeInMillis = this
|
||||||
|
return DateFormat.format("dd.MM.yyyy HH:mm", cal).toString()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue