Ans fix
This commit is contained in:
parent
f31d033caf
commit
3fbce93445
@ -444,7 +444,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
|||||||
varBuilder.setValue(result);
|
varBuilder.setValue(result);
|
||||||
varBuilder.setDescription(CalculatorMessages.getBundle().getString("ans_description"));
|
varBuilder.setDescription(CalculatorMessages.getBundle().getString("ans_description"));
|
||||||
|
|
||||||
varsRegistry.add(varBuilder);
|
CalculatorVarsRegistry.saveVariable(varsRegistry, varBuilder, ansVar, this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,12 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||||
import org.solovyev.android.calculator.model.Var;
|
import org.solovyev.android.calculator.model.Var;
|
||||||
import org.solovyev.android.calculator.model.Vars;
|
import org.solovyev.android.calculator.model.Vars;
|
||||||
import org.solovyev.common.JBuilder;
|
import org.solovyev.common.JBuilder;
|
||||||
|
import org.solovyev.common.math.MathEntity;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -41,6 +44,23 @@ public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<ICons
|
|||||||
super(mathRegistry, "c_var_description_", mathEntityDao);
|
super(mathRegistry, "c_var_description_", mathEntityDao);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends MathEntity> void saveVariable(@NotNull CalculatorMathRegistry<T> registry,
|
||||||
|
@NotNull MathEntityBuilder<? extends T> builder,
|
||||||
|
@Nullable T editedInstance,
|
||||||
|
@NotNull Object source, boolean save) {
|
||||||
|
final T addedVar = registry.add(builder);
|
||||||
|
|
||||||
|
if (save) {
|
||||||
|
registry.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editedInstance == null) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
|
||||||
|
} else {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getSubstitutes() {
|
protected Map<String, String> getSubstitutes() {
|
||||||
|
@ -14,7 +14,10 @@ import jscl.text.ParseException;
|
|||||||
import jscl.text.Parser;
|
import jscl.text.Parser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
|
import org.solovyev.android.calculator.CalculatorMathRegistry;
|
||||||
|
import org.solovyev.android.calculator.CalculatorVarsRegistry;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
@ -116,14 +119,7 @@ class VarEditorSaver<T extends MathEntity> implements View.OnClickListener {
|
|||||||
if (error != null) {
|
if (error != null) {
|
||||||
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(error, MessageType.error);
|
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(error, MessageType.error);
|
||||||
} else {
|
} else {
|
||||||
final T addedVar = mathRegistry.add(varBuilder);
|
CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
|
||||||
mathRegistry.save();
|
|
||||||
|
|
||||||
if (editedInstance == null) {
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
|
|
||||||
} else {
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user