Guest User

Untitled

a guest
Oct 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. package com.example.senamit.stationaryhutpro.fragments;
  2.  
  3. import android.content.Context;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9.  
  10. import com.example.senamit.stationaryhutpro.R;
  11. import com.example.senamit.stationaryhutpro.adapters.FilterCategoryAdapter;
  12. import com.example.senamit.stationaryhutpro.interfaces.FilterCategoryInterface;
  13. import com.example.senamit.stationaryhutpro.models.FilterCategoryModel;
  14. import com.example.senamit.stationaryhutpro.viewModels.ProductCategoryViewModel;
  15.  
  16. import java.util.List;
  17.  
  18. import androidx.annotation.NonNull;
  19. import androidx.annotation.Nullable;
  20. import androidx.fragment.app.Fragment;
  21. import androidx.lifecycle.Observer;
  22. import androidx.lifecycle.ViewModelProviders;
  23. import androidx.recyclerview.widget.LinearLayoutManager;
  24. import androidx.recyclerview.widget.RecyclerView;
  25.  
  26. public class FilterCategory extends Fragment implements FilterCategoryInterface {
  27.  
  28. private static final String TAG = FilterCategory.class.getSimpleName();
  29. private Context context;
  30. private String productCategory;
  31.  
  32. private RecyclerView mRecyclerView;
  33. private RecyclerView.LayoutManager mLayoutManager;
  34. private FilterCategoryAdapter mAdapter;
  35. private ProductCategoryViewModel mViewModel;
  36.  
  37. @Override
  38. public void onCreate(@Nullable Bundle savedInstanceState) {
  39. super.onCreate(savedInstanceState);
  40. //keep it in mind to get the context, might be i m wrong here
  41. context= getActivity();
  42. Log.i(TAG, "the context is "+context.toString());
  43. mViewModel = ViewModelProviders.of(getActivity()).get(ProductCategoryViewModel.class);
  44. }
  45.  
  46. @Nullable
  47. @Override
  48. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  49.  
  50. // context = container.getContext();
  51. View view = inflater.inflate(R.layout.activity_filter_category, container, false);
  52. return view;
  53. }
  54.  
  55. @Override
  56. public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  57. super.onViewCreated(view, savedInstanceState);
  58.  
  59. mRecyclerView = view.findViewById(R.id.reycler_category);
  60. mLayoutManager = new LinearLayoutManager(context);
  61. mAdapter = new FilterCategoryAdapter(context, this);
  62. mRecyclerView.setLayoutManager(mLayoutManager);
  63. mRecyclerView.setAdapter(mAdapter);
  64.  
  65. productCategory = mViewModel.getProductCategoryName();
  66. mViewModel.getFilterCategory(productCategory).observe(this, new Observer<List<FilterCategoryModel>>() {
  67. @Override
  68. public void onChanged(List<FilterCategoryModel> filterCategoryModels) {
  69. if (filterCategoryModels!= null){
  70. Log.i(TAG, "the size of list is "+filterCategoryModels.size());
  71. mAdapter.setCategory(filterCategoryModels);
  72. }else {
  73. Log.i(TAG, "the size of list is null");
  74. }
  75. }
  76. });
  77. }
  78.  
  79. @Override
  80. public void funFilterCategoty(String filterCategorySelection) {
  81. mViewModel.setFilterCategorySelected(filterCategorySelection);
  82. }
  83. }
Add Comment
Please, Sign In to add comment