CalculatorHistory -> History
This commit is contained in:
parent
6d91013858
commit
5813f41f4c
@ -25,12 +25,14 @@ package org.solovyev.android.calculator;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ACRAConfiguration;
|
||||
import org.acra.sender.HttpSender;
|
||||
import org.solovyev.android.Android;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.language.Language;
|
||||
import org.solovyev.android.calculator.language.Languages;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
@ -40,11 +42,12 @@ import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
|
||||
import org.solovyev.android.calculator.view.EditorTextProcessor;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@Nonnull
|
||||
private final List<CalculatorEventListener> listeners = new ArrayList<>();
|
||||
@ -74,7 +77,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
new AndroidCalculatorEngine(this),
|
||||
new AndroidCalculatorClipboard(this),
|
||||
new AndroidCalculatorNotifier(this),
|
||||
new CalculatorHistory(),
|
||||
new History(),
|
||||
new AndroidCalculatorLogger(),
|
||||
new AndroidCalculatorPreferenceService(this),
|
||||
new CalculatorKeyboard(),
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.text.TextProcessorEditorResult;
|
||||
@ -41,7 +41,7 @@ public interface CalculatorLocator {
|
||||
@Nonnull CalculatorEngine engine,
|
||||
@Nonnull CalculatorClipboard clipboard,
|
||||
@Nonnull CalculatorNotifier notifier,
|
||||
@Nonnull CalculatorHistory history,
|
||||
@Nonnull History history,
|
||||
@Nonnull CalculatorLogger logger,
|
||||
@Nonnull CalculatorPreferenceService preferenceService,
|
||||
@Nonnull CalculatorKeyboard keyboard,
|
||||
@ -70,7 +70,7 @@ public interface CalculatorLocator {
|
||||
CalculatorNotifier getNotifier();
|
||||
|
||||
@Nonnull
|
||||
CalculatorHistory getHistory();
|
||||
History getHistory();
|
||||
|
||||
@Nonnull
|
||||
CalculatorLogger getLogger();
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.text.TextProcessorEditorResult;
|
||||
@ -50,7 +50,7 @@ public class Locator implements CalculatorLocator {
|
||||
@Nonnull
|
||||
private CalculatorKeyboard calculatorKeyboard;
|
||||
@Nonnull
|
||||
private CalculatorHistory calculatorHistory;
|
||||
private History history;
|
||||
@Nonnull
|
||||
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
|
||||
@Nonnull
|
||||
@ -76,7 +76,7 @@ public class Locator implements CalculatorLocator {
|
||||
@Nonnull CalculatorEngine engine,
|
||||
@Nonnull CalculatorClipboard clipboard,
|
||||
@Nonnull CalculatorNotifier notifier,
|
||||
@Nonnull CalculatorHistory history,
|
||||
@Nonnull History history,
|
||||
@Nonnull CalculatorLogger logger,
|
||||
@Nonnull CalculatorPreferenceService preferenceService,
|
||||
@Nonnull CalculatorKeyboard keyboard,
|
||||
@ -87,7 +87,7 @@ public class Locator implements CalculatorLocator {
|
||||
this.calculatorEngine = engine;
|
||||
this.calculatorClipboard = clipboard;
|
||||
this.calculatorNotifier = notifier;
|
||||
this.calculatorHistory = history;
|
||||
this.history = history;
|
||||
this.calculatorLogger = logger;
|
||||
this.calculatorPreferenceService = preferenceService;
|
||||
this.calculatorPlotter = plotter;
|
||||
@ -145,8 +145,8 @@ public class Locator implements CalculatorLocator {
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CalculatorHistory getHistory() {
|
||||
return calculatorHistory;
|
||||
public History getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +51,7 @@ import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CalculatorHistory {
|
||||
public class History {
|
||||
|
||||
public static final String TAG = App.subTag("History");
|
||||
@Nonnull
|
||||
@ -62,7 +62,7 @@ public class CalculatorHistory {
|
||||
private EditorState lastEditorState;
|
||||
private boolean initialized;
|
||||
|
||||
public CalculatorHistory() {
|
||||
public History() {
|
||||
App.getBus().register(this);
|
||||
App.getInitThread().execute(new Runnable() {
|
||||
@Override
|
@ -121,7 +121,7 @@ public class HistoryList {
|
||||
try {
|
||||
array.put(i, state.toJson());
|
||||
} catch (JSONException e) {
|
||||
Log.e(CalculatorHistory.TAG, e.getMessage(), e);
|
||||
Log.e(History.TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
@ -138,7 +138,7 @@ public class HistoryList {
|
||||
try {
|
||||
states.add(HistoryState.create(json));
|
||||
} catch (JSONException e) {
|
||||
Log.e(CalculatorHistory.TAG, e.getMessage(), e);
|
||||
Log.e(History.TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return states;
|
||||
|
@ -23,7 +23,7 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
public class AbstractCalculatorTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Locator.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ import android.content.Context;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
@ -56,7 +56,7 @@ public class CalculatorTestUtils {
|
||||
public static final int TIMEOUT = 3;
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().getEngine().init();
|
||||
|
||||
final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
|
||||
@ -66,7 +66,7 @@ public class CalculatorTestUtils {
|
||||
}
|
||||
|
||||
public static void staticSetUp(@Nullable Context context) throws Exception {
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().getEngine().init();
|
||||
|
||||
if (context != null) {
|
||||
|
@ -38,7 +38,7 @@ import javax.annotation.Nonnull;
|
||||
* Date: 10.10.12
|
||||
* Time: 15:07
|
||||
*/
|
||||
public class CalculatorHistoryTest {
|
||||
public class HistoryTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@ -47,29 +47,29 @@ public class CalculatorHistoryTest {
|
||||
|
||||
@Test
|
||||
public void testGetStates() throws Exception {
|
||||
CalculatorHistory calculatorHistory = new CalculatorHistory();
|
||||
History history = new History();
|
||||
|
||||
addState(calculatorHistory, "1");
|
||||
addState(calculatorHistory, "12");
|
||||
addState(calculatorHistory, "123");
|
||||
addState(calculatorHistory, "123+");
|
||||
addState(calculatorHistory, "123+3");
|
||||
addState(calculatorHistory, "");
|
||||
addState(calculatorHistory, "2");
|
||||
addState(calculatorHistory, "23");
|
||||
addState(calculatorHistory, "235");
|
||||
addState(calculatorHistory, "2355");
|
||||
addState(calculatorHistory, "235");
|
||||
addState(calculatorHistory, "2354");
|
||||
addState(calculatorHistory, "23547");
|
||||
addState(history, "1");
|
||||
addState(history, "12");
|
||||
addState(history, "123");
|
||||
addState(history, "123+");
|
||||
addState(history, "123+3");
|
||||
addState(history, "");
|
||||
addState(history, "2");
|
||||
addState(history, "23");
|
||||
addState(history, "235");
|
||||
addState(history, "2355");
|
||||
addState(history, "235");
|
||||
addState(history, "2354");
|
||||
addState(history, "23547");
|
||||
|
||||
final List<HistoryState> states = calculatorHistory.getCurrent();
|
||||
final List<HistoryState> states = history.getCurrent();
|
||||
Assert.assertEquals(2, states.size());
|
||||
Assert.assertEquals("23547", states.get(1).editor.getTextString());
|
||||
Assert.assertEquals("123+3", states.get(0).editor.getTextString());
|
||||
}
|
||||
|
||||
private void addState(@Nonnull CalculatorHistory calculatorHistory, @Nonnull String text) {
|
||||
calculatorHistory.addCurrent(HistoryState.newBuilder(EditorState.create(text, 3), DisplayState.empty()));
|
||||
private void addState(@Nonnull History history, @Nonnull String text) {
|
||||
history.addCurrent(HistoryState.newBuilder(EditorState.create(text, 3), DisplayState.empty()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user