/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


package org.mozilla.focus.locale;

import android.content.res.Configuration;
import android.support.v4.app.Fragment;

import java.util.Locale;

public abstract class LocaleAwareFragment extends Fragment {
    private Locale cachedLocale = null;

    /**
     * Is called whenever the application locale has changed. Your fragment must either update
     * all localised Strings, or replace itself with an updated version.
     */
    public abstract void applyLocale();

    @Override
    public void onResume() {
        super.onResume();

        if (cachedLocale == null) {
            cachedLocale = Locale.getDefault();
        } else {
            Locale newLocale = LocaleManager.getInstance().getCurrentLocale(getActivity().getApplicationContext());

            if (newLocale == null) {
                // Using system locale:
                newLocale = Locale.getDefault();
            }
            if (!newLocale.equals(cachedLocale)) {
                cachedLocale = newLocale;
                applyLocale();
            }
        }
    }
}

@@ -239,50 +239,8 @@
 e;%0A%0A
-import android.content.res.Configuration;%0A
 impo
@@ -693,24 +693,166 @@
 .onResume();
+%0A        %0A        LocaleManager.getInstance()%0A                .correctLocale(getContext(), getResources(), getResources().getConfiguration());
 %0A%0A        if

Correct locale if LocaleAwareFragment is resumed. (#707)