use of com.yellowmessenger.sdk.models.Product 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();
}
}
use of com.yellowmessenger.sdk.models.Product in project yellowmessenger-sdk by yellowmessenger.
the class ChatListAdapter method getSearchView.
private View getSearchView(int position, View convertView, ViewGroup parent, boolean portraitMode) {
View view = convertView;
final ChatMessage chatMessage = values.get(position);
SearchViewHolder searchViewHolder = null;
if (view == null) {
view = inflater.inflate(R.layout.chat_list_item_search, parent, false);
searchViewHolder = new SearchViewHolder();
searchViewHolder.timestamp = (TextView) view.findViewById(R.id.timestamp);
searchViewHolder.message = (TextView) view.findViewById(R.id.message);
for (int i = 0; i < 10; i++) {
View productView = inflater.inflate(portraitMode ? R.layout.list_product_portrait_view : R.layout.list_product_view, parent, false);
((ViewGroup) view.findViewById(R.id.productsView)).addView(productView);
searchViewHolder.productsLayouts.add(productView);
}
searchViewHolder.scrollView = (HorizontalScrollView) view.findViewById(R.id.scrollView);
view.setTag(searchViewHolder);
} else {
searchViewHolder = (SearchViewHolder) view.getTag();
}
searchViewHolder.scrollView.scrollTo(0, 0);
final ChatResponse chatResponse = chatMessage.getChatResponse();
if (chatResponse.getSearchResults().getMessage() != null) {
searchViewHolder.message.setVisibility(View.VISIBLE);
searchViewHolder.message.setText(chatResponse.getSearchResults().getMessage());
} else {
searchViewHolder.message.setVisibility(GONE);
}
int productSize = chatResponse.getSearchResults().getProducts() != null ? chatResponse.getSearchResults().getProducts().size() : 0;
final List<Product> products = chatResponse.getSearchResults().getProducts();
if (productSize == 0) {
for (int i = 0; i < 10; i++) {
searchViewHolder.productsLayouts.get(i).setVisibility(GONE);
}
}
for (int i = 0; i < 10; i++) {
final int index = i;
if (productSize > i) {
searchViewHolder.productsLayouts.get(i).setVisibility(View.VISIBLE);
searchViewHolder.productsLayouts.get(i).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (products.get(index).getJsonUrl() != null) {
((ChatActivity) context).openProductView(products.get(index));
}
}
});
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_name)).setText(products.get(i).getName());
if (products.get(i).getPrice() != null) {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price).setVisibility(View.VISIBLE);
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price)).setText(Html.fromHtml(products.get(i).getPrice()));
} else {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price).setVisibility(GONE);
}
if (products.get(i).getPriceOriginal() != null && !products.get(i).getPriceOriginal().equals(products.get(i).getPrice())) {
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price_original)).setText(Html.fromHtml(products.get(i).getPriceOriginal()));
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price_original)).setPaintFlags(((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price_original)).getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price_original).setVisibility(View.VISIBLE);
if (products.get(i).getDiscount() != null) {
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_discount)).setText(Html.fromHtml(products.get(i).getDiscount()));
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_discount).setVisibility(View.VISIBLE);
}
} else {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_price_original).setVisibility(GONE);
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_discount).setVisibility(GONE);
}
if (products.get(i).getDescription() != null) {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_description).setVisibility(View.VISIBLE);
((TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_description)).setText(Html.fromHtml(products.get(i).getDescription()));
} else {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_description).setVisibility(GONE);
}
TextView buttonPrimary = (TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_action_button);
TextView buttonSecondary = (TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_action_button_secondary);
TextView button1 = (TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_action_button_1);
TextView button2 = (TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_action_button_2);
TextView button3 = (TextView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_action_button_3);
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_details).setVisibility(View.VISIBLE);
if (products.get(i).getActions() != null && products.get(i).getActions().size() > 0) {
if (products.get(i).getActions().size() > 2 || chatResponse.getSearchResults().isSelection()) {
button1.setVisibility(View.GONE);
button2.setVisibility(View.GONE);
button3.setVisibility(View.GONE);
for (int x = 0; x < products.get(i).getActions().size(); x++) {
final Action action = products.get(i).getActions().get(x);
switch(x) {
case 0:
button1.setVisibility(View.VISIBLE);
button1.setText(action.getTitle());
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (action.getUrl() != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(action.getUrl()));
context.startActivity(i);
} else {
((ChatActivity) context).sendActionEvent(new SendActionEvent(action));
}
}
});
break;
case 1:
button2.setVisibility(View.VISIBLE);
button2.setText(action.getTitle());
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (action.getUrl() != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(action.getUrl()));
context.startActivity(i);
} else {
((ChatActivity) context).sendActionEvent(new SendActionEvent(action));
}
}
});
break;
case 2:
button3.setVisibility(View.VISIBLE);
button3.setText(action.getTitle());
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (action.getUrl() != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(action.getUrl()));
context.startActivity(i);
} else {
((ChatActivity) context).sendActionEvent(new SendActionEvent(action));
}
}
});
break;
}
if (x == 2) {
break;
}
}
buttonPrimary.setVisibility(GONE);
buttonSecondary.setVisibility(GONE);
} else {
button1.setVisibility(View.GONE);
button2.setVisibility(View.GONE);
button3.setVisibility(View.GONE);
buttonPrimary.setVisibility(View.VISIBLE);
buttonPrimary.setText(products.get(i).getActions().get(0).getTitle());
final Action action = products.get(i).getActions().get(0);
buttonPrimary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (action.getUrl() != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(action.getUrl()));
context.startActivity(i);
} else {
((ChatActivity) context).sendActionEvent(new SendActionEvent(action));
}
}
});
if (products.get(i).getActions().size() > 1) {
buttonSecondary.setVisibility(View.VISIBLE);
buttonSecondary.setText(products.get(i).getActions().get(1).getTitle());
final Action actionSecondary = products.get(i).getActions().get(1);
buttonSecondary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (actionSecondary.getUrl() != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(actionSecondary.getUrl()));
context.startActivity(i);
} else {
((ChatActivity) context).sendActionEvent(new SendActionEvent(actionSecondary));
}
}
});
} else {
buttonSecondary.setVisibility(GONE);
}
}
} else {
buttonPrimary.setVisibility(GONE);
buttonSecondary.setVisibility(GONE);
}
int detailsMarginBottom = products.get(i).getActions() != null ? (products.get(i).getActions().size() > 1 ? margin42 * 2 : (products.get(i).getActions().size() > 0) ? margin42 : 0) : 0;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, 0, detailsMarginBottom);
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_details).setLayoutParams(layoutParams);
if (products.get(i).getImage() != null) {
DrawableManager.getInstance(context).fetchDrawableOnThread(products.get(i).getImage(), ((ImageView) searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_image)));
} else {
searchViewHolder.productsLayouts.get(i).findViewById(R.id.product_image).setVisibility(GONE);
}
} else {
searchViewHolder.productsLayouts.get(i).setVisibility(GONE);
}
}
try {
searchViewHolder.timestamp.setText(DateUtils.getRelativeTimeSpanString(format.parse(values.get(position).getTimestamp()).getTime(), (new Date()).getTime(), DateUtils.FORMAT_ABBREV_RELATIVE).toString());
} catch (ParseException e) {
e.printStackTrace();
}
return view;
}
use of com.yellowmessenger.sdk.models.Product in project yellowmessenger-sdk by yellowmessenger.
the class ChatListAdapter method getProductView.
private View getProductView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final ChatMessage chatMessage = values.get(position);
ProductViewHolder productViewHolder = null;
if (view == null) {
view = inflater.inflate(R.layout.chat_list_item_product, parent, false);
productViewHolder = new ProductViewHolder();
productViewHolder.timestamp = (TextView) view.findViewById(R.id.timestamp);
productViewHolder.productName = (TextView) view.findViewById(R.id.product_name);
productViewHolder.productPrice = (TextView) view.findViewById(R.id.product_price);
productViewHolder.productPriceOriginal = (TextView) view.findViewById(R.id.product_price_original);
productViewHolder.productImageLayout = view.findViewById(R.id.product_image_layout);
productViewHolder.productPriceDiscount = (TextView) view.findViewById(R.id.product_price_discount);
productViewHolder.productDescription = (TextView) view.findViewById(R.id.product_description);
productViewHolder.buy = view.findViewById(R.id.buy_layout);
productViewHolder.productActions = view.findViewById(R.id.product_actions);
productViewHolder.imageView = (ImageView) view.findViewById(R.id.product_image);
productViewHolder.buyButton = (TextView) view.findViewById(R.id.buy_button);
productViewHolder.productDetails = view.findViewById(R.id.product_details);
view.setTag(productViewHolder);
} else {
productViewHolder = (ProductViewHolder) view.getTag();
}
productViewHolder.productActions.setVisibility(GONE);
productViewHolder.timestamp.setVisibility(View.VISIBLE);
try {
productViewHolder.timestamp.setText(DateUtils.getRelativeTimeSpanString(format.parse(values.get(position).getTimestamp()).getTime(), (new Date()).getTime(), DateUtils.FORMAT_ABBREV_RELATIVE).toString());
} catch (ParseException e) {
e.printStackTrace();
}
ChatResponse chatResponse = chatMessage.getChatResponse();
if (chatResponse != null) {
final Product product = chatResponse.getProduct();
if (product != null) {
productViewHolder.imageView.setVisibility(GONE);
if (product.getName() != null) {
productViewHolder.productName.setVisibility(View.VISIBLE);
productViewHolder.productName.setText(product.getName());
productViewHolder.productDetails.setVisibility(View.VISIBLE);
} else {
productViewHolder.productName.setVisibility(GONE);
productViewHolder.productDetails.setVisibility(GONE);
}
if (product.getPrice() != null) {
productViewHolder.productPrice.setText(Html.fromHtml(product.getPrice()));
productViewHolder.productPrice.setVisibility(View.VISIBLE);
} else {
productViewHolder.productPrice.setVisibility(GONE);
}
if (product.getPriceOriginal() != null && !product.getPriceOriginal().equals(product.getPrice())) {
productViewHolder.productPriceOriginal.setText(Html.fromHtml(product.getPriceOriginal()));
productViewHolder.productPriceOriginal.setPaintFlags(productViewHolder.productPriceOriginal.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
productViewHolder.productPriceOriginal.setVisibility(View.VISIBLE);
if (product.getDiscount() != null) {
productViewHolder.productPriceDiscount.setText(Html.fromHtml(product.getDiscount()));
productViewHolder.productPriceDiscount.setVisibility(View.VISIBLE);
}
} else {
productViewHolder.productPriceOriginal.setVisibility(GONE);
productViewHolder.productPriceDiscount.setVisibility(GONE);
}
if (product.getDescription() != null) {
productViewHolder.productDescription.setVisibility(View.VISIBLE);
productViewHolder.productDescription.setText(Html.fromHtml(product.getDescription()));
} else {
productViewHolder.productDescription.setVisibility(GONE);
}
if (product.getUrl() != null) {
productViewHolder.productActions.setVisibility(View.VISIBLE);
final String buyUrl = product.getUrl();
final String buyTitle = product.getAction();
productViewHolder.buyButton.setText(Html.fromHtml(product.getAction()));
productViewHolder.buy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
} else {
productViewHolder.productActions.setVisibility(GONE);
}
if (product.getImage() != null) {
productViewHolder.imageView.setVisibility(View.VISIBLE);
DrawableManager.getInstance(context).fetchDrawableOnThread(product.getImage(), productViewHolder.imageView);
final String imageUrl = product.getImage();
productViewHolder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*Intent intent = new Intent(context, ImageActivity.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("urls", new ArrayList<>(Collections.singletonList(imageUrl)));
intent.putExtras(bundle);
((Activity) context).startActivityForResult(intent, 0);*/
}
});
}
}
}
return view;
}
Aggregations