Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the description of an PrimaryDrawerItem #2445

Closed
lcapellanWork opened this issue May 3, 2019 · 12 comments
Closed

Updating the description of an PrimaryDrawerItem #2445

lcapellanWork opened this issue May 3, 2019 · 12 comments
Assignees
Labels

Comments

@lcapellanWork
Copy link

I'm kind of using the MaterialDrawer as a shopping cart, everything is perfect, the only problem that I'm having is when trying to update the description of an item, as I have seen, can only update the bade, name, or the icon, but not the description, is there any way that I could update the description? in the meanwhile, I'm deleting de item and just adding it again, but is not an efficient way, and the item changes the position to the last place.
image

@lcapellanWork
Copy link
Author

In the meanwhile, I'm deleting the item and add it again at the same position, no problems at the moment

@mikepenz
Copy link
Owner

mikepenz commented May 3, 2019

https://github.com/mikepenz/MaterialDrawer#modify-items-or-the-drawer

you can change the item, and then notify the drawer about the update:

//modify an item of the drawer
item1.withName("A new name for this drawerItem").withBadge("19").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700));
//notify the drawer about the updated element. it will take care about everything else
result.updateItem(item1);

@lcapellanWork
Copy link
Author

` SecondaryDrawerItem Precio = new SecondaryDrawerItem()
.withBadge("RD$" + producto.getPrecio())
.withName("Precio")
.withSelectable(false)
.withTag("Sec");

    SecondaryDrawerItem ITBIS = new SecondaryDrawerItem()
            .withBadge("RD$" + producto.getITBIS())
            .withName("ITBIS")
            .withSelectable(false)
            .withTag("Sec");

    SecondaryDrawerItem Desc = new SecondaryDrawerItem()
            .withBadge("RD$" + producto.getDesc())
            .withName("Descuento")
            .withSelectable(false)
            .withTag("Sec");
    double total = producto.getPrecio() + producto.getITBIS() - producto.getDesc();

    PrimaryDrawerItem newItem = new PrimaryDrawerItem()
            .withIdentifier((long) productos.indexOf(producto))
            .withSubItems(Precio, ITBIS, Desc)
            .withName("" + producto.getNombre())
            .withDescription(producto.getCant() + "")
            .withBadge(total + "").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700));
    drawer.addItemAtPosition(newItem, pos + 1);

`
as you may see in my code, i add dynamically every item, so is kind of an array, i just call the method add item and pass some atributtes and thats it, the problem is retrieving those datas

@mikepenz
Copy link
Owner

mikepenz commented May 4, 2019

@lcapellanWork when you need to modify then, I highly recommend to either keep the reference to the item modify the object, and then notify the drawer about the change.

Alternative you could give the items a unique identifier and retrieve the item via the identifier and do the same:
https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L429

Or you will just update the item at the position with a new element:
https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L712

@mikepenz mikepenz self-assigned this May 4, 2019
@lcapellanWork
Copy link
Author

lcapellanWork commented May 6, 2019

Thanks for the help, I use the update item at position and it works, but now I think I found a new bug, or maybe I'm doing something wrong, as you see at my code, I have subitems, when I add a new item, if an item at the drawer is open, it will add the sub item, but not the item.
image

there should be a new primary item with 4 subitems, but the new primary item is never added and there are only 4 new subitems without a parent primary item.

@lcapellanWork
Copy link
Author

in the meanwhile, I have a really not that memory-friendly of a solution, delete all the items, and reload it again since I save all of the data at an array, I tried to use the notify, but it gives me some kind of thread error.

@mikepenz
Copy link
Owner

mikepenz commented Jun 8, 2019

Can you please be a bit more specific related to the subitems?

you change the subItem or you change just an item?

perhaps you might check out v7.0.0-rc01 which comes with the fastAdapter v4 which might fixes this problem

@Guziq
Copy link

Guziq commented Jun 9, 2019

@mikepenz is there any way to update the ProfileDrawerItem on v7.0.0-rc01? I am failing with:

drawer?.updateName(1, StringHolder("Test"))

looks like ProfileDrawerItem is not Nameable to perform such action. Your link here is not valid anymore: #2429

Sorry for asking this question under this ticket, but I think this might be kinda related.

@mikepenz
Copy link
Owner

mikepenz commented Jun 9, 2019

@Guziq there is a specific method to update profiles: https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.kt#L201

@lcapellanWork
Copy link
Author

Can you please be a bit more specific related to the subitems?

you change the subItem or you change just an item?

perhaps you might check out v7.0.0-rc01 which comes with the fastAdapter v4 which might fixes this problem

As you may see, when we add a new PrimaryItem, we can add SecondaryItems as subitems, the problem is when I delete the parent, in this case, the primaryItem, the subitems (SecondaryItems) does not, and stay floating there. Is there a way to delete the parent and then the subitems be deleted with the parent?

@mikepenz
Copy link
Owner

@lcapellanWork the most simple and best solution to this is to simply collapse the expanded item and remove the parent then.

@lcapellanWork
Copy link
Author

@lcapellanWork the most simple and best solution to this is to simply collapse the expanded item and remove the parent then.

Mhmm gonna try that now, thanks for the help, a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants