package com.team.app.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.fragment.app.Fragment;

import com.team.app.R;
import com.team.app.activities.GameDetailActivity;

public class PreviewFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_preview, viewGroup, false);
        WebView webView = inflate.findViewById(R.id.textView);
        webView.setFocusableInTouchMode(false);
        webView.setFocusable(false);
        WebSettings webSettings = webView.getSettings();
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDefaultFontSize(16);
        String mimeType = "text/html; charset=UTF-8";
        String encoding = "utf-8";
        if (GameDetailActivity.cricket != null) {
            webView.loadDataWithBaseURL(null, GameDetailActivity.cricket.getMatch_detail(), mimeType, encoding, null);
        }
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                webView.setVisibility(View.VISIBLE);
            }
        });
        return inflate;
    }
}
