rubensousa / BottomSheetBuilder

A simple library that creates BottomSheets according to the Material Design specs
Apache License 2.0
558 stars 98 forks source link

Runtime editing #4

Closed csibesz07 closed 8 years ago

csibesz07 commented 8 years ago

Hi, i would like to edit, add, remove menu items, submenus without creating a new view with the builder, dynamically. I think a class which allows editing List<BottomSheetItem> items would solve it. The recyclerview could animate changes. What do you think? Is it possible?

rubensousa commented 8 years ago

Can you explain your use-case? I don't see how editing items in real-time might be a good option

csibesz07 commented 8 years ago

I'm making a plugin for an app called Tasker. The plugin allows the user to create material style menus, messages. And i thought i would make a preview which changes on user interaction to represent the menu that will appear. I'm new to android but i've learnt a lot making the plugin.

rubensousa commented 8 years ago

I see. Do you want to give this a try and send a pull request later? It's not on my plans to implement such behavior, so, any contributions would be helpful.

csibesz07 commented 8 years ago

Alright, I'll see what I can do.

ch-muhammad-adil commented 7 years ago

@rubensousa I hope I will add this feature, as it is really required. :)

ch-muhammad-adil commented 7 years ago

This has been resolved in commit #13 . Sooner release will be added.

Here is some code to handle dynamic behaviour.

private void createShareMenu() {
        BottomSheetBuilder builder = new BottomSheetBuilder(MyCardsActivity.this, R.style.AppTheme_BottomSheetDialog_Custom)
                .setMode(BottomSheetBuilder.MODE_GRID)
                .setItemClickListener(new BottomSheetItemClickListener() {
                    @Override
                    public void onBottomSheetItemClick(MenuItem item) {

                    }
                });
        for (YourMenuItem yourMenuItem : ListOfYourMenuItems) {
            builder.addItem(yourMenuItem.getMenuId(), yourMenuItem.getName(), new BitmapDrawable(getResources(), yourMenuItem.getBitmap()));
        }
        BottomSheetMenuDialog dialog = builder.createDialog();
        dialog.show();
    }

you need to preload your menu items with bitmap in this case. you can also just pass its drawable.