Home

Awesome

blitz

<img src="https://jitpack.io/v/Perfomer/blitz.svg"> GitHub license

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.

<img src="art/blitz_preview.gif" width="420">

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 ViewHolders, '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:

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 {
   implementation 'com.github.perfomer:blitz:LATEST_VERSION'
}

See the latest release version here: <img src="https://jitpack.io/v/Perfomer/blitz.svg">.

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:

License:

Apache 2.0 LICENSE

Copyright (c) 2020 Denis Balchugov.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.