B3nedikt / reword

Reword is a android library to update the texts of views when the apps texts have changed due to a language change or an update of the apps string resources.
Apache License 2.0
32 stars 7 forks source link

Unable to update TabItem view strings #19

Closed ashu5398 closed 3 years ago

ashu5398 commented 3 years ago

Hi, There is no transformer for TabItem in the library and I am unable to make a view transformer for TabItem view as there is no setText method in it. Can you suggest me anyway of doing that?

B3nedikt commented 3 years ago

TabItem is not a real view, but a dummy view which only exists in XMLs and will be replaced by a TabView when it gets added to the TabLayout. Therefore it does not need a setText method.

So the general solution looks like this:

The main issues here are

While there are multiple ways to do this, I think the cleanest way would be to have separate Transformers for TabItem/TabLayout/TabView and share the attributes using tags, to stay consistent with the rest of the lib. However the only way to do this would be to replace the TabLayout with a custom one which sets the tag and updates the text when the addChild(...) methods in the TabLayout get called. This would be a API change though, as the ViewTransformer.transform method cannot replace views at the moment, it just modifies them.

It think there are simpler but less generic and clean ways to do this, by sharing attributes using a global variable or just don't set the TabItems in XML but use TabViews from code directly if you need a quick fix. I am working on a clean solution in Reword 4 for the end of this week though :)

ashu5398 commented 3 years ago

Even if I will follow the approach of having multiple transformers, sharing the attributes using global variables. How can I connect a TabLayout and a TabItem as there may me multiple TabLayout(s) in multiple XMLs. Also this doesn't seem like a clean solution to me or may be I didn't get the solution exactly. I am good to make change in API and transform function if you can guide me on this, or if you are planning an update to the library yourself that will help to fix this problem, that will be coolest! Let me know if I can be of any help too. :)

B3nedikt commented 3 years ago

Yeah, the quickfix is even worse the more I think about it, I just implemented a clean version similar to what I described above but without needing any incompatible API change, so I just released it as a new minor release 3.1.0 just now. The API for the ViewTransformers is not ideal though, I might make small changes to it in Reword 4. I think most people don't use custom ViewTransformers, so that would be a easy to update major release anyway xD

Feel free to try out the new version, and check if it works for you. If you have some ViewTransformers for common android views which don't exist yet, I am happy for contributions :)

ashu5398 commented 3 years ago

Checked out the update. This is quite clean approach. Thanks for the help :)