From b15856e08fdaaeb63a2e871503c245fdd386d4c8 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 30 Jan 2016 11:20:47 +0100 Subject: [PATCH] FunctionsActivity doesn't set pass function to FunctionsFragment now --- .../functions/FunctionsActivity.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) 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 e0ab2801..ee321c84 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 @@ -24,16 +24,19 @@ 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; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.math.edit.FunctionsFragment; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public class FunctionsActivity extends BaseActivity { public static final String EXTRA_FUNCTION = "function"; + private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.functions; public FunctionsActivity() { super(R.layout.main_empty, FunctionsActivity.class.getSimpleName()); @@ -43,16 +46,24 @@ public class FunctionsActivity extends BaseActivity { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - final Bundle extras = getIntent().getExtras(); - final Parcelable function = extras != null ? extras.getParcelable(EXTRA_FUNCTION) : null; - for (FunctionCategory category : FunctionCategory.values()) { - final Bundle arguments = new Bundle(2); - if (category == FunctionCategory.my && function != null) { - arguments.putParcelable(FunctionsFragment.ARG_FUNCTION, function); + addTab(category); + } + + 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()); } - 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); } } -} + + private void addTab(@Nonnull FunctionCategory category) { + final Bundle arguments = new Bundle(1); + arguments.putString(FunctionsFragment.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); + } +} \ No newline at end of file