package is.eyra.eyra;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mWebView.reload();
            }
        });

        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // Enable DOM storage, thanks Lewis, http://stackoverflow.com/a/29978620/5272567
        webSettings.setDomStorageEnabled(true);
        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new EyraWebViewClient());
        // Allow location
        mWebView.setWebChromeClient(new GeoWebChromeClient());

        mWebView.addJavascriptInterface(new RecorderJSInterface(), "AndroidRecorder");

        mWebView.loadUrl(getString(R.string.website_url));
        //mWebView.loadUrl("http://beta.html5test.com/");
    }

    // code from here: https://developer.chrome.com/multidevice/webview/gettingstarted
    // license: http://creativecommons.org/licenses/by/3.0/
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -1735,24 +1735,332 @@
 ecorder%22);%0A%0A
+        // enable appcache%0A        webSettings.setDomStorageEnabled(true);%0A        webSettings.setAppCachePath(%22/data/data/%22+ getPackageName() +%22/cache%22);%0A        webSettings.setAllowFileAccess(true);%0A        webSettings.setAppCacheEnabled(true);%0A        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);%0A%0A
         mWeb

Fix appcache so now it works in webview.