package ui.android.dialogalchemy;

import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;

import ui.android.dialogalchemy.circle.MetalTransmutationCircle;

/**
 * Created by JasonYang on 2016/6/2.
 */
public class DialogAlchemy {

    private static final TransmutationCircle DEFAULT_CIRCLE = new MetalTransmutationCircle();
    private static TransmutationCircle CUSTOM_CIRCLE = null;

    private DialogAlchemy() {
    }

    public static Alchemist show(@NonNull FragmentManager fragmentManager,
            @NonNull Material model) {
        return show(fragmentManager, model, CUSTOM_CIRCLE != null ? CUSTOM_CIRCLE : DEFAULT_CIRCLE);
    }

    public static Alchemist show(@NonNull FragmentManager fragmentManager,
            @NonNull Material model, String tag) {
        return show(fragmentManager, model, CUSTOM_CIRCLE != null ? CUSTOM_CIRCLE : DEFAULT_CIRCLE,
                tag);
    }

    public static Alchemist show(@NonNull FragmentManager fragmentManager,
            @NonNull Material model, @NonNull TransmutationCircle circle) {
        return show(fragmentManager, model, circle, null);
    }

    public static Alchemist show(@NonNull FragmentManager fragmentManager,
            @NonNull Material model, @NonNull TransmutationCircle circle, String tag) {
        Alchemist alchemist = assignToAlchemist(model, circle);
        tag = TextUtils.isEmpty(tag) ? String.valueOf(System.currentTimeMillis()) : tag;
        alchemist.show(fragmentManager, tag);
        return alchemist;
    }

    private static Alchemist assignToAlchemist(Material model, TransmutationCircle circle) {
        Alchemist alchemist = Alchemist.createInstance();
        alchemist.setMaterial(model);
        alchemist.setTransmutationCircle(circle);
        return alchemist;
    }

    public static void setDefaultCircle(TransmutationCircle circle) {
        CUSTOM_CIRCLE = circle;
    }
}

@@ -118,16 +118,67 @@
 anager;%0A
+import android.support.v4.app.FragmentTransaction;%0A
 import a
@@ -661,43 +661,36 @@
     
-return show(fragmentManager, model,
+TransmutationCircle circle =
  CUS
@@ -740,16 +740,68 @@
 T_CIRCLE
+;%0A        return show(fragmentManager, model, circle
 );%0A    %7D
@@ -940,43 +940,36 @@
     
-return show(fragmentManager, model,
+TransmutationCircle circle =
  CUS
@@ -1019,17 +1019,17 @@
 T_CIRCLE
-,
+;
 %0A       
@@ -1029,23 +1029,59 @@
         
-       
+return show(fragmentManager, model, circle,
  tag);%0A 
@@ -1694,24 +1694,1308 @@
 ist;%0A    %7D%0A%0A
+    public static Alchemist showDark(@NonNull FragmentManager fragmentManager,%0A            @NonNull Material model) %7B%0A        TransmutationCircle circle = CUSTOM_CIRCLE != null ? CUSTOM_CIRCLE : DEFAULT_CIRCLE;%0A        return showDark(fragmentManager, model, circle);%0A    %7D%0A%0A    public static Alchemist showDark(@NonNull FragmentManager fragmentManager,%0A            @NonNull Material model, String tag) %7B%0A        TransmutationCircle circle = CUSTOM_CIRCLE != null ? CUSTOM_CIRCLE : DEFAULT_CIRCLE;%0A        return showDark(fragmentManager, model, circle, tag);%0A    %7D%0A%0A    public static Alchemist showDark(@NonNull FragmentManager fragmentManager,%0A            @NonNull Material model, @NonNull TransmutationCircle circle) %7B%0A        return showDark(fragmentManager, model, circle, null);%0A    %7D%0A%0A    public static Alchemist showDark(@NonNull FragmentManager fragmentManager,%0A            @NonNull Material model, @NonNull TransmutationCircle circle, String tag) %7B%0A        Alchemist alchemist = assignToAlchemist(model, circle);%0A        tag = TextUtils.isEmpty(tag) ? String.valueOf(System.currentTimeMillis()) : tag;%0A        FragmentTransaction ft = fragmentManager.beginTransaction();%0A        ft.add(alchemist, tag);%0A        ft.commitAllowingStateLoss();%0A        return alchemist;%0A    %7D%0A%0A
     private 

Add showDark method - commitAllowingStateLoss.