// Path: app/src/main/java/com/yunq/gankio/presenter/view/ICustomDialog.java
// public interface ICustomDialog extends IBaseView {
// }
// 
// Path: app/src/main/java/com/yunq/gankio/ui/fragment/CustomWebViewDialog.java
// public class CustomWebViewDialog extends DialogFragment implements ICustomDialog {
// 
//     public static final String EXTRA_DIALOG_TITLE = "DIALOG_TITLE";
//     public static final String EXTRA_HTML_FILE_NAME = "HTML_FILE_NAME";
//     public static final String EXTRA_ACCENT_COLOR = "ACCENT_COLOR";
// 
//     @Inject
//     CustomDialogPresenter mPresenter;
//     @Inject
//     Context mContext;
// 
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         initInjection();
//     }
// 
//     private void initInjection() {
//         DaggerFragmentComponent.builder()
//                 .fragmentModule(new FragmentModule(this))
//                 .applicationComponent(GankApp.get(this.getActivity()).getComponent())
//                 .build()
//                 .inject(this);
//     }
// 
//     @NonNull
//     @Override
//     public Dialog onCreateDialog(Bundle savedInstanceState) {
//         final View customView;
//         try {
//             customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null);
//         } catch (InflateException e) {
//             throw new IllegalStateException("This device does not support Web Views.");
//         }
// 
//         return mPresenter.makeDialog(this, customView);
// 
// 
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         GankApp.getRefWatcher(mContext).watch(this);
//         mPresenter.detachView();
//     }
// }


import android.content.Context;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.webkit.WebView;
import com.yunq.gankio.R;
import com.yunq.gankio.presenter.view.ICustomDialog;
import com.yunq.gankio.ui.fragment.CustomWebViewDialog;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.inject.Inject;
package com.yunq.gankio.presenter;






/**
 * Created by admin on 16/1/6.
 */
public class CustomDialogPresenter extends BasePresenter<ICustomDialog> {


    private static final String KEY_UTF_8 = "UTF-8";

    private Context mContext;

    @Inject
    public CustomDialogPresenter(Context context) {
        mContext = context;
    }

    public AlertDialog makeDialog(Fragment fragment, View customView) {

        String dialogTitle = fragment.getArguments().getString(CustomWebViewDialog.EXTRA_DIALOG_TITLE);
        String htmlFileName = fragment.getArguments().getString(CustomWebViewDialog.EXTRA_HTML_FILE_NAME);
        int accentColor = fragment.getArguments().getInt(CustomWebViewDialog.EXTRA_ACCENT_COLOR);

        final WebView webView = (WebView) customView.findViewById(R.id.webView);
        webView.getSettings().setDefaultTextEncodingName(KEY_UTF_8);
        loadData(webView, htmlFileName, accentColor);

        AlertDialog dialog = new AlertDialog.Builder(mContext)
                .setTitle(dialogTitle)
                .setView(customView)
                .setPositiveButton(android.R.string.ok, null)
                .show();
        return dialog;
    }

    private void loadData(WebView webView, String htmlFileName, int accentColor) {
        try {
            StringBuilder buf = new StringBuilder();
// Path: app/src/main/java/com/yunq/gankio/presenter/view/ICustomDialog.java
// public interface ICustomDialog extends IBaseView {
// }
// 
// Path: app/src/main/java/com/yunq/gankio/ui/fragment/CustomWebViewDialog.java
// public class CustomWebViewDialog extends DialogFragment implements ICustomDialog {
// 
//     public static final String EXTRA_DIALOG_TITLE = "DIALOG_TITLE";
//     public static final String EXTRA_HTML_FILE_NAME = "HTML_FILE_NAME";
//     public static final String EXTRA_ACCENT_COLOR = "ACCENT_COLOR";
// 
//     @Inject
//     CustomDialogPresenter mPresenter;
//     @Inject
//     Context mContext;
// 
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         initInjection();
//     }
// 
//     private void initInjection() {
//         DaggerFragmentComponent.builder()
//                 .fragmentModule(new FragmentModule(this))
//                 .applicationComponent(GankApp.get(this.getActivity()).getComponent())
//                 .build()
//                 .inject(this);
//     }
// 
//     @NonNull
//     @Override
//     public Dialog onCreateDialog(Bundle savedInstanceState) {
//         final View customView;
//         try {
//             customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null);
//         } catch (InflateException e) {
//             throw new IllegalStateException("This device does not support Web Views.");
//         }
// 
//         return mPresenter.makeDialog(this, customView);
// 
// 
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         GankApp.getRefWatcher(mContext).watch(this);
//         mPresenter.detachView();
//     }
// }


// Path: app/src/main/java/com/yunq/gankio/presenter/CustomDialogPresenter.java
import android.content.Context;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.webkit.WebView;
import com.yunq.gankio.R;
import com.yunq.gankio.presenter.view.ICustomDialog;
import com.yunq.gankio.ui.fragment.CustomWebViewDialog;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.inject.Inject;

package com.yunq.gankio.presenter;






/**
 * Created by admin on 16/1/6.
 */
public class CustomDialogPresenter extends BasePresenter<ICustomDialog> {


    private static final String KEY_UTF_8 = "UTF-8";

    private Context mContext;

    @Inject
    public CustomDialogPresenter(Context context) {
        mContext = context;
    }

    public AlertDialog makeDialog(Fragment fragment, View customView) {

        String dialogTitle = fragment.getArguments().getString(CustomWebViewDialog.EXTRA_DIALOG_TITLE);
        String htmlFileName = fragment.getArguments().getString(CustomWebViewDialog.EXTRA_HTML_FILE_NAME);
        int accentColor = fragment.getArguments().getInt(CustomWebViewDialog.EXTRA_ACCENT_COLOR);

        final WebView webView = (WebView) customView.findViewById(R.id.webView);
        webView.getSettings().setDefaultTextEncodingName(KEY_UTF_8);
        loadData(webView, htmlFileName, accentColor);

        AlertDialog dialog = new AlertDialog.Builder(mContext)
                .setTitle(dialogTitle)
                .setView(customView)
                .setPositiveButton(android.R.string.ok, null)
                .show();
        return dialog;
    }

    private void loadData(WebView webView, String htmlFileName, int accentColor) {
        try {
            StringBuilder buf = new StringBuilder();
            InputStream json = mContext.getAssets().open(htmlFileName);