Guest User

Untitled

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public class RecipesFragment extends Fragment implements Callback<List<Recipe>> {
  2.  
  3. private FragmentRecipesBinding mBinding = null;
  4.  
  5. public RecipesFragment() {}
  6.  
  7. @Nullable
  8. @Override
  9. public View onCreateView(
  10. @NonNull LayoutInflater inflater,
  11. @Nullable ViewGroup container,
  12. @Nullable Bundle savedInstanceState)
  13. {
  14. mBinding = DataBindingUtil.inflate(
  15. inflater,
  16. R.layout.fragment_recipes,
  17. container,
  18. false);
  19.  
  20. LinearLayoutManager layoutManager =
  21. new LinearLayoutManager(getContext(),
  22. LinearLayoutManager.VERTICAL,
  23. false);
  24.  
  25. AppAdapter<Recipe, RecipeView<Recipe>> adapter = new AppAdapter<>();
  26.  
  27. mBinding.rvRecipes.setAdapter(adapter);
  28. mBinding.rvRecipes.setLayoutManager(layoutManager);
  29. mBinding.rvRecipes.setHasFixedSize(true);
  30.  
  31. return mBinding.getRoot();
  32. }
  33.  
  34. @Override
  35. public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) {
  36. if (response != null && response.body() != null) {
  37. AppAdapter<Recipe, RecipeView<Recipe>> adapter = null;
  38.  
  39. // Warning of unchecked cast.
  40. if (mBinding.rvRecipes.getAdapter() instanceof AppAdapter) {
  41. adapter = (AppAdapter) mBinding.rvRecipes.getAdapter();
  42.  
  43. adapter.setData(response.body());
  44. }
  45. }
  46. }
  47.  
  48. @Override
  49. public void onFailure(Call<List<Recipe>> call, Throwable t) {
  50.  
  51. }
  52. }
Add Comment
Please, Sign In to add comment