/**
 * Copyright 2016 Lloyd Torres
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lloydtorres.stately.core;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;

import java.lang.reflect.Field;

/**
 * Created by Lloyd on 2016-11-01.
 * Workaround for illegal state exception in fragments, as shown in http://stackoverflow.com/a/15656428
 * Same as DetachFragment, but this is for DialogFragments specifically.
 */
public abstract class DetachDialogFragment extends DialogFragment {
    @Override
    public void onDetach() {
        super.onDetach();
        try {
            Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
            childFragmentManager.setAccessible(true);
            childFragmentManager.set(this, null);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -716,16 +716,63 @@
 ragment;
+%0Aimport android.support.v4.app.FragmentManager;
 %0A%0Aimport
@@ -1086,16 +1086,171 @@
 gment %7B%0A
+    @Override%0A    public void show(FragmentManager manager, String tag) %7B%0A        if (!isAdded()) %7B%0A            super.show(manager, tag);%0A        %7D%0A    %7D%0A%0A
     @Ove

Add safety check on dialog fragments