From e82d7d2a9110e7a40aa9f6a1e4c4a6823af73af0 Mon Sep 17 00:00:00 2001 From: serso Date: Fri, 29 Jan 2016 21:33:26 +0100 Subject: [PATCH] Refactor variables --- .../android/calculator/VariablesRegistry.java | 20 ++++----- ...lesCategory.java => VariableCategory.java} | 8 ++-- .../variables/VariablesActivity.java | 41 ++++++------------- .../variables/VariablesFragment.java | 2 + 4 files changed, 25 insertions(+), 46 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/variables/{VariablesCategory.java => VariableCategory.java} (93%) diff --git a/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java b/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java index 9e097681..6885de0c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java +++ b/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java @@ -23,9 +23,9 @@ package org.solovyev.android.calculator; import android.support.annotation.NonNull; - import com.google.common.base.Strings; - +import jscl.JsclMathEngine; +import jscl.math.function.IConstant; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; import org.solovyev.android.Check; @@ -36,23 +36,19 @@ import org.solovyev.android.calculator.json.Json; import org.solovyev.android.calculator.json.Jsonable; import org.solovyev.android.calculator.variables.CppVariable; import org.solovyev.android.calculator.variables.OldVars; -import org.solovyev.android.calculator.variables.VariablesCategory; +import org.solovyev.android.calculator.variables.VariableCategory; import org.solovyev.android.io.FileSaver; import org.solovyev.common.JBuilder; import org.solovyev.common.math.MathEntity; -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; - -import jscl.JsclMathEngine; -import jscl.math.function.IConstant; +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Singleton public class VariablesRegistry extends BaseEntitiesRegistry { @@ -162,6 +158,6 @@ public class VariablesRegistry extends BaseEntitiesRegistry { @Override public Category getCategory(@Nonnull IConstant variable) { - return Entities.getCategory(variable, VariablesCategory.values()); + return Entities.getCategory(variable, VariableCategory.values()); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesCategory.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariableCategory.java similarity index 93% rename from app/src/main/java/org/solovyev/android/calculator/variables/VariablesCategory.java rename to app/src/main/java/org/solovyev/android/calculator/variables/VariableCategory.java index c12d0e0c..e40a1097 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesCategory.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariableCategory.java @@ -23,15 +23,13 @@ package org.solovyev.android.calculator.variables; import android.support.annotation.StringRes; - +import jscl.math.function.IConstant; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.entities.Category; import javax.annotation.Nonnull; -import jscl.math.function.IConstant; - -public enum VariablesCategory implements Category { +public enum VariableCategory implements Category { my(R.string.c_var_my) { @Override @@ -50,7 +48,7 @@ public enum VariablesCategory implements Category { @StringRes private final int title; - VariablesCategory(@StringRes int title) { + VariableCategory(@StringRes int title) { this.title = title; } 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 efdfca94..00ac8006 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 @@ -22,22 +22,17 @@ package org.solovyev.android.calculator.variables; -import android.content.Intent; import android.os.Bundle; - -import org.solovyev.android.calculator.BaseActivity; -import org.solovyev.android.calculator.CalculatorEventData; -import org.solovyev.android.calculator.CalculatorEventListener; -import org.solovyev.android.calculator.CalculatorEventType; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.math.edit.BaseEntitiesFragment; +import android.os.Parcelable; +import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class VariablesActivity extends BaseActivity implements CalculatorEventListener { + public static final String EXTRA_VARIABLE = "variable"; + public VariablesActivity() { super(R.layout.main_empty, VariablesActivity.class.getSimpleName()); } @@ -46,28 +41,16 @@ public class VariablesActivity extends BaseActivity implements CalculatorEventLi public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - final Bundle bundle; + final Bundle extras = getIntent().getExtras(); + final Parcelable variable = extras != null ? extras.getParcelable(EXTRA_VARIABLE) : null; - final Intent intent = getIntent(); - if (intent != null) { - bundle = intent.getExtras(); - } else { - bundle = null; - } - - final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables; - - for (VariablesCategory category : VariablesCategory.values()) { - - final Bundle fragmentParameters; - - if (category == VariablesCategory.my && bundle != null) { - BaseEntitiesFragment.putCategory(bundle, category.name()); - fragmentParameters = bundle; - } else { - fragmentParameters = BaseEntitiesFragment.createBundleFor(category.name()); + for (VariableCategory category : VariableCategory.values()) { + final Bundle arguments = new Bundle(2); + if (category == VariableCategory.my && variable != null) { + arguments.putParcelable(VariablesFragment.ARG_VARIABLE, variable); } - ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.title(), R.id.main_layout); + 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); } } 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 63c00455..b79330a6 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 @@ -48,6 +48,7 @@ import java.util.List; public class VariablesFragment extends BaseEntitiesFragment implements CalculatorEventListener { + public static final String ARG_VARIABLE = "variable"; public static final String CREATE_VAR_EXTRA_STRING = "create_var"; @Inject VariablesRegistry registry; @@ -76,6 +77,7 @@ public class VariablesFragment extends BaseEntitiesFragment implement public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // FIXME: 2016-01-29 continue final Bundle bundle = getArguments(); if (bundle != null) { final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);