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);
App.getGa().reportInitially(preferences);
Locator.getInstance().init(calculator, engine, keyboard);
Locator.getInstance().init(engine);
calculator.init(initThread);

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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() {

View File

@ -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) {

View File

@ -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<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() {
@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) {