package im.tny.segvault.disturbances;

import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;

import org.sufficientlysecure.htmltextview.HtmlTextView;

/**
 * Created by gabriel on 7/12/17.
 */
public class HtmlDialogFragment extends DialogFragment {
    private static final String ARG_CONTENT = "content";
    private static final String ARG_HTML = "html";

    public static HtmlDialogFragment newInstance(String content, boolean isHtml) {
        HtmlDialogFragment fragment = new HtmlDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_CONTENT, content);
        args.putBoolean(ARG_HTML, isHtml);
        fragment.setArguments(args);
        return fragment;
    }

    public static HtmlDialogFragment newInstance(String content) {
        return newInstance(content, true);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        String content = "";
        boolean isHtml = false;
        if (getArguments() != null) {
            content = getArguments().getString(ARG_CONTENT);
            isHtml = getArguments().getBoolean(ARG_HTML);
        }
        LayoutInflater inflater = getActivity().getLayoutInflater();

        View view = inflater.inflate(R.layout.dialog_html, null);

        HtmlTextView htmltv = (HtmlTextView) view.findViewById(R.id.html_view);
        if(isHtml) {
            htmltv.setHtml(content);
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                htmltv.setTextAppearance(R.style.TextAppearance_AppCompat_Small);
            } else {
                htmltv.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Small);
            }
            htmltv.setText(content);
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(view);
        return builder.create();
    }
}

@@ -156,16 +156,114 @@
 agment;%0A
+import android.support.v4.app.FragmentManager;%0Aimport android.support.v4.app.FragmentTransaction;%0A
 import a
@@ -1615,16 +1615,17 @@
       if
+ 
 (isHtml)
@@ -2155,11 +2155,492 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public int show(FragmentTransaction transaction, String tag) %7B%0A        try %7B%0A            return super.show(transaction, tag);%0A        %7D catch (IllegalStateException e) %7B%0A            // ignore state loss%0A            return -1;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void show(FragmentManager manager, String tag) %7B%0A        try %7B%0A            super.show(manager, tag);%0A        %7D catch (IllegalStateException e) %7B%0A            // ignore state loss%0A        %7D%0A    %7D
 %0A%7D%0A

Fix crash related to fragment state loss