From 53796043c3dcd0b5be475080a9bb3814dba2d865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Wed, 7 Dec 2016 22:19:43 +0100 Subject: [PATCH] Start reCaptchaActivity when reCaptcha is requested and fix Typo * Fix typo setSearchWorkerResultListner to setSearchWorkerResultListener --- .../SearchInfoItemFragment.java | 12 +++++++++- .../newpipe/search_fragment/SearchWorker.java | 23 +++++++++++++------ 2 files changed, 27 insertions(+), 8 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 782f7a78b..e710bbbd9 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 @@ -18,6 +18,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.ProgressBar; import android.widget.Toast; +import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.info_list.InfoItemBuilder; @@ -149,7 +150,7 @@ public class SearchInfoItemFragment extends Fragment { } SearchWorker sw = SearchWorker.getInstance(); - sw.setSearchWorkerResultListner(new SearchWorker.SearchWorkerResultListner() { + sw.setSearchWorkerResultListener(new SearchWorker.SearchWorkerResultListener() { @Override public void onResult(SearchResult result) { infoListAdapter.addStreamItemList(result.resultList); @@ -174,6 +175,15 @@ public class SearchInfoItemFragment extends Fragment { isLoading = false; loadingIndicator.setVisibility(View.GONE); } + + @Override + 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); + } }); } diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java index b6be1e259..7ce0d30c5 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java @@ -8,6 +8,7 @@ import android.util.Log; import android.view.View; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.reCaptchaException; import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.report.ErrorActivity; @@ -40,10 +41,11 @@ import java.io.IOException; public class SearchWorker { private static final String TAG = SearchWorker.class.toString(); - public interface SearchWorkerResultListner { + public interface SearchWorkerResultListener { void onResult(SearchResult result); void onNothingFound(final int stringResource); void onError(String message); + void onReCaptchaChallenge(); } private class ResultRunnable implements Runnable { @@ -56,7 +58,7 @@ public class SearchWorker { @Override public void run() { if(this.requestId == SearchWorker.this.requestId) { - searchWorkerResultListner.onResult(result); + searchWorkerResultListener.onResult(result); } } } @@ -121,11 +123,18 @@ public class SearchWorker { } // hard errors: + } catch (reCaptchaException e) { + h.post(new Runnable() { + @Override + public void run() { + searchWorkerResultListener.onReCaptchaChallenge(); + } + }); } catch(IOException e) { h.post(new Runnable() { @Override public void run() { - searchWorkerResultListner.onNothingFound(R.string.network_error); + searchWorkerResultListener.onNothingFound(R.string.network_error); } }); e.printStackTrace(); @@ -133,7 +142,7 @@ public class SearchWorker { h.post(new Runnable() { @Override public void run() { - searchWorkerResultListner.onError(e.getMessage()); + searchWorkerResultListener.onError(e.getMessage()); } }); } catch(ExtractionException e) { @@ -155,7 +164,7 @@ public class SearchWorker { } private static SearchWorker searchWorker = null; - private SearchWorkerResultListner searchWorkerResultListner = null; + private SearchWorkerResultListener searchWorkerResultListener = null; private SearchRunnable runnable = null; private int requestId = 0; //prevents running requests that have already ben expired @@ -163,8 +172,8 @@ public class SearchWorker { return searchWorker == null ? (searchWorker = new SearchWorker()) : searchWorker; } - public void setSearchWorkerResultListner(SearchWorkerResultListner listener) { - searchWorkerResultListner = listener; + public void setSearchWorkerResultListener(SearchWorkerResultListener listener) { + searchWorkerResultListener = listener; } private SearchWorker() {