package com.kaltura.kalturaplayertoolkit;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

import com.kaltura.playersdk.KPPlayerConfig;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import Fragments.FullscreenFragment;
import Fragments.LoginFragment;
import Fragments.PlayerFragment;
import Utilities.FragmentUtilities;


public class MainActivity extends Activity implements LoginFragment.OnFragmentInteractionListener, PlayerFragment.OnFragmentInteractionListener, FullscreenFragment.OnFragmentInteractionListener{
	public static String TAG = MainActivity.class.getSimpleName();

    @SuppressLint("NewApi") @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_main);
        
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

        loadFragment();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        loadFragment();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onFragmentInteraction(Uri uri) {
        Intent intent = getIntent();
        Fragment fragment = new FullscreenFragment();
        Bundle extras = intent.getExtras();
        if (extras == null) {
            extras = new Bundle();
        }
        KPPlayerConfig config = new  KPPlayerConfig("http://cdnapi.kaltura.com", "30666052", "1782391");
        config.addConfig("streamerType", "applehttp");
        config.addConfig("Kaltura.LeadHLSOnAndroid", "true");
        config.addConfig("watchwithPlugin.text", "Ideanova Watermark");
        config.addConfig("ks", "djJ8MTc4MjM5MXzeUabzSd9BpWzRRkrsrDVUW_EYqubJF9-srYlXEoqD_meZU-ViGihNhfaBfDsXZ3FqoS1pR1MBTyIR3v5Amvth5GII43TVrJMjKPwbN5MKuTpqktgbhUFytm4n3fyjGC48pHdcdjzPtE7fadpBEUcK8ldz-AnAspUrJV9IEFsf9w==");
        config.setEntryId("0_javdshwx");
        extras.putString(getString(R.string.prop_iframe_url), config.getVideoURL());
        FragmentUtilities.loadFragment(false, fragment, extras, getFragmentManager());
    }

    private void loadFragment(){
        Intent intent = getIntent();
        Fragment fragment = new LoginFragment();
        Bundle extras = intent.getExtras();

        if (Intent.ACTION_VIEW.equals( intent.getAction())) {
            Uri uri = intent.getData();
            String[] params = null;
            try {
                params = URLDecoder.decode(uri.toString(), "UTF-8").split(":=");
            } catch (UnsupportedEncodingException e) {
                Log.w(TAG, "couldn't decode/split intent url");
                e.printStackTrace();
            }
            if (params != null && params.length > 1) {
                String iframeUrl = params[1];

                extras.putString(getString(R.string.prop_iframe_url), iframeUrl);
                fragment = new FullscreenFragment();

            } else {
                Log.w(TAG, "didn't load iframe, invalid iframeUrl parameter was passed");
            }

        }

        FragmentUtilities.loadFragment(false, fragment, extras, getFragmentManager());
    }
}

@@ -2455,32 +2455,41 @@
 le();%0A        %7D%0A
+        %0A
         KPPlayer
@@ -2558,440 +2558,27 @@
 %22, %22
-30666052%22, %221782391%22);%0A        config.addConfig(%22streamerType%22, %22applehttp%22);%0A        config.addConfig(%22Kaltura.LeadHLSOnAndroid%22, %22true%22);%0A        config.addConfig(%22watchwithPlugin.text%22, %22Ideanova Watermark%22);%0A        config.addConfig(%22ks%22, %22djJ8MTc4MjM5MXzeUabzSd9BpWzRRkrsrDVUW_EYqubJF9-srYlXEoqD_meZU-ViGihNhfaBfDsXZ3FqoS1pR1MBTyIR3v5Amvth5GII43TVrJMjKPwbN5MKuTpqktgbhUFytm4n3fyjGC48pHdcdjzPtE7fadpBEUcK8ldz-AnAspUrJV9IEFsf9w==
+26698911%22, %221831271
 %22);%0A
@@ -2608,21 +2608,22 @@
 Id(%22
-0_javdshwx
+1_o426d3i4
 %22);
+ 
 %0A   

Update MainActivity.java