android-ago icon indicating copy to clipboard operation
android-ago copied to clipboard

Modify time update interval

Open ryandt opened this issue 7 years ago • 1 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 avatar Aug 02 '18 14:08 ryandt

@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.

curioustechizen avatar Aug 05 '18 10:08 curioustechizen