Search in sources :

Example 11 with MultiTypeAdapter

use of me.drakeet.multitype.MultiTypeAdapter in project MultiType by drakeet.

the class OneDataToManyActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    recyclerView = findViewById(R.id.list);
    adapter = new MultiTypeAdapter();
    /*
        adapter.register(Data.class).to(
            new DataType1ViewBinder(),
            new DataType2ViewBinder()
        ).withLinker((position, data) ->
            data.type == Data.TYPE_2 ? 1 : 0
        );
        */
    adapter.register(Data.class).to(new DataType1ViewBinder(), new DataType2ViewBinder()).withClassLinker((position, data) -> {
        if (data.type == Data.TYPE_2) {
            return DataType2ViewBinder.class;
        } else {
            return DataType1ViewBinder.class;
        }
    });
    List<Data> dataList = getDataFromService();
    adapter.setItems(dataList);
    adapter.notifyDataSetChanged();
    recyclerView.setAdapter(adapter);
}
Also used : MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 12 with MultiTypeAdapter

use of me.drakeet.multitype.MultiTypeAdapter in project MultiType by drakeet.

the class TestPayloadActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    RecyclerView recyclerView = findViewById(R.id.list);
    recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
    MultiTypeAdapter adapter = new MultiTypeAdapter();
    recyclerView.setAdapter(adapter);
    adapter.register(HeavyItem.class, new HeavyItemViewBinder());
    Items items = new Items();
    for (int i = 0; i < 30; i++) {
        items.add(new HeavyItem("1000" + i));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
    Toast.makeText(this, "Try to click or long click items", Toast.LENGTH_SHORT).show();
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) Items(me.drakeet.multitype.Items) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 13 with MultiTypeAdapter

use of me.drakeet.multitype.MultiTypeAdapter in project MultiType by drakeet.

the class WeiboActivity method onCreate.

/* @formatter:on */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    RecyclerView recyclerView = findViewById(R.id.list);
    adapter = new MultiTypeAdapter();
    adapter.register(Weibo.class).to(new SimpleTextViewBinder(), new SimpleImageViewBinder()).withLinker((position, weibo) -> {
        if (weibo.content instanceof SimpleText) {
            return 0;
        } else if (weibo.content instanceof SimpleImage) {
            return 1;
        }
        return 0;
    });
    recyclerView.setAdapter(adapter);
    items = new Items();
    User user = new User("drakeet", R.mipmap.avatar);
    SimpleText simpleText = new SimpleText("A simple text Weibo: Hello World.");
    SimpleImage simpleImage = new SimpleImage(R.drawable.img_10);
    for (int i = 0; i < 20; i++) {
        items.add(new Weibo(user, simpleText));
        items.add(new Weibo(user, simpleImage));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
    assertAllRegistered(adapter, items);
    loadRemoteData();
}
Also used : SimpleText(me.drakeet.multitype.sample.weibo.content.SimpleText) SimpleImageViewBinder(me.drakeet.multitype.sample.weibo.content.SimpleImageViewBinder) SimpleImage(me.drakeet.multitype.sample.weibo.content.SimpleImage) SimpleTextViewBinder(me.drakeet.multitype.sample.weibo.content.SimpleTextViewBinder) RecyclerView(android.support.v7.widget.RecyclerView) Items(me.drakeet.multitype.Items) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 14 with MultiTypeAdapter

use of me.drakeet.multitype.MultiTypeAdapter in project MultiType by drakeet.

the class SimpleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    Items items = new Items();
    adapter = new MultiTypeAdapter();
    adapter.register(TextItem.class, new TextItemWithOutsizeDataViewBinder(aFieldValue));
    recyclerView.setAdapter(adapter);
    assertHasTheSameAdapter(recyclerView, adapter);
    for (int i = 0; i < 20; i++) {
        items.add(new TextItem(valueOf(i)));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
    assertAllRegistered(adapter, items);
}
Also used : TextItem(me.drakeet.multitype.sample.normal.TextItem) RecyclerView(android.support.v7.widget.RecyclerView) Items(me.drakeet.multitype.Items) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 15 with MultiTypeAdapter

use of me.drakeet.multitype.MultiTypeAdapter in project MultiType by drakeet.

the class MoreApisPlayground method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_more_apis_playground);
    recyclerView = findViewById(R.id.list);
    terminal = findViewById(R.id.terminal);
    terminal.setText(TERMINAL_DEFAULT_TEXT);
    items = new Items();
    adapter = new MultiTypeAdapter();
    adapter.register(TextItem.class, new ObservableTextItemViewBinder());
    recyclerView.setAdapter(adapter);
    for (int i = 0; i < 200; i++) {
        items.add(new TextItem(valueOf(i)));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
}
Also used : TextItem(me.drakeet.multitype.sample.normal.TextItem) Items(me.drakeet.multitype.Items) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter) SuppressLint(android.annotation.SuppressLint)

Aggregations

MultiTypeAdapter (me.drakeet.multitype.MultiTypeAdapter)16 Items (me.drakeet.multitype.Items)11 RecyclerView (android.support.v7.widget.RecyclerView)8 GridLayoutManager (android.support.v7.widget.GridLayoutManager)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 Category (me.drakeet.multitype.sample.common.Category)3 TextItem (me.drakeet.multitype.sample.normal.TextItem)3 CategoryItemViewBinder (me.drakeet.multitype.sample.common.CategoryItemViewBinder)2 AlarmInfoProvider (adapter.AlarmInfoProvider)1 LogInfoProvider (adapter.LogInfoProvider)1 RecordFileProvider (adapter.RecordFileProvider)1 SensorProvider (adapter.SensorProvider)1 SerialAppProvider (adapter.SerialAppProvider)1 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)1 Category (com.jweihao.jdemo.bean.Category)1 Post (com.jweihao.jdemo.bean.Post)1