From f914704a9c229d6a8350e9383c38585a284e9d8f Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 30 Jan 2016 11:24:56 +0100 Subject: [PATCH] Changes --- .../CalculatorActivityLauncher.java | 4 +-- .../functions/FunctionsActivity.java | 7 ++--- .../variables/VariablesActivity.java | 26 ++++++++++++------- .../variables/VariablesFragment.java | 9 +++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index 0a5322b3..dde535d8 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -42,7 +42,7 @@ import org.solovyev.android.calculator.history.CalculatorHistoryActivity; import org.solovyev.android.calculator.functions.FunctionsActivity; import org.solovyev.android.calculator.math.edit.OperatorsActivity; 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.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity; @@ -146,7 +146,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener if (!Strings.isEmpty(varValue)) { if (VariablesFragment.isValidValue(varValue)) { if (context instanceof AppCompatActivity) { - VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager()); + EditVariableFragment.showDialog(EditVariableFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, VariablesActivity.class); intent.putExtra(VariablesFragment.CREATE_VAR_EXTRA_STRING, varValue); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java index ee321c84..4b966d0d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java @@ -23,7 +23,6 @@ package org.solovyev.android.calculator.functions; import android.os.Bundle; -import android.os.Parcelable; import android.support.v4.app.Fragment; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.CalculatorFragmentType; @@ -52,10 +51,8 @@ public class FunctionsActivity extends BaseActivity { if (savedInstanceState == null) { final Bundle extras = getIntent().getExtras(); - final Parcelable function = extras != null ? extras.getParcelable(EXTRA_FUNCTION) : null; - if (function instanceof CppFunction) { - EditFunctionFragment.showDialog((CppFunction) function, getSupportFragmentManager()); - } + final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null; + EditFunctionFragment.showDialog(function, getSupportFragmentManager()); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java index 00ac8006..be5d6dfd 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java @@ -23,7 +23,7 @@ package org.solovyev.android.calculator.variables; import android.os.Bundle; -import android.os.Parcelable; +import android.support.v4.app.Fragment; import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; @@ -32,6 +32,7 @@ import javax.annotation.Nullable; public class VariablesActivity extends BaseActivity implements CalculatorEventListener { public static final String EXTRA_VARIABLE = "variable"; + private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.variables; public VariablesActivity() { 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) { super.onCreate(savedInstanceState); - final Bundle extras = getIntent().getExtras(); - final Parcelable variable = extras != null ? extras.getParcelable(EXTRA_VARIABLE) : null; - for (VariableCategory category : VariableCategory.values()) { - final Bundle arguments = new Bundle(2); - if (category == VariableCategory.my && variable != null) { - arguments.putParcelable(VariablesFragment.ARG_VARIABLE, variable); - } - 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); + addTab(category); } + + 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()); + final String fragmentTag = FRAGMENT_TYPE.createSubFragmentTag(category.name()); + final Class fragmentClass = FRAGMENT_TYPE.getFragmentClass(); + ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title(), R.id.main_layout); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java index b79330a6..165f0799 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java @@ -35,7 +35,6 @@ import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.edit.BaseEntitiesFragment; 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.collections.Collections; import org.solovyev.common.text.Strings; @@ -82,7 +81,7 @@ public class VariablesFragment extends BaseEntitiesFragment implement if (bundle != null) { final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); 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 bundle.remove(CREATE_VAR_EXTRA_STRING); @@ -107,7 +106,7 @@ public class VariablesFragment extends BaseEntitiesFragment implement fab.setOnClickListener(new View.OnClickListener() { @Override 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 implement @SuppressWarnings({"UnusedDeclaration"}) public void addVarButtonClickHandler(@Nonnull View v) { - VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager()); + EditVariableFragment.showDialog(EditVariableFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager()); } @Nonnull @@ -180,7 +179,7 @@ public class VariablesFragment extends BaseEntitiesFragment implement Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant); return true; case R.string.c_edit: - VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromConstant(constant), activity.getSupportFragmentManager()); + EditVariableFragment.showDialog(EditVariableFragment.Input.newFromConstant(constant), activity.getSupportFragmentManager()); return true; case R.string.c_remove: MathEntityRemover.newConstantRemover(constant, null, activity, activity).showConfirmationDialog();