Comments (7)
@nayana123 I'm not sure what you mean. Could you provide an example? RelativeTimeTextView
is after all a TextView
so you could just call setText()
on it but that defeats the purpose.
from android-ago.
Yaah sure, in my case i want to display time as "Today", "Yesterday","Days ago".
so when setReferenceTime(long) is setTexted to RelativeTimeTextView in case of "2mins ago" or "1 hour ago" i want manually setText as "Today".
from android-ago.
i tried by calling setText("Today") but it does't sets the text
from android-ago.
@nayana123 Ah I see the problem now.
Unfortunately, your use case is not supported by the library currently. Once you call setReferenceTime()
, the library automatically calls setText()
internally at some intervals.
I will consider providing a way to override the reference time and force callers to set the text instead, however don't expect this to happen anytime soon.
In the meantime, I suggest you look into the source code of RelativeTimeTextView
and customize it for your needs. It is only one file and there's not much logic in there any way.
In particular, look at these lines. I haven't actually tried this, but you should be able to do something like
return (difference >= 0 && difference<=DateUtils.DAY_IN_MILLIS) ?
getResources().getString(R.string.today): //Define "today" in your strings.xml
DateUtils.getRelativeTimeSpanString(
mReferenceTime,
now,
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
from android-ago.
@nayana123 Having said that, if you do not need the display string to be updated in the resolution of minutes, i.e., if you are only going to show differences in days, I strongly suggest you not to use this library at all. Just use a regular TextView
along with the DateUtils
class as follows:
myTextView.setText(
DateUtils.getRelativeTimeSpanString(
mReferenceTime,
System.currentTimeInMillis(),
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE));
The android-ago library is useful if you have to keep refreshing the time even while the user is viewing your app. Once you set "Today" as the time, it won't change for a long time and the user will almost definitely NOT be looking at your time till it changes
from android-ago.
OK - I have a very general use case that I need to setText for the RelativeTimeTextView for. For example, when I refresh the view, I want the RelativeTimeTextView to say "Updating" but since I cannot setText on the RelativeTimeTextView, I could not change the TextView to reflect this. I had to create another textView on top of the RelativeTimeTextView and toggle the visibility of that textview and the RelativeTimeTextView when refreshing.
I think it would be a good enhance to make to your library if one can setText on the RelativeTimeTextView.
from android-ago.
@Winghin2517 That is a valid use case. Thanks for pointing it out.
Do note that you can simply use setText
on an RTTV. If you use both setReferenceTime
and setText
, the last one wins. So, if you want to set the text to "Updating", simply using rttv.setText("Updating");
should be enough.
If you have a different use case that prevents you from using this, please let me know so I can investigate how we can accommodate it.
from android-ago.
Related Issues (20)
- Time ago calculation HOT 13
- Strings in Portuguese
- in 0 mins HOT 14
- Now LATEST_VERSION is what ? HOT 2
- Lack of consistent capitalization (English) HOT 3
- A String Completed added prior to time HOT 3
- Once the `UpdateTimeRunnable` is detached and the `weakRefRttv` cleared, it is never attached again HOT 4
- Add automated tests HOT 4
- Change lang of "hours ago" ... HOT 1
- Locale HOT 1
- Time is one hour behind on old Galaxy Tab 3 using Android 4.4.2 HOT 3
- add font family option HOT 6
- this work fine in recyclerviews? HOT 1
- Removing the "ago" word HOT 6
- Save timeago when close the app HOT 1
- Add a `getReferenceTime()` method
- Modify time update interval HOT 1
- Text format has extra charcters in it HOT 2
- Enhancement - short suffix HOT 1
- In new update, issue with Just Now
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-ago.