Remove Locator methods

This commit is contained in:
serso 2016-02-28 13:24:02 +01:00
parent 6b4d1118e0
commit d761ef553e
7 changed files with 14 additions and 34 deletions

View File

@ -137,7 +137,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
languages.updateContextLocale(this, true); languages.updateContextLocale(this, true);
App.getGa().reportInitially(preferences); App.getGa().reportInitially(preferences);
Locator.getInstance().init(calculator, engine, keyboard); Locator.getInstance().init(engine);
calculator.init(initThread); calculator.init(initThread);

View File

@ -26,12 +26,7 @@ import javax.annotation.Nonnull;
public interface CalculatorLocator { public interface CalculatorLocator {
void init(@Nonnull Calculator calculator, void init(@Nonnull Engine engine);
@Nonnull Engine engine,
@Nonnull Keyboard keyboard);
@Nonnull
Calculator getCalculator();
@Nonnull @Nonnull
Engine getEngine(); Engine getEngine();

View File

@ -30,8 +30,6 @@ public class Locator implements CalculatorLocator {
private static final Locator instance = new Locator(); private static final Locator instance = new Locator();
@Nonnull @Nonnull
private Engine engine; private Engine engine;
@Nonnull
private Calculator calculator;
public Locator() { public Locator() {
} }
@ -42,11 +40,8 @@ public class Locator implements CalculatorLocator {
} }
@Override @Override
public void init(@Nonnull Calculator calculator, public void init(@Nonnull Engine engine) {
@Nonnull Engine engine,
@Nonnull Keyboard keyboard) {
this.calculator = calculator;
this.engine = engine; this.engine = engine;
} }
@ -56,10 +51,4 @@ public class Locator implements CalculatorLocator {
return engine; return engine;
} }
@Nonnull
@Override
public Calculator getCalculator() {
return this.calculator;
}
} }

View File

@ -72,7 +72,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
Check.isTrue(IMAGE_SCALE == 0.6f); Check.isTrue(IMAGE_SCALE == 0.6f);
// backspace button is too big, scale it more // backspace button is too big, scale it more
prepareButton(eraseButton, IMAGE_SCALE_ERASE); prepareButton(eraseButton, IMAGE_SCALE_ERASE);
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress()); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator);
} }
if (isSimpleLayout()) { if (isSimpleLayout()) {
hideText(clearButton, left, up, down); hideText(clearButton, left, up, down);

View File

@ -10,20 +10,22 @@ import static android.text.TextUtils.isEmpty;
public class EditorLongClickEraser extends BaseLongClickEraser { public class EditorLongClickEraser extends BaseLongClickEraser {
@Nonnull @Nonnull
private final Editor editor = App.getEditor(); private final Editor editor;
@Nonnull @Nonnull
private final Calculator calculator = Locator.getInstance().getCalculator(); private final Calculator calculator;
private boolean wasCalculatingOnFly; 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); super(view, vibrateOnKeypress);
this.editor = editor;
this.calculator = calculator;
} }
@Nonnull @Nonnull
public static EditorLongClickEraser attachTo(@Nonnull View view, boolean vibrateOnKeypress) { public static EditorLongClickEraser attachTo(@Nonnull View view, boolean vibrateOnKeypress, @Nonnull Editor editor, @Nonnull Calculator calculator) {
return new EditorLongClickEraser(view, vibrateOnKeypress); return new EditorLongClickEraser(view, vibrateOnKeypress, editor, calculator);
} }
protected boolean erase() { protected boolean erase() {

View File

@ -22,9 +22,6 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.SharedPreferences;
import com.squareup.otto.Bus;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -37,7 +34,7 @@ import static org.mockito.Mockito.mock;
public class AbstractCalculatorTest { public class AbstractCalculatorTest {
protected void setUp() throws Exception { 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() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {

View File

@ -25,9 +25,6 @@ package org.solovyev.android.calculator;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import com.squareup.otto.Bus;
import org.junit.Assert; import org.junit.Assert;
import org.robolectric.fakes.RoboSharedPreferences; import org.robolectric.fakes.RoboSharedPreferences;
@ -67,7 +64,7 @@ public class CalculatorTestUtils {
public static void staticSetUp() throws Exception { public static void staticSetUp() throws Exception {
App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0))); App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "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() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {
@ -82,7 +79,7 @@ public class CalculatorTestUtils {
} }
public static void staticSetUp(@Nullable Context context) throws Exception { 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() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {