Search in sources :

Example 1 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates3.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.adapterdelegates3.sample.model.Dog)

Example 2 with DisplayableItem

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

the class GeckoAdapterDelegate method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull List<DisplayableItem> items, int position, @NonNull RecyclerView.ViewHolder holder, @Nullable List<Object> payloads) {
    GeckoViewHolder vh = (GeckoViewHolder) holder;
    Gecko gecko = (Gecko) items.get(position);
    vh.name.setText(gecko.getName());
    vh.race.setText(gecko.getRace());
    Log.d("Scroll", "GeckoAdapterDelegate bind  " + position);
}
Also used : Gecko(com.hannesdorfmann.adapterdelegates3.sample.model.Gecko)

Example 3 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates3.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 4 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates3.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 5 with DisplayableItem

use of com.hannesdorfmann.adapterdelegates3.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)

Aggregations

ArrayList (java.util.ArrayList)4 Gecko (com.hannesdorfmann.adapterdelegates3.sample.model.Gecko)3 DisplayableItem (com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem)3 Cat (com.hannesdorfmann.adapterdelegates3.sample.model.Cat)2 DisplayableItem (com.hannesdorfmann.adapterdelegates3.sample.model.DisplayableItem)2 Dog (com.hannesdorfmann.adapterdelegates3.sample.model.Dog)2 Snake (com.hannesdorfmann.adapterdelegates3.sample.model.Snake)2 Gecko (com.hannesdorfmann.adapterdelegates4.sample.model.Gecko)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 UnknownReptile (com.hannesdorfmann.adapterdelegates3.sample.model.UnknownReptile)1 AdapterDelegatesManager (com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager)1 PagedListDelegationAdapter (com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter)1 AdvertisementAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.AdvertisementAdapterDelegate)1 CatAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.CatAdapterDelegate)1