Skip to content

Commit

Permalink
Merge pull request #27 from bartoszwilk/refactor-sample-recyclerview
Browse files Browse the repository at this point in the history
Refactor sample-recyclerview
  • Loading branch information
mkoslacz authored Dec 20, 2016
2 parents 0735fd2 + 57114ae commit 3878cb3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.hannesdorfmann.mosby.mvp.MvpView;
import com.mateuszkoslacz.moviper.base.view.MvpRecyclerViewAdapter;
import com.mateuszkoslacz.moviper.base.view.MvpBaseViewHolder;
import com.mateuszkoslacz.moviper.recyclerviewsample.viper.view.adapter.agregate.HeaderListingItem;
import com.mateuszkoslacz.moviper.recyclerviewsample.viper.view.adapter.agregate.ListingItem;
import com.mateuszkoslacz.moviper.recyclerviewsample.viper.view.adapter.agregate.ProductListingItem;
import com.mateuszkoslacz.moviper.recyclerviewsample.viper.view.adapter.delegate.HeaderAdapterDelegate;
import com.mateuszkoslacz.moviper.recyclerviewsample.viper.view.adapter.delegate.ProductAdapterDelegate;

Expand All @@ -23,14 +25,14 @@ public class ProductAdapter
MvpBaseViewHolder> {

private List<ListingItem> mListingItems;
private AdapterDelegatesManager mDelegatesManager;
private AdapterDelegatesManager<List<ListingItem>> mDelegatesManager;

public ProductAdapter() {
mListingItems = new ArrayList<>();
mDelegatesManager = new AdapterDelegatesManager();
mDelegatesManager = new AdapterDelegatesManager<>();
mDelegatesManager
.addDelegate(ListingItem.TYPE_HEADER, new HeaderAdapterDelegate())
.addDelegate(ListingItem.TYPE_PRODUCT, new ProductAdapterDelegate());
.addDelegate(HeaderListingItem.TYPE, new HeaderAdapterDelegate())
.addDelegate(ProductListingItem.TYPE, new ProductAdapterDelegate());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class HeaderListingItem implements ListingItem {

public static final int TYPE = HeaderListingItem.class.hashCode();
private Category mCategory;

public HeaderListingItem(Category category) {
Expand All @@ -16,7 +17,7 @@ public HeaderListingItem(Category category) {

@Override
public int getType() {
return ListingItem.TYPE_HEADER;
return TYPE;
}

public Category getCategory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

public interface ListingItem {

int TYPE_HEADER = 0;
int TYPE_PRODUCT = 1;

int getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class ProductListingItem implements ListingItem {

public static final int TYPE = ProductListingItem.class.hashCode();
private Product mProduct;

public ProductListingItem(Product product) {
Expand All @@ -16,7 +17,7 @@ public ProductListingItem(Product product) {

@Override
public int getType() {
return ListingItem.TYPE_PRODUCT;
return TYPE;
}

public Product getProduct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class HeaderAdapterDelegate extends AdapterDelegate<List<ListingItem>> {

@Override
protected boolean isForViewType(@NonNull List<ListingItem> items, int position) {
return items.get(position).getType() == ListingItem.TYPE_HEADER;
return items.get(position).getType() == HeaderListingItem.TYPE;
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ProductAdapterDelegate extends AdapterDelegate<List<ListingItem>> {

@Override
protected boolean isForViewType(@NonNull List<ListingItem> items, int position) {
return items.get(position).getType() == ListingItem.TYPE_PRODUCT;
return items.get(position).getType() == ProductListingItem.TYPE;
}

@NonNull
Expand Down

0 comments on commit 3878cb3

Please sign in to comment.