How to change Time text to custome one?
YuvPrime opened this issue · comments
I want to change the Time's text to something like 5s, 5m instead of 5 seconds ago and 5 minutes ago.
I don't know where to change to custom text.
The reason i want to minimize is, it takes too much space when designing custom row layout.
Thanks,
@YuvPrime With the current implementation this might be impossible. The library uses [getRelativeTimeSpanString
](https://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeTimeSpanString%28long, long, long, int%29) from DateUtils class in the Android SDK. It already passes the flag FORMAT_ABBREV_RELATIVE
so relative times are already abbreviated. For example, instead of 5 minutes ago it displays 5 mins ago. Beyond this, the entire String is returned by the DateUtils class and android-ago simply sets this text on the TextView. Here is the code from RelativeTimeTextView.java
:
private CharSequence getRelativeTimeDisplayString() {
long now = System.currentTimeMillis();
long difference = now - mReferenceTime;
return (difference >= 0 && difference<=DateUtils.MINUTE_IN_MILLIS) ?
getResources().getString(R.string.just_now):
DateUtils.getRelativeTimeSpanString(
mReferenceTime,
now,
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
}
My suggestion to you is to look at the DateUtils class - it has a very large number of options and flags - one of those might allow you to further customize the time text. You can then fork android-ago and call the appropriate method of DateUtils here.
However do note that DateUtils is locale-sensitive. The time string it returns changes based on locale settings. If you customize it you might lose the customizations in other languages.
I will keep this issue open and explore if it makes sense to expose the various flags of DateUtils class as custom attributes on RTTV. Any suggestions on this are welcome!