From c324c1408e0c1b1a6819d8a3153e82de064d5910 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 28 Feb 2016 13:28:17 +0100 Subject: [PATCH] Inject WidgetProvider --- .../android/calculator/AppComponent.java | 2 ++ .../calculator/widget/CalculatorWidget.java | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index 2e0724bc..070e7f13 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -21,6 +21,7 @@ import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.variables.EditVariableFragment; import org.solovyev.android.calculator.variables.VariablesFragment; import org.solovyev.android.calculator.view.Tabs; +import org.solovyev.android.calculator.widget.CalculatorWidget; import org.solovyev.android.calculator.wizard.DragButtonWizardStep; import dagger.Component; @@ -61,4 +62,5 @@ public interface AppComponent { void inject(PlotDimensionsFragment fragment); void inject(HistoryActivity activity); void inject(Tabs tabs); + void inject(CalculatorWidget widget); } diff --git a/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java b/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java index aacbc566..655cbbb0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java +++ b/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java @@ -48,11 +48,13 @@ import org.solovyev.android.calculator.buttons.CppButton; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.inject.Inject; import java.util.EnumMap; import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT; import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.os.Build.VERSION_CODES.JELLY_BEAN; +import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.Broadcaster.*; import static org.solovyev.android.calculator.WidgetReceiver.newButtonClickedIntent; @@ -64,6 +66,12 @@ public class CalculatorWidget extends AppWidgetProvider { private static final Intents intents = new Intents(); @Nullable private static SpannedString cursorString; + @Inject + Editor editor; + @Inject + Display display; + @Inject + Engine engine; public CalculatorWidget() { } @@ -109,8 +117,8 @@ public class CalculatorWidget extends AppWidgetProvider { @Nonnull AppWidgetManager manager, @Nonnull int[] widgetIds, boolean partially) { - final EditorState editorState = App.getEditor().getState(); - final DisplayState displayState = App.getDisplay().getState(); + final EditorState editorState = editor.getState(); + final DisplayState displayState = display.getState(); final Resources resources = context.getResources(); final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme()); @@ -136,7 +144,7 @@ public class CalculatorWidget extends AppWidgetProvider { updateEditorState(context, views, editorState, theme); updateDisplayState(context, views, displayState, theme); - views.setTextViewText(R.id.cpp_button_multiplication, Locator.getInstance().getEngine().getMultiplicationSign()); + views.setTextViewText(R.id.cpp_button_multiplication, engine.getMultiplicationSign()); if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { manager.partiallyUpdateAppWidget(widgetId, views); @@ -186,6 +194,8 @@ public class CalculatorWidget extends AppWidgetProvider { @Override public void onReceive(@Nonnull Context context, @Nonnull Intent intent) { + cast(context).getComponent().inject(this); + super.onReceive(context, intent); final String action = intent.getAction();