SHARE
TWEET

Untitled

a guest Aug 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static final String API_KEY = "2e08750083b7e21e96e915011d3f8e2d";
  2. private static final String TAG = SearchAdapter.class.getSimpleName();
  3. private RecyclerView recyclerView;
  4.  
  5. public Search() {
  6.     // Required empty public constructor
  7. }
  8.  
  9. @Override
  10. public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,
  11.                          Bundle savedInstanceState) {
  12.     View view = inflater.inflate(R.layout.fragment_search, container, false);
  13.  
  14.     SearchView searchView = view.findViewById(R.id.search_view);
  15.     recyclerView = view.findViewById(R.id.search_result_tv);
  16.  
  17.     RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
  18.     recyclerView.setLayoutManager(layoutManager);
  19.  
  20.     searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
  21.         @Override
  22.         public boolean onQueryTextSubmit(String s) {
  23.             loadData(s);
  24.             return false;
  25.         }
  26.  
  27.         @Override
  28.         public boolean onQueryTextChange(String s) {
  29.             return false;
  30.         }
  31.     });
  32.  
  33.     return view;
  34. }
  35.  
  36. private void loadData(String s) {
  37.  
  38.     ApiInterface apiInterface = ApiClient.getList().create(ApiInterface.class);
  39.  
  40.     Call<Response> responseCall = apiInterface.getMovieSearch(API_KEY, s);
  41.     responseCall.enqueue(new Callback<Response>() {
  42.         @Override
  43.         public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
  44.  
  45.             /* Load search from String here */
  46.             ArrayList<ResultsItem> resultsItemList;
  47.             if (response.body() != null) {
  48.                 resultsItemList = (ArrayList<ResultsItem>) response.body().getResults();
  49.  
  50.                 SearchAdapter searchAdapter = new SearchAdapter(resultsItemList, getContext());
  51.                 recyclerView.setAdapter(searchAdapter);
  52.  
  53.             } else {
  54.                 Log.d("NoResponse", "response null");
  55.             }
  56.         }
  57.  
  58.         @Override
  59.         public void onFailure(@NotNull Call<Response> call, Throwable t) {
  60.             Log.d(TAG, t.toString());
  61.         }
  62.     });
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top