curioustechizen / android-ago

An Android TextView that always displays an auto refreshing relative time span with respect to a reference time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modify time update interval

ryandt opened this issue · comments

I'm wanting to show ETAs that will commonly be less than 60 minutes but may occasionally be up to 120 minutes. In the case that the ETA is 60 minutes or less, the ETA text of my RelativeTextView updates every minute. In the case where an ETA is greater than 60 minutes, the ETA text updates every hour. However, I need the ETA to update every minute regardless of the difference between now and the reference time.

Current interval logic:

if (difference > DateUtils.WEEK_IN_MILLIS) {
   interval = DateUtils.WEEK_IN_MILLIS;
} else if (difference > DateUtils.DAY_IN_MILLIS) {
   interval = DateUtils.DAY_IN_MILLIS;
} else if (difference > DateUtils.HOUR_IN_MILLIS) {
   interval = DateUtils.HOUR_IN_MILLIS;
}

I think it would be helpful to add the ability to modify the time update interval. This could be achieved in a couple ways.
A) Add a public setter to set and override the time interval.
B) Allow subclasses to override the method that determines the interval.

I prefer option B as it provides more flexibility to the client.

@curioustechizen What are your thoughts on adding the ability to modify the time update interval?

@ryandt For now, you can override the getRelativeTimeDisplayString() method and there use your own logic to determine the update interval.

However, I'm not happy about the flexibility (or lack of it) in this library. The default algorithm to calculate the update interval does not fit all use cases.

I'm open to suggestions about an elegant way to expose the update interval as an API.