You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
68 lines
1.9 KiB
package net.pokeranalytics.android.util
|
|
|
|
import android.content.res.Resources
|
|
import android.widget.Toast
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
|
|
import java.text.DateFormat
|
|
import java.text.DecimalFormat
|
|
import java.text.SimpleDateFormat
|
|
import java.util.*
|
|
|
|
// Sizes
|
|
val Int.dp: Int
|
|
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
|
|
val Int.px: Int
|
|
get() = (this * Resources.getSystem().displayMetrics.density).toInt()
|
|
val Float.dp: Float
|
|
get() = (this / Resources.getSystem().displayMetrics.density)
|
|
val Float.px: Float
|
|
get() = (this * Resources.getSystem().displayMetrics.density)
|
|
|
|
|
|
// Double
|
|
|
|
fun Double.round(): String {
|
|
val formatter = DecimalFormat("##.##")
|
|
return formatter.format(this)
|
|
}
|
|
|
|
fun Double.toCurrency(): String {
|
|
val formatter = DecimalFormat("##.##")
|
|
return "$ ${formatter.format(this)}"
|
|
}
|
|
|
|
|
|
// Date
|
|
|
|
// Return a short string of the date
|
|
fun Date.short(): String {
|
|
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(this)
|
|
}
|
|
// Return a medium string of the date
|
|
fun Date.medium(): String {
|
|
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this)
|
|
}
|
|
// Return the full string of the date
|
|
fun Date.full(): String {
|
|
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(this)
|
|
}
|
|
// Return the day number of the date
|
|
fun Date.getDayNumber() : String {
|
|
return SimpleDateFormat("dd", Locale.getDefault()).format(this)
|
|
}
|
|
// Return the 3 first letters of the date's day
|
|
fun Date.getShortDayName() : String {
|
|
return SimpleDateFormat("EE", Locale.getDefault()).format(this)
|
|
}
|
|
|
|
|
|
// Toast
|
|
|
|
fun PokerAnalyticsActivity.toast(message: String) {
|
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
|
}
|
|
|
|
fun PokerAnalyticsFragment.toast(message: String) {
|
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
|
} |