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);
}
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();
}
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();
}
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);
}
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();
}
Aggregations