From 0b4318f05f518ae72eb1a60f35105556741408a0 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 1 Mar 2016 12:11:57 +0100 Subject: [PATCH] Fix cached title for non-system languages --- .../android/calculator/BaseActivity.java | 18 +++++++++++++----- .../android/calculator/CalculatorActivity.java | 2 +- .../calculator/about/AboutActivity.java | 5 +++++ .../functions/FunctionsActivity.java | 4 ++++ .../calculator/history/HistoryActivity.java | 11 ++++++++++- .../matrix/CalculatorMatrixActivity.java | 7 ++++++- .../operators/OperatorsActivity.java | 4 ++++ .../android/calculator/plot/PlotActivity.java | 8 +++++--- .../preferences/PreferencesActivity.java | 2 +- .../variables/VariablesActivity.java | 4 ++++ .../calculator/wizard/WizardActivity.java | 2 +- 11 files changed, 54 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java index cb5c6a3a..3a40aaed 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -8,6 +8,7 @@ import android.graphics.Typeface; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.LayoutRes; +import android.support.annotation.StringRes; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -40,6 +41,7 @@ public class BaseActivity extends AppCompatActivity { @Nonnull protected final Tabs tabs; private final int layoutId; + private final int titleId; @Inject SharedPreferences preferences; @Inject @@ -69,12 +71,13 @@ public class BaseActivity extends AppCompatActivity { @Nonnull private Language language = Languages.SYSTEM_LANGUAGE; - public BaseActivity() { - this(R.layout.activity_tabs); + public BaseActivity(@StringRes int titleId) { + this(R.layout.activity_tabs, titleId); } - public BaseActivity(@LayoutRes int layout) { - this.layoutId = layout; + public BaseActivity(@LayoutRes int layoutId, @StringRes int titleId) { + this.layoutId = layoutId; + this.titleId = titleId; this.tabs = new Tabs(this); } @@ -139,6 +142,11 @@ public class BaseActivity extends AppCompatActivity { private void createView() { 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); fixFonts(mainView); @@ -177,7 +185,7 @@ public class BaseActivity extends AppCompatActivity { setTheme(theme.getThemeFor(this)); layout = Preferences.Gui.getLayout(preferences); - language = App.getLanguages().getCurrent(); + language = languages.getCurrent(); } protected void populateTabs(@Nonnull Tabs tabs) { diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index ae408e9d..d28956ae 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -82,7 +82,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference private boolean useBackAsPrevious; public CalculatorActivity() { - super(R.layout.activity_main); + super(R.layout.activity_main, R.string.c_app_name); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java index a3f3223f..5bd6a65e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java @@ -28,12 +28,17 @@ import android.support.annotation.NonNull; import org.solovyev.android.calculator.App; 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 javax.annotation.Nonnull; public class AboutActivity extends BaseActivity { + public AboutActivity() { + super(R.string.cpp_about); + } + public static class Dialog extends AboutActivity { } diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java index 172677d6..82ec8d2d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java @@ -40,6 +40,10 @@ public class FunctionsActivity extends BaseActivity { public static final String EXTRA_FUNCTION = "function"; + public FunctionsActivity() { + super(R.string.c_functions); + } + @Nonnull public static Class getClass(@NonNull Context context) { return App.isTablet(context) ? Dialog.class : FunctionsActivity.class; diff --git a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java index 9ece0b23..62953c93 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java @@ -29,7 +29,12 @@ import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; 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 javax.annotation.Nonnull; @@ -39,6 +44,10 @@ import static org.solovyev.android.calculator.FragmentTab.saved_history; public class HistoryActivity extends BaseActivity { + public HistoryActivity() { + super(R.string.c_history); + } + public static class Dialog extends HistoryActivity { } diff --git a/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java b/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java index e0eb8a72..60447160 100644 --- a/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java @@ -22,15 +22,20 @@ package org.solovyev.android.calculator.matrix; -import android.os.Bundle; 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 javax.annotation.Nonnull; public class CalculatorMatrixActivity extends BaseActivity { + public CalculatorMatrixActivity() { + super(R.string.c_plot_graph); + // FIXME: 2016-03-01 string + } + @Override protected void populateTabs(@Nonnull Tabs tabs) { super.populateTabs(tabs); diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java index dc36487e..0664d5e0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java @@ -35,6 +35,10 @@ import javax.annotation.Nonnull; public class OperatorsActivity extends BaseActivity { + public OperatorsActivity() { + super(R.string.c_operators); + } + public static class Dialog extends OperatorsActivity { } diff --git a/app/src/main/java/org/solovyev/android/calculator/plot/PlotActivity.java b/app/src/main/java/org/solovyev/android/calculator/plot/PlotActivity.java index 0f26d3a1..ff7f6fdc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/plot/PlotActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/plot/PlotActivity.java @@ -7,8 +7,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import butterknife.Bind; -import butterknife.ButterKnife; + import org.solovyev.android.calculator.AppComponent; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseFragment; @@ -20,6 +19,9 @@ import org.solovyev.android.plotter.Plotter; import javax.annotation.Nonnull; import javax.inject.Inject; +import butterknife.Bind; +import butterknife.ButterKnife; + public class PlotActivity extends BaseActivity { public static class MyFragment extends BaseFragment implements PlotViewFrame.Listener { @@ -90,7 +92,7 @@ public class PlotActivity extends BaseActivity { } public PlotActivity() { - super(R.layout.activity_empty); + super(R.layout.activity_empty, R.string.c_plot); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java index e4c13835..bb66b057 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java @@ -58,7 +58,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc Languages languages; public PreferencesActivity() { - super(R.layout.activity_empty); + super(R.layout.activity_empty, R.string.cpp_settings); } @Nonnull diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java index 4671e227..6567f20c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java @@ -40,6 +40,10 @@ public class VariablesActivity extends BaseActivity { public static final String EXTRA_VARIABLE = "variable"; + public VariablesActivity() { + super(R.string.c_vars_and_constants); + } + @Nonnull public static Class getClass(@NonNull Context context) { return App.isTablet(context) ? Dialog.class : VariablesActivity.class; diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java b/app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java index 79c3bc1b..cc40ee7c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java @@ -49,7 +49,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared Languages languages; public WizardActivity() { - super(R.layout.cpp_activity_wizard); + super(R.layout.cpp_activity_wizard, 0); } @Override