use of xyz.zedler.patrick.grocy.model.Product in project grocy-android by patzly.
the class ShoppingListItemAdapter method fillShoppingListItem.
// Only for PurchaseFragment
public static void fillShoppingListItem(Context context, ShoppingListItem item, RowShoppingListItemBinding binding, HashMap<Integer, Product> productHashMap, HashMap<Integer, QuantityUnit> quantityUnitHashMap, HashMap<Integer, Double> shoppingListItemAmountsHashMap, PluralUtil pluralUtil) {
// NAME
Product product = null;
if (item.hasProduct())
product = productHashMap.get(item.getProductIdInt());
if (product != null) {
binding.name.setText(product.getName());
binding.name.setVisibility(View.VISIBLE);
} else {
binding.name.setText(null);
binding.name.setVisibility(View.GONE);
}
if (item.isUndone()) {
binding.name.setPaintFlags(binding.name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
} else {
binding.name.setPaintFlags(binding.name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
if (binding.name.getVisibility() == View.VISIBLE) {
binding.noteAsName.setVisibility(View.GONE);
binding.noteAsName.setText(null);
}
// AMOUNT
Double amountInQuUnit = shoppingListItemAmountsHashMap.get(item.getId());
if (product != null && amountInQuUnit != null) {
QuantityUnit quantityUnit = quantityUnitHashMap.get(item.getQuIdInt());
String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, amountInQuUnit);
if (quStr != null) {
binding.amount.setText(context.getString(R.string.subtitle_amount, NumUtil.trim(amountInQuUnit), quStr));
} else {
binding.amount.setText(NumUtil.trim(amountInQuUnit));
}
} else if (product != null) {
QuantityUnit quantityUnit = quantityUnitHashMap.get(product.getQuIdStockInt());
String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, item.getAmountDouble());
if (quStr != null) {
binding.amount.setText(context.getString(R.string.subtitle_amount, NumUtil.trim(item.getAmountDouble()), quStr));
} else {
binding.amount.setText(NumUtil.trim(item.getAmountDouble()));
}
} else {
binding.amount.setText(NumUtil.trim(item.getAmountDouble()));
}
binding.amount.setTypeface(ResourcesCompat.getFont(context, R.font.jost_book));
binding.amount.setTextColor(ContextCompat.getColor(context, R.color.on_background_secondary));
if (item.isUndone()) {
binding.amount.setPaintFlags(binding.amount.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
} else {
binding.amount.setPaintFlags(binding.amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
if (item.getNote() != null && !item.getNote().isEmpty()) {
if (binding.name.getVisibility() == View.VISIBLE) {
binding.note.setVisibility(View.VISIBLE);
binding.note.setText(item.getNote().trim());
} else {
binding.noteAsName.setVisibility(View.VISIBLE);
binding.noteAsName.setText(item.getNote().trim());
}
} else {
if (binding.name.getVisibility() == View.VISIBLE) {
binding.note.setVisibility(View.GONE);
binding.note.setText(null);
}
}
if (binding.noteAsName.getVisibility() == View.VISIBLE) {
if (item.isUndone()) {
binding.noteAsName.setPaintFlags(binding.noteAsName.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
} else {
binding.noteAsName.setPaintFlags(binding.noteAsName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
} else {
if (item.isUndone()) {
binding.note.setPaintFlags(binding.note.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
} else {
binding.note.setPaintFlags(binding.note.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
}
}
use of xyz.zedler.patrick.grocy.model.Product in project grocy-android by patzly.
the class ShoppingListItemAdapter method onBindViewHolder.
@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionDoNotUse) {
GroupedListItem groupedListItem = groupedListItems.get(viewHolder.getAdapterPosition());
int type = getItemViewType(viewHolder.getAdapterPosition());
if (type == GroupedListItem.TYPE_HEADER) {
ShoppingListGroupViewHolder holder = (ShoppingListGroupViewHolder) viewHolder;
if (((GroupHeader) groupedListItem).getDisplayDivider() == 1) {
holder.binding.divider.setVisibility(View.VISIBLE);
} else {
holder.binding.divider.setVisibility(View.GONE);
}
holder.binding.name.setText(((GroupHeader) groupedListItem).getGroupName());
return;
}
if (type == GroupedListItem.TYPE_BOTTOM_NOTES) {
ShoppingListNotesViewHolder holder = (ShoppingListNotesViewHolder) viewHolder;
holder.binding.notes.setText(((ShoppingListBottomNotes) groupedListItem).getNotes());
holder.binding.container.setOnClickListener(view -> listener.onItemRowClicked(groupedListItem));
return;
}
ShoppingListItem item = (ShoppingListItem) groupedListItem;
RowShoppingListItemBinding binding = ((ShoppingListItemViewHolder) viewHolder).binding;
// NAME
Product product = null;
if (item.hasProduct()) {
product = productHashMap.get(item.getProductIdInt());
}
if (product != null) {
binding.name.setText(product.getName());
binding.name.setVisibility(View.VISIBLE);
} else {
binding.name.setText(null);
binding.name.setVisibility(View.GONE);
}
if (item.isUndone()) {
binding.name.setPaintFlags(binding.name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
binding.name.setAlpha(1.0f);
} else {
binding.name.setPaintFlags(binding.name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
binding.name.setAlpha(0.6f);
}
if (binding.name.getVisibility() == View.VISIBLE) {
binding.noteAsName.setVisibility(View.GONE);
binding.noteAsName.setText(null);
}
// AMOUNT
Double amountInQuUnit = shoppingListItemAmountsHashMap.get(item.getId());
if (product != null && amountInQuUnit != null) {
QuantityUnit quantityUnit = quantityUnitHashMap.get(item.getQuIdInt());
String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, amountInQuUnit);
if (quStr != null) {
binding.amount.setText(binding.amount.getContext().getString(R.string.subtitle_amount, NumUtil.trim(amountInQuUnit), quStr));
} else {
binding.amount.setText(NumUtil.trim(amountInQuUnit));
}
} else if (product != null) {
QuantityUnit quantityUnit = quantityUnitHashMap.get(product.getQuIdStockInt());
String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, item.getAmountDouble());
if (quStr != null) {
binding.amount.setText(binding.amount.getContext().getString(R.string.subtitle_amount, NumUtil.trim(item.getAmountDouble()), quStr));
} else {
binding.amount.setText(NumUtil.trim(item.getAmountDouble()));
}
} else {
binding.amount.setText(NumUtil.trim(item.getAmountDouble()));
}
if (item.hasProduct() && missingProductIds.contains(item.getProductIdInt())) {
binding.amount.setTypeface(ResourcesCompat.getFont(binding.amount.getContext(), R.font.jost_medium));
binding.amount.setTextColor(ContextCompat.getColor(binding.amount.getContext(), R.color.retro_blue_fg));
} else {
binding.amount.setTypeface(ResourcesCompat.getFont(binding.amount.getContext(), R.font.jost_book));
binding.amount.setTextColor(ContextCompat.getColor(binding.amount.getContext(), R.color.on_background_secondary));
}
if (item.isUndone()) {
binding.amount.setPaintFlags(binding.amount.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
binding.amount.setAlpha(1.0f);
} else {
binding.amount.setPaintFlags(binding.amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
binding.amount.setAlpha(0.6f);
}
if (item.getNote() != null && !item.getNote().trim().isEmpty()) {
if (binding.name.getVisibility() == View.VISIBLE) {
binding.note.setVisibility(View.VISIBLE);
binding.note.setText(item.getNote().trim());
} else {
binding.noteAsName.setVisibility(View.VISIBLE);
binding.noteAsName.setText(item.getNote().trim());
binding.note.setVisibility(View.GONE);
binding.note.setText(null);
}
} else {
if (binding.name.getVisibility() == View.VISIBLE) {
binding.note.setVisibility(View.GONE);
binding.note.setText(null);
}
}
if (binding.noteAsName.getVisibility() == View.VISIBLE) {
if (item.isUndone()) {
binding.noteAsName.setPaintFlags(binding.noteAsName.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
binding.noteAsName.setAlpha(1.0f);
} else {
binding.noteAsName.setPaintFlags(binding.noteAsName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
binding.noteAsName.setAlpha(0.6f);
}
} else {
if (item.isUndone()) {
binding.note.setPaintFlags(binding.note.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
binding.note.setAlpha(1.0f);
} else {
binding.note.setPaintFlags(binding.note.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
binding.note.setAlpha(0.6f);
}
}
// CONTAINER
binding.containerRow.setOnClickListener(view -> listener.onItemRowClicked(groupedListItem));
}
use of xyz.zedler.patrick.grocy.model.Product in project grocy-android by patzly.
the class MasterProductCatOptionalFragment method onItemAutoCompleteClick.
public void onItemAutoCompleteClick(AdapterView<?> adapterView, int pos) {
Product product = (Product) adapterView.getItemAtPosition(pos);
viewModel.getFormData().getProductLive().setValue(product);
clearInputFocus();
}
use of xyz.zedler.patrick.grocy.model.Product in project grocy-android by patzly.
the class MasterProductFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
MasterProductFragmentArgs args = MasterProductFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductViewModel.MasterProductViewModelFactory(activity.getApplication(), args)).get(MasterProductViewModel.class);
if (!viewModel.isActionEdit() && args.getProductName() != null) {
// remove product name from arguments because it was filled
// in the form during ViewModel creation
setArguments(new MasterProductFragmentArgs.Builder(args).setProductName(null).setProductId(null).build().toBundle());
}
binding.setActivity(activity);
binding.setFormData(viewModel.getFormData());
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
binding.categoryOptional.setOnClickListener(v -> navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatOptionalFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct())));
binding.categoryLocation.setOnClickListener(v -> navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatLocationFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct())));
binding.categoryDueDate.setOnClickListener(v -> navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatDueDateFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct())));
binding.categoryAmount.setOnClickListener(v -> navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatAmountFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct())));
binding.categoryQuantityUnit.setOnClickListener(v -> navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatQuantityUnitFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct())));
binding.categoryBarcodes.setOnClickListener(v -> {
if (!viewModel.isActionEdit()) {
activity.showMessage(R.string.subtitle_product_not_on_server);
return;
}
navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatBarcodesFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct()));
});
binding.categoryQuConversions.setOnClickListener(v -> {
if (!viewModel.isActionEdit()) {
activity.showMessage(R.string.subtitle_product_not_on_server);
return;
}
navigate(MasterProductFragmentDirections.actionMasterProductFragmentToMasterProductCatConversionsFragment(viewModel.getAction()).setProduct(viewModel.getFilledProduct()));
});
Product product = (Product) getFromThisDestinationNow(Constants.ARGUMENT.PRODUCT);
if (product != null) {
viewModel.setCurrentProduct(product);
removeForThisDestination(Constants.ARGUMENT.PRODUCT);
}
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
SnackbarMessage message = (SnackbarMessage) event;
Snackbar snack = message.getSnackbar(activity, activity.binding.frameMainContainer);
activity.showSnackbar(snack);
} else if (event.getType() == Event.NAVIGATE_UP) {
activity.navigateUp();
} else if (event.getType() == Event.SET_PRODUCT_ID) {
int id = event.getBundle().getInt(Constants.ARGUMENT.PRODUCT_ID);
setForPreviousDestination(Constants.ARGUMENT.PRODUCT_ID, id);
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
} else if (event.getType() == Event.FOCUS_INVALID_VIEWS) {
if (binding.editTextName.getText() == null || binding.editTextName.getText().length() == 0) {
activity.showKeyboard(binding.editTextName);
}
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
String action = (String) getFromThisDestinationNow(Constants.ARGUMENT.ACTION);
if (action != null) {
removeForThisDestination(Constants.ARGUMENT.ACTION);
switch(action) {
case ACTION.SAVE_CLOSE:
new Handler().postDelayed(() -> viewModel.saveProduct(true), 500);
break;
case ACTION.SAVE_NOT_CLOSE:
new Handler().postDelayed(() -> viewModel.saveProduct(false), 500);
break;
case ACTION.DELETE:
new Handler().postDelayed(() -> viewModel.deleteProductSafely(), 500);
break;
}
}
viewModel.getIsOnlineLive().observe(getViewLifecycleOwner(), isOnline -> {
// if(isOnline ) viewModel.downloadData();
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.model.Product in project grocy-android by patzly.
the class ShoppingListItemEditFragment method onItemAutoCompleteClick.
public void onItemAutoCompleteClick(AdapterView<?> adapterView, int pos) {
Product product = (Product) adapterView.getItemAtPosition(pos);
viewModel.setProduct(product);
focusNextView();
}
Aggregations