package com.sharefaith.thesharefaithapp.base;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

import com.sharefaith.thesharefaithapp.ui.SFBibleActivity;

/**
 * Created by Anthony on 3/1/16.
 * Webview for Bible for getting scroll position
 */
public class SFBibleWebView extends WebView
{

    public SFBibleWebView( Context context, AttributeSet attrs )
    {
        super( context, attrs );
    }

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

    public SFBibleWebView( Context context, AttributeSet attrs, int defStyle )
    {
        super( context, attrs, defStyle );
    }

    /**
     * get the scroll position
     * @param x
     * @param y
     * @param oldx
     * @param oldy
     */
    @Override
    protected void onScrollChanged( int x, int y, int oldx, int oldy )
    {
        SFApplication application = SFApplication.getInstance();
        int contentHeight = (int) (this.getContentHeight()*this.getResources().getDisplayMetrics().density);
        if( getScrollY() >= contentHeight- this.getHeight()-50 )
        {
            application.isAtBottomOfChapter = true;
            SFBibleActivity.showMenus();
        }

        else if(y>(oldy))
        {
            SFBibleActivity.hideMenus();
        }
        else if(y<(oldy))
        {
            application.isAtBottomOfChapter = false;
            SFBibleActivity.showMenus();
        }
        //SFApplication.getInstance().bibleScrollY = getScrollY();
        super.onScrollChanged( x,y,oldx,oldy );
    }
}
