Variables refactor

This commit is contained in:
serso
2016-01-30 22:27:25 +01:00
parent a52bc5f5e4
commit 51ced42d8e
21 changed files with 310 additions and 664 deletions

View File

@@ -4,7 +4,9 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -14,16 +16,11 @@ import org.solovyev.android.calculator.json.Jsonable;
import org.solovyev.common.JBuilder;
import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
public class CppFunction implements Jsonable, Parcelable {
public static final Json.Creator<CppFunction> JSON_CREATOR = new Json.Creator<CppFunction>() {
@@ -192,6 +189,15 @@ public class CppFunction implements Jsonable, Parcelable {
return builder;
}
@Override
public String toString() {
if (id == NO_ID) {
return name + parameters.toString() + "{" + body + "}";
} else {
return name + "[#" + id + "]" + parameters.toString() + "{" + body + "}";
}
}
public static final class Builder {
@NonNull

View File

@@ -45,8 +45,8 @@ import jscl.math.function.Function;
import org.solovyev.android.Activities;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.entities.EntityRemovalDialog;
import org.solovyev.android.calculator.keyboard.FloatingKeyboardWindow;
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
import org.solovyev.android.calculator.view.EditTextCompat;
import org.solovyev.common.math.MathRegistry;
@@ -185,7 +185,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
}
private void showRemovalDialog(@NonNull final CppFunction function) {
FunctionRemovalDialog.show(getActivity(), function.name, new DialogInterface.OnClickListener() {
EntityRemovalDialog.showForFunction(getActivity(), function.name, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Check.isTrue(which == DialogInterface.BUTTON_POSITIVE);
@@ -292,7 +292,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
private boolean validateName() {
final String name = nameView.getText().toString();
if (!VarEditorSaver.isValidName(name)) {
if (!Engine.isValidName(name)) {
setError(nameLabel, getString(R.string.function_name_is_not_valid));
return false;
}
@@ -344,7 +344,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
final TextInputLayout paramLabel = paramsView.getParamLabel(i);
if (TextUtils.isEmpty(parameter)) {
clearError(paramLabel);
} else if (!VarEditorSaver.isValidName(parameter)) {
} else if (!Engine.isValidName(parameter)) {
valid = false;
setError(paramLabel, getString(R.string.invalid_name));
} else if (usedParameters.contains(parameter)) {

View File

@@ -1,45 +0,0 @@
package org.solovyev.android.calculator.functions;
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
public class FunctionRemovalDialog {
@Nonnull
private final Activity activity;
@Nonnull
private final String functionName;
@Nonnull
private final DialogInterface.OnClickListener listener;
private FunctionRemovalDialog(@Nonnull Activity activity, @Nonnull String functionName, @Nonnull DialogInterface.OnClickListener listener) {
this.activity = activity;
this.functionName = functionName;
this.listener = listener;
}
public static void show(@Nonnull Activity activity, @Nonnull String functionName, @Nonnull DialogInterface.OnClickListener listener) {
new FunctionRemovalDialog(activity, functionName, listener).show();
}
public void show() {
new AlertDialog.Builder(activity, App.getTheme().alertDialogTheme)
.setCancelable(true)
.setTitle(R.string.removal_confirmation)
.setMessage(activity.getString(R.string.function_removal_confirmation_question, functionName))
.setNegativeButton(R.string.c_no, null)
.setPositiveButton(R.string.c_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
dialog.dismiss();
}
})
.create().show();
}
}