From d761ef553e76c0ec81a5805c1e8b997cd785eced Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 28 Feb 2016 13:24:02 +0100 Subject: [PATCH] Remove Locator methods --- .../android/calculator/CalculatorApplication.java | 2 +- .../android/calculator/CalculatorLocator.java | 7 +------ .../org/solovyev/android/calculator/Locator.java | 13 +------------ .../calculator/keyboard/PartialKeyboardUi.java | 2 +- .../calculator/view/EditorLongClickEraser.java | 12 +++++++----- .../android/calculator/AbstractCalculatorTest.java | 5 +---- .../android/calculator/CalculatorTestUtils.java | 7 ++----- 7 files changed, 14 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 7a9c09ce..8c52cea4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -137,7 +137,7 @@ public class CalculatorApplication extends android.app.Application implements Sh languages.updateContextLocale(this, true); App.getGa().reportInitially(preferences); - Locator.getInstance().init(calculator, engine, keyboard); + Locator.getInstance().init(engine); calculator.init(initThread); diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java index 4e0c196f..f85e6ee9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java @@ -26,12 +26,7 @@ import javax.annotation.Nonnull; public interface CalculatorLocator { - void init(@Nonnull Calculator calculator, - @Nonnull Engine engine, - @Nonnull Keyboard keyboard); - - @Nonnull - Calculator getCalculator(); + void init(@Nonnull Engine engine); @Nonnull Engine getEngine(); diff --git a/app/src/main/java/org/solovyev/android/calculator/Locator.java b/app/src/main/java/org/solovyev/android/calculator/Locator.java index 6ac87982..0e25edd4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Locator.java +++ b/app/src/main/java/org/solovyev/android/calculator/Locator.java @@ -30,8 +30,6 @@ public class Locator implements CalculatorLocator { private static final Locator instance = new Locator(); @Nonnull private Engine engine; - @Nonnull - private Calculator calculator; public Locator() { } @@ -42,11 +40,8 @@ public class Locator implements CalculatorLocator { } @Override - public void init(@Nonnull Calculator calculator, - @Nonnull Engine engine, - @Nonnull Keyboard keyboard) { + public void init(@Nonnull Engine engine) { - this.calculator = calculator; this.engine = engine; } @@ -56,10 +51,4 @@ public class Locator implements CalculatorLocator { return engine; } - @Nonnull - @Override - public Calculator getCalculator() { - return this.calculator; - } - } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java index 90690310..cef3250b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java @@ -72,7 +72,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi { Check.isTrue(IMAGE_SCALE == 0.6f); // backspace button is too big, scale it more prepareButton(eraseButton, IMAGE_SCALE_ERASE); - longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress()); + longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); } if (isSimpleLayout()) { hideText(clearButton, left, up, down); diff --git a/app/src/main/java/org/solovyev/android/calculator/view/EditorLongClickEraser.java b/app/src/main/java/org/solovyev/android/calculator/view/EditorLongClickEraser.java index 3da45939..44652b08 100644 --- a/app/src/main/java/org/solovyev/android/calculator/view/EditorLongClickEraser.java +++ b/app/src/main/java/org/solovyev/android/calculator/view/EditorLongClickEraser.java @@ -10,20 +10,22 @@ import static android.text.TextUtils.isEmpty; public class EditorLongClickEraser extends BaseLongClickEraser { @Nonnull - private final Editor editor = App.getEditor(); + private final Editor editor; @Nonnull - private final Calculator calculator = Locator.getInstance().getCalculator(); + private final Calculator calculator; private boolean wasCalculatingOnFly; - private EditorLongClickEraser(@Nonnull View view, boolean vibrateOnKeypress) { + private EditorLongClickEraser(@Nonnull View view, boolean vibrateOnKeypress, @Nonnull Editor editor, @Nonnull Calculator calculator) { super(view, vibrateOnKeypress); + this.editor = editor; + this.calculator = calculator; } @Nonnull - public static EditorLongClickEraser attachTo(@Nonnull View view, boolean vibrateOnKeypress) { - return new EditorLongClickEraser(view, vibrateOnKeypress); + public static EditorLongClickEraser attachTo(@Nonnull View view, boolean vibrateOnKeypress, @Nonnull Editor editor, @Nonnull Calculator calculator) { + return new EditorLongClickEraser(view, vibrateOnKeypress, editor, calculator); } protected boolean erase() { diff --git a/app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java b/app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java index 43ebd09a..49af66ad 100644 --- a/app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java @@ -22,9 +22,6 @@ package org.solovyev.android.calculator; -import android.content.SharedPreferences; -import com.squareup.otto.Bus; - import java.util.concurrent.Executor; import static org.mockito.Mockito.mock; @@ -37,7 +34,7 @@ import static org.mockito.Mockito.mock; public class AbstractCalculatorTest { protected void setUp() throws Exception { - Locator.getInstance().init(new Calculator(mock(SharedPreferences.class), mock(Bus.class), mock(Executor.class), mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), mock(Keyboard.class)); + Locator.getInstance().init(CalculatorTestUtils.newCalculatorEngine()); Locator.getInstance().getEngine().init(new Executor() { @Override public void execute(Runnable command) { diff --git a/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index ad99c36d..c676d420 100644 --- a/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -25,9 +25,6 @@ package org.solovyev.android.calculator; import static org.mockito.Mockito.mock; import android.content.Context; -import android.content.SharedPreferences; - -import com.squareup.otto.Bus; import org.junit.Assert; import org.robolectric.fakes.RoboSharedPreferences; @@ -67,7 +64,7 @@ public class CalculatorTestUtils { public static void staticSetUp() throws Exception { App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap>(), "test", 0))); - Locator.getInstance().init(new Calculator(mock(SharedPreferences.class), mock(Bus.class), mock(Executor.class), mock(Executor.class)), newCalculatorEngine(), mock(Keyboard.class)); + Locator.getInstance().init(newCalculatorEngine()); Locator.getInstance().getEngine().init(new Executor() { @Override public void execute(Runnable command) { @@ -82,7 +79,7 @@ public class CalculatorTestUtils { } public static void staticSetUp(@Nullable Context context) throws Exception { - Locator.getInstance().init(new Calculator(mock(SharedPreferences.class), mock(Bus.class), mock(Executor.class), mock(Executor.class)), newCalculatorEngine(), mock(Keyboard.class)); + Locator.getInstance().init(newCalculatorEngine()); Locator.getInstance().getEngine().init(new Executor() { @Override public void execute(Runnable command) {