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;
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<IConstant> {
@ -162,6 +158,6 @@ public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
@Override
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;
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<IConstant> {
public enum VariableCategory implements Category<IConstant> {
my(R.string.c_var_my) {
@Override
@ -50,7 +48,7 @@ public enum VariablesCategory implements Category<IConstant> {
@StringRes
private final int title;
VariablesCategory(@StringRes int title) {
VariableCategory(@StringRes int title) {
this.title = title;
}

View File

@ -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);
}
}

View File

@ -48,6 +48,7 @@ import java.util.List;
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";
@Inject
VariablesRegistry registry;
@ -76,6 +77,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> 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);