From c87da9903faf1b6f1ae7df17e6ed891dd62a86aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Mon, 2 Jan 2017 17:30:35 +0100 Subject: [PATCH] Set result code and finish() Activity instead of starting MainActivity * Activities will start reCaptchaActivity with startActivityForResult and look for RECAPTCHA_REQUEST and RESULT_OK | RESULT_CANCELED in : 'onActivityResult()' --- .../org/schabi/newpipe/ReCaptchaActivity.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java index f503bfcff..45c4dfeb8 100644 --- a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java @@ -2,6 +2,7 @@ package org.schabi.newpipe; import android.app.Activity; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; import android.support.v4.app.NavUtils; @@ -34,6 +35,8 @@ import android.webkit.WebViewClient; * along with NewPipe. If not, see . */ public class ReCaptchaActivity extends AppCompatActivity { + public static final int RECAPTCHA_REQUEST = 10; + public static final String TAG = ReCaptchaActivity.class.toString(); public static final String YT_URL = "https://www.youtube.com"; @@ -42,6 +45,9 @@ public class ReCaptchaActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recaptcha); + // Set return to Cancel by default + setResult(RESULT_CANCELED); + ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.reCaptcha_title); @@ -80,19 +86,26 @@ public class ReCaptchaActivity extends AppCompatActivity { context = ctx; } + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + // TODO: Start Loader + super.onPageStarted(view, url, favicon); + } + @Override public void onPageFinished(WebView view, String url) { String cookies = CookieManager.getInstance().getCookie(url); + // TODO: Stop Loader + // find cookies : s_gl & goojf and Add cookies to Downloader if (find_access_cookies(cookies)) { // Give cookies to Downloader class Downloader.setCookies(mCookies); - // Closing activity and return to parent. - Intent intent = new Intent(context, org.schabi.newpipe.MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - NavUtils.navigateUpTo(context, intent); + // Closing activity and return to parent + setResult(RESULT_OK); + finish(); } }