use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class SettingsFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentSettingsBinding.inflate(inflater, container, false);
activity = (MainActivity) requireActivity();
args = SettingsFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
clickUtil = new ClickUtil();
debug = PrefsUtil.isDebuggingEnabled(sharedPrefs);
queue = viewModel.getDownloadHelper().newQueue(null, this::showVolleyError);
binding.setFragment(this);
binding.setActivity(activity);
binding.setClickUtil(clickUtil);
binding.setLifecycleOwner(getViewLifecycleOwner());
String category = args.getShowCategory();
if (category == null) {
// showOverview();
} else if (category.equals(Constants.SETTINGS.SERVER.class.getSimpleName())) {
// showCategoryServer();
} else if (category.equals(Constants.SETTINGS.APPEARANCE.class.getSimpleName())) {
// showCategoryAppearance();
} else if (category.equals(Constants.SETTINGS.NETWORK.class.getSimpleName())) {
// showCategoryNetwork();
} else if (category.equals(Constants.SETTINGS.BEHAVIOR.class.getSimpleName())) {
// showCategoryBehavior();
} else if (category.equals(Constants.SETTINGS.SCANNER.class.getSimpleName())) {
showCategoryScanner();
} else if (category.equals(Constants.SETTINGS.STOCK.class.getSimpleName())) {
showCategoryStock();
} else if (category.equals(Constants.SETTINGS.SHOPPING_MODE.class.getSimpleName())) {
showCategoryShoppingMode();
} else if (category.equals(Constants.SETTINGS.DEBUGGING.class.getSimpleName())) {
// showCategoryDebugging();
}
return binding.getRoot();
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class ShoppingListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(ShoppingListViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.setViewModel(viewModel);
binding.setActivity(activity);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.frame);
clickUtil = new ClickUtil();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
pluralUtil = new PluralUtil(activity);
// APP BAR BEHAVIOR
appBarBehavior = new AppBarBehavior(activity, binding.appBarDefault, binding.appBarSearch, savedInstanceState);
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setAdapter(new ShoppingPlaceholderAdapter());
if (savedInstanceState == null) {
binding.recycler.scrollToPosition(0);
viewModel.resetSearch();
}
Object forcedSelectedId = getFromThisDestinationNow(Constants.ARGUMENT.SELECTED_ID);
if (forcedSelectedId != null) {
viewModel.selectShoppingList((Integer) forcedSelectedId);
removeForThisDestination(Constants.ARGUMENT.SELECTED_ID);
}
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getSelectedShoppingListIdLive().observe(getViewLifecycleOwner(), this::changeAppBarTitle);
viewModel.getFilteredShoppingListItemsLive().observe(getViewLifecycleOwner(), items -> {
if (items == null)
return;
if (binding.recycler.getAdapter() instanceof ShoppingListItemAdapter) {
((ShoppingListItemAdapter) binding.recycler.getAdapter()).updateData(requireContext(), items, viewModel.getProductHashMap(), viewModel.getProductNamesHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getProductGroupHashMap(), viewModel.getStoreHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds(), viewModel.getShoppingListNotes(), viewModel.getGroupingMode());
} else {
binding.recycler.setAdapter(new ShoppingListItemAdapter(requireContext(), items, viewModel.getProductHashMap(), viewModel.getProductNamesHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getProductGroupHashMap(), viewModel.getStoreHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds(), this, viewModel.getShoppingListNotes(), viewModel.getGroupingMode()));
binding.recycler.scheduleLayoutAnimation();
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
if (swipeBehavior == null) {
swipeBehavior = new SwipeBehavior(activity, swipeStarted -> binding.swipeShoppingList.setEnabled(!swipeStarted)) {
@Override
public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
if (viewHolder.getItemViewType() != GroupedListItem.TYPE_ENTRY)
return;
if (!(binding.recycler.getAdapter() instanceof ShoppingListItemAdapter))
return;
int position = viewHolder.getAdapterPosition();
ArrayList<GroupedListItem> groupedListItems = ((ShoppingListItemAdapter) binding.recycler.getAdapter()).getGroupedListItems();
if (groupedListItems == null || position < 0 || position >= groupedListItems.size()) {
return;
}
GroupedListItem item = groupedListItems.get(position);
if (!(item instanceof ShoppingListItem)) {
return;
}
ShoppingListItem shoppingListItem = (ShoppingListItem) item;
underlayButtons.add(new SwipeBehavior.UnderlayButton(R.drawable.ic_round_done, pos -> {
if (position >= groupedListItems.size()) {
return;
}
viewModel.toggleDoneStatus(shoppingListItem);
}));
}
};
}
swipeBehavior.attachToRecyclerView(binding.recycler);
hideDisabledFeatures();
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(ShoppingListFragmentArgs.fromBundle(requireArguments()).getAnimateStart() && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class StockOverviewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(StockOverviewViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.setViewModel(viewModel);
binding.setActivity(activity);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.frame);
clickUtil = new ClickUtil();
// APP BAR BEHAVIOR
appBarBehavior = new AppBarBehavior(activity, binding.appBarDefault, binding.appBarSearch, savedInstanceState);
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setAdapter(new StockPlaceholderAdapter());
if (savedInstanceState == null) {
binding.recycler.scrollToPosition(0);
viewModel.resetSearch();
}
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getFilteredStockItemsLive().observe(getViewLifecycleOwner(), items -> {
if (items == null)
return;
if (binding.recycler.getAdapter() instanceof StockOverviewItemAdapter) {
((StockOverviewItemAdapter) binding.recycler.getAdapter()).updateData(requireContext(), items, viewModel.getShoppingListItemsProductIds(), viewModel.getQuantityUnitHashMap(), viewModel.getProductGroupHashMap(), viewModel.getProductHashMap(), viewModel.getLocationHashMap(), viewModel.getProductIdsMissingStockItems(), viewModel.getSortMode(), viewModel.isSortAscending(), viewModel.getGroupingMode());
} else {
binding.recycler.setAdapter(new StockOverviewItemAdapter(requireContext(), items, viewModel.getShoppingListItemsProductIds(), viewModel.getQuantityUnitHashMap(), viewModel.getProductGroupHashMap(), viewModel.getProductHashMap(), viewModel.getLocationHashMap(), viewModel.getProductIdsMissingStockItems(), this, viewModel.isFeatureEnabled(PREF.FEATURE_STOCK_BBD_TRACKING), viewModel.isFeatureEnabled(PREF.FEATURE_SHOPPING_LIST), viewModel.getDaysExpriringSoon(), viewModel.getCurrency(), viewModel.getSortMode(), viewModel.isSortAscending(), viewModel.getGroupingMode()));
binding.recycler.scheduleLayoutAnimation();
}
});
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getScannerVisibilityLive());
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
if (swipeBehavior == null) {
swipeBehavior = new SwipeBehavior(activity, swipeStarted -> binding.swipe.setEnabled(!swipeStarted)) {
@Override
public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
if (viewHolder.getItemViewType() != GroupedListItem.TYPE_ENTRY)
return;
if (!(binding.recycler.getAdapter() instanceof StockOverviewItemAdapter))
return;
int position = viewHolder.getAdapterPosition();
ArrayList<GroupedListItem> groupedListItems = ((StockOverviewItemAdapter) binding.recycler.getAdapter()).getGroupedListItems();
if (groupedListItems == null || position < 0 || position >= groupedListItems.size()) {
return;
}
GroupedListItem item = groupedListItems.get(position);
if (!(item instanceof StockItem)) {
return;
}
StockItem stockItem = (StockItem) item;
if (stockItem.getAmountAggregatedDouble() > 0 && stockItem.getProduct().getEnableTareWeightHandlingInt() == 0) {
underlayButtons.add(new SwipeBehavior.UnderlayButton(R.drawable.ic_round_consume_product, pos -> {
if (pos >= groupedListItems.size()) {
return;
}
swipeBehavior.recoverLatestSwipedItem();
viewModel.performAction(Constants.ACTION.CONSUME, stockItem);
}));
}
if (stockItem.getAmountAggregatedDouble() > stockItem.getAmountOpenedAggregatedDouble() && stockItem.getProduct().getEnableTareWeightHandlingInt() == 0 && viewModel.isFeatureEnabled(Constants.PREF.FEATURE_STOCK_OPENED_TRACKING)) {
underlayButtons.add(new SwipeBehavior.UnderlayButton(R.drawable.ic_round_open, pos -> {
if (pos >= groupedListItems.size()) {
return;
}
swipeBehavior.recoverLatestSwipedItem();
viewModel.performAction(Constants.ACTION.OPEN, stockItem);
}));
}
if (underlayButtons.isEmpty()) {
underlayButtons.add(new SwipeBehavior.UnderlayButton(R.drawable.ic_round_close, pos -> swipeBehavior.recoverLatestSwipedItem()));
}
}
};
}
swipeBehavior.attachToRecyclerView(binding.recycler);
hideDisabledFeatures();
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI();
}
Aggregations