# aspsine/irecyclerview architecture

> Architecture diagram of the GitHub repository aspsine/irecyclerview, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aspsine/irecyclerview
- Repository: https://github.com/aspsine/irecyclerview

## Overview

##### Main Components
- Library Module:
- Core Component: Custom RecyclerView (IRecyclerView) that extends Android’s RecyclerView.
- Supporting Interfaces and Classes: For handling refresh (OnRefreshListener, RefreshHeaderLayout, RefreshTrigger), load more (OnLoadMoreListener, LoadMoreFooterView), header and footer management (methods for adding header/footer views), plus adapter wrappers like WrapperAdapter.
- Utility Classes: For animations, view holders (IViewHolder), and other helper functions.
- Resource Files: Layouts for refresh headers, loadmore footers, animations (rotate_up/rotate_down), and attribute definitions (attrs.xml).

- Demo (App) Module:
- Activity: The MainActivity demonstrating the usage of IRecyclerView.
- Custom Adapters & Models: For example, ImageAdapter and model classes like Image.java.
- Network Helpers: Classes like NetworkAPI and OkHttp wrapper (for simulating API calls via local assets).
- Assets: Static API responses (JSON files in assets for galleries) to emulate backend data.
- UI Components: Custom widgets such as BannerView and various header/footer views for demonstration.

- External Dependencies & Android Framework:
- Android core framework classes, especially RecyclerView and various LayoutManagers (LinearLayoutManager, GridLayoutManager, etc.).
- Build systems and Gradle setup (build.gradle files, Gradle wrapper) which handle project configuration and module dependencies.

##### Relationships and Interactions
- The Demo App depends on and integrates the Library:
- MainActivity uses IRecyclerView component and sets up its layout manager, adapters, and event listeners (for refresh and load more).
- Custom UI components and adapters are linked to library methods (e.g., setIAdapter instead of the regular setAdapter).
- Within the Library:
- The IRecyclerView class is composed of multiple smaller components: refresh header (RefreshHeaderLayout), loadmore footer (LoadMoreFooterView), interface-based callbacks (OnRefreshListener, OnLoadMoreListener).
- Utilizes Android resource files to render layouts and animations.
- Communication Flow:
- User interactions in the Demo App (such as swipe gestures) trigger events in IRecyclerView.
- IRecyclerView then interfaces with the custom adapters (like WrapperAdapter) and propagates events via callbacks to the demo’s registered listeners.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The library encapsulates the reusable core logic for RecyclerView customization.
- The demo app demonstrates its integration via a clear separation between UI (activities, layouts) and business logic (network calls, data processing).
- Modular Design:
- Two distinct modules (library and app) enable independent development, testing, and reuse.
- Customization & Extensibility:
- The design supports multiple header/footer views by providing methods to add these dynamically.
- Extensible event handling via interfaces (OnRefreshListener, OnLoadMoreListener) encourages decoupling of UI actions from business logic.
- Custom View Composition:
- The library extends Android’s RecyclerView by wrapping it with additional UI elements and behaviors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Library Module
    subgraph "Library Module"
        %% Core Components
        subgraph "Core Components"
            IRecyclerView["IRecyclerView"]:::library
        end
        %% Interfaces & Components
        subgraph "Interfaces & Components"
            OnRefreshListener["OnRefreshListener"]:::library
            RefreshTrigger["RefreshTrigger"]:::library
            RefreshHeaderLayout["RefreshHeaderLayout"]:::library
            OnLoadMoreListener["OnLoadMoreListener"]:::library
            WrapperAdapter["WrapperAdapter"]:::library
        end
        %% Utility & Resources
        subgraph "Utility & Resources"
            IViewHolder["IViewHolder"]:::util
            SimpleAnimatorListener["SimpleAnimatorListener"]:::util
            Attrs["attrs.xml"]:::resource
        end
    end

    %% Demo App Module
    subgraph "Demo App Module"
        %% UI & Activities
        subgraph "UI & Activities"
            MainActivity["MainActivity"]:::demo
        end
        %% Adapters & Models
        subgraph "Adapters & Models"
            ImageAdapter["ImageAdapter"]:::demo
            OnItemClickListener["OnItemClickListener"]:::demo
        end
        %% Network & Assets
        subgraph "Network & Assets"
            NetworkAPI["NetworkAPI"]:::network
            OkHttp["OkHttp"]:::network
            Assets["API_JSON_Assets"]:::resource
        end
        %% Custom UI Components
        subgraph "Custom UI Components"
            BatVsSupperHeaderView["BatVsSupperHeaderView"]:::demo
            ClassicRefreshHeaderView["ClassicRefreshHeaderView"]:::demo
            LoadMoreFooterView["LoadMoreFooterView"]:::demo
            BannerView["BannerView"]:::demo
        end
        %% Animations
        subgraph "Animations"
            RotateUp["rotate_up.xml"]:::resource
            RotateDown["rotate_down.xml"]:::resource
        end
    end

    %% Relationships between Demo and Library
    MainActivity -->|"uses"| IRecyclerView

    %% Library internal component interactions
    IRecyclerView -->|"triggers"| OnRefreshListener
    IRecyclerView -->|"triggers"| OnLoadMoreListener
    IRecyclerView -->|"incorporates"| RefreshHeaderLayout
    IRecyclerView -->|"supports"| WrapperAdapter
    IRecyclerView -->|"utilizes"| IViewHolder
    IRecyclerView -->|"animatesVia"| SimpleAnimatorListener
    IRecyclerView -->|"appliesAttributes"| Attrs

    %% Further Demo integrations
    MainActivity -->|"integratesAdapter"| ImageAdapter
    ImageAdapter -->|"handlesClick"| OnItemClickListener
    MainActivity -->|"callsNetwork"| NetworkAPI
    NetworkAPI -->|"wrapsCalls"| OkHttp
    NetworkAPI -->|"fetchesDataFrom"| Assets
    MainActivity -->|"displaysHeader"| BatVsSupperHeaderView
    MainActivity -->|"displaysHeader"| ClassicRefreshHeaderView
    MainActivity -->|"displaysFooter"| LoadMoreFooterView
    MainActivity -->|"showsBanner"| BannerView
    MainActivity -->|"loadsAnimation"| RotateUp
    MainActivity -->|"loadsAnimation"| RotateDown
    WrapperAdapter -->|"wrapsAdapter"| ImageAdapter

    %% Click Events
    click IRecyclerView "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/IRecyclerView.java"
    click IViewHolder "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/IViewHolder.java"
    click OnRefreshListener "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/OnRefreshListener.java"
    click RefreshHeaderLayout "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/RefreshHeaderLayout.java"
    click RefreshTrigger "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/RefreshTrigger.java"
    click OnLoadMoreListener "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/OnLoadMoreListener.java"
    click WrapperAdapter "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/WrapperAdapter.java"
    click SimpleAnimatorListener "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/java/com/aspsine/irecyclerview/SimpleAnimatorListener.java"
    click Attrs "https://github.com/aspsine/irecyclerview/blob/master/library/src/main/res/values/attrs.xml"
    click RotateUp "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/res/anim/rotate_up.xml"
    click RotateDown "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/res/anim/rotate_down.xml"
    click MainActivity "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/activity/MainActivity.java"
    click ImageAdapter "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/ImageAdapter.java"
    click OnItemClickListener "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/OnItemClickListener.java"
    click NetworkAPI "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/network/NetworkAPI.java"
    click OkHttp "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/network/OkHttp.java"
    click BatVsSupperHeaderView "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/widget/header/BatVsSupperHeaderView.java"
    click ClassicRefreshHeaderView "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/widget/header/ClassicRefreshHeaderView.java"
    click LoadMoreFooterView "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/widget/footer/LoadMoreFooterView.java"
    click BannerView "https://github.com/aspsine/irecyclerview/blob/master/app/src/main/java/com/aspsine/irecyclerview/demo/ui/widget/BannerView.java"
    click Assets "https://github.com/aspsine/irecyclerview/tree/master/app/src/main/assets/api/superman_vs_batman/gallery"

    %% Styles
    classDef library fill:#FEF2D8,stroke:#E69900,stroke-width:2px;
    classDef demo fill:#D7E8D5,stroke:#38761D,stroke-width:2px;
    classDef util fill:#D0E0E3,stroke:#1155CC,stroke-width:2px;
    classDef resource fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
    classDef network fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
```
