Search in sources :

Example 1 with ShoppingListFragment

use of xyz.zedler.patrick.grocy.fragment.ShoppingListFragment in project grocy-android by patzly.

the class ShoppingListsBottomSheet method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_bottomsheet_list_selection, container, false);
    activity = (MainActivity) requireActivity();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
    boolean multipleListsFeature = sharedPrefs.getBoolean(Constants.PREF.FEATURE_MULTIPLE_SHOPPING_LISTS, true);
    MutableLiveData<Integer> selectedIdLive = activity.getCurrentFragment().getSelectedShoppingListIdLive();
    if (selectedIdLive == null) {
        dismiss();
        return view;
    }
    ShoppingListRepository repository = new ShoppingListRepository(activity.getApplication());
    TextView textViewTitle = view.findViewById(R.id.text_list_selection_title);
    textViewTitle.setText(activity.getString(R.string.property_shopping_lists));
    RecyclerView recyclerView = view.findViewById(R.id.recycler_list_selection);
    recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(new ShoppingPlaceholderAdapter());
    repository.getShoppingListsLive().observe(getViewLifecycleOwner(), shoppingLists -> {
        if (shoppingLists == null) {
            return;
        }
        if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
            recyclerView.setAdapter(new ShoppingListAdapter(shoppingLists, selectedIdLive.getValue(), this, activity.getCurrentFragment() instanceof ShoppingListFragment && activity.isOnline()));
        } else {
            ((ShoppingListAdapter) recyclerView.getAdapter()).updateData(shoppingLists, selectedIdLive.getValue());
        }
    });
    selectedIdLive.observe(getViewLifecycleOwner(), selectedId -> {
        if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
            return;
        }
        ((ShoppingListAdapter) recyclerView.getAdapter()).updateSelectedId(selectedIdLive.getValue());
    });
    ActionButton buttonNew = view.findViewById(R.id.button_list_selection_new);
    if (activity.isOnline() && multipleListsFeature && activity.getCurrentFragment() instanceof ShoppingListFragment) {
        buttonNew.setVisibility(View.VISIBLE);
        buttonNew.setOnClickListener(v -> {
            dismiss();
            navigate(ShoppingListFragmentDirections.actionShoppingListFragmentToShoppingListEditFragment());
        });
    }
    progressConfirm = view.findViewById(R.id.progress_confirmation);
    return view;
}
Also used : SharedPreferences(android.content.SharedPreferences) ShoppingPlaceholderAdapter(xyz.zedler.patrick.grocy.adapter.ShoppingPlaceholderAdapter) ShoppingListFragment(xyz.zedler.patrick.grocy.fragment.ShoppingListFragment) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ShoppingListAdapter(xyz.zedler.patrick.grocy.adapter.ShoppingListAdapter) ActionButton(xyz.zedler.patrick.grocy.view.ActionButton) ShoppingListRepository(xyz.zedler.patrick.grocy.repository.ShoppingListRepository) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with ShoppingListFragment

use of xyz.zedler.patrick.grocy.fragment.ShoppingListFragment in project grocy-android by patzly.

the class DrawerBottomSheet method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    binding = FragmentBottomsheetDrawerBinding.inflate(inflater, container, false);
    activity = (MainActivity) requireActivity();
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
    binding.buttonDrawerShoppingMode.setOnClickListener(v -> navigateDeepLink(R.string.deep_link_shoppingModeFragment));
    ClickUtil.setOnClickListeners(this, binding.linearDrawerStock, binding.linearDrawerShoppingList, binding.linearDrawerConsume, binding.linearDrawerPurchase, binding.linearDrawerTransfer, binding.linearDrawerInventory, binding.linearDrawerMasterData, binding.linearDrawerSettings, binding.linearDrawerFeedback, binding.linearDrawerHelp);
    BaseFragment currentFragment = activity.getCurrentFragment();
    if (currentFragment instanceof StockOverviewFragment) {
        select(binding.linearDrawerStock, binding.textDrawerStock, false);
    } else if (currentFragment instanceof ShoppingListFragment) {
        select(binding.linearDrawerShoppingList, binding.textDrawerShoppingList, false);
    } else if (currentFragment instanceof ConsumeFragment) {
        select(binding.linearDrawerConsume, null, true);
    } else if (currentFragment instanceof PurchaseFragment) {
        select(binding.linearDrawerPurchase, null, true);
    } else if (currentFragment instanceof TransferFragment) {
        select(binding.linearDrawerTransfer, null, true);
    } else if (currentFragment instanceof InventoryFragment) {
        select(binding.linearDrawerInventory, null, true);
    } else if (currentFragment instanceof MasterObjectListFragment) {
        select(binding.linearDrawerMasterData, binding.textDrawerMasterData, false);
    } else if (currentFragment instanceof SettingsFragment) {
        select(binding.linearDrawerSettings, binding.textDrawerSettings, false);
    }
    hideDisabledFeatures();
    return binding.getRoot();
}
Also used : SettingsFragment(xyz.zedler.patrick.grocy.fragment.SettingsFragment) StockOverviewFragment(xyz.zedler.patrick.grocy.fragment.StockOverviewFragment) MasterObjectListFragment(xyz.zedler.patrick.grocy.fragment.MasterObjectListFragment) ConsumeFragment(xyz.zedler.patrick.grocy.fragment.ConsumeFragment) ShoppingListFragment(xyz.zedler.patrick.grocy.fragment.ShoppingListFragment) PurchaseFragment(xyz.zedler.patrick.grocy.fragment.PurchaseFragment) InventoryFragment(xyz.zedler.patrick.grocy.fragment.InventoryFragment) BaseFragment(xyz.zedler.patrick.grocy.fragment.BaseFragment) TransferFragment(xyz.zedler.patrick.grocy.fragment.TransferFragment)

Aggregations

ShoppingListFragment (xyz.zedler.patrick.grocy.fragment.ShoppingListFragment)2 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ShoppingListAdapter (xyz.zedler.patrick.grocy.adapter.ShoppingListAdapter)1 ShoppingPlaceholderAdapter (xyz.zedler.patrick.grocy.adapter.ShoppingPlaceholderAdapter)1 BaseFragment (xyz.zedler.patrick.grocy.fragment.BaseFragment)1 ConsumeFragment (xyz.zedler.patrick.grocy.fragment.ConsumeFragment)1 InventoryFragment (xyz.zedler.patrick.grocy.fragment.InventoryFragment)1 MasterObjectListFragment (xyz.zedler.patrick.grocy.fragment.MasterObjectListFragment)1 PurchaseFragment (xyz.zedler.patrick.grocy.fragment.PurchaseFragment)1 SettingsFragment (xyz.zedler.patrick.grocy.fragment.SettingsFragment)1 StockOverviewFragment (xyz.zedler.patrick.grocy.fragment.StockOverviewFragment)1 TransferFragment (xyz.zedler.patrick.grocy.fragment.TransferFragment)1 ShoppingListRepository (xyz.zedler.patrick.grocy.repository.ShoppingListRepository)1 ActionButton (xyz.zedler.patrick.grocy.view.ActionButton)1