package com.goodtech.tq;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.goodtech.tq.utils.Constants;
import com.umeng.analytics.MobclickAgent;

public class PrivateActivity extends BaseActivity {

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agreement);

        TextView mTitleView = findViewById(R.id.tv_title);
        if (mTitleView != null) mTitleView.setText(R.string.title_private);

        //  配置station
        configStationBar(findViewById(R.id.private_station_bar));

        mWebView = findViewById(R.id.web_agreement);
        mWebView.setLayerType(View.LAYER_TYPE_HARDWARE,null);
//        mWebView.setLongClickable(true);
//        mWebView.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                return true;
//            }
//        });
        //  设置url
        String guideUrl = String.format(Constants.URL_PRIVACY, BuildConfig.FLAVOR);
        mWebView.loadUrl(guideUrl);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
                //fixme 更新localStorage缓存，web端加载页面前需要token，这时候设置才有效，否则拿到的是之前的缓存
                super.doUpdateVisitedHistory(view, url, isReload);
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onLoadResource(WebView view, String url) {
                super.onLoadResource(view, url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }

//            //  屏蔽超链接，使其不可跳转
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//                return true;
//            }
        });

        findViewById(R.id.button_back).setOnClickListener(v -> finish());
    }

    @Override
    protected void onDestroy() {
        if (mWebView != null) {
            mWebView.destroy();
            mWebView = null;
        }
        super.onDestroy();
    }
}
