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 1/6] 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(); } } From 143df9a5292ab1eb2144132f59db8943d8ee5ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Tue, 3 Jan 2017 14:22:07 +0100 Subject: [PATCH 2/6] Start reCaptcha activity when starting video directly --- .../newpipe/detail/StreamInfoWorker.java | 10 +++++- .../detail/VideoItemDetailFragment.java | 36 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index bb1130fdf..df2f8454d 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -5,8 +5,8 @@ import android.os.Handler; import android.util.Log; import android.view.View; -import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.report.ErrorActivity; @@ -44,6 +44,7 @@ public class StreamInfoWorker { public interface OnStreamInfoReceivedListener { void onReceive(StreamInfo info); void onError(int messageId); + void onReCaptchaException(); void onBlockedByGemaError(); void onContentErrorWithMessage(int messageId); void onContentError(); @@ -107,6 +108,13 @@ public class StreamInfoWorker { } // These errors render the stream information unusable. + } catch (ReCaptchaException e) { + h.post(new Runnable() { + @Override + public void run() { + onStreamInfoReceivedListener.onReCaptchaException(); + } + }); } catch (IOException e) { h.post(new Runnable() { @Override diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index 1fa80175f..d44b7887e 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -43,6 +43,7 @@ import java.util.Vector; import org.schabi.newpipe.ActivityCommunicator; import org.schabi.newpipe.ChannelActivity; +import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; import org.schabi.newpipe.info_list.InfoItemBuilder; @@ -59,6 +60,9 @@ import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.PlayVideoActivity; import org.schabi.newpipe.player.ExoPlayerActivity; +import static android.app.Activity.RESULT_OK; +import static org.schabi.newpipe.ReCaptchaActivity.RECAPTCHA_REQUEST; + /** * Copyright (C) Christian Schabesberger 2015 @@ -604,6 +608,17 @@ public class VideoItemDetailFragment extends Fragment { postNewErrorToast(messageId); } + @Override + public void onReCaptchaException() { + Toast.makeText(getActivity(), R.string.recaptcha_request_toast, + Toast.LENGTH_LONG).show(); + + // Starting ReCaptcha Challenge Activity + startActivityForResult( + new Intent(getActivity(), ReCaptchaActivity.class), + RECAPTCHA_REQUEST); + } + @Override public void onBlockedByGemaError() { onErrorBlockedByGema(); @@ -793,4 +808,23 @@ public class VideoItemDetailFragment extends Fragment { VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId); activity.startActivity(detailIntent); } -} \ No newline at end of file + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case RECAPTCHA_REQUEST: + if (resultCode == RESULT_OK) { + String videoUrl = getArguments().getString(VIDEO_URL); + StreamInfoWorker siw = StreamInfoWorker.getInstance(); + siw.search(streamingServiceId, videoUrl, getActivity()); + } else { + Log.d(TAG, "ReCaptcha failed"); + } + break; + + default: + Log.e(TAG, "Request code from activity not supported [" + requestCode + "]"); + break; + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 208cac70d..bdada975d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -271,6 +271,7 @@ Settings reCaptcha reCaptcha Challenge + ReCaptcha Challenge requested From c9edac2820b61b8012ba832be99f82edd1e60c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Tue, 3 Jan 2017 14:25:22 +0100 Subject: [PATCH 3/6] Change the way to start reCaptchaActivity * Use startActivityForResult() and onActivityResult() to refresh the search request when returning from reCaptcha activity. --- .../SearchInfoItemFragment.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index e710bbbd9..9d3d7b839 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -8,6 +8,7 @@ import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -28,6 +29,9 @@ import org.schabi.newpipe.detail.VideoItemDetailActivity; import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.info_list.InfoListAdapter; +import static android.app.Activity.RESULT_OK; +import static org.schabi.newpipe.ReCaptchaActivity.RECAPTCHA_REQUEST; + /** * Created by Christian Schabesberger on 02.08.16. * @@ -180,9 +184,11 @@ public class SearchInfoItemFragment extends Fragment { public void onReCaptchaChallenge() { Toast.makeText(getActivity(), "ReCaptcha Challenge requested", Toast.LENGTH_LONG).show(); + // Starting ReCaptcha Challenge Activity - Intent i = new Intent(getActivity(), ReCaptchaActivity.class); - getActivity().startActivity(i); + startActivityForResult( + new Intent(getActivity(), ReCaptchaActivity.class), + RECAPTCHA_REQUEST); } }); } @@ -289,4 +295,23 @@ public class SearchInfoItemFragment extends Fragment { Thread suggestionThread = new Thread(suggestionSearchRunnable); suggestionThread.start(); } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case RECAPTCHA_REQUEST: + if (resultCode == RESULT_OK) { + if (searchQuery.length() != 0) { + search(searchQuery); + } + } else { + Log.d(TAG, "ReCaptcha failed"); + } + break; + + default: + Log.e(TAG, "Request code from activity not supported [" + requestCode + "]"); + break; + } + } } From 80c9dbf180f3f4864c4406b1fa2a8f698bd8e0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Tue, 3 Jan 2017 14:28:11 +0100 Subject: [PATCH 4/6] Cosmetic --- .../schabi/newpipe/detail/StreamInfoWorker.java | 5 ++--- .../search_fragment/SearchInfoItemFragment.java | 17 ++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index df2f8454d..dd1ae9f5a 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -123,9 +123,8 @@ public class StreamInfoWorker { } }); e.printStackTrace(); - } - // custom service related exceptions - catch (YoutubeStreamExtractor.DecryptException de) { + } catch (YoutubeStreamExtractor.DecryptException de) { + // custom service related exceptions h.post(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index 9d3d7b839..57b63c209 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -72,7 +72,7 @@ public class SearchInfoItemFragment extends Fragment { //noinspection ConstantConditions inputManager.hideSoftInputFromWindow( a.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); - } catch(NullPointerException e) { + } catch (NullPointerException e) { e.printStackTrace(); ErrorActivity.reportError(a, e, null, a.findViewById(android.R.id.content), @@ -86,7 +86,7 @@ public class SearchInfoItemFragment extends Fragment { // onQueryTextSubmit to trigger twice when focus is not cleared. // See: http://stackoverflow.com/questions/17874951/searchview-onquerytextsubmit-runs-twice-while-i-pressed-once a.getCurrentFocus().clearFocus(); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } View bg = a.findViewById(R.id.mainBG); @@ -96,7 +96,7 @@ public class SearchInfoItemFragment extends Fragment { @Override public boolean onQueryTextChange(String newText) { - if(!newText.isEmpty()) { + if (!newText.isEmpty()) { searchSuggestions(newText); } return true; @@ -137,13 +137,13 @@ public class SearchInfoItemFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if(savedInstanceState != null) { + if (savedInstanceState != null) { searchQuery = savedInstanceState.getString(QUERY); streamingServiceId = savedInstanceState.getInt(STREAMING_SERVICE); } else { try { streamingServiceId = NewPipe.getIdOfService("Youtube"); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); ErrorActivity.reportError(getActivity(), e, null, getActivity().findViewById(android.R.id.content), @@ -222,14 +222,13 @@ public class SearchInfoItemFragment extends Fragment { public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int pastVisiblesItems, visibleItemCount, totalItemCount; super.onScrolled(recyclerView, dx, dy); - if(dy > 0) //check for scroll down + if (dy > 0) //check for scroll down { visibleItemCount = streamInfoListLayoutManager.getChildCount(); totalItemCount = streamInfoListLayoutManager.getItemCount(); pastVisiblesItems = streamInfoListLayoutManager.findFirstVisibleItemPosition(); - if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading) - { + if ((visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading) { pageNumber++; search(searchQuery, pageNumber); } @@ -270,7 +269,7 @@ public class SearchInfoItemFragment extends Fragment { searchView.setSuggestionsAdapter(suggestionListAdapter); searchView.setOnSuggestionListener(new SearchSuggestionListener(searchView, suggestionListAdapter)); searchView.setOnQueryTextListener(new SearchQueryListener()); - if(searchQuery != null && !searchQuery.isEmpty()) { + if (searchQuery != null && !searchQuery.isEmpty()) { searchView.setQuery(searchQuery, false); searchView.setIconifiedByDefault(false); } From 410c4ca7363bafde45ffbf8a9cc3a71fdabfd577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Tue, 3 Jan 2017 14:29:08 +0100 Subject: [PATCH 5/6] Remove old comment --- .../org/schabi/newpipe/detail/VideoItemDetailFragment.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index d44b7887e..2c6e4b55a 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -583,11 +583,6 @@ public class VideoItemDetailFragment extends Fragment { return true; } - /** - * Mandatory empty constructor for the fragment manager to instantiate the - * fragment (e.g. upon screen orientation changes). - */ - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); From 92db9cb59bf9c196c59bc34edb2a3230b3b7bcb9 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 4 Jan 2017 17:20:01 +0100 Subject: [PATCH 6/6] update support lib and move on to 0.8.7 --- app/build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 381ea7ad3..266f7fadb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.schabi.newpipe" minSdkVersion 15 targetSdkVersion 25 - versionCode 20 - versionName "0.8.6" + versionCode 21 + versionName "0.8.7" } buildTypes { release { @@ -32,10 +32,10 @@ android { dependencies { testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.android.support:support-v4:25.0.0' - compile 'com.android.support:design:25.0.0' - compile 'com.android.support:recyclerview-v7:25.0.0' + compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:support-v4:25.1.0' + compile 'com.android.support:design:25.1.0' + compile 'com.android.support:recyclerview-v7:25.1.0' compile 'org.jsoup:jsoup:1.8.3' compile 'org.mozilla:rhino:1.7.7' compile 'info.guardianproject.netcipher:netcipher:1.2'