package com.hainaos.vc.activity.privacy;

import android.content.Intent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hainaos.vc.R;
import com.hainaos.vc.base.mvvm.BaseMvvmActivity;
import com.hainaos.vc.databinding.ActivityPrivacyaBinding;

public class PrivacyActivity extends BaseMvvmActivity<PrivacyViewModel, ActivityPrivacyaBinding> {
    private static final String TAG = "PrivacyActivity";


    @Override
    public boolean setNightMode() {
        return false;
    }

    @Override
    public boolean setfitWindow() {
        return true;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_privacya;
    }

    @Override
    protected void initDataBinding() {
        mViewModel.setCtx(this);
        mViewModel.setVDBinding(mViewDataBinding);
        mViewModel.setLifecycle(getLifecycleSubject());
        mViewDataBinding.setClick(new BtnClick());
    }

    @Override
    protected void initView() {
        WebSettings settings = mViewDataBinding.webView.getSettings();
//        settings.setUseWideViewPort(true);
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(true);
        settings.setAllowContentAccess(true);
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

        mViewDataBinding.webView.setWebViewClient(new WebViewClient());
        mViewDataBinding.webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    mViewDataBinding.progressBar.setVisibility(View.GONE);
                } else {
                    mViewDataBinding.progressBar.setVisibility(View.VISIBLE);
                    mViewDataBinding.progressBar.setMax(100);
                    mViewDataBinding.progressBar.setProgress(newProgress);
                }
            }
        });
        Intent intent = getIntent();
        int contentType = intent.getIntExtra("ContentType", 1);
        switch (contentType) {
            default:
            case 1:
                mViewDataBinding.tvTitle.setText("用户协议");
                mViewDataBinding.webView.loadUrl("https://www.uiuios.com/agreement.html?section=1-5&projectId=10&status=1");
                break;

        }

    }

    @Override
    protected void initData() {

    }


    public class BtnClick {
        public void exit(View view) {
            finish();
        }
    }
}
