Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean running_wishlist_query = false;
- private ViewPager productImagesViewPager;
- private TextView productTitle;
- private TextView averageratingMiniView;
- private TextView totalratingMiniView;
- private TextView productPrice;
- private TextView cuttedPrice;
- private ImageView codIndicator;
- private TextView tvCodIndicator;
- private TabLayout viewpagerIndicator;
- private Button couponReedenBtn;
- private LinearLayout couponReedemtionLayout;
- ///////////coupondialog
- public static TextView couponTitle;
- public static TextView couponExpirydate;
- public static TextView couponBody;
- private static RecyclerView coupenRecyclerview;
- private static LinearLayout selectedCoupen;
- /////////coupondialog
- private TextView productOnlyDescriptionBody;
- private List<ProductSpecificationModel> productSpecificationModelList = new ArrayList<>();
- private String productDescription;
- private String productOtherDetails;
- private TextView rewardTitle;
- private TextView rewardBody;
- private ViewPager productDetailsViewpager;
- private TabLayout productDetailsTablayout;
- public static LinearLayout rateNowContainer;
- ///Product Description
- private ConstraintLayout productDetailsOnlyContainer;
- private ConstraintLayout productDetailsTabsContainer;
- ///Product Description
- ////////rating layout
- private TextView totalRatings;
- private LinearLayout ratingsNoContainer;
- private TextView totalRatingsFigure;
- private LinearLayout ratingProgressBarContainer;
- private TextView averageRating;
- private Button buyNowBtn;
- private LinearLayout addToCartBtn;
- private Dialog signInDialog;
- private FirebaseUser currentUser;
- ////////rating layout
- public static boolean ALLREADY_ADDED_TO_WISHLIST = false;
- public static FloatingActionButton addToWishlistBtn;
- private FirebaseFirestore firebaseFirestore;
- public static String productID;
- private Dialog loadingDialog;
- private DocumentSnapshot documentSnapshot;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_product_details);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- productImagesViewPager = findViewById(R.id.product_image_viewpager);
- viewpagerIndicator = findViewById(R.id.viewpager_indicator);
- addToWishlistBtn = findViewById(R.id.add_to_wishlist_btn);
- productDetailsViewpager = findViewById(R.id.product_details_viewpager);
- productDetailsTablayout = findViewById(R.id.product_details_tablayout);
- buyNowBtn = findViewById(R.id.buy_now_btn);
- productTitle = findViewById(R.id.product_title);
- averageratingMiniView = findViewById(R.id.tv_product_rating_miniview);
- totalratingMiniView = findViewById(R.id.total_rating_miniview);
- productPrice = findViewById(R.id.product_price);
- cuttedPrice = findViewById(R.id.cutted_price);
- tvCodIndicator = findViewById(R.id.tv_cod_indicator);
- codIndicator = findViewById(R.id.cod_indicator_imageview);
- rewardTitle = findViewById(R.id.reward_title);
- rewardBody = findViewById(R.id.reward_body);
- productDetailsTabsContainer = findViewById(R.id.product_details_tab_container);
- productDetailsOnlyContainer = findViewById(R.id.product_details_container);
- productOnlyDescriptionBody = findViewById(R.id.product_details_body);
- totalRatings = findViewById(R.id.total_ratings);
- ratingsNoContainer = findViewById(R.id.ratings_numbers_container);
- totalRatingsFigure = findViewById(R.id.total_ratings_feagure);
- ratingProgressBarContainer = findViewById(R.id.ratings_progressbar_container);
- averageRating = findViewById(R.id.average_rating);
- couponReedenBtn = findViewById(R.id.coupon_redeemation_btn);
- addToCartBtn = findViewById(R.id.add_to_cart_btn);
- couponReedemtionLayout = findViewById(R.id.coupon_redeemation_layout);
- loadingDialog = new Dialog(ProductDetailsActivity.this);
- loadingDialog.setContentView(R.layout.loading_progress_dialog);
- loadingDialog.setCancelable(false);
- loadingDialog.getWindow().setBackgroundDrawable(getDrawable(R.drawable.slider_background));
- loadingDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- loadingDialog.show();
- firebaseFirestore = FirebaseFirestore.getInstance();
- final List<String> productImages = new ArrayList<>();
- productID = getIntent().getStringExtra("PRODUCT_ID");
- firebaseFirestore.collection("PRODUCTS").document(productID)
- .get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
- @Override
- public void onComplete(@NonNull Task<DocumentSnapshot> task) {
- if (task.isSuccessful()) {
- documentSnapshot = task.getResult();
- for (long x = 1; x < (long) documentSnapshot.get("no_of_product_images") + 1; x++) {
- productImages.add(documentSnapshot.get("product_image_"+x).toString());
- }
- ProductImagesAdapter productImagesAdapter = new ProductImagesAdapter(productImages);
- productImagesViewPager.setAdapter(productImagesAdapter);
- productTitle.setText(documentSnapshot.get("product_title").toString());
- averageratingMiniView.setText(documentSnapshot.get("average_rating").toString());
- totalratingMiniView.setText("(" + (long) documentSnapshot.get("total_ratings") + ")ratings");
- productPrice.setText("Rs." + documentSnapshot.get("product_price").toString() + "/-");
- cuttedPrice.setText("Rs." + documentSnapshot.get("cutted_price").toString() + "/-");
- if ((boolean) documentSnapshot.get("COD")) {
- codIndicator.setVisibility(View.VISIBLE);
- tvCodIndicator.setVisibility(View.VISIBLE);
- } else {
- codIndicator.setVisibility(View.INVISIBLE);
- tvCodIndicator.setVisibility(View.INVISIBLE);
- }
- rewardTitle.setText((long) documentSnapshot.get("free_coupens") + documentSnapshot.get("free_coupen_title").toString());
- rewardBody.setText(documentSnapshot.get("free_coupen_body").toString());
- if ((boolean) documentSnapshot.get("use_tab_layout")) {
- productDetailsTabsContainer.setVisibility(View.VISIBLE);
- productDetailsOnlyContainer.setVisibility(View.GONE);
- productDescription = documentSnapshot.get("product_description").toString();
- productOtherDetails = documentSnapshot.get("product_other_details").toString();
- for (long x = 1; x < (long) documentSnapshot.get("total_spec_titles") + 1; x++) {
- productSpecificationModelList.add(new ProductSpecificationModel(0, documentSnapshot.get("spec_title_" + x).toString()));
- for (long y = 1; y < (long) documentSnapshot.get("spec_title_" + x + "_total_fields") + 1; y++) {
- productSpecificationModelList.add(new ProductSpecificationModel(1, documentSnapshot.get("spec_title_" + x + "_field_" + y + "_name").toString(), documentSnapshot.get("spec_title_" + x + "_field_" + y + "_value").toString()));
- }
- }
- } else {
- productDetailsTabsContainer.setVisibility(View.GONE);
- productDetailsOnlyContainer.setVisibility(View.VISIBLE);
- productOnlyDescriptionBody.setText(documentSnapshot.get("product_description").toString());
- }
- totalRatings.setText((long) documentSnapshot.get("total_ratings") + "ratings");
- for (int x = 0; x < 5; x++) {
- TextView rating = (TextView) ratingsNoContainer.getChildAt(x);
- rating.setText(String.valueOf((long) documentSnapshot.get(5 - x + "_star")));
- ProgressBar progressBar = (ProgressBar) ratingProgressBarContainer.getChildAt(x);
- int maxProgress = Integer.parseInt(String.valueOf((long) documentSnapshot.get("total_ratings")));
- progressBar.setMax(maxProgress);
- progressBar.setProgress(Integer.parseInt(String.valueOf((long) documentSnapshot.get((5 - x) + "_star"))));
- }
- totalRatingsFigure.setText(String.valueOf((long) documentSnapshot.get("total_ratings")));
- averageRating.setText(documentSnapshot.get("average_rating").toString());
- productDetailsViewpager.setAdapter(new ProductDetailsAdapter(getSupportFragmentManager(), productDetailsTablayout.getTabCount(), productDescription, productOtherDetails, productSpecificationModelList));
- if (currentUser != null) {
- if (DBqueries.myRating.size() == 0) {
- DBqueries.loadRating(ProductDetailsActivity.this);
- }
- if (DBqueries.wishList.size() == 0) {
- DBqueries.loadWishList(ProductDetailsActivity.this, loadingDialog, false);
- } else {
- loadingDialog.dismiss();
- }
- } else {
- loadingDialog.dismiss();
- }
- if (DBqueries.wishList.contains(productID)) {
- ALLREADY_ADDED_TO_WISHLIST = true;
- addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
- } else {
- addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
- ALLREADY_ADDED_TO_WISHLIST = false;
- }
- } else {
- loadingDialog.dismiss();
- String error = task.getException().getMessage();
- Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
- }
- }
- });
- viewpagerIndicator.setupWithViewPager(productImagesViewPager, true);
- addToWishlistBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (currentUser == null) {
- signInDialog.show();
- } else {
- if (!running_wishlist_query) {
- running_wishlist_query = true;
- if (ALLREADY_ADDED_TO_WISHLIST) {
- int index = DBqueries.wishList.indexOf(productID);
- DBqueries.removeFromWishlist(index, ProductDetailsActivity.this);
- ALLREADY_ADDED_TO_WISHLIST = false;
- addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
- } else {
- Map<String, Object> addProduct = new HashMap<>();
- addProduct.put("product_ID_" + String.valueOf(DBqueries.wishList.size()), productID);
- firebaseFirestore.collection("USERS").document(currentUser.getUid()).collection("USER_DATA").document("MY_WISHLIST")
- .update(addProduct).addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if (task.isSuccessful()) {
- Map<String, Object> updateListSize = new HashMap<>();
- updateListSize.put("list_size", (long) (DBqueries.wishList.size() + 1));
- firebaseFirestore.collection("USERS").document(currentUser.getUid()).collection("USER_DATA").document("MY_WISHLIST")
- .update(updateListSize).addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if (task.isSuccessful()) {
- if (DBqueries.wishlistModelList.size() != 0) {
- DBqueries.wishlistModelList.add(new WishlistModel(productID, documentSnapshot.get("product_image_1").toString()
- , documentSnapshot.get("product_title").toString()
- , (long) documentSnapshot.get("free_coupens")
- , documentSnapshot.get("average_rating").toString()
- , (long) documentSnapshot.get("total_ratings")
- , documentSnapshot.get("product_price").toString()
- , documentSnapshot.get("cutted_price").toString()
- , (boolean) documentSnapshot.get("COD")));
- }
- ALLREADY_ADDED_TO_WISHLIST = true;
- addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
- DBqueries.wishList.add(productID);
- Toast.makeText(ProductDetailsActivity.this, "Product added successfully.", Toast.LENGTH_SHORT).show();
- } else {
- String error = task.getException().getMessage();
- Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
- }
- running_wishlist_query = false;
- }
- });
- } else {
- running_wishlist_query = false;
- String error = task.getException().getMessage();
- Toast.makeText(ProductDetailsActivity.this, error, Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
- }
- }
- });
- productDetailsViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(productDetailsTablayout));
- productDetailsTablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
- @Override
- public void onTabSelected(TabLayout.Tab tab) {
- productImagesViewPager.setCurrentItem(tab.getPosition());
- }
- @Override
- public void onTabUnselected(TabLayout.Tab tab) {
- }
- @Override
- public void onTabReselected(TabLayout.Tab tab) {
- }
- });
- ////////rating layout
- rateNowContainer = findViewById(R.id.rate_now_container);
- for (int x = 0; x < rateNowContainer.getChildCount(); x++) {
- final int starPosition = x;
- rateNowContainer.getChildAt(x).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (currentUser == null) {
- signInDialog.show();
- } else {
- setRating(starPosition);
- }
- }
- });
- }
- ////////rating layout
- buyNowBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (currentUser == null) {
- signInDialog.show();
- } else {
- Intent deliveryIntent = new Intent(ProductDetailsActivity.this, DeliveryActivity.class);
- startActivity(deliveryIntent);
- }
- }
- });
- addToCartBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (currentUser == null) {
- signInDialog.show();
- } else {
- ////////todo aff to cart
- }
- }
- });
- /////////////////
- final Dialog checkCoupenPriceDialog = new Dialog(ProductDetailsActivity.this);
- checkCoupenPriceDialog.setContentView(R.layout.coupon_redeem_dialog);
- checkCoupenPriceDialog.setCancelable(true);
- checkCoupenPriceDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- ImageView toggleRecyclerView = checkCoupenPriceDialog.findViewById(R.id.toggle_recyclerview);
- coupenRecyclerview = checkCoupenPriceDialog.findViewById(R.id.coupons_recyclerview);
- selectedCoupen = checkCoupenPriceDialog.findViewById(R.id.selected_coupon);
- couponTitle = checkCoupenPriceDialog.findViewById(R.id.coupen_title);
- couponExpirydate = checkCoupenPriceDialog.findViewById(R.id.coupen_validity);
- couponBody = checkCoupenPriceDialog.findViewById(R.id.coupen_body);
- TextView originalPrice = checkCoupenPriceDialog.findViewById(R.id.original_price);
- TextView discountedPrice = checkCoupenPriceDialog.findViewById(R.id.discount_price);
- LinearLayoutManager layoutManager = new LinearLayoutManager(ProductDetailsActivity.this);
- layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
- coupenRecyclerview.setLayoutManager(layoutManager);
- List<RewardModel> rewardModelList = new ArrayList<>();
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- rewardModelList.add(new RewardModel("cashback", "till 20th June,2016", "get 20% discount purchasing above Rs.5000/- and below Rs.5000/-."));
- MyRewardsAdapter myRewardsAdapter = new MyRewardsAdapter(rewardModelList, true);
- coupenRecyclerview.setAdapter(myRewardsAdapter);
- myRewardsAdapter.notifyDataSetChanged();
- toggleRecyclerView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showDialogRecyclerView();
- }
- });
- //////////////
- couponReedenBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- checkCoupenPriceDialog.show();
- }
- });
- /////////////coupon dialog
- /////////////signin dialog
- signInDialog = new Dialog(ProductDetailsActivity.this);
- signInDialog.setContentView(R.layout.sign_in_dialog);
- signInDialog.setCancelable(true);
- signInDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- Button dialogSignInBtn = signInDialog.findViewById(R.id.sign_in_btn);
- Button dialogSignUpBtn = signInDialog.findViewById(R.id.sign_up_btn);
- final Intent registerIntent = new Intent(ProductDetailsActivity.this, RegisterActivity.class);
- dialogSignInBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- SignInFragment.disableCloseBtn = true;
- SignUpFragment.disableCloseBtn = true;
- signInDialog.dismiss();
- setSignUpFragment = false;
- startActivity(registerIntent);
- }
- });
- dialogSignUpBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- SignInFragment.disableCloseBtn = true;
- SignUpFragment.disableCloseBtn = true;
- signInDialog.dismiss();
- setSignUpFragment = false;
- startActivity(registerIntent);
- }
- });
- //////////signin dialog
- }
- @Override
- protected void onStart() {
- super.onStart();
- currentUser = FirebaseAuth.getInstance().getCurrentUser();
- if (currentUser == null) {
- couponReedemtionLayout.setVisibility(View.GONE);
- } else {
- couponReedemtionLayout.setVisibility(View.VISIBLE);
- }
- if (currentUser != null) {
- if (DBqueries.myRating.size() == 0) {
- DBqueries.loadRating(ProductDetailsActivity.this);
- }
- if (DBqueries.wishList.size() == 0) {
- DBqueries.loadWishList(ProductDetailsActivity.this, loadingDialog, false);
- } else {
- loadingDialog.dismiss();
- }
- } else {
- loadingDialog.dismiss();
- }
- if (DBqueries.wishList.contains(productID)) {
- ALLREADY_ADDED_TO_WISHLIST = true;
- addToWishlistBtn.setImageTintList(getResources().getColorStateList(R.color.colorPrimary));
- } else {
- addToWishlistBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#dfdfdf")));
- ALLREADY_ADDED_TO_WISHLIST = false;
- }
- }
- public static void showDialogRecyclerView() {
- if (coupenRecyclerview.getVisibility() == View.GONE) {
- coupenRecyclerview.setVisibility(View.VISIBLE);
- selectedCoupen.setVisibility(View.GONE);
- } else {
- coupenRecyclerview.setVisibility(View.GONE);
- selectedCoupen.setVisibility(View.VISIBLE);
- }
- }
- public static void setRating(int starPosition) {
- for (int x = 0; x < rateNowContainer.getChildCount(); x++) {
- ImageView starBtn = (ImageView) rateNowContainer.getChildAt(x);
- starBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#b7b6b6")));
- if (x <= starPosition) {
- starBtn.setImageTintList(ColorStateList.valueOf(Color.parseColor("#6600FF")));
- }
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.search_and_cart_icon, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == android.R.id.home) {
- finish();
- return true;
- } else if (id == R.id.action_search) {
- return true;
- } else if (id == R.id.action_cart_icon) {
- if (currentUser == null) {
- signInDialog.show();
- } else {
- Intent cartIntent = new Intent(ProductDetailsActivity.this, MainActivity.class);
- showCart = true;
- startActivity(cartIntent);
- return true;
- }
- }
- return super.onOptionsItemSelected(item);
- }
- public static FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
- public static List<CategoryModal> categoryModalList = new ArrayList<>();
- public static List<List<HomePageModel>> lists = new ArrayList<>();
- public static List<String> loadedCategoriesName = new ArrayList<>();
- public static List<String> wishList = new ArrayList<>();
- public static List<WishlistModel> wishlistModelList = new ArrayList<>();
- public static List<String> myRatedIds = new ArrayList<>();
- public static List<Long> myRating = new ArrayList<>();
- public static void loadCategories(final RecyclerView categoryRecyclerView, final Context context) {
- categoryModalList.clear();
- firebaseFirestore.collection("CATEGORIES").orderBy("index").get()
- .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
- @Override
- public void onComplete(@NonNull Task<QuerySnapshot> task) {
- if (task.isSuccessful()) {
- for (DocumentSnapshot documentSnapshot : task.getResult()) {
- categoryModalList.add(new CategoryModal(documentSnapshot.get("icon").toString(), documentSnapshot.get("categoryName").toString()));
- }
- CategoryAdapter categoryAdapter = new CategoryAdapter(categoryModalList);
- categoryRecyclerView.setAdapter(categoryAdapter);
- categoryAdapter.notifyDataSetChanged();
- } else {
- String error = task.getException().getMessage();
- Toast.makeText(context, error, Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- 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