From 9a03036e3850bf156f23e2cac177b22d46d70127 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 13:15:33 +0200 Subject: [PATCH 1/8] add vararg to manager --- .../AdapterDelegatesManager.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AdapterDelegatesManager.java b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AdapterDelegatesManager.java index 14bede7..7cd9a77 100644 --- a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AdapterDelegatesManager.java +++ b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AdapterDelegatesManager.java @@ -73,6 +73,21 @@ public class AdapterDelegatesManager { */ protected SparseArrayCompat> delegates = new SparseArrayCompat(); protected AdapterDelegate fallbackDelegate; + + /** + * Creates a AdapterDelegatesManager without any delegates. + */ + public AdapterDelegatesManager() { + } + + /** + * Creates a AdapterDelegatesManager which already has the gived delegates added to it. + */ + public AdapterDelegatesManager(@NonNull AdapterDelegate... delegates) { + for (int i = 0; i < delegates.length; i++) { + addDelegate(delegates[i]); + } + } /** * Adds an {@link AdapterDelegate}. From 75f182075922eda0a5dc97b0f6149443ccb7591e Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 13:16:18 +0200 Subject: [PATCH 2/8] Update AsyncListDifferDelegationAdapter.java --- .../AsyncListDifferDelegationAdapter.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java index 9e31ba9..dc8e075 100644 --- a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java +++ b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java @@ -75,6 +75,41 @@ public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig, this.differ = new AsyncListDiffer(new AdapterListUpdateCallback(this), differConfig); this.delegatesManager = delegatesManager; } + + /** + * Adds a list of {@link AdapterDelegate}s + * + * @param delegates + * @since 4.2.0 + */ + public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback diffCallback, + @NonNull AdapterDelegate... delegates) { + + if (diffCallback == null) { + throw new NullPointerException("ItemCallback is null"); + } + + this.differ = new AsyncListDiffer(this, diffCallback); + this.delegatesManager = new AdapterDelegatesManager(delegates); + } + + + /** + * Adds a list of {@link AdapterDelegate}s + * + * @param delegates + * @since 4.2.0 + */ + public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig, + @NonNull AdapterDelegate... delegates) { + + if (differConfig == null) { + throw new NullPointerException("AsyncDifferConfig is null"); + } + + this.differ = new AsyncListDiffer(new AdapterListUpdateCallback(this), differConfig); + this.delegatesManager = new AdapterDelegatesManager(delegates); + } @NonNull @Override From 7ff85220a479234eeb194cdbcd7e5b244cac0d7e Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 13:17:10 +0200 Subject: [PATCH 3/8] Update AbsDelegationAdapter.java --- .../adapterdelegates4/AbsDelegationAdapter.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AbsDelegationAdapter.java b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AbsDelegationAdapter.java index 0768bd7..e08fe7f 100644 --- a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AbsDelegationAdapter.java +++ b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AbsDelegationAdapter.java @@ -79,10 +79,7 @@ public AbsDelegationAdapter(@NonNull AdapterDelegatesManager delegatesManager * @since 4.1.0 */ public AbsDelegationAdapter(@NonNull AdapterDelegate... delegates) { - this(); - for (int i = 0; i < delegates.length; i++) { - delegatesManager.addDelegate(delegates[i]); - } + this(new AdapterDelegatesManager(delegates)); } @NonNull From 2851c6950a2ed8d24fffa53cff9a5347803fa76a Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 15:28:09 +0200 Subject: [PATCH 4/8] Update AsyncListDifferDelegationAdapter.java --- .../adapterdelegates4/AsyncListDifferDelegationAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java index dc8e075..845a5f7 100644 --- a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java +++ b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java @@ -90,7 +90,7 @@ public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback diffCa } this.differ = new AsyncListDiffer(this, diffCallback); - this.delegatesManager = new AdapterDelegatesManager(delegates); + this.delegatesManager = new AdapterDelegatesManager>(delegates); } @@ -108,7 +108,7 @@ public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig, } this.differ = new AsyncListDiffer(new AdapterListUpdateCallback(this), differConfig); - this.delegatesManager = new AdapterDelegatesManager(delegates); + this.delegatesManager = new AdapterDelegatesManager>(delegates); } @NonNull From f4a00849d294750a9fd1c85ceb8b042f5fef4d9b Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 15:31:52 +0200 Subject: [PATCH 5/8] Update AsyncListDifferDelegationAdapter.java --- .../adapterdelegates4/AsyncListDifferDelegationAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java index 845a5f7..1e88336 100644 --- a/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java +++ b/library/src/main/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapter.java @@ -83,7 +83,7 @@ public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig, * @since 4.2.0 */ public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback diffCallback, - @NonNull AdapterDelegate... delegates) { + @NonNull AdapterDelegate>... delegates) { if (diffCallback == null) { throw new NullPointerException("ItemCallback is null"); @@ -101,7 +101,7 @@ public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback diffCa * @since 4.2.0 */ public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig, - @NonNull AdapterDelegate... delegates) { + @NonNull AdapterDelegate>... delegates) { if (differConfig == null) { throw new NullPointerException("AsyncDifferConfig is null"); From 28ba520148691cb2c1d09a5a0b88cf16b2d1136b Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 15:54:19 +0200 Subject: [PATCH 6/8] Update AsyncListDifferDelegationAdapterTest.java --- .../adapterdelegates4/AsyncListDifferDelegationAdapterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/test/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapterTest.java b/library/src/test/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapterTest.java index 9a24c54..6b9cbf0 100644 --- a/library/src/test/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapterTest.java +++ b/library/src/test/java/com/hannesdorfmann/adapterdelegates4/AsyncListDifferDelegationAdapterTest.java @@ -48,7 +48,7 @@ public int getItemCount() { @Test public void adapterDelegateManagerIsNull() { try { - AsyncListDifferDelegationAdapter adapter = new AsyncListDifferDelegationAdapter(callback, null) { + AsyncListDifferDelegationAdapter adapter = new AsyncListDifferDelegationAdapter(callback, (AdapterDelegatesManager) null) { @Override public int getItemCount() { return 0; From 8f3b782b150a8acca8db74ff334efb5a2205571d Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 16:02:34 +0200 Subject: [PATCH 7/8] Update PagedListDelegationAdapterTest.java --- .../paging/PagedListDelegationAdapterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java b/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java index eedc160..821da7c 100644 --- a/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java +++ b/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java @@ -49,7 +49,7 @@ public int getItemCount() { @Test public void adapterDelegateManagerIsNull() { try { - AsyncListDifferDelegationAdapter adapter = new AsyncListDifferDelegationAdapter(callback, null) { + AsyncListDifferDelegationAdapter adapter = new PagedListDelegationAdapter(null, callback) { @Override public int getItemCount() { return 0; From ecc59b0f165ea15375ba3a2152764b95728ae4e1 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Wed, 4 Sep 2019 16:13:14 +0200 Subject: [PATCH 8/8] Update PagedListDelegationAdapterTest.java --- .../paging/PagedListDelegationAdapterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java b/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java index 821da7c..43af5b3 100644 --- a/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java +++ b/paging/src/test/java/com/hannesdorfmann/adapterdelegates4/paging/PagedListDelegationAdapterTest.java @@ -49,7 +49,7 @@ public int getItemCount() { @Test public void adapterDelegateManagerIsNull() { try { - AsyncListDifferDelegationAdapter adapter = new PagedListDelegationAdapter(null, callback) { + PagedListDelegationAdapter adapter = new PagedListDelegationAdapter(null, callback) { @Override public int getItemCount() { return 0;