package fr.coding.yourandroidwebapp;

import android.app.Activity;
import android.content.Intent;
import android.media.audiofx.BassBoost;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

import fr.coding.tools.AutoAuthSslWebView;
import fr.coding.tools.gdrive.GoogleDriveApiActivity;
import fr.coding.yourandroidwebapp.settings.AppSettings;
import fr.coding.yourandroidwebapp.settings.AppSettingsCallback;
import fr.coding.yourandroidwebapp.settings.WebApp;
import fr.coding.yourandroidwebapp.settings.AppSettingsManager;


public class WebMainActivity extends Activity {

    private WebView mWebView;

    private String url;

    private String webAppId;

    private boolean needLoad = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_main);

        url = "http://toutestquantique.fr/en/";
        webAppId = getIntent().getStringExtra("webappid");

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // Force links and redirects to open in the WebView instead of in a browser
        AutoAuthSslWebView wvc = new AutoAuthSslWebView();
        mWebView.setWebViewClient(wvc);


        AppSettingsManager settingsManager = new AppSettingsManager(this);
        AppSettings settings = settingsManager.LoadSettingsLocally();

        if ((webAppId != null) && (!webAppId.isEmpty())) {
            WebApp wa = settings.getWebAppById(webAppId);
            if (wa != null) {
                url = wa.url;
            }
        }

        mWebView.postDelayed(new Runnable() {
            @Override
            public void run() {

                LoadWebView();

                needLoad = false;
            }
        }, 5);

    }

    @Override
    protected void onResume() {
        super.onResume();
        //todo: add wifi/mobile test here
    }

    protected void LoadWebView() {
        mWebView.loadUrl(url);
    }

    @Override
    public void onBackPressed() {
        if (mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            Intent intent = new Intent(this, SettingsActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("EXIT", true);
            startActivity(intent);
            finish();
        }
    }

}

@@ -157,16 +157,83 @@
 Bundle;%0A
+import android.view.Window;%0Aimport android.webkit.WebChromeClient;%0A
 import a
@@ -255,24 +255,24 @@
 ebSettings;%0A
-
 import andro
@@ -868,24 +868,86 @@
 nceState) %7B%0A
+        getWindow().requestFeature(Window.FEATURE_PROGRESS);%0A%0A
         supe
@@ -1027,24 +1027,68 @@
 web_main);%0A%0A
+        final Activity webactivity = this;%0A%0A
         url 
@@ -1338,24 +1338,24 @@
 Settings();%0A
-
         webS
@@ -1387,24 +1387,410 @@
 led(true);%0A%0A
+        mWebView.setWebChromeClient(new WebChromeClient() %7B%0A            public void onProgressChanged(WebView view, int progress) %7B%0A                // Activities and WebViews measure progress with different scales.%0A                // The progress meter will automatically disappear when we reach 100%25%0A                webactivity.setProgress(progress * 1000);%0A            %7D%0A        %7D);%0A%0A
         // F

add progress bar ? to test