Search in sources :

Example 1 with ChatActivity

use of com.yellowmessenger.sdk.ChatActivity in project yellowmessenger-sdk by yellowmessenger.

the class ProductFragment method showProduct.

public void showProduct() {
    if (getView() != null && getActivity() != null && product != null) {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (getActivity() != null) {
                    images.clear();
                    if (product.getImageUrls() != null && product.getImageUrls().size() > 0) {
                        images.addAll(product.getImageUrls());
                    } else {
                        images.add(product.getImage());
                    }
                    imageViewerAdapter.notifyDataSetChanged();
                    initiateIndicators();
                }
            }
        });
        View buyButton = getView().findViewById(R.id.buy_layout);
        TextView productName = (TextView) getView().findViewById(R.id.product_name);
        TextView productPrice = (TextView) getView().findViewById(R.id.product_price);
        TextView productPriceOriginal = (TextView) getView().findViewById(R.id.product_price_original);
        TextView productDiscount = (TextView) getView().findViewById(R.id.product_discount);
        productName.setText(product.getName());
        productPrice.setText(Html.fromHtml(product.getPrice()));
        if (product.getPriceOriginal() != null && !product.getPriceOriginal().equals(product.getPrice())) {
            productPriceOriginal.setText(Html.fromHtml(product.getPriceOriginal()));
            productPriceOriginal.setPaintFlags(productPriceOriginal.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            productPriceOriginal.setVisibility(View.VISIBLE);
            if (product.getDiscount() != null) {
                productDiscount.setText(Html.fromHtml(product.getDiscount()));
                productDiscount.setVisibility(View.VISIBLE);
            }
        } else {
            productPriceOriginal.setVisibility(View.INVISIBLE);
            productDiscount.setVisibility(View.INVISIBLE);
        }
        if (product.getDescription() != null) {
            TextView description = (TextView) getView().findViewById(R.id.description);
            description.setText(Html.fromHtml(product.getDescription()));
        }
        buyButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(product.getUrl()));
                startActivity(i);
            }
        });
        if (product.getSimilarProducts() != null && product.getSimilarProducts().size() > 0) {
            getView().findViewById(R.id.similar_products_label).setVisibility(View.VISIBLE);
            int imageWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 120, getResources().getDisplayMetrics());
            int imageHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 140, getResources().getDisplayMetrics());
            int priceSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, 13, getResources().getDisplayMetrics());
            int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());
            int pricePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
            int paddingProduct = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
            for (final Product similarProduct : product.getSimilarProducts()) {
                LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                linearLayoutParams.setMargins(0, 0, padding, 0);
                LinearLayout linearLayout = new LinearLayout(getActivity());
                linearLayout.setPadding(paddingProduct, paddingProduct, paddingProduct, paddingProduct);
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                linearLayout.setLayoutParams(linearLayoutParams);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    linearLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.product_background, null));
                } else {
                    linearLayout.setBackgroundDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.product_background, null));
                }
                linearLayout.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (getActivity() instanceof ChatActivity) {
                            ((ChatActivity) getActivity()).openProductView(similarProduct);
                        } else if (getActivity() instanceof ResultsActivity) {
                        // ((ResultsActivity)getActivity()).openProductView(similarProduct);
                        }
                    }
                });
                LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
                ImageView similarImageView = new ImageView(getActivity());
                similarImageView.setAdjustViewBounds(true);
                similarImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                similarImageView.setLayoutParams(imageLayoutParams);
                linearLayout.addView(similarImageView);
                DrawableManager.getInstance(getActivity()).fetchDrawableOnThread(similarProduct.getImage(), similarImageView);
                LinearLayout.LayoutParams priceLayoutParams = new LinearLayout.LayoutParams(imageWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
                LinearLayout priceLayout = new LinearLayout(getActivity());
                priceLayout.setOrientation(LinearLayout.HORIZONTAL);
                priceLayout.setLayoutParams(priceLayoutParams);
                priceLayout.setBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.white, null));
                LinearLayout.LayoutParams priceParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                TextView price = new TextView(getActivity());
                price.setLayoutParams(priceParams);
                price.setText(Html.fromHtml(similarProduct.getPrice()));
                price.setTypeface(Typeface.SERIF, Typeface.BOLD);
                price.setTextColor(ResourcesCompat.getColor(getResources(), R.color.primary_color, null));
                price.setTextSize(priceSize);
                price.setPadding(pricePadding, pricePadding, pricePadding, pricePadding);
                priceLayout.addView(price);
                if (similarProduct.getPriceOriginal() != null && !similarProduct.getPriceOriginal().equals(similarProduct.getPrice())) {
                    TextView priceOriginal = new TextView(getActivity());
                    priceOriginal.setLayoutParams(priceParams);
                    priceOriginal.setText(Html.fromHtml(similarProduct.getPriceOriginal()));
                    priceOriginal.setTypeface(Typeface.SERIF);
                    priceOriginal.setTextSize(priceSize);
                    priceOriginal.setPaintFlags(priceOriginal.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                    priceOriginal.setPadding(pricePadding, pricePadding, pricePadding, pricePadding);
                    priceLayout.addView(priceOriginal);
                }
                linearLayout.addView(priceLayout);
                ((LinearLayout) getView().findViewById(R.id.similar_products)).addView(linearLayout);
            }
        }
    } else {
        if (getActivity() != null)
            getActivity().finish();
    }
}
Also used : ChatActivity(com.yellowmessenger.sdk.ChatActivity) Product(com.yellowmessenger.sdk.models.Product) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) ResultsActivity(com.yellowmessenger.sdk.ResultsActivity)

Aggregations

Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ChatActivity (com.yellowmessenger.sdk.ChatActivity)1 ResultsActivity (com.yellowmessenger.sdk.ResultsActivity)1 Product (com.yellowmessenger.sdk.models.Product)1