use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatBarcodesEditFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
MasterProductCatBarcodesEditFragmentArgs args = MasterProductCatBarcodesEditFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductCatBarcodesEditViewModel.MasterProductCatBarcodesEditViewModelFactory(activity.getApplication(), args)).get(MasterProductCatBarcodesEditViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
binding.setFormData(viewModel.getFormData());
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
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_SHOPPING_LIST_ID) {
int id = event.getBundle().getInt(Constants.ARGUMENT.SELECTED_ID);
setForDestination(R.id.shoppingListFragment, Constants.ARGUMENT.SELECTED_ID, id);
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), offline -> {
InfoFullscreen infoFullscreen = offline ? new InfoFullscreen(InfoFullscreen.ERROR_OFFLINE, () -> updateConnectivity(true)) : null;
viewModel.getInfoFullscreenLive().setValue(infoFullscreen);
});
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
// necessary because else getValue() doesn't give current value (?)
viewModel.getFormData().getQuantityUnitsLive().observe(getViewLifecycleOwner(), qUs -> {
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI();
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper 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.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class OverviewStartFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(OverviewStartViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setActivity(activity);
binding.setLifecycleOwner(getViewLifecycleOwner());
clickUtil = new ClickUtil(1000);
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.frameContainer);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), this::appBarOfflineInfo);
binding.toolbar.setOnMenuItemClickListener(item -> {
int id = item.getItemId();
if (id == R.id.action_settings) {
navigateDeepLink(getString(R.string.deep_link_settingsFragment));
} else if (id == R.id.action_about) {
navigateDeepLink(getString(R.string.deep_link_aboutFragment));
} else if (id == R.id.action_feedback) {
activity.showBottomSheet(new FeedbackBottomSheet());
} else if (id == R.id.action_changelog) {
activity.showBottomSheet(new ChangelogBottomSheet());
}
return false;
});
// for offline info in app bar
binding.swipe.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
// UPDATE UI
updateUI((getArguments() == null || getArguments().getBoolean(Constants.ARGUMENT.ANIMATED, true)) && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class TransferFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
TransferFragmentArgs args = TransferFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new TransferViewModelFactory(activity.getApplication(), args)).get(TransferViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setFormData(viewModel.getFormData());
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isDownloading -> binding.swipe.setRefreshing(isDownloading));
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
} else if (event.getType() == Event.CONSUME_SUCCESS) {
assert getArguments() != null;
if (PurchaseFragmentArgs.fromBundle(getArguments()).getCloseWhenFinished()) {
activity.navigateUp();
} else {
viewModel.getFormData().clearForm();
focusProductInputIfNecessary();
embeddedFragmentScanner.startScannerIfVisible();
}
} 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) {
focusNextInvalidView();
} else if (event.getType() == Event.QUICK_MODE_ENABLED) {
focusProductInputIfNecessary();
} else if (event.getType() == Event.QUICK_MODE_DISABLED) {
clearInputFocus();
} else if (event.getType() == Event.CONTINUE_SCANNING) {
embeddedFragmentScanner.startScannerIfVisible();
} else if (event.getType() == Event.CHOOSE_PRODUCT) {
String barcode = event.getBundle().getString(ARGUMENT.BARCODE);
navigate(TransferFragmentDirections.actionTransferFragmentToChooseProductFragment(barcode).setForbidCreateProduct(true));
}
});
Integer productIdSavedSate = (Integer) getFromThisDestinationNow(Constants.ARGUMENT.PRODUCT_ID);
if (productIdSavedSate != null) {
removeForThisDestination(Constants.ARGUMENT.PRODUCT_ID);
viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productIdSavedSate, null, null));
} else if (NumUtil.isStringInt(args.getProductId())) {
int productId = Integer.parseInt(args.getProductId());
setArguments(new TransferFragmentArgs.Builder(args).setProductId(null).build().toBundle());
viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productId, null, null));
}
String barcode = (String) getFromThisDestinationNow(ARGUMENT.BARCODE);
if (barcode != null) {
removeForThisDestination(Constants.ARGUMENT.BARCODE);
viewModel.addBarcodeToExistingProduct(barcode);
}
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
// following line is necessary because no observers are set in Views
viewModel.getFormData().getQuantityUnitStockLive().observe(getViewLifecycleOwner(), i -> {
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
focusProductInputIfNecessary();
updateUI(args.getAnimateStart() && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class ShoppingModeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(ShoppingModeViewModel.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);
debug = PrefsUtil.isDebuggingEnabled(sharedPrefs);
handler = new Handler();
if (savedInstanceState == null) {
binding.recycler.scrollTo(0, 0);
}
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setAdapter(new ShoppingPlaceholderAdapter());
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.getFilteredGroupedListItemsLive().observe(getViewLifecycleOwner(), items -> {
if (items == null) {
return;
}
if (items.isEmpty()) {
InfoFullscreen info = new InfoFullscreen(InfoFullscreen.INFO_EMPTY_SHOPPING_LIST);
viewModel.getInfoFullscreenLive().setValue(info);
} else {
viewModel.getInfoFullscreenLive().setValue(null);
}
if (binding.recycler.getAdapter() instanceof ShoppingModeItemAdapter) {
((ShoppingModeItemAdapter) binding.recycler.getAdapter()).updateData(items, viewModel.getProductHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds());
} else {
binding.recycler.setAdapter(new ShoppingModeItemAdapter(activity, (LinearLayoutManager) binding.recycler.getLayoutManager(), items, viewModel.getProductHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds(), this, sharedPrefs.getBoolean(SHOPPING_MODE.USE_SMALLER_FONT, SETTINGS_DEFAULT.SHOPPING_MODE.USE_SMALLER_FONT), sharedPrefs.getBoolean(SHOPPING_MODE.SHOW_PRODUCT_DESCRIPTION, SETTINGS_DEFAULT.SHOPPING_MODE.SHOW_PRODUCT_DESCRIPTION)));
binding.recycler.scheduleLayoutAnimation();
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
hideDisabledFeatures();
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(ShoppingModeFragmentArgs.fromBundle(requireArguments()).getAnimateStart() && savedInstanceState == null);
}
Aggregations