use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class MasterProductCatConversionsFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
clickUtil = new ClickUtil();
MasterProductFragmentArgs args = MasterProductFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductCatConversionsViewModel.MasterProductCatConversionsViewModelFactory(activity.getApplication(), args)).get(MasterProductCatConversionsViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
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.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.frameContainer);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setItemAnimator(new DefaultItemAnimator());
binding.recycler.setAdapter(new MasterPlaceholderAdapter());
viewModel.getQuantityUnitConversionsLive().observe(getViewLifecycleOwner(), conversions -> {
if (conversions == null) {
return;
}
if (conversions.isEmpty()) {
InfoFullscreen info = new InfoFullscreen(InfoFullscreen.INFO_EMPTY_UNIT_CONVERSIONS);
viewModel.getInfoFullscreenLive().setValue(info);
} else {
viewModel.getInfoFullscreenLive().setValue(null);
}
if (binding.recycler.getAdapter() instanceof QuantityUnitConversionAdapter) {
((QuantityUnitConversionAdapter) binding.recycler.getAdapter()).updateData(conversions);
} else {
binding.recycler.setAdapter(new QuantityUnitConversionAdapter(requireContext(), conversions, this, viewModel.getQuantityUnitHashMap()));
}
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class MasterObjectListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
clickUtil = new ClickUtil();
viewModel = new ViewModelProvider(this, new MasterObjectListViewModel.MasterObjectListViewModelFactory(activity.getApplication(), entity)).get(MasterObjectListViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
binding.swipe.setRefreshing(state);
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
binding.swipe.setOnRefreshListener(() -> viewModel.downloadDataForceUpdate());
// for offline info in app bar
binding.swipe.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
binding.swipe.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(activity, R.color.surface));
binding.swipe.setColorSchemeColors(ContextCompat.getColor(activity, R.color.secondary));
viewModel.getDisplayedItemsLive().observe(getViewLifecycleOwner(), objects -> {
if (objects == null) {
return;
}
if (objects.isEmpty()) {
InfoFullscreen info;
if (viewModel.isSearchActive()) {
info = new InfoFullscreen(InfoFullscreen.INFO_NO_SEARCH_RESULTS);
} else {
int fullscreenType;
switch(entity) {
case GrocyApi.ENTITY.PRODUCTS:
fullscreenType = InfoFullscreen.INFO_EMPTY_PRODUCTS;
break;
case GrocyApi.ENTITY.QUANTITY_UNITS:
fullscreenType = InfoFullscreen.INFO_EMPTY_QUS;
break;
case GrocyApi.ENTITY.LOCATIONS:
fullscreenType = InfoFullscreen.INFO_EMPTY_LOCATIONS;
break;
case GrocyApi.ENTITY.PRODUCT_GROUPS:
fullscreenType = InfoFullscreen.INFO_EMPTY_PRODUCT_GROUPS;
break;
case ENTITY.TASK_CATEGORIES:
fullscreenType = InfoFullscreen.INFO_EMPTY_TASK_CATEGORIES;
break;
default:
// STORES
fullscreenType = InfoFullscreen.INFO_EMPTY_STORES;
}
info = new InfoFullscreen(fullscreenType);
}
viewModel.getInfoFullscreenLive().setValue(info);
} else {
viewModel.getInfoFullscreenLive().setValue(null);
}
if (binding.recycler.getAdapter() instanceof MasterObjectListAdapter) {
((MasterObjectListAdapter) binding.recycler.getAdapter()).updateData(objects);
} else {
binding.recycler.setAdapter(new MasterObjectListAdapter(getContext(), entity, objects, this, viewModel.getHorizontalFilterBarMulti()));
binding.recycler.scheduleLayoutAnimation();
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
SnackbarMessage msg = (SnackbarMessage) event;
Snackbar snackbar = msg.getSnackbar(activity, activity.binding.frameMainContainer);
activity.showSnackbar(snackbar);
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), this::appBarOfflineInfo);
if (savedInstanceState == null) {
// delete search if navigating back from other fragment
viewModel.deleteSearch();
}
// INITIALIZE VIEWS
binding.back.setOnClickListener(v -> activity.onBackPressed());
binding.searchClose.setOnClickListener(v -> dismissSearch());
binding.editTextSearch.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
if (appBarBehavior.isPrimaryLayout()) {
return;
}
viewModel.setSearch(s != null ? s.toString() : "");
}
});
binding.editTextSearch.setOnEditorActionListener((TextView v, int actionId, KeyEvent event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
activity.hideKeyboard();
return true;
}
return false;
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.frameContainer);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
// APP BAR BEHAVIOR
appBarBehavior = new AppBarBehavior(activity, binding.appBarDefault, binding.appBarSearch, savedInstanceState);
if (viewModel.isSearchActive()) {
appBarBehavior.switchToSecondary();
}
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setItemAnimator(new DefaultItemAnimator());
binding.recycler.setAdapter(new MasterPlaceholderAdapter());
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
// UPDATE UI
updateUI(true);
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class SettingsCatBehaviorFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
binding.setActivity(activity);
binding.setFragment(this);
binding.setViewModel(viewModel);
binding.setSharedPrefs(PreferenceManager.getDefaultSharedPreferences(activity));
binding.setClickUtil(new ClickUtil());
binding.setLifecycleOwner(getViewLifecycleOwner());
viewModel.getEventHandler().observe(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
if (activity.binding.bottomAppBar.getVisibility() == View.VISIBLE) {
activity.getScrollBehavior().setUpScroll(binding.scroll);
activity.getScrollBehavior().setHideOnScroll(true);
activity.updateBottomAppBar(Constants.FAB.POSITION.GONE, R.menu.menu_empty, false, () -> {
});
activity.binding.fabMain.hide();
}
updateShortcuts();
setForPreviousDestination(Constants.ARGUMENT.ANIMATED, false);
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class SettingsCatNetworkFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
binding.setActivity(activity);
binding.setFragment(this);
binding.setViewModel(viewModel);
binding.setSharedPrefs(PreferenceManager.getDefaultSharedPreferences(activity));
binding.setClickUtil(new ClickUtil());
binding.setLifecycleOwner(getViewLifecycleOwner());
viewModel.getEventHandler().observe(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
viewModel.getTorEnabledLive().observe(getViewLifecycleOwner(), enabled -> {
viewModel.setTorEnabled(enabled);
assert viewModel.getProxyEnabledLive().getValue() != null;
if (enabled && viewModel.getProxyEnabledLive().getValue()) {
viewModel.getProxyEnabledLive().setValue(false);
}
});
viewModel.getProxyEnabledLive().observe(getViewLifecycleOwner(), enabled -> {
viewModel.setProxyEnabled(enabled);
assert viewModel.getTorEnabledLive().getValue() != null;
if (enabled && viewModel.getTorEnabledLive().getValue()) {
viewModel.getTorEnabledLive().setValue(false);
}
});
proxyHostLive = new MutableLiveData<>(viewModel.getProxyHost());
proxyPortLive = new MutableLiveData<>(String.valueOf(viewModel.getProxyPort()));
if (activity.binding.bottomAppBar.getVisibility() == View.VISIBLE) {
activity.getScrollBehavior().setUpScroll(binding.scroll);
activity.getScrollBehavior().setHideOnScroll(true);
activity.updateBottomAppBar(Constants.FAB.POSITION.GONE, R.menu.menu_empty, false, () -> {
});
activity.binding.fabMain.hide();
}
setForPreviousDestination(Constants.ARGUMENT.ANIMATED, false);
updateTimeoutValue();
}
use of xyz.zedler.patrick.grocy.util.ClickUtil in project grocy-android by patzly.
the class SettingsCatStockFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
binding.setActivity(activity);
binding.setFragment(this);
binding.setViewModel(viewModel);
binding.setSharedPrefs(PreferenceManager.getDefaultSharedPreferences(activity));
binding.setClickUtil(new ClickUtil());
binding.setLifecycleOwner(getViewLifecycleOwner());
viewModel.getEventHandler().observe(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
if (activity.binding.bottomAppBar.getVisibility() == View.VISIBLE) {
activity.getScrollBehavior().setUpScroll(binding.scroll);
activity.getScrollBehavior().setHideOnScroll(true);
activity.updateBottomAppBar(Constants.FAB.POSITION.GONE, R.menu.menu_empty, false, () -> {
});
activity.binding.fabMain.hide();
}
setForPreviousDestination(Constants.ARGUMENT.ANIMATED, false);
viewModel.loadProductPresets();
}
Aggregations