Start reCaptchaActivity when reCaptcha is requested and fix Typo

* Fix typo setSearchWorkerResultListner to setSearchWorkerResultListener
This commit is contained in:
Benoît Mauduit 2016-12-07 22:19:43 +01:00
parent a5ac528c02
commit 53796043c3
2 changed files with 27 additions and 8 deletions

View file

@ -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);
}
});
}

View file

@ -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() {