1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 17:10:33 +00:00

Change the way to start reCaptchaActivity

* Use startActivityForResult() and onActivityResult() to refresh the
  search request when returning from reCaptcha activity.
This commit is contained in:
Benoît Mauduit 2017-01-03 14:25:22 +01:00
parent 143df9a529
commit c9edac2820

View File

@ -8,6 +8,7 @@ import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -28,6 +29,9 @@ import org.schabi.newpipe.detail.VideoItemDetailActivity;
import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.detail.VideoItemDetailFragment;
import org.schabi.newpipe.info_list.InfoListAdapter; 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. * Created by Christian Schabesberger on 02.08.16.
* *
@ -180,9 +184,11 @@ public class SearchInfoItemFragment extends Fragment {
public void onReCaptchaChallenge() { public void onReCaptchaChallenge() {
Toast.makeText(getActivity(), "ReCaptcha Challenge requested", Toast.makeText(getActivity(), "ReCaptcha Challenge requested",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
// Starting ReCaptcha Challenge Activity // Starting ReCaptcha Challenge Activity
Intent i = new Intent(getActivity(), ReCaptchaActivity.class); startActivityForResult(
getActivity().startActivity(i); new Intent(getActivity(), ReCaptchaActivity.class),
RECAPTCHA_REQUEST);
} }
}); });
} }
@ -289,4 +295,23 @@ public class SearchInfoItemFragment extends Fragment {
Thread suggestionThread = new Thread(suggestionSearchRunnable); Thread suggestionThread = new Thread(suggestionSearchRunnable);
suggestionThread.start(); 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;
}
}
} }