package com.ymlabs.stormplayer.objects;

import android.content.Context;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.ymlabs.stormplayer.utils.StaticMethods;
import com.ymlabs.stormplayer.vlc.Dialog;

/**
 * Created by ym on 11/06/14.
 */
public class YoutubeSearchWebViewClient extends WebViewClient{


    public YoutubeSearchWebViewClient(Context context){
        super();
    }


    //If the new URL link to a video, stay in search and store URL
    //Else if new search, allow it
    //Else, block it
    @Override
    public void onLoadResource (WebView view, String url) {

        if (url.contains("watch")) {
            view.stopLoading();
            //stop ads
            if(!url.contains("googleads"))
                new Dialog(view.getContext(), null, Dialog.ADD, StaticMethods.formatYoutubeUrl(url)).proceed();
            view.goBack();
        }else {
            super.onLoadResource(view, url);
        }

    }



}
