FunctionsActivity doesn't set pass function to FunctionsFragment now

This commit is contained in:
serso 2016-01-30 11:20:47 +01:00
parent e82d7d2a91
commit b15856e08f

View File

@ -24,16 +24,19 @@ package org.solovyev.android.calculator.functions;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
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;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.edit.FunctionsFragment; import org.solovyev.android.calculator.math.edit.FunctionsFragment;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class FunctionsActivity extends BaseActivity { public class FunctionsActivity extends BaseActivity {
public static final String EXTRA_FUNCTION = "function"; public static final String EXTRA_FUNCTION = "function";
private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.functions;
public FunctionsActivity() { public FunctionsActivity() {
super(R.layout.main_empty, FunctionsActivity.class.getSimpleName()); super(R.layout.main_empty, FunctionsActivity.class.getSimpleName());
@ -43,16 +46,24 @@ public class FunctionsActivity extends BaseActivity {
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
for (FunctionCategory category : FunctionCategory.values()) {
addTab(category);
}
if (savedInstanceState == null) {
final Bundle extras = getIntent().getExtras(); final Bundle extras = getIntent().getExtras();
final Parcelable function = extras != null ? extras.getParcelable(EXTRA_FUNCTION) : null; final Parcelable function = extras != null ? extras.getParcelable(EXTRA_FUNCTION) : null;
if (function instanceof CppFunction) {
EditFunctionFragment.showDialog((CppFunction) function, getSupportFragmentManager());
}
}
}
for (FunctionCategory category : FunctionCategory.values()) { private void addTab(@Nonnull FunctionCategory category) {
final Bundle arguments = new Bundle(2); final Bundle arguments = new Bundle(1);
if (category == FunctionCategory.my && function != null) {
arguments.putParcelable(FunctionsFragment.ARG_FUNCTION, function);
}
arguments.putString(FunctionsFragment.ARG_CATEGORY, category.name()); arguments.putString(FunctionsFragment.ARG_CATEGORY, category.name());
ui.addTab(this, CalculatorFragmentType.functions.createSubFragmentTag(category.name()), CalculatorFragmentType.functions.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);
} }
} }