package com.genlot.ninglottery.module.function.help;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.genlot.ninglottery.R;
import com.genlot.ninglottery.base.BaseFragment;
import com.genlot.ninglottery.model.Constant;

import butterknife.BindView;

/**
 * @author ZhuYongKang
 * @description 类描述
 * @date 2019/9/27
 */
public class HelpFragment extends BaseFragment {

    public static final int TYPE_LAW = 0;
    public static final int TYPE_GAME_RULE = 1;
    public static final int TYPE_ABOUT_COMPANY = 2;
    public static final int TYPE_ABOUT_RIGHT = 3;
    private String aboutRight = "CopyRight (C) 2018-2019 深圳市穗彩科技开发有限公司";

    public static HelpFragment newInstance(int type) {
        Bundle args = new Bundle();
        args.putInt(Constant.KEY_TYPE, type);
        HelpFragment fragment = new HelpFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_help;
    }

    @Override
    public void onCreateViewFinished(Bundle state) {
       if(getArguments() != null){
           int type = getArguments().getInt(Constant.KEY_TYPE);
           switch (type) {
               case TYPE_ABOUT_RIGHT:
                   webView.setVisibility(View.GONE);
                   tvContent.setText(aboutRight);
                   break;
               case TYPE_ABOUT_COMPANY:
                   showWeb("file:///android_asset/genlot.html");
                   break;
               case TYPE_LAW:
                   showWeb("file:///android_asset/law.html");
                   break;
               case TYPE_GAME_RULE:
                   showWeb("file:///android_asset/gamerule.html");
                   break;
           }
       }
    }

    private void showWeb(String url) {
        tvContent.setVisibility(View.GONE);
        webView.loadUrl(url);
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setLoadWithOverviewMode(true);
    }

    @BindView(R.id.content)
    TextView tvContent;
    @BindView(R.id.webView)
    WebView webView;
}
