Rxjava + retro fit + MVP to realize shopping cart
This example shares the specific code of rxjava retro to display the shopping cart for your reference. The specific contents are as follows
Let's show you the renderings first
Frame structure:
1. Project framework: MVP, fresco for picture loading, The network request is implemented with okhttp + retrofit (self encapsulation and single example mode). 2. Complete the addition of shopping cart data (if there is no data in the interface, you can use the interface tool to add data). 3. The user-defined view implements the addition and subtraction button. Each time you click the addition and subtraction button, the total number and total price in the item will be changed accordingly. 4. When the quantity is 1, click the minus sign, the quantity will remain unchanged, and toast will prompt the user that the minimum quantity is 1. 5. The total number and total price at the bottom are the total price and total price in all item items, and the quantity and price in each item For the change of the grid, the total price at the bottom shall be linked with it. 6 Realize the function of single selection and inverse selection of all, and enter the default selection of all for the first time. When the item is not selected, the total number and total price are not included in the bottom data. When the selected status is changed, the total number and total price at the bottom can be modified correctly. 7 Click the delete button to delete the item, the total number and total price at the bottom can be modified correctly, and the interface data can be deleted.
Add the required dependencies and networking permissions
Subcontracting before using MVP mode
Net package
API
ServiceAPI
Successful interface
Retrofit packaging
Bean package
Bean class of detail page
Bean added to shopping cart
Commodity category
app
View layer
Write two interfaces first
Master page layout
Main page
Second page layout
Implementation of shopping cart code
Eventbus package
Set a quantity and price class
EventBus
model
Implement the interface of the model layer of the detail page
Implementation details page model
Shopping cart model
Presenter layer
Level P of detail page
P floor of shopping cart
adapter
group_ item. xml
child_ item. xml
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.