Git Product home page Git Product logo

Comments (7)

curioustechizen avatar curioustechizen commented on July 16, 2024

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

NayanaRBhoj avatar NayanaRBhoj commented on July 16, 2024

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.

NayanaRBhoj avatar NayanaRBhoj commented on July 16, 2024

i tried by calling setText("Today") but it does't sets the text

from android-ago.

curioustechizen avatar curioustechizen commented on July 16, 2024

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

curioustechizen avatar curioustechizen commented on July 16, 2024

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

Winghin2517 avatar Winghin2517 commented on July 16, 2024

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.

curioustechizen avatar curioustechizen commented on July 16, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.