Comments (4)
@curioustechizen I think the right course of action consists of including the following class in the codebase, the presence of which should be sufficient for the binding to work correctly.
However, the version of gradle has to be updated (is that a bad thing...?) from 1.0.0 to at least 1.5.0-alpha1 as mentioned at the top of the Data Binding guide. The latest version of the android-gradle plugin at the time of writing is 2.0.0-beta2. I was trying to do this locally but ran into some difficulties. (Possibly because one can't have data-binding inside a apply plugin: 'com.android.library'
-type module.)
BTW, not only the gradle plugin, but also the build tools and the target sdk should be updated (to API-23).
As per the example class in this link, a class like this should appear in the project:
package com.your.package;
import android.databinding.BindingAdapter;
import android.databinding.BindingMethod;
import android.databinding.BindingMethods;
import com.github.curioustechizen.ago.RelativeTimeTextView;
@BindingMethods({
@BindingMethod(type = RelativeTimeTextView.class, attribute = "rttv:relative_time_prefix", method = "setPrefix"),
@BindingMethod(type = RelativeTimeTextView.class, attribute = "rttv:relative_time_suffix", method = "setSuffix"),
})
public class RelativeTimeTextViewBindingAdapter {
@BindingAdapter("rttv:reference_time")
public static void setReferenceTime(RelativeTimeTextView view, long time) {
view.setReferenceTime(time);
}
}
(Note the custom namespace rttv:
, which is an optional modification that makes sense to include). The XML is then:
<com.github.curioustechizen.ago.RelativeTimeTextView
android:id="@+id/time_n_sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
rttv:relative_time_prefix='@{"by " + message.senderName + ", "}'
rttv:reference_time='@{message.timestamp}'
tools:textColor="@color/gray"
tools:text="by Mike, 30/02/2016 22:22:10"/>
Note to users:
Adding the above anywhere in a project which uses this library should make it work with data-binding.
from android-ago.
The problem as you rightly pointed out is the way the custom attribute and its setter method have been named. The naming is incompatible with data binding.
I am considering deprecating the prefix and suffix attributes in favor of a more general mechanism (like a format specifier with positional parameters). See #15
Hence I don't see myself updating the library to include this functionality. However, if you take the time to implement it (simply adding a setRelativeTimePrefix
method that just calls setPrefix
) then I would be glad to accept pull requests.
For your question about the date format - see #19
from android-ago.
A complete example of RelativeTimeTextView
with data-binding can be found here:
Dev-iL@37ab447
from android-ago.
@Dev-iL This is very helpful. Thanks!
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.