Search in sources :

Example 1 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem in project AdapterDelegates by sockeqwe.

the class ReptilesActivity method getAnimals.

private List<DisplayableItem> getAnimals() {
    List<DisplayableItem> animals = new ArrayList<>();
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    animals.add(new UnknownReptile());
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    Collections.shuffle(animals);
    return animals;
}
Also used : DisplayableItem(com.hannesdorfmann.adapterdelegates3.sample.model.DisplayableItem) Snake(com.hannesdorfmann.adapterdelegates3.sample.model.Snake) UnknownReptile(com.hannesdorfmann.adapterdelegates3.sample.model.UnknownReptile) ArrayList(java.util.ArrayList) Gecko(com.hannesdorfmann.adapterdelegates3.sample.model.Gecko)

Example 2 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem in project AdapterDelegates by sockeqwe.

the class PaginationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pagination);
    RecyclerView recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    AdapterDelegatesManager<List<DisplayableItem>> delegatesManager = new AdapterDelegatesManager<List<DisplayableItem>>().addDelegate(new AdvertisementAdapterDelegate(this)).addDelegate(new CatAdapterDelegate(this)).addDelegate(new DogAdapterDelegate(this)).addDelegate(new GeckoAdapterDelegate(this)).addDelegate(new SnakeListItemAdapterDelegate(this)).setFallbackDelegate(new LoadingAdapterDelegate(this));
    final PagedListDelegationAdapter<DisplayableItem> adapter = new PagedListDelegationAdapter<DisplayableItem>(delegatesManager, callback);
    recyclerView.setAdapter(adapter);
    LiveData<PagedList<DisplayableItem>> pagedListLiveData = new LivePagedListBuilder<>(new SampleDataSource.Factory(), 20).setBoundaryCallback(new PagedList.BoundaryCallback<DisplayableItem>() {

        @Override
        public void onZeroItemsLoaded() {
            Log.d("PaginationSource", "onZeroItemsLoaded");
            super.onZeroItemsLoaded();
        }

        @Override
        public void onItemAtFrontLoaded(@NonNull DisplayableItem itemAtFront) {
            Log.d("PaginationSource", "onItemAtFrontLoaded " + itemAtFront);
            super.onItemAtFrontLoaded(itemAtFront);
        }

        @Override
        public void onItemAtEndLoaded(@NonNull DisplayableItem itemAtEnd) {
            Log.d("PaginationSource", "onItemAtEndLoaded " + itemAtEnd);
            super.onItemAtEndLoaded(itemAtEnd);
        }
    }).build();
    pagedListLiveData.observe(this, new Observer<PagedList<DisplayableItem>>() {

        @Override
        public void onChanged(PagedList<DisplayableItem> displayableItems) {
            adapter.submitList(displayableItems);
        }
    });
}
Also used : CatAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.CatAdapterDelegate) DisplayableItem(com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem) PagedList(androidx.paging.PagedList) SnakeListItemAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.SnakeListItemAdapterDelegate) DogAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.DogAdapterDelegate) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AdapterDelegatesManager(com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager) GeckoAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.GeckoAdapterDelegate) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) NonNull(androidx.annotation.NonNull) AdvertisementAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.AdvertisementAdapterDelegate) RecyclerView(androidx.recyclerview.widget.RecyclerView) PagedList(androidx.paging.PagedList) List(java.util.List) PagedListDelegationAdapter(com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter)

Example 3 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem in project AdapterDelegates by sockeqwe.

the class ReptilesActivity method getAnimals.

private List<DisplayableItem> getAnimals() {
    List<DisplayableItem> animals = new ArrayList<>();
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    animals.add(new UnknownReptile());
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    Collections.shuffle(animals);
    return animals;
}
Also used : DisplayableItem(com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem) Snake(com.hannesdorfmann.adapterdelegates4.sample.model.Snake) UnknownReptile(com.hannesdorfmann.adapterdelegates4.sample.model.UnknownReptile) ArrayList(java.util.ArrayList) Gecko(com.hannesdorfmann.adapterdelegates4.sample.model.Gecko)

Example 4 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem in project AdapterDelegates by sockeqwe.

the class DogAdapterDelegate method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull List<DisplayableItem> items, int position, @NonNull RecyclerView.ViewHolder holder, @Nullable List<Object> payloads) {
    DogViewHolder vh = (DogViewHolder) holder;
    Dog dog = (Dog) items.get(position);
    vh.name.setText(dog.getName());
    Log.d("Scroll", "DogAdapterDelegate bind  " + position);
}
Also used : Dog(com.hannesdorfmann.adapterdelegates4.sample.model.Dog)

Example 5 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem in project AdapterDelegates by sockeqwe.

the class MainActivity method getAnimals.

private List<DisplayableItem> getAnimals() {
    List<DisplayableItem> animals = new ArrayList<>();
    animals.add(new Cat("American Curl"));
    animals.add(new Cat("Baliness"));
    animals.add(new Cat("Bengal"));
    animals.add(new Cat("Corat"));
    animals.add(new Cat("Manx"));
    animals.add(new Cat("Nebelung"));
    animals.add(new Dog("Aidi"));
    animals.add(new Dog("Chinook"));
    animals.add(new Dog("Appenzeller"));
    animals.add(new Dog("Collie"));
    animals.add(new Snake("Mub Adder", "Adder"));
    animals.add(new Snake("Texas Blind Snake", "Blind snake"));
    animals.add(new Snake("Tree Boa", "Boa"));
    animals.add(new Gecko("Fat-tailed", "Hemitheconyx"));
    animals.add(new Gecko("Stenodactylus", "Dune Gecko"));
    animals.add(new Gecko("Leopard Gecko", "Eublepharis"));
    animals.add(new Gecko("Madagascar Gecko", "Phelsuma"));
    animals.add(new Advertisement());
    animals.add(new Advertisement());
    animals.add(new Advertisement());
    animals.add(new Advertisement());
    animals.add(new Advertisement());
    Collections.shuffle(animals);
    return animals;
}
Also used : DisplayableItem(com.hannesdorfmann.adapterdelegates3.sample.model.DisplayableItem) Snake(com.hannesdorfmann.adapterdelegates3.sample.model.Snake) Cat(com.hannesdorfmann.adapterdelegates3.sample.model.Cat) ArrayList(java.util.ArrayList) Advertisement(com.hannesdorfmann.adapterdelegates3.sample.model.Advertisement) Dog(com.hannesdorfmann.adapterdelegates3.sample.model.Dog) Gecko(com.hannesdorfmann.adapterdelegates3.sample.model.Gecko)

Aggregations

ArrayList (java.util.ArrayList)4 DisplayableItem (com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem)3 Gecko (com.hannesdorfmann.adapterdelegates4.sample.model.Gecko)3 DisplayableItem (com.hannesdorfmann.adapterdelegates3.sample.model.DisplayableItem)2 Gecko (com.hannesdorfmann.adapterdelegates3.sample.model.Gecko)2 Snake (com.hannesdorfmann.adapterdelegates3.sample.model.Snake)2 Cat (com.hannesdorfmann.adapterdelegates4.sample.model.Cat)2 Dog (com.hannesdorfmann.adapterdelegates4.sample.model.Dog)2 Snake (com.hannesdorfmann.adapterdelegates4.sample.model.Snake)2 NonNull (androidx.annotation.NonNull)1 LivePagedListBuilder (androidx.paging.LivePagedListBuilder)1 PagedList (androidx.paging.PagedList)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Advertisement (com.hannesdorfmann.adapterdelegates3.sample.model.Advertisement)1 Cat (com.hannesdorfmann.adapterdelegates3.sample.model.Cat)1 Dog (com.hannesdorfmann.adapterdelegates3.sample.model.Dog)1 UnknownReptile (com.hannesdorfmann.adapterdelegates3.sample.model.UnknownReptile)1 AdapterDelegatesManager (com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager)1 PagedListDelegationAdapter (com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter)1