Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not change the language in some places #579

Closed
TikTak123 opened this issue Dec 18, 2019 · 6 comments
Closed

Do not change the language in some places #579

TikTak123 opened this issue Dec 18, 2019 · 6 comments

Comments

@TikTak123
Copy link

I use the Lingver library in my project to change the language. But on some phones in some places sometimes the text does not change.

This is how I change the language in my application.

@Override
public void changeLanguage(@NotNull String lang) {
    Lingver.getInstance().setLocale(binding.getRoot().getContext(), lang);
    getActivity().recreate();
}

Here is the code in places where the text does not change

@PerController
public class TabOffersViewModel extends BaseViewModel<TabOffersCallback> {
    @Inject
    TabOffersViewModel() {
    }

    @Override
    protected void init(Bundle args) {
        RouterPagerAdapter pagerAdapter = new RouterPagerAdapter((Controller) mCallback) {
            @Override
            public void configureRouter(@NonNull Router router, int position) {
                if (!router.hasRootController()) {
                    Controller page;
                    switch (position) {
                        case 0:
                            page = new PriceplansController();
                            break;
                        case 1:
                            page = new ServicesController();
                            break;
                        case 2:
                            page = new TabNewsController(TabNewsController.TAB_ACTIONS);
                            break;
                        case 3:
                            page = new TabNewsController(TabNewsController.TAB_NEWS);
                            break;
                        default:
                            page = new PriceplansController();
                            break;

                    }
                    router.setRoot(RouterTransaction.with(page));
                }
            }

            @Override
            public int getCount() {
                return 4;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                switch (position) {
                    case 0:
                        return mContext.getString(R.string.priceplans_title);
                    case 1:
                        return mContext.getString(R.string.services_title);
                    case 2:
                        return mContext.getString(R.string.title_actions);
                    case 3:
                        return mContext.getString(R.string.title_news);
                    default:
                        return mContext.getString(R.string.priceplans_title);
                }
            }
        };

        mCallback.bindPager(pagerAdapter);
    }
}

There is still a code fragment of the layout file. I include this layout to other layouts.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/black"
    android:orientation="horizontal"
    android:padding="@dimen/_12sdp">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/det_alert_text"
        android:textColor="@color/white"
        android:textSize="@dimen/_12ssp" />

    <ImageView
        android:id="@+id/close_notif"
        android:layout_width="@dimen/_16sdp"
        android:layout_height="@dimen/_16sdp"
        android:layout_marginStart="@dimen/_12sdp"
        android:contentDescription="close notification"
        app:srcCompat="@drawable/ic_close_yellow_24dp" />

</LinearLayout>

This is how I pass context

@Module
public class ControllerModule {

    protected final Activity activity;

    public ControllerModule(Activity activity) {
        this.activity = activity;
    }

    @Provides
    @PerController
    public Activity provideActivityContext() {
        return this.activity;
    }
}

This is my question from the Lingver repository
YarikSOffice/lingver#11

@PaulWoitaschek
Copy link
Collaborator

This is a bug in WebView. To workaround you can call the WebView contructor in your applications onCreate once, that should fix the problem.
And it's completely unrealted to conductor.

@PaulWoitaschek
Copy link
Collaborator

Also see YarikSOffice/lingver#13

@vincent-paing
Copy link

Having same issue and it's not WebView, If I update locale on basecontext in app level, then controllers are not respecting that basecontext

@PaulWoitaschek
Copy link
Collaborator

How should controllers respect the basecontext? A controller doesn't do anything special with the base context. Can you post an example?

@vincent-paing
Copy link

I figured it out and it seems to be an issue on some Chinese phone with older version (Android 5 specifically) I moved the locale code to the activity onResume that is hosting the router and it works now

@dimsuz
Copy link
Contributor

dimsuz commented Jun 17, 2020

There's also this bug which breaks runtime language changes when using appcompat-1.1.0 (latest stable version at the time of writing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants