Skip to content

Commit

Permalink
Fix NPE of MenuItem in ProductOverviewBottomSheet, fixes #750
Browse files Browse the repository at this point in the history
  • Loading branch information
patzly committed Aug 10, 2023
1 parent d0d32fb commit eb47dd1
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
Expand Down Expand Up @@ -164,10 +165,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
boolean isInStock = stockItem != null && stockItem.getAmountDouble() > 0;
MenuCompat.setGroupDividerEnabled(binding.toolbar.getMenu(), true);
// disable actions if necessary
binding.toolbar.getMenu().findItem(R.id.action_consume_all).setEnabled(isInStock);
binding.toolbar.getMenu().findItem(R.id.action_consume_spoiled).setEnabled(
isInStock && product.getEnableTareWeightHandlingInt() == 0
);
MenuItem itemConsumeAll = binding.toolbar.getMenu().findItem(R.id.action_consume_all);
if (itemConsumeAll != null) {
itemConsumeAll.setEnabled(isInStock);
}
MenuItem itemConsumeSpoiled = binding.toolbar.getMenu().findItem(R.id.action_consume_spoiled);
if (itemConsumeSpoiled != null) {
itemConsumeSpoiled.setEnabled(isInStock && product.getEnableTareWeightHandlingInt() == 0);
}
BaseFragment fragmentCurrent = activity.getCurrentFragment();
binding.toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.action_add_to_shopping_list) {
Expand Down Expand Up @@ -698,7 +703,10 @@ private void showDeleteConfirmationDialog() {

private void hideDisabledFeatures() {
if (!isFeatureEnabled(Constants.PREF.FEATURE_SHOPPING_LIST)) {
binding.toolbar.getMenu().findItem(R.id.action_add_to_shopping_list).setVisible(false);
MenuItem item = binding.toolbar.getMenu().findItem(R.id.action_add_to_shopping_list);
if (item != null) {
item.setVisible(false);
}
}
if (!isFeatureEnabled(Constants.PREF.FEATURE_STOCK_BBD_TRACKING)) {
binding.itemDueDate.setVisibility(View.GONE);
Expand Down

0 comments on commit eb47dd1

Please sign in to comment.