Search in sources :

Example 1 with DefaultHeader

use of com.shizhefei.view.coolrefreshview.header.DefaultHeader in project MVCHelper by LuckyJayce.

the class StateHeaderFragment method onCreateViewLazy.

@Override
protected void onCreateViewLazy(Bundle savedInstanceState) {
    super.onCreateViewLazy(savedInstanceState);
    setContentView(R.layout.fragment_recyclerview);
    coolRefreshView = (CoolRefreshView) findViewById(R.id.recyclerview_funnyRefreshView);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview_recyclerView);
    coolRefreshView.setPullHeader(new DefaultHeader());
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mvcHelper = new MVCCoolHelper<>(coolRefreshView);
    mvcHelper.setDataSource(new BooksOkHttp_AsyncDataSource());
    //        mvcHelper.setAdapter(adapter = new ReBooksAdapter(getContext()));
    //这里模拟viewAdapter 和 dataAdapter不是同一个的情况
    mvcHelper.setAdapter2(adapter = new ReBooksAdapter(getContext()), new IDataAdapter<List<Book>>() {

        @Override
        public void notifyDataChanged(List<Book> books, boolean isRefresh) {
            if (books.size() > 5) {
                adapter.notifyDataChanged(books.subList(0, 5), isRefresh);
            } else {
                adapter.notifyDataChanged(books, isRefresh);
            }
        }

        @Override
        public List<Book> getData() {
            return adapter.getData();
        }

        @Override
        public boolean isEmpty() {
            return adapter.isEmpty();
        }
    });
    mvcHelper.refresh();
}
Also used : BooksOkHttp_AsyncDataSource(com.shizhefei.test.models.datasource.okhttp.BooksOkHttp_AsyncDataSource) Book(com.shizhefei.test.models.enties.Book) DefaultHeader(com.shizhefei.view.coolrefreshview.header.DefaultHeader) ReBooksAdapter(com.shizhefei.test.view.adapters.ReBooksAdapter) List(java.util.List) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 2 with DefaultHeader

use of com.shizhefei.view.coolrefreshview.header.DefaultHeader in project MVCHelper by LuckyJayce.

the class MultiTypeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multi_type);
    backButton = findViewById(R.id.button1);
    coolRefreshView = (CoolRefreshView) findViewById(R.id.multiType_coolRefreshView);
    recyclerView = (RecyclerView) findViewById(R.id.multiType_recyclerView);
    coolRefreshView.setPullHeader(new DefaultHeader());
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    ItemBinderFactory factory = new ItemBinderFactory();
    factory.registerProvider(Book.class, new BookProvider());
    factory.registerProvider(Message.class, new ItemViewProviderSet<Message>(new MessageProvider(MessageProvider.ALIGN_LEFT), new MessageProvider(MessageProvider.ALIGN_RIGHT)) {

        @Override
        protected int selectIndex(Message message) {
            return myUserId.equals(message.userId) ? 1 : 0;
        }
    });
    multiTypeDataAdapter = new MultiTypeDataAdapter<>(factory);
    //        adapter.addHeader(view);
    multiTypeDataAdapter.setOnItemClickListener(OnItemClickListener);
    mvcHelper = new MVCCoolHelper<>(coolRefreshView);
    mvcHelper.setDataSource(new MyDataSource());
    mvcHelper.setAdapter(multiTypeDataAdapter);
    mvcHelper.refresh();
    backButton.setOnClickListener(OnClickListener);
}
Also used : MyDataSource(com.shizhefei.test.models.datasource.MyDataSource) MessageProvider(com.shizhefei.test.view.adapters.multitype.provider.MessageProvider) Message(com.shizhefei.test.view.adapters.multitype.Message) ItemBinderFactory(com.shizhefei.view.multitype.ItemBinderFactory) DefaultHeader(com.shizhefei.view.coolrefreshview.header.DefaultHeader) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BookProvider(com.shizhefei.test.view.adapters.multitype.provider.BookProvider)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 DefaultHeader (com.shizhefei.view.coolrefreshview.header.DefaultHeader)2 MyDataSource (com.shizhefei.test.models.datasource.MyDataSource)1 BooksOkHttp_AsyncDataSource (com.shizhefei.test.models.datasource.okhttp.BooksOkHttp_AsyncDataSource)1 Book (com.shizhefei.test.models.enties.Book)1 ReBooksAdapter (com.shizhefei.test.view.adapters.ReBooksAdapter)1 Message (com.shizhefei.test.view.adapters.multitype.Message)1 BookProvider (com.shizhefei.test.view.adapters.multitype.provider.BookProvider)1 MessageProvider (com.shizhefei.test.view.adapters.multitype.provider.MessageProvider)1 ItemBinderFactory (com.shizhefei.view.multitype.ItemBinderFactory)1 List (java.util.List)1