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.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import fr.free.nrw.commons.R;

public class SignupActivity extends Activity {

    private boolean otherPage;

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

        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 (url.equals("https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes")) {
                // Signup success, so load LoginActivity again
                Log.d("SignupActivity", "Overriding URL" + url);
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                intent.putExtra("Redirected", true);
                startActivity(intent);
                return true;
            }
        else {
                Log.d("SignupActivity", "Not overriding URL, URL is: " + url);
                otherPage = true;
                return false;
            }
        }
    }

    @Override
    public void onBackPressed() {
        if (otherPage == true) {
            Intent intent = new Intent(this, SignupActivity.class);
            startActivity(intent);
        }
        else {
            Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
            intent.putExtra("Redirected", true);
            startActivity(intent);
        }
    }
}

@@ -1587,17 +1587,16 @@
       //
- 
 Signup s
@@ -1631,16 +1631,16 @@
 y again%0A
+
         
@@ -1912,32 +1912,39 @@
 e;%0A            %7D
+ else %7B
 %0A        else %7B%0A
@@ -1928,38 +1928,87 @@
  else %7B%0A        
-else %7B
+        //If user clicks any other links in the webview
 %0A               
@@ -2243,24 +2243,136 @@
  == true) %7B%0A
+            //If we are in any page except the main signup page, back button should take us back to signup page%0A
             
@@ -2464,32 +2464,32 @@
 ent);%0A        %7D%0A
-
         else %7B%0A 
@@ -2479,32 +2479,121 @@
 %0A        else %7B%0A
+            //If we are in signup page, back button should take us back to LoginActivity%0A
             Inte

Add comments