Giter VIP home page Giter VIP logo

tangram's Introduction

Tangram

Gradle

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.ShortStickBoy:Tangram:5.2.8'
}

Use

Step 1. Add the TangramView to your layout file

<com.sunzn.tangram.library.view.TangramView
    android:id="@+id/tangram"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:FooterDone="@layout/state_view_done"
    app:FooterFail="@layout/state_view_fail"
    app:FooterLoad="@layout/state_view_load" />

Step 2. Bind the view id to the entity class with @LayoutAnnotation

@LayoutAnnotation(R.layout.item)
public class Item extends TangramBean {

    private String name;
    private String pass;

}

Step 3. Create ItemViewHolder, set OnClickListener and bind the view

public class ItemViewHolder extends TangramViewHolder<Item, RecyclerAdapter> {

    private final String TAG = "ItemViewHolder";

    public ItemViewHolder(final View itemView, RecyclerAdapter adapter) {
        super(itemView, adapter);
        TextView view = getView(R.id.item_tv);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "item:" + getAdapterPosition());
            }
        });
    }

    @Override
    public void onBindViewHolder(Item model, int position, RecyclerAdapter adapter) {
        TextView view = getView(R.id.item_tv);
        view.setText("item" + position);
    }

}

Step 4. Create RecyclerAdapter, create custom ViewHolder and set view's SpanCount

public class RecyclerAdapter extends TangramAdapter implements GridSpanSizeListener {

    public RecyclerAdapter() {
        super();
        setSpanSizeListener(this);
    }

    public RecyclerAdapter(List<TangramBean> beans) {
        super(beans);
        setSpanSizeListener(this);
    }

    @Override
    public TangramViewHolder onCreateViewHolder(int viewType, View itemView) {
        switch (viewType) {
            case R.layout.item_head:
                return new HeadViewHolder(itemView, this);
            case R.layout.item:
                return new ItemViewHolder(itemView, this);
            case R.layout.foot:
                return new FootViewHolder(itemView, this);
            case R.layout.done:
                return new DoneViewHolder(itemView, this);
            case R.layout.line:
                return new LineViewHolder(itemView, this);
        }
        return null;
    }

    @Override
    public int onGetSpanCount(int viewType, GridLayoutManager manager) {
        switch (viewType) {
            case R.layout.item_head:
                return manager.getSpanCount();
            case R.layout.item:
                return manager.getSpanCount();
            case R.layout.foot:
                return 3;
            case R.layout.done:
                return 2;
            case R.layout.line:
                return manager.getSpanCount();
        }
        return manager.getSpanCount();
    }

}

Step 5. Use in activity

TangramView tangram = findViewById(R.id.tangram);
ArrayList<TangramBean> beans = new ArrayList<>();

for (int i = 0; i < 1; i++) {
    beans.add(new Item());
}
for (int i = 0; i < 9; i++) {
    beans.add(new Done());
}
for (int i = 0; i < 1; i++) {
    beans.add(new Item());
}
for (int i = 0; i < 9; i++) {
    beans.add(new Done());
}

tangram.setLayoutManager(new GridLayoutManager(this, 6));
adapter = new RecyclerAdapter();
adapter.setData(beans);
tangram.setCompatAdapter(adapter);

Attribute

Attribute Describe Additional
FooterLoad Footer status for load If you setLoadMoreListener, this value must never be null.
FooterFail Footer status for fail If you setLoadMoreListener, this value must never be null.
FooterDone Footer status for done If you setLoadMoreListener, this value must never be null.

License

Copyright [2016-2019] sunzn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

tangram's People

Contributors

uncn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.