/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.view.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.util.StringUtil;

/**
 * WebDialog
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 18.]   [최초 작성]
 * @since 2018. 9. 18.
 */
public class WebDialog extends DialogBase {

  private String url;
  private WebView webView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public void onDestroyView() {
    super.onDestroyView();
  }

  /**
   * 표시할 url 지정
   *
   * @param url
   */
  public void setUrl(String url) {
    this.url = url;

    render();
  }

  private void render() {
    if (null != webView && StringUtil.isFull(url)) {
      webView.loadUrl(url);
    }
  }

  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.web_dialog, container, false);
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    webView = getView().findViewById(R.id.web_view);
    webView.setWebViewClient(new WebViewClient() {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
      }
    });
//    webView.getSettings().setJavaScriptEnabled(true);

    render();

  }
}
