history changes

This commit is contained in:
serso 2011-10-27 12:01:31 +04:00
parent 6935733c9c
commit 6524eb3928
2 changed files with 9 additions and 6 deletions

View File

@ -2,8 +2,8 @@
<manifest xmlns:a="http://schemas.android.com/apk/res/android" <manifest xmlns:a="http://schemas.android.com/apk/res/android"
package="org.solovyev.android.calculator" package="org.solovyev.android.calculator"
a:versionCode="5" a:versionCode="6"
a:versionName="1.1.3"> a:versionName="1.1.4">
<uses-permission a:name="android.permission.VIBRATE"/> <uses-permission a:name="android.permission.VIBRATE"/>

View File

@ -145,6 +145,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation, @Nullable CalculatorHistoryState historyState) { private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation, @Nullable CalculatorHistoryState historyState) {
final CalculatorHistoryState localHistoryState; final CalculatorHistoryState localHistoryState;
if (historyState == null) { if (historyState == null) {
this.display.setText("");
localHistoryState = getCurrentHistoryState(); localHistoryState = getCurrentHistoryState();
} else { } else {
localHistoryState = historyState; localHistoryState = historyState;
@ -160,11 +161,10 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
// actually nothing shall be logged while text operations are done // actually nothing shall be logged while text operations are done
evaluate(expression, operation, this); evaluate(expression, operation, this);
localHistoryState.setDisplayState(getCurrentHistoryState().getDisplayState());
if (pendingOperation.getObject() == this) { if (pendingOperation.getObject() == this) {
// todo serso: of course there is small probability that someone will set pendingOperation after if statement but before .setObject(null) // todo serso: of course there is small probability that someone will set pendingOperation after if statement but before .setObject(null)
pendingOperation.setObject(null); pendingOperation.setObject(null);
localHistoryState.setDisplayState(getCurrentHistoryState().getDisplayState());
} }
} }
} }
@ -204,10 +204,10 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression); final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
if (currentRunner == pendingOperation.getObject()) { if (currentRunner == pendingOperation.getObject()) {
display.setText(result.getResult()); display.setText(result.getResult());
display.setJsclOperation(result.getUserOperation());
} else { } else {
display.setText(""); display.setText("");
} }
display.setJsclOperation(result.getUserOperation());
} catch (EvalError e) { } catch (EvalError e) {
handleEvaluationException(expression, display, operation, e); handleEvaluationException(expression, display, operation, e);
} catch (ParseException e) { } catch (ParseException e) {
@ -215,8 +215,11 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
} }
} else { } else {
this.display.setText(""); this.display.setText("");
this.display.setJsclOperation(operation);
} }
this.display.redraw(); this.display.redraw();
} }
@ -300,7 +303,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
final String expression = this.editor.getText().toString(); final String expression = this.editor.getText().toString();
if ( !StringUtils.isEmpty(expression) ) { if ( !StringUtils.isEmpty(expression) ) {
if ( StringUtils.isEmpty(this.display.getText().toString()) ) { if ( StringUtils.isEmpty(this.display.getText().toString()) ) {
evaluate(false, expression, JsclOperation.numeric, editorHistoryState); evaluate(false, expression, this.display.getJsclOperation(), editorHistoryState);
} }
} }