package fr.free.nrw.commons.auth;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import fr.free.nrw.commons.R;

public class SignupActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("SignupActivity", "Signup Activity started");

        WebView webView = new WebView(this);
        setContentView(webView);

        webView.setWebViewClient(new MyWebViewClient());
        //myWebView.loadUrl("https://commons.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page");
        //Mobile page, looks better than the above
        webView.loadUrl("https://commons.m.wikimedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page&returntoquery=welcome%3Dyes");

        //After Create Account button is pressed within WebView, it brings user to https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes. So can we just override that URL?
        //Do we NEED to enable JS? Validation seems to work fine here
    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes")) {
                // This is my web site, so do not override; let my WebView load the page
                Log.d("SignupActivity", "Overriding URL");
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
                return true;
            } else {
                Log.d("SignupActivity", "Not overriding URL");
                return false;
            }

        }
    }
}

@@ -163,16 +163,59 @@
 il.Log;%0A
+import android.webkit.WebResourceResponse;%0A
 import a
@@ -1554,77 +1554,51 @@
  // 
-This is my web site, so do not override; let my WebView load the page
+Signup success, so load LoginActivity again
 %0A   
@@ -1883,33 +1883,70 @@
 t overriding URL
-%22
+, URL is: %22 + Uri.parse(url).getHost()
 );%0A             
@@ -1987,16 +1987,17 @@
       %7D%0A
+%0A
     %7D%0A%7D%0A

Add logging