Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.01 KB | None | 0 0
  1. public static boolean running_wishlist_query = false;
  2.  
  3. private ViewPager productImagesViewPager;
  4. private TextView productTitle;
  5. private TextView averageratingMiniView;
  6. private TextView totalratingMiniView;
  7. private TextView productPrice;
  8. private TextView cuttedPrice;
  9. private ImageView codIndicator;
  10. private TextView tvCodIndicator;
  11. private TabLayout viewpagerIndicator;
  12.  
  13. private Button couponReedenBtn;
  14. private LinearLayout couponReedemtionLayout;
  15.  
  16. ///////////coupondialog
  17.  
  18. public static TextView couponTitle;
  19. public static TextView couponExpirydate;
  20. public static TextView couponBody;
  21. private static RecyclerView coupenRecyclerview;
  22. private static LinearLayout selectedCoupen;
  23.  
  24. /////////coupondialog
  25.  
  26. private TextView productOnlyDescriptionBody;
  27.  
  28. private List<ProductSpecificationModel> productSpecificationModelList = new ArrayList<>();
  29. private String productDescription;
  30. private String productOtherDetails;
  31.  
  32.  
  33. private TextView rewardTitle;
  34. private TextView rewardBody;
  35.  
  36. private ViewPager productDetailsViewpager;
  37. private TabLayout productDetailsTablayout;
  38.  
  39.  
  40. public static LinearLayout rateNowContainer;
  41.  
  42. ///Product Description
  43. private ConstraintLayout productDetailsOnlyContainer;
  44. private ConstraintLayout productDetailsTabsContainer;
  45.  
  46.  
  47. ///Product Description
  48.  
  49. ////////rating layout
  50.  
  51.  
  52. private TextView totalRatings;
  53. private LinearLayout ratingsNoContainer;
  54. private TextView totalRatingsFigure;
  55. private LinearLayout ratingProgressBarContainer;
  56. private TextView averageRating;
  57.  
  58. private Button buyNowBtn;
  59. private LinearLayout addToCartBtn;
  60. private Dialog signInDialog;
  61. private FirebaseUser currentUser;
  62.  
  63.  
  64. ////////rating layout
  65.  
  66. public static boolean ALLREADY_ADDED_TO_WISHLIST = false;
  67. public static FloatingActionButton addToWishlistBtn;
  68.  
  69. private FirebaseFirestore firebaseFirestore;
  70.  
  71. public static String productID;
  72. private Dialog loadingDialog;
  73.  
  74. private DocumentSnapshot documentSnapshot;
  75.  
  76.  
  77. @Override
  78. protected void onCreate(Bundle savedInstanceState) {
  79. super.onCreate(savedInstanceState);
  80. setContentView(R.layout.activity_product_details);
  81. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  82. setSupportActionBar(toolbar);
  83. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  84.  
  85. productImagesViewPager = findViewById(R.id.product_image_viewpager);
  86. viewpagerIndicator = findViewById(R.id.viewpager_indicator);
  87. addToWishlistBtn = findViewById(R.id.add_to_wishlist_btn);
  88. productDetailsViewpager = findViewById(R.id.product_details_viewpager);
  89. productDetailsTablayout = findViewById(R.id.product_details_tablayout);
  90. buyNowBtn = findViewById(R.id.buy_now_btn);
  91. productTitle = findViewById(R.id.product_title);
  92. averageratingMiniView = findViewById(R.id.tv_product_rating_miniview);
  93. totalratingMiniView = findViewById(R.id.total_rating_miniview);
  94. productPrice = findViewById(R.id.product_price);
  95. cuttedPrice = findViewById(R.id.cutted_price);
  96. tvCodIndicator = findViewById(R.id.tv_cod_indicator);
  97. codIndicator = findViewById(R.id.cod_indicator_imageview);
  98. rewardTitle = findViewById(R.id.reward_title);
  99. rewardBody = findViewById(R.id.reward_body);
  100. productDetailsTabsContainer = findViewById(R.id.product_details_tab_container);
  101. productDetailsOnlyContainer = findViewById(R.id.product_details_container);
  102. productOnlyDescriptionBody = findViewById(R.id.product_details_body);
  103. totalRatings = findViewById(R.id.total_ratings);
  104. ratingsNoContainer = findViewById(R.id.ratings_numbers_container);
  105. totalRatingsFigure = findViewById(R.id.total_ratings_feagure);
  106. ratingProgressBarContainer = findViewById(R.id.ratings_progressbar_container);
  107. averageRating = findViewById(R.id.average_rating);
  108. couponReedenBtn = findViewById(R.id.coupon_redeemation_btn);
  109. addToCartBtn = findViewById(R.id.add_to_cart_btn);
  110. couponReedemtionLayout = findViewById(R.id.coupon_redeemation_layout);
  111.  
  112. loadingDialog = new Dialog(ProductDetailsActivity.this);
  113. loadingDialog.setContentView(R.layout.loading_progress_dialog);
  114. loadingDialog.setCancelable(false);
  115. loadingDialog.getWindow().setBackgroundDrawable(getDrawable(R.drawable.slider_background));
  116. loadingDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  117. loadingDialog.show();
  118.  
  119.  
  120. firebaseFirestore = FirebaseFirestore.getInstance();
  121.  
  122.  
  123. final List<String> productImages = new ArrayList<>();
  124. productID = getIntent().getStringExtra("PRODUCT_ID");
  125. firebaseFirestore.collection("PRODUCTS").document(productID)
  126. .get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
  127. @Override
  128. public void onComplete(@NonNull Task<DocumentSnapshot> task) {
  129. if (task.isSuccessful()) {
  130.  
  131. documentSnapshot = task.getResult();
  132. for (long x = 1; x < (long) documentSnapshot.get("no_of_product_images") + 1; x++) {
  133. productImages.add(documentSnapshot.get("product_image_"+x).toString());
  134. }
  135. ProductImagesAdapter productImagesAdapter = new ProductImagesAdapter(productImages);
  136. productImagesViewPager.setAdapter(productImagesAdapter);
  137.  
  138. productTitle.setText(documentSnapshot.get("product_title").toString());
  139. averageratingMiniView.setText(documentSnapshot.get("average_rating").toString());
  140. totalratingMiniView.setText("(" + (long) documentSnapshot.get("total_ratings") + ")ratings");
  141. productPrice.setText("Rs." + documentSnapshot.get("product_price").toString() + "/-");
  142. cuttedPrice.setText("Rs." + documentSnapshot.get("cutted_price").toString() + "/-");
  143. if ((boolean) documentSnapshot.get("COD")) {
  144. codIndicator.setVisibility(View.VISIBLE);
  145. tvCodIndicator.setVisibility(View.VISIBLE);
  146. } else {
  147. codIndicator.setVisibility(View.INVISIBLE);
  148. tvCodIndicator.setVisibility(View.INVISIBLE);
  149. }
  150. rewardTitle.setText((long) documentSnapshot.get("free_coupens") + documentSnapshot.get("free_coupen_title").toString());
  151. rewardBody.setText(documentSnapshot.get("free_coupen_body").toString());
  152.  
  153. if ((boolean) documentSnapshot.get("use_tab_layout")) {
  154. productDetailsTabsContainer.setVisibility(View.VISIBLE);
  155. productDetailsOnlyContainer.setVisibility(View.GONE);
  156. productDescription = documentSnapshot.get("product_description").toString();
  157.  
  158. productOtherDetails = documentSnapshot.get("product_other_details").toString();
  159.  
  160. for (long x = 1; x < (long) documentSnapshot.get("total_spec_titles") + 1; x++) {
  161. productSpecificationModelList.add(new ProductSpecificationModel(0, documentSnapshot.get("spec_title_" + x).toString()));
  162. for (long y = 1; y < (long) documentSnapshot.get("spec_title_" + x + "_total_fields") + 1; y++) {
  163. productSpecificationModelList.add(new ProductSpecificationModel(1, documentSnapshot.get("spec_title_" + x + "_field_" + y + "_name").toString(), documentSnapshot.get("spec_title_" + x + "_field_" + y + "_value").toString()));
  164. }
  165. }
  166. } else {
  167. productDetailsTabsContainer.setVisibility(View.GONE);
  168. productDetailsOnlyContainer.setVisibility(View.VISIBLE);
  169. productOnlyDescriptionBody.setText(documentSnapshot.get("product_description").toString());
  170. }
  171.  
  172. totalRatings.setText((long) documentSnapshot.get("total_ratings") + "ratings");
  173.  
  174. for (int x = 0; x < 5; x++) {
  175. TextView rating = (TextView) ratingsNoContainer.getChildAt(x);
  176. rating.setText(String.valueOf((long) documentSnapshot.get(5 - x + "_star")));
  177.  
  178. ProgressBar progressBar = (ProgressBar) ratingProgressBarContainer.getChildAt(x);
  179. int maxProgress = Integer.parseInt(String.valueOf((long) documentSnapshot.get("total_ratings")));
  180. progressBar.setMax(maxProgress);
  181. progressBar.setProgress(Integer.parseInt(String.valueOf((long) documentSnapshot.get((5 - x) + "_star"))));
  182. }
  183. totalRatingsFigure.setText(String.valueOf((long) documentSnapshot.get("total_ratings")));
  184. averageRating.setText(documentSnapshot.get("average_rating").toString());
  185. productDetailsViewpager.setAdapter(new ProductDetailsAdapter(getSupportFragmentManager(), productDetailsTablayout.getTabCount(), productDescription, productOtherDetails, productSpecificationModelList));
  186.  
  187. if (currentUser != null) {
  188. if (DBqueries.myRating.size() == 0) {
  189. DBqueries.loadRating(ProductDetailsActivity.this);
  190. }
  191. if (DBqueries.wishList.size() == 0) {
  192. DBqueries.loadWishList(ProductDetailsActivity.this, loadingDialog, false);
  193. } else {
  194. loadingDialog.dismiss();
  195. }
  196. } else {
  197. loadingDialog.dismiss();
  198. }
  199. if (DBqueries.wishList.contains(productID)) {
  200. ALLREADY_ADDED_TO_WISHLIST = true;
  201. addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
  202. } else {
  203. addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
  204. ALLREADY_ADDED_TO_WISHLIST = false;
  205. }
  206.  
  207. } else {
  208. loadingDialog.dismiss();
  209. String error = task.getException().getMessage();
  210. Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
  211. }
  212. }
  213. });
  214. viewpagerIndicator.setupWithViewPager(productImagesViewPager, true);
  215.  
  216. addToWishlistBtn.setOnClickListener(new View.OnClickListener() {
  217. @Override
  218. public void onClick(View v) {
  219. if (currentUser == null) {
  220. signInDialog.show();
  221. } else {
  222.  
  223. if (!running_wishlist_query) {
  224. running_wishlist_query = true;
  225.  
  226. if (ALLREADY_ADDED_TO_WISHLIST) {
  227. int index = DBqueries.wishList.indexOf(productID);
  228. DBqueries.removeFromWishlist(index, ProductDetailsActivity.this);
  229. ALLREADY_ADDED_TO_WISHLIST = false;
  230. addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
  231. } else {
  232. Map<String, Object> addProduct = new HashMap<>();
  233. addProduct.put("product_ID_" + String.valueOf(DBqueries.wishList.size()), productID);
  234.  
  235. firebaseFirestore.collection("USERS").document(currentUser.getUid()).collection("USER_DATA").document("MY_WISHLIST")
  236. .update(addProduct).addOnCompleteListener(new OnCompleteListener<Void>() {
  237. @Override
  238. public void onComplete(@NonNull Task<Void> task) {
  239. if (task.isSuccessful()) {
  240.  
  241. Map<String, Object> updateListSize = new HashMap<>();
  242. updateListSize.put("list_size", (long) (DBqueries.wishList.size() + 1));
  243.  
  244. firebaseFirestore.collection("USERS").document(currentUser.getUid()).collection("USER_DATA").document("MY_WISHLIST")
  245. .update(updateListSize).addOnCompleteListener(new OnCompleteListener<Void>() {
  246. @Override
  247. public void onComplete(@NonNull Task<Void> task) {
  248. if (task.isSuccessful()) {
  249.  
  250. if (DBqueries.wishlistModelList.size() != 0) {
  251.  
  252. DBqueries.wishlistModelList.add(new WishlistModel(productID, documentSnapshot.get("product_image_1").toString()
  253. , documentSnapshot.get("product_title").toString()
  254. , (long) documentSnapshot.get("free_coupens")
  255. , documentSnapshot.get("average_rating").toString()
  256. , (long) documentSnapshot.get("total_ratings")
  257. , documentSnapshot.get("product_price").toString()
  258. , documentSnapshot.get("cutted_price").toString()
  259. , (boolean) documentSnapshot.get("COD")));
  260. }
  261.  
  262.  
  263. ALLREADY_ADDED_TO_WISHLIST = true;
  264. addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
  265. DBqueries.wishList.add(productID);
  266. Toast.makeText(ProductDetailsActivity.this, "Product added successfully.", Toast.LENGTH_SHORT).show();
  267. } else {
  268. String error = task.getException().getMessage();
  269. Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
  270. }
  271. running_wishlist_query = false;
  272. }
  273. });
  274.  
  275. } else {
  276. running_wishlist_query = false;
  277. String error = task.getException().getMessage();
  278. Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
  279. }
  280. }
  281. });
  282.  
  283.  
  284. }
  285. }
  286. }
  287. }
  288. });
  289.  
  290.  
  291. productDetailsViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(productDetailsTablayout));
  292. productDetailsTablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
  293. @Override
  294. public void onTabSelected(TabLayout.Tab tab) {
  295. productImagesViewPager.setCurrentItem(tab.getPosition());
  296. }
  297.  
  298. @Override
  299. public void onTabUnselected(TabLayout.Tab tab) {
  300.  
  301. }
  302.  
  303. @Override
  304. public void onTabReselected(TabLayout.Tab tab) {
  305.  
  306. }
  307. });
  308.  
  309. ////////rating layout
  310. rateNowContainer = findViewById(R.id.rate_now_container);
  311. for (int x = 0; x < rateNowContainer.getChildCount(); x++) {
  312. final int starPosition = x;
  313. rateNowContainer.getChildAt(x).setOnClickListener(new View.OnClickListener() {
  314. @Override
  315. public void onClick(View view) {
  316. if (currentUser == null) {
  317. signInDialog.show();
  318. } else {
  319. setRating(starPosition);
  320. }
  321. }
  322. });
  323. }
  324.  
  325. ////////rating layout
  326.  
  327. buyNowBtn.setOnClickListener(new View.OnClickListener() {
  328. @Override
  329. public void onClick(View v) {
  330. if (currentUser == null) {
  331. signInDialog.show();
  332. } else {
  333. Intent deliveryIntent = new Intent(ProductDetailsActivity.this, DeliveryActivity.class);
  334. startActivity(deliveryIntent);
  335. }
  336. }
  337. });
  338. addToCartBtn.setOnClickListener(new View.OnClickListener() {
  339. @Override
  340. public void onClick(View v) {
  341. if (currentUser == null) {
  342. signInDialog.show();
  343. } else {
  344. ////////todo aff to cart
  345. }
  346. }
  347. });
  348.  
  349. /////////////////
  350.  
  351. final Dialog checkCoupenPriceDialog = new Dialog(ProductDetailsActivity.this);
  352. checkCoupenPriceDialog.setContentView(R.layout.coupon_redeem_dialog);
  353. checkCoupenPriceDialog.setCancelable(true);
  354. checkCoupenPriceDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  355.  
  356. ImageView toggleRecyclerView = checkCoupenPriceDialog.findViewById(R.id.toggle_recyclerview);
  357. coupenRecyclerview = checkCoupenPriceDialog.findViewById(R.id.coupons_recyclerview);
  358. selectedCoupen = checkCoupenPriceDialog.findViewById(R.id.selected_coupon);
  359.  
  360. couponTitle = checkCoupenPriceDialog.findViewById(R.id.coupen_title);
  361. couponExpirydate = checkCoupenPriceDialog.findViewById(R.id.coupen_validity);
  362. couponBody = checkCoupenPriceDialog.findViewById(R.id.coupen_body);
  363.  
  364.  
  365. TextView originalPrice = checkCoupenPriceDialog.findViewById(R.id.original_price);
  366. TextView discountedPrice = checkCoupenPriceDialog.findViewById(R.id.discount_price);
  367.  
  368. LinearLayoutManager layoutManager = new LinearLayoutManager(ProductDetailsActivity.this);
  369. layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  370. coupenRecyclerview.setLayoutManager(layoutManager);
  371.  
  372. List<RewardModel> rewardModelList = new ArrayList<>();
  373. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  374. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  375. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  376. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  377. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  378. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  379. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  380. rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
  381.  
  382. MyRewardsAdapter myRewardsAdapter = new MyRewardsAdapter(rewardModelList, true);
  383. coupenRecyclerview.setAdapter(myRewardsAdapter);
  384. myRewardsAdapter.notifyDataSetChanged();
  385.  
  386. toggleRecyclerView.setOnClickListener(new View.OnClickListener() {
  387. @Override
  388. public void onClick(View v) {
  389. showDialogRecyclerView();
  390. }
  391. });
  392.  
  393. //////////////
  394.  
  395. couponReedenBtn.setOnClickListener(new View.OnClickListener() {
  396. @Override
  397. public void onClick(View v) {
  398.  
  399. checkCoupenPriceDialog.show();
  400. }
  401. });
  402. /////////////coupon dialog
  403.  
  404. /////////////signin dialog
  405. signInDialog = new Dialog(ProductDetailsActivity.this);
  406. signInDialog.setContentView(R.layout.sign_in_dialog);
  407. signInDialog.setCancelable(true);
  408. signInDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  409.  
  410. Button dialogSignInBtn = signInDialog.findViewById(R.id.sign_in_btn);
  411. Button dialogSignUpBtn = signInDialog.findViewById(R.id.sign_up_btn);
  412. final Intent registerIntent = new Intent(ProductDetailsActivity.this, RegisterActivity.class);
  413.  
  414. dialogSignInBtn.setOnClickListener(new View.OnClickListener() {
  415. @Override
  416. public void onClick(View v) {
  417. SignInFragment.disableCloseBtn = true;
  418. SignUpFragment.disableCloseBtn = true;
  419. signInDialog.dismiss();
  420. setSignUpFragment = false;
  421. startActivity(registerIntent);
  422. }
  423. });
  424.  
  425. dialogSignUpBtn.setOnClickListener(new View.OnClickListener() {
  426. @Override
  427. public void onClick(View v) {
  428. SignInFragment.disableCloseBtn = true;
  429. SignUpFragment.disableCloseBtn = true;
  430. signInDialog.dismiss();
  431. setSignUpFragment = false;
  432. startActivity(registerIntent);
  433. }
  434. });
  435.  
  436.  
  437. //////////signin dialog
  438.  
  439.  
  440. }
  441.  
  442. @Override
  443. protected void onStart() {
  444. super.onStart();
  445. currentUser = FirebaseAuth.getInstance().getCurrentUser();
  446. if (currentUser == null) {
  447. couponReedemtionLayout.setVisibility(View.GONE);
  448. } else {
  449. couponReedemtionLayout.setVisibility(View.VISIBLE);
  450. }
  451. if (currentUser != null) {
  452. if (DBqueries.myRating.size() == 0) {
  453. DBqueries.loadRating(ProductDetailsActivity.this);
  454. }
  455. if (DBqueries.wishList.size() == 0) {
  456. DBqueries.loadWishList(ProductDetailsActivity.this, loadingDialog, false);
  457. } else {
  458. loadingDialog.dismiss();
  459. }
  460. } else {
  461. loadingDialog.dismiss();
  462. }
  463. if (DBqueries.wishList.contains(productID)) {
  464. ALLREADY_ADDED_TO_WISHLIST = true;
  465. addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
  466. } else {
  467. addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
  468. ALLREADY_ADDED_TO_WISHLIST = false;
  469. }
  470. }
  471.  
  472. public static void showDialogRecyclerView() {
  473. if (coupenRecyclerview.getVisibility() == View.GONE) {
  474. coupenRecyclerview.setVisibility(View.VISIBLE);
  475. selectedCoupen.setVisibility(View.GONE);
  476. } else {
  477. coupenRecyclerview.setVisibility(View.GONE);
  478. selectedCoupen.setVisibility(View.VISIBLE);
  479. }
  480. }
  481.  
  482. public static void setRating(int starPosition) {
  483. for (int x = 0; x < rateNowContainer.getChildCount(); x++) {
  484. ImageView starBtn = (ImageView) rateNowContainer.getChildAt(x);
  485. starBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#b7b6b6")));
  486. if (x <= starPosition) {
  487. starBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#6600FF")));
  488. }
  489. }
  490. }
  491.  
  492. @Override
  493. public boolean onCreateOptionsMenu(Menu menu) {
  494. // Inflate the menu; this adds items to the action bar if it is present.
  495. getMenuInflater().inflate(R.menu.search_and_cart_icon, menu);
  496. return true;
  497. }
  498.  
  499. @Override
  500. public boolean onOptionsItemSelected(MenuItem item) {
  501. // Handle action bar item clicks here. The action bar will
  502. // automatically handle clicks on the Home/Up button, so long
  503. // as you specify a parent activity in AndroidManifest.xml.
  504. int id = item.getItemId();
  505.  
  506. //noinspection SimplifiableIfStatement
  507. if (id == android.R.id.home) {
  508. finish();
  509. return true;
  510. } else if (id == R.id.action_search) {
  511. return true;
  512. } else if (id == R.id.action_cart_icon) {
  513. if (currentUser == null) {
  514. signInDialog.show();
  515. } else {
  516. Intent cartIntent = new Intent(ProductDetailsActivity.this, MainActivity.class);
  517. showCart = true;
  518. startActivity(cartIntent);
  519. return true;
  520. }
  521. }
  522.  
  523. return super.onOptionsItemSelected(item);
  524. }
  525.  
  526. public static FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
  527. public static List<CategoryModal> categoryModalList = new ArrayList<>();
  528.  
  529. public static List<List<HomePageModel>> lists = new ArrayList<>();
  530. public static List<String> loadedCategoriesName = new ArrayList<>();
  531. public static List<String> wishList = new ArrayList<>();
  532. public static List<WishlistModel> wishlistModelList = new ArrayList<>();
  533.  
  534. public static List<String> myRatedIds = new ArrayList<>();
  535. public static List<Long> myRating = new ArrayList<>();
  536.  
  537. public static void loadCategories(final RecyclerView categoryRecyclerView, final Context context) {
  538. categoryModalList.clear();
  539. firebaseFirestore.collection("CATEGORIES").orderBy("index").get()
  540. .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
  541. @Override
  542. public void onComplete(@NonNull Task<QuerySnapshot> task) {
  543. if (task.isSuccessful()) {
  544. for (DocumentSnapshot documentSnapshot : task.getResult()) {
  545. categoryModalList.add(new CategoryModal(documentSnapshot.get("icon").toString(), documentSnapshot.get("categoryName").toString()));
  546. }
  547. CategoryAdapter categoryAdapter = new CategoryAdapter(categoryModalList);
  548. categoryRecyclerView.setAdapter(categoryAdapter);
  549. categoryAdapter.notifyDataSetChanged();
  550. } else {
  551. String error = task.getException().getMessage();
  552. Toast.makeText(context, error, Toast.LENGTH_SHORT).show();
  553. }
  554. }
  555. });
  556. }
  557.  
  558. public static void loadFragmentData(final RecyclerView homePageRecyclerView, final Context context, final int index, String categoryName) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement