CN5E-shop (菜鸟商城)

repository·master·Indexed 43 days ago

https://github.com/15829238397/cn5e-shop

An Android e-commerce application template mimicking the Taobao shopping experience. It demonstrates professional Android development practices, including hybrid H5/Native development via WebAppInterface, payment SDK integration (Alipay, WeChat Pay, Baidu Wallet), and user management with SMSSDK. The project utilizes OkHttp, Gson, Fresco, and Picasso for networking and image management.

Tokens
1.3K
Snippets
3
Records
5
Agent score
5%

What's inside CN5E-shop

  1. Overview of CN5E-shop (菜鸟商城)

    master

    CN5E-shop (菜鸟商城) is a commercial-grade Android project designed as a Taobao-style e-commerce client. It serves as a comprehensive implementation of modern Android development patterns, covering core e-commerce features including payment integration, product management, user authentication, and shopping cart functionality.

    Core Features:

    • Payments: Integration with Alipay, WeChat Pay, and Baidu Wallet.
    • Product Discovery: Home screen, hot sales, product catalogs, and detailed product views.
    • Shopping Experience: Shopping cart management, product sorting, and layout switching.
    • User Management: Registration, login (with interceptors), SMS SDK integration, and profile management.
    • Order Management: Order history (including a nine-grid display), favorites, and shipping address selection.
    • Social/Sharing: Product sharing via ShareSDK and social-style nine-grid order displays.
  2. Technical Stack and Dependencies in CN5E-shop

    master

    The project utilizes Android 5.0+ technologies and several industry-standard libraries to implement its features. Developers using or studying this project should be aware of the following stack:

    Android UI Components:

    • Toolbar for custom navigation bars.
    • RecyclerView for efficient list rendering.
    • CardView for modern UI layouts.
    • TabLayout for category and product sorting.
    • SwipeRefreshLayout for pull-to-refresh functionality.
    • Custom views for quantity controllers, address pickers (via XML reading), and carousel advertisements.

    Networking and Data:

    • OkHttp & Xutils: For network requests and encapsulation.
    • Gson: For JSON parsing.
    • Fresco & Picasso: For image loading and management.

    Integrations:

    • ShareSDK: For social sharing capabilities.
    • SMSSDK: For SMS-based user registration.
    • H5 & Native Interaction: For hybrid web/native product detail pages.
  3. Access the CN5E-shop Source Code

    master

    The complete source code for this project is hosted on GitHub. You can clone the repository to explore the implementation of the features described in the documentation.

    Repository URL: https://github.com/15829238397/CN5E-shop

    git clone https://github.com/15829238397/CN5E-shop
  4. Navigate to checkout with product data via buy()

    master

    When the appInterface.buy(id) method is called from JavaScript, the activity performs the following sequence:

    1. Displays a Toast message: 立即购买.
    2. Constructs a JSON string of the current product (wrapped in a ShoppingCart object) using JsonUtil.toJSON().
    3. Creates an Intent for NewOrderActivity.
    4. Attaches the following extras to the intent:
      • CartFragment.SUM_PRICE: The product price as a Float.
      • CartFragment.ORDER_WARES: A JSON string representing the list of ordered items.
    5. Starts the activity using startActivityWithLogin(intent, true, MyApplication.START_NO_RESULT).

    This ensures that the checkout process receives the correct product context and pricing.

    // Internal logic triggered by JS:
    intent.putExtra(CartFragment.SUM_PRICE, Float.valueOf(mWare.getPrice()));
    intent.putExtra(ORDER_WARES, getOrderWares());
    startActivityWithLogin(intent, true, MyApplication.START_NO_RESULT);
  5. Expose Native Android functionality to WebView via WebAppInterface

    master

    The WareDetialActivity uses a WebAppInterface class to bridge the gap between JavaScript running in a WebView and native Android code. This allows HTML/JS content loaded in the WebView to trigger native actions like showing product details, adding items to a cart, or initiating a purchase.

    To use this interface in your web content, you must call the methods on the global appInterface object (the name assigned via addJavascriptInterface).

    Available JavaScript Methods

    MethodParameterDescription
    appInterface.showDetail()NoneTriggers a native call to reload the web view with specific product details using javascript:showDetail(id)
    appInterface.buy(id)long idShows a "立即购买" (Buy Now) Toast and navigates to NewOrderActivity
    appInterface.addToCart(id)long idAdds the current product to the shopping cart via CartProvider

    Implementation Details

    • The interface is injected into the WebView using the name appInterface.
    • Methods must be annotated with @JavascriptInterface to be accessible.
    • UI-related operations (like loadUrl) inside the interface are wrapped in runOnUiThread to ensure they execute on the main thread.
    // Example usage within your HTML/JavaScript code:
    
    // 1. Show product details
    appInterface.showDetail();
    
    // 2. Add product to cart
    appInterface.addToCart(12345);
    
    // 3. Buy product immediately
    appInterface.buy(12345);