Refactor variables

This commit is contained in:
serso 2016-01-29 21:33:26 +01:00
parent f13c6dd493
commit e82d7d2a91
4 changed files with 25 additions and 46 deletions

View File

@ -23,9 +23,9 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import jscl.JsclMathEngine;
import jscl.math.function.IConstant;
import org.simpleframework.xml.Serializer; import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import org.solovyev.android.Check; 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.json.Jsonable;
import org.solovyev.android.calculator.variables.CppVariable; import org.solovyev.android.calculator.variables.CppVariable;
import org.solovyev.android.calculator.variables.OldVars; 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.android.io.FileSaver;
import org.solovyev.common.JBuilder; import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity; 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.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.File;
import jscl.JsclMathEngine; import java.util.HashMap;
import jscl.math.function.IConstant; import java.util.List;
import java.util.Map;
@Singleton @Singleton
public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> { public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
@ -162,6 +158,6 @@ public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
@Override @Override
public Category getCategory(@Nonnull IConstant variable) { public Category getCategory(@Nonnull IConstant variable) {
return Entities.getCategory(variable, VariablesCategory.values()); return Entities.getCategory(variable, VariableCategory.values());
} }
} }

View File

@ -23,15 +23,13 @@
package org.solovyev.android.calculator.variables; package org.solovyev.android.calculator.variables;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import jscl.math.function.IConstant;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.entities.Category;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import jscl.math.function.IConstant; public enum VariableCategory implements Category<IConstant> {
public enum VariablesCategory implements Category<IConstant> {
my(R.string.c_var_my) { my(R.string.c_var_my) {
@Override @Override
@ -50,7 +48,7 @@ public enum VariablesCategory implements Category<IConstant> {
@StringRes @StringRes
private final int title; private final int title;
VariablesCategory(@StringRes int title) { VariableCategory(@StringRes int title) {
this.title = title; this.title = title;
} }

View File

@ -22,22 +22,17 @@
package org.solovyev.android.calculator.variables; package org.solovyev.android.calculator.variables;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.*;
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 javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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 VariablesActivity() { public VariablesActivity() {
super(R.layout.main_empty, VariablesActivity.class.getSimpleName()); 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) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(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(); for (VariableCategory category : VariableCategory.values()) {
if (intent != null) { final Bundle arguments = new Bundle(2);
bundle = intent.getExtras(); if (category == VariableCategory.my && variable != null) {
} else { arguments.putParcelable(VariablesFragment.ARG_VARIABLE, variable);
bundle = null;
} }
arguments.putString(VariablesFragment.ARG_CATEGORY, category.name());
final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables; ui.addTab(this, CalculatorFragmentType.variables.createSubFragmentTag(category.name()), CalculatorFragmentType.variables.getFragmentClass(), arguments, category.title(), R.id.main_layout);
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());
}
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.title(), R.id.main_layout);
} }
} }

View File

@ -48,6 +48,7 @@ import java.util.List;
public class VariablesFragment extends BaseEntitiesFragment<IConstant> implements CalculatorEventListener { public class VariablesFragment extends BaseEntitiesFragment<IConstant> implements CalculatorEventListener {
public static final String ARG_VARIABLE = "variable";
public static final String CREATE_VAR_EXTRA_STRING = "create_var"; public static final String CREATE_VAR_EXTRA_STRING = "create_var";
@Inject @Inject
VariablesRegistry registry; VariablesRegistry registry;
@ -76,6 +77,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// FIXME: 2016-01-29 continue
final Bundle bundle = getArguments(); final Bundle bundle = getArguments();
if (bundle != null) { if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);