XFrame Android Rapid Development Framework

repository·master·Indexed 22 days ago

https://github.com/youth5201314/xframe

An Android rapid development framework providing utility tools and wrappers to reduce boilerplate. Key features include XHttp for network isolation, XLog for formatted logging, XPermission for dynamic permission management, XRecyclerViewAdapter for advanced list handling, and XCache for data caching.

Tokens
1.3K
Snippets
2
Records
3
Agent score
28%

What's inside XFrame

  1. Overview of XFrame features

    master

    XFrame is a collection of Android development tools designed to reduce boilerplate and simplify complex operations. Key features include:

    • XHttp: A network request isolation framework that allows switching between third-party network libraries with a single line of code and provides automatic JSON parsing.
    • XLog: A logging utility that supports formatted output for JSON, XML, Map, and List, with global configuration support.
    • XLoadingView: A unified manager for page states (Loading, No Network, No Data, Error).
    • XLoadingDialog: A simple implementation for loading/waiting dialogs.
    • XPermission: Simplifies Android dynamic permission management.
    • XRecyclerViewAdapter: A library for RecyclerView.Adapter that supports Headers, Footers, 'Load More', 'Load Failed', 'Reached Bottom', and multiple layout types.
    • XCache: A caching utility for Strings, Bitmaps, Drawables, Serializable Java objects, and byte data.
    • XStatusBar: Implements immersive status bar effects.
    • XToast: A simplified Toast implementation.
    • Utils: A collection of common utility classes.
    • Custom Views: A set of built-in custom UI controls.
  2. Install XFrame in your Android project

    master

    You can integrate XFrame into your Android project using either a remote Gradle dependency or by referencing a local module.

    Note: The project uses the compile configuration, which is common in older Gradle versions. For modern projects, you may need to replace compile with implementation.

    // Option 1: Using remote Gradle dependency
    dependencies {
        compile 'com.youth.xframe:xframe:1.1.2'
    }
    
    // Option 2: Referencing a local module
    dependencies {
        compile project(':xframe')
    }
  3. Implement StickyHeaderAdapter for RecyclerView sticky headers

    master

    To implement sticky headers in a RecyclerView, you must implement the StickyHeaderDecoration.IStickyHeaderAdapter<VH> interface. This interface allows you to define how header IDs are calculated, how the header view is created, and how the header data is bound to the view holder.

    Key methods to implement:

    • getHeaderId(int position): Returns a unique long ID for the header at the given position. This is used to determine when a header should change.
    • onCreateHeaderViewHolder(ViewGroup parent): Inflates the layout for the header and returns a new ViewHolder instance.
    • onBindHeaderViewHolder(VH viewholder, int position): Binds the data to the header view holder based on the position.

    Note: The StickyHeaderAdapter class provided in the source is a concrete implementation example that uses a custom HeaderHolder to manage a TextView.

    // Example implementation of the IStickyHeaderAdapter interface
    public class MyStickyHeaderAdapter implements StickyHeaderDecoration.IStickyHeaderAdapter<MyHeaderHolder> {
        private LayoutInflater mInflater;
    
        public MyStickyHeaderAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
        }
    
        @Override
        public long getHeaderId(int position) {
            // Logic to group items into headers (e.g., every 3 items)
            return position / 3;
        }
    
        @Override
        public MyHeaderHolder onCreateHeaderViewHolder(ViewGroup parent) {
            final View view = mInflater.inflate(R.layout.your_header_layout, parent, false);
            return new MyHeaderHolder(view);
        }
    
        @Override
        public void onBindHeaderViewHolder(MyHeaderHolder viewholder, int position) {
            // Bind data to the header view
            viewholder.textView.setText("Header " + getHeaderId(position));
        }
    
        static class MyHeaderHolder extends RecyclerView.ViewHolder {
            public TextView textView;
            public MyHeaderHolder(View itemView) {
                super(itemView);
                textView = (TextView) itemView;
            }
        }
    }