package com.sharefaith.thesharefaithapp.ui;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.sharefaith.thesharefaithapp.R;
import com.sharefaith.thesharefaithapp.base.SFApplication;
import com.sharefaith.thesharefaithapp.base.SFUtil;
import com.sharefaith.thesharefaithapp.models.SFVideoStreamModel;

/**
 * Created by sfwebsitedev on 12/13/16.
 * Activity to show a video stream
 */

public class SFVideoPlayerActivity extends Activity
{
    SFApplication mApplication;
    SFVideoStreamModel mVideoStream;
    String mContent;

    WebView mWebView;

    @Override
    protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.sf_fullscreenvideo );
        mWebView = (WebView) findViewById( R.id.sf_video_webView );
        mApplication = SFApplication.getInstance();
        mVideoStream = mApplication.sfCurrentVideoStream;

        mWebView.getSettings().setJavaScriptEnabled(true);
        //mWebView.getSettings().setAppCacheEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.setHorizontalScrollBarEnabled( false );
        mWebView.setVerticalScrollBarEnabled( false );
        mWebView.getSettings().setLayoutAlgorithm( WebSettings.LayoutAlgorithm.SINGLE_COLUMN );
        setContent();
    }

    private void setContent()
    {
        if( mVideoStream.mSource.equals( "YouTube" ) )
        {
            mContent = "<iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/" +
                    mVideoStream.mId + "\"" +
                    "frameborder=\"0\" allowfullscreen></iframe>";

            String fullHTML = SFUtil.htmlFullScreenVideoEnvelope( mContent );
            mWebView.loadDataWithBaseURL("https://www.youtube.com", fullHTML , "text/html; charset=UTF-8", null ,null);
        }
//        else //if( mVideoStream.mSource.equals( "BoxCast" ) )
//        {
////////            mContent = "<iframe width=\"100%\" height=\"100%\" src=\"" +
////////                    mVideoStream.mContent + "\"" +
////////                    "frameborder=\"0\" allowfullscreen></iframe>";
//////
//////            String fullHTML = SFUtil.htmlFullScreenVideoEnvelope( mContent );
//            mWebView.loadUrl( mVideoStream.mContent );
//        }
//
    }

    @Override
    public void onBackPressed()
    {
        this.finish();
        overridePendingTransition( R.anim.sf_activity_slidein_left, R.anim.sf_activity_slideout_right );
    }

    @Override
    public void onPause() {
        super.onPause();
        mWebView.onPause();
    }
}
