blitz
blitz is a very lightweight Android library that allows you to set a self-updating string with relative time in TextView in just one line of code.
DOESN'T require using custom TextView
.
It will not overheadly update your TextView
: e.g. if your relative time is 5 minutes ago
then blitz will send update only after one minute, not every second. The same with others time units: hours updates once an hour, etc.
Don't be scared to use it in your ViewHolder
s, 'cause blitz won't let anything leak and will take care of the system resources.
Briefly usage:
val myTextView: TextView = ...
val eventTime: Long = ...
// just one line of code and that is it!
myTextView.setTimeAgo(eventTime)
Languages support:
- English
- Russian
There's not your language? You can help the community by sending a Pull Request.
Installation:
Step 1
Add repository to your gradle.build
file (project)
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2
Add dependency to your gradle.build
file (app) or other module
dependencies {
implemetation 'com.github.perfomer:blitz:LATEST_VERSION'
}
See the lastest release version here: .
Usage
TextView
If you want to set the self-updating string with relative time direct into the TextView
then use extesnsion method:
myTextView.setTimeAgo(eventTime)
You can also customize it a bit:
myTextView.setTimeAgo(
// Can be Long or java.util.Date
time = eventTime,
// If [true]: Show the exact seconds count if time difference is less than minute
// Or if [false]: Show "just now" message in that case.
showSeconds = true,
// Don't want auto-update? Just set it to false.
autoUpdate = false
)
If you don't want to get time updates more than use cancel method:
myTextView.cancelTimeAgoUpdates()
String
If you just want to get a time-relative string, then you can use the following extension methods:
val contextString: String = context.getTimeAgo(time = eventTime, showSeconds = false)
val resourcesString: String = resources.getTimeAgo(time = eventTime, showSeconds = false)
Communication
- If you found a bug, please open an Issue.
- If you have a feature request, please open an Issue.
- If you want to contribute, please submit a Pull request.