This commit is contained in:
serso 2016-01-30 11:24:56 +01:00
parent bb6ac5f144
commit f914704a9c
4 changed files with 24 additions and 22 deletions

View File

@ -42,7 +42,7 @@ import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.functions.FunctionsActivity; import org.solovyev.android.calculator.functions.FunctionsActivity;
import org.solovyev.android.calculator.math.edit.OperatorsActivity; import org.solovyev.android.calculator.math.edit.OperatorsActivity;
import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.variables.VariablesActivity;
import org.solovyev.android.calculator.math.edit.VarEditDialogFragment; import org.solovyev.android.calculator.variables.EditVariableFragment;
import org.solovyev.android.calculator.variables.VariablesFragment; import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
@ -146,7 +146,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
if (!Strings.isEmpty(varValue)) { if (!Strings.isEmpty(varValue)) {
if (VariablesFragment.isValidValue(varValue)) { if (VariablesFragment.isValidValue(varValue)) {
if (context instanceof AppCompatActivity) { if (context instanceof AppCompatActivity) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager()); EditVariableFragment.showDialog(EditVariableFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager());
} else { } else {
final Intent intent = new Intent(context, VariablesActivity.class); final Intent intent = new Intent(context, VariablesActivity.class);
intent.putExtra(VariablesFragment.CREATE_VAR_EXTRA_STRING, varValue); intent.putExtra(VariablesFragment.CREATE_VAR_EXTRA_STRING, varValue);

View File

@ -23,7 +23,6 @@
package org.solovyev.android.calculator.functions; package org.solovyev.android.calculator.functions;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
@ -52,10 +51,8 @@ public class FunctionsActivity extends BaseActivity {
if (savedInstanceState == null) { if (savedInstanceState == null) {
final Bundle extras = getIntent().getExtras(); final Bundle extras = getIntent().getExtras();
final Parcelable function = extras != null ? extras.getParcelable(EXTRA_FUNCTION) : null; final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null;
if (function instanceof CppFunction) { EditFunctionFragment.showDialog(function, getSupportFragmentManager());
EditFunctionFragment.showDialog((CppFunction) function, getSupportFragmentManager());
}
} }
} }

View File

@ -23,7 +23,7 @@
package org.solovyev.android.calculator.variables; package org.solovyev.android.calculator.variables;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.support.v4.app.Fragment;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -32,6 +32,7 @@ import javax.annotation.Nullable;
public class VariablesActivity extends BaseActivity implements CalculatorEventListener { public class VariablesActivity extends BaseActivity implements CalculatorEventListener {
public static final String EXTRA_VARIABLE = "variable"; public static final String EXTRA_VARIABLE = "variable";
private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.variables;
public VariablesActivity() { public VariablesActivity() {
super(R.layout.main_empty, VariablesActivity.class.getSimpleName()); super(R.layout.main_empty, VariablesActivity.class.getSimpleName());
@ -41,17 +42,22 @@ public class VariablesActivity extends BaseActivity implements CalculatorEventLi
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Bundle extras = getIntent().getExtras();
final Parcelable variable = extras != null ? extras.getParcelable(EXTRA_VARIABLE) : null;
for (VariableCategory category : VariableCategory.values()) { for (VariableCategory category : VariableCategory.values()) {
final Bundle arguments = new Bundle(2); addTab(category);
if (category == VariableCategory.my && variable != null) {
arguments.putParcelable(VariablesFragment.ARG_VARIABLE, variable);
} }
if (savedInstanceState == null) {
final Bundle extras = getIntent().getExtras();
final CppVariable variable = extras != null ? (CppVariable) extras.getParcelable(EXTRA_VARIABLE) : null;
}
}
private void addTab(@Nonnull VariableCategory category) {
final Bundle arguments = new Bundle(1);
arguments.putString(VariablesFragment.ARG_CATEGORY, category.name()); arguments.putString(VariablesFragment.ARG_CATEGORY, category.name());
ui.addTab(this, CalculatorFragmentType.variables.createSubFragmentTag(category.name()), CalculatorFragmentType.variables.getFragmentClass(), arguments, category.title(), R.id.main_layout); final String fragmentTag = FRAGMENT_TYPE.createSubFragmentTag(category.name());
} final Class<? extends Fragment> fragmentClass = FRAGMENT_TYPE.getFragmentClass();
ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title(), R.id.main_layout);
} }
@Override @Override

View File

@ -35,7 +35,6 @@ import org.solovyev.android.calculator.entities.Category;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.math.edit.BaseEntitiesFragment; import org.solovyev.android.calculator.math.edit.BaseEntitiesFragment;
import org.solovyev.android.calculator.math.edit.MathEntityRemover; import org.solovyev.android.calculator.math.edit.MathEntityRemover;
import org.solovyev.android.calculator.math.edit.VarEditDialogFragment;
import org.solovyev.common.JPredicate; import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.Collections; import org.solovyev.common.collections.Collections;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
@ -82,7 +81,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
if (bundle != null) { if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
if (!Strings.isEmpty(varValue)) { if (!Strings.isEmpty(varValue)) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), getFragmentManager()); EditVariableFragment.showDialog(EditVariableFragment.Input.newFromValue(varValue), getFragmentManager());
// in order to stop intent for other tabs // in order to stop intent for other tabs
bundle.remove(CREATE_VAR_EXTRA_STRING); bundle.remove(CREATE_VAR_EXTRA_STRING);
@ -107,7 +106,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newInstance(), getFragmentManager()); EditVariableFragment.showDialog(EditVariableFragment.Input.newInstance(), getFragmentManager());
} }
}); });
} }
@ -119,7 +118,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void addVarButtonClickHandler(@Nonnull View v) { public void addVarButtonClickHandler(@Nonnull View v) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager()); EditVariableFragment.showDialog(EditVariableFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager());
} }
@Nonnull @Nonnull
@ -180,7 +179,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant);
return true; return true;
case R.string.c_edit: case R.string.c_edit:
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromConstant(constant), activity.getSupportFragmentManager()); EditVariableFragment.showDialog(EditVariableFragment.Input.newFromConstant(constant), activity.getSupportFragmentManager());
return true; return true;
case R.string.c_remove: case R.string.c_remove:
MathEntityRemover.newConstantRemover(constant, null, activity, activity).showConfirmationDialog(); MathEntityRemover.newConstantRemover(constant, null, activity, activity).showConfirmationDialog();