Closed adanecito closed 1 year ago
I guess this means you are not using the appCompat library?
Correct. I did create a BaseActivity class that extends AppCompatActivity but I could not use it since I needed the FragmentActivity class. My Activity class is the starting point of my Application and in there I open dialogs from my toolbar. I use FragmentManager for those Dialogs which are extended DialogFragments.
This is not supported out of the box, as Reword uses my ViewPump library, which uses appCompat to intercept view inflation. My recommendation would be to overwrite `getBaseContext(...)' directly, and emulate what ViewPump does by simply recreating your root view. Using fragments you can do this easily by just repeating the transaction ;)
In the getBaseContext(...)
perform whatever context wrapping is needed for your use case, e.g. Restring.wrapContext(baseContext)
I am doing that already. I overrode getResources() in that Activity class and has only one line of code. return Restring,wrapContext(getBaseContext()).getResources(); The challenge I am seeing is the text in the views I have are not changing to the language I selected. It looks as if the Restring is working even the Locale is updated (for Restring)to in my case to German from English. I call a method in my Activity to get the rootView and then Reword.reword(rootView). Does reword need to have Locale set for it? I tried that but Reword.setLocale() is not found like the Reword API does not support it anymore.
Yeah, as I wrote Reword does not work without appCompat, as ViewPump can't hook into view inflation without it. The Locale can be simply set with Restring.setLocale(...)
though, you don't need Reword for this. The easiest way to reproduce what Reword does in your case is by just recreating the fragment or the activity hosting it. Alternatively you could go recursively through the view hierarchy and update the views with reflection, but I would recommend against it, as such a solution is not very generic.
I am willing to do something with all my dialogs if I need to which was a question I have in the discussion forum. My main Activity is just a container for those. I am trying to avoid a restart or anything like that since that affects my users. I understand avoiding not making my app generic and not working with some variation of Android running on different devices. And thanks for your help it is much appreciated!
I am wondering since my Activity is just a container and my text is all in DialogFragments if I can get away from this challenge and just reword the text in those. I have a toolbar that my activity uses but it has icons for the buttons.
So in the DialogFragments just add Reword.reword(rootView) in the createView?
No, at the moment Reword does not do anything without appCompat and ViewPump. So you would need to integrate both of these libraries. One option would be to modify ViewPump so it can also work without appCompat, but that would take a day of programming for me, for quite a niche case. Feel free to look into it yourself though, I take PRs ;) I really would recommend to just take the appCompat road though, it saves you quite a bit of effort. Is there any hard reason for you against using it?
I can only extend once and it is usually Fragment. For my Activity I have fragmentmanager or supportframentmanager and If I do not use fragmentactivity I do not have access to those. I will look at being creative. I understand about this being a nitch case. Most of the examples I have seen are simple ones so no one I have seen goes beyond that. Anyway I will look into a PR after I have tried my best to get around this issue (for me). Many Thanks!
Ok I went through and got the errors out for using AppCompatActivity. My class that extends that "BaseActivity has getDelegate() and AttachBaseContext() but still no text is updated in the views. So some more work there. I will look some more to see what I might have done wrong. Thanks
The getDelegate() in BaseActivity seems to be not called for some reason. That class is an exact duplicate of what is in the java example here. If I knew why that is then maybe that is the last challenge. :-)
And Restring.init(this) and ViewPump.init(RewordInterceptor.INSTANCE) are called in my Application class in the onCreate() method.
Sounds like you are on the right track ;)
Thanks! Any idea why getDelegate in the BaseActivity class might not get called? Should I worry about that?
It could have many reasons, as I don't know your code, it is hard to tell. If you have a single activity application, it should only get called once. So it is likely okay ;)
Ok. I was wondering if DialogFragments are considered Activities. I do not know if for Reword they are. The definition for Activity seems to center on focus on a GUI which has a view. Otherwise, I am only using one that has the name Activity for the class. I have plenty of dialogs with no reference to Reword.
Ok I verified that getDelegate() in BaseActivity is not getting called. I am assuming that it should be and that should occur when I call Reword.reword(rootView) . I did call the getWindow().getDecorView.findViewById(android.R.id.content) but that is not the layout set my contentView in my Activity. I have a layout I call in my onCreate() setContentView(R.layout.main_swipe). So I need to look into that. That is because in examples I have found there was slight differences. In one getWindow().getDecorView.findViewById
Ok, I downloaded a simple example and discovered it worked and that getDelegate in the BaseActivity class is getting called without the MainActivity doing anything. To verify that I commented out all the code in MainActivity and still getDelegate() in BaseActivity was getting called. So please close this issue. Thanks!
You're welcome, happy it works for you :)
I am currently extending my Activity by FragmentActivity. so I get errors if I just add a getDelegate() since FragmentActivity does not have a method for that so I can not override it. Any suggestions?
Thanks!