Fix cached title for non-system languages

This commit is contained in:
serso 2016-03-01 12:11:57 +01:00
parent a6bb109514
commit 0b4318f05f
11 changed files with 54 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -40,6 +41,7 @@ public class BaseActivity extends AppCompatActivity {
@Nonnull @Nonnull
protected final Tabs tabs; protected final Tabs tabs;
private final int layoutId; private final int layoutId;
private final int titleId;
@Inject @Inject
SharedPreferences preferences; SharedPreferences preferences;
@Inject @Inject
@ -69,12 +71,13 @@ public class BaseActivity extends AppCompatActivity {
@Nonnull @Nonnull
private Language language = Languages.SYSTEM_LANGUAGE; private Language language = Languages.SYSTEM_LANGUAGE;
public BaseActivity() { public BaseActivity(@StringRes int titleId) {
this(R.layout.activity_tabs); this(R.layout.activity_tabs, titleId);
} }
public BaseActivity(@LayoutRes int layout) { public BaseActivity(@LayoutRes int layoutId, @StringRes int titleId) {
this.layoutId = layout; this.layoutId = layoutId;
this.titleId = titleId;
this.tabs = new Tabs(this); this.tabs = new Tabs(this);
} }
@ -139,6 +142,11 @@ public class BaseActivity extends AppCompatActivity {
private void createView() { private void createView() {
setContentView(layoutId); setContentView(layoutId);
// title must be updated as if a non-system language is used the value from AndroidManifest
// might be cached
if (titleId != 0) {
setTitle(titleId);
}
ButterKnife.bind(this, this); ButterKnife.bind(this, this);
fixFonts(mainView); fixFonts(mainView);
@ -177,7 +185,7 @@ public class BaseActivity extends AppCompatActivity {
setTheme(theme.getThemeFor(this)); setTheme(theme.getThemeFor(this));
layout = Preferences.Gui.getLayout(preferences); layout = Preferences.Gui.getLayout(preferences);
language = App.getLanguages().getCurrent(); language = languages.getCurrent();
} }
protected void populateTabs(@Nonnull Tabs tabs) { protected void populateTabs(@Nonnull Tabs tabs) {

View File

@ -82,7 +82,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
private boolean useBackAsPrevious; private boolean useBackAsPrevious;
public CalculatorActivity() { public CalculatorActivity() {
super(R.layout.activity_main); super(R.layout.activity_main, R.string.c_app_name);
} }
@Override @Override

View File

@ -28,12 +28,17 @@ import android.support.annotation.NonNull;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.FragmentTab;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.view.Tabs; import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class AboutActivity extends BaseActivity { public class AboutActivity extends BaseActivity {
public AboutActivity() {
super(R.string.cpp_about);
}
public static class Dialog extends AboutActivity { public static class Dialog extends AboutActivity {
} }

View File

@ -40,6 +40,10 @@ public class FunctionsActivity extends BaseActivity {
public static final String EXTRA_FUNCTION = "function"; public static final String EXTRA_FUNCTION = "function";
public FunctionsActivity() {
super(R.string.c_functions);
}
@Nonnull @Nonnull
public static Class<? extends FunctionsActivity> getClass(@NonNull Context context) { public static Class<? extends FunctionsActivity> getClass(@NonNull Context context) {
return App.isTablet(context) ? Dialog.class : FunctionsActivity.class; return App.isTablet(context) ? Dialog.class : FunctionsActivity.class;

View File

@ -29,7 +29,12 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.FragmentTab;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.view.Tabs; import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -39,6 +44,10 @@ import static org.solovyev.android.calculator.FragmentTab.saved_history;
public class HistoryActivity extends BaseActivity { public class HistoryActivity extends BaseActivity {
public HistoryActivity() {
super(R.string.c_history);
}
public static class Dialog extends HistoryActivity { public static class Dialog extends HistoryActivity {
} }

View File

@ -22,15 +22,20 @@
package org.solovyev.android.calculator.matrix; package org.solovyev.android.calculator.matrix;
import android.os.Bundle;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.FragmentTab;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.view.Tabs; import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class CalculatorMatrixActivity extends BaseActivity { public class CalculatorMatrixActivity extends BaseActivity {
public CalculatorMatrixActivity() {
super(R.string.c_plot_graph);
// FIXME: 2016-03-01 string
}
@Override @Override
protected void populateTabs(@Nonnull Tabs tabs) { protected void populateTabs(@Nonnull Tabs tabs) {
super.populateTabs(tabs); super.populateTabs(tabs);

View File

@ -35,6 +35,10 @@ import javax.annotation.Nonnull;
public class OperatorsActivity extends BaseActivity { public class OperatorsActivity extends BaseActivity {
public OperatorsActivity() {
super(R.string.c_operators);
}
public static class Dialog extends OperatorsActivity { public static class Dialog extends OperatorsActivity {
} }

View File

@ -7,8 +7,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.calculator.AppComponent; import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.BaseFragment; import org.solovyev.android.calculator.BaseFragment;
@ -20,6 +19,9 @@ import org.solovyev.android.plotter.Plotter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
public class PlotActivity extends BaseActivity { public class PlotActivity extends BaseActivity {
public static class MyFragment extends BaseFragment implements PlotViewFrame.Listener { public static class MyFragment extends BaseFragment implements PlotViewFrame.Listener {
@ -90,7 +92,7 @@ public class PlotActivity extends BaseActivity {
} }
public PlotActivity() { public PlotActivity() {
super(R.layout.activity_empty); super(R.layout.activity_empty, R.string.c_plot);
} }
@Override @Override

View File

@ -58,7 +58,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
Languages languages; Languages languages;
public PreferencesActivity() { public PreferencesActivity() {
super(R.layout.activity_empty); super(R.layout.activity_empty, R.string.cpp_settings);
} }
@Nonnull @Nonnull

View File

@ -40,6 +40,10 @@ public class VariablesActivity extends BaseActivity {
public static final String EXTRA_VARIABLE = "variable"; public static final String EXTRA_VARIABLE = "variable";
public VariablesActivity() {
super(R.string.c_vars_and_constants);
}
@Nonnull @Nonnull
public static Class<? extends VariablesActivity> getClass(@NonNull Context context) { public static Class<? extends VariablesActivity> getClass(@NonNull Context context) {
return App.isTablet(context) ? Dialog.class : VariablesActivity.class; return App.isTablet(context) ? Dialog.class : VariablesActivity.class;

View File

@ -49,7 +49,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
Languages languages; Languages languages;
public WizardActivity() { public WizardActivity() {
super(R.layout.cpp_activity_wizard); super(R.layout.cpp_activity_wizard, 0);
} }
@Override @Override