Permalink
Browse files

Reformat code with K&R code style

  • Loading branch information...
petrnohejl committed Jun 22, 2018
1 parent 820ef3a commit c981c9de7e67638bc32244fb0f12df82efcbe139
Showing with 1,918 additions and 4,762 deletions.
  1. +8 −16 alfonz-adapter/README.md
  2. +2 −5 alfonz-adapter/build.gradle
  3. +1 −3 alfonz-adapter/src/main/java/org/alfonz/adapter/AdapterView.java
  4. +5 −16 alfonz-adapter/src/main/java/org/alfonz/adapter/BaseDataBoundPagerAdapter.java
  5. +17 −44 alfonz-adapter/src/main/java/org/alfonz/adapter/BaseDataBoundRecyclerAdapter.java
  6. +4 −12 alfonz-adapter/src/main/java/org/alfonz/adapter/BaseDataBoundRecyclerViewHolder.java
  7. +11 −30 alfonz-adapter/src/main/java/org/alfonz/adapter/DataBoundListAdapter.java
  8. +14 −34 alfonz-adapter/src/main/java/org/alfonz/adapter/MultiDataBoundPagerAdapter.java
  9. +10 −27 alfonz-adapter/src/main/java/org/alfonz/adapter/MultiDataBoundRecyclerAdapter.java
  10. +10 −27 alfonz-adapter/src/main/java/org/alfonz/adapter/MultiMapDataBoundRecyclerAdapter.java
  11. +9 −24 alfonz-adapter/src/main/java/org/alfonz/adapter/SimpleDataBoundPagerAdapter.java
  12. +7 −21 alfonz-adapter/src/main/java/org/alfonz/adapter/SimpleDataBoundRecyclerAdapter.java
  13. +7 −21 alfonz-adapter/src/main/java/org/alfonz/adapter/SimpleMapDataBoundRecyclerAdapter.java
  14. +10 −29 alfonz-adapter/src/main/java/org/alfonz/adapter/callback/OnPagerListChangedCallback.java
  15. +19 −51 alfonz-adapter/src/main/java/org/alfonz/adapter/callback/OnRecyclerListChangedCallback.java
  16. +5 −14 alfonz-adapter/src/main/java/org/alfonz/adapter/callback/OnRecyclerMapChangedCallback.java
  17. +11 −27 alfonz-adapter/src/main/java/org/alfonz/adapter/callback/RecyclerListChangedCallbackHolder.java
  18. +11 −27 alfonz-adapter/src/main/java/org/alfonz/adapter/callback/RecyclerMapChangedCallbackHolder.java
  19. +22 −62 alfonz-adapter/src/main/java/org/alfonz/adapter/utility/BindingUtility.java
  20. +19 −50 alfonz-adapter/src/main/java/org/alfonz/adapter/widget/GridDividerItemDecoration.java
  21. +51 −98 alfonz-adapter/src/main/java/org/alfonz/adapter/widget/GridSpacingItemDecoration.java
  22. +6 −3 alfonz-adapter/src/main/res/layout/binding_variables.xml
  23. +24 −48 alfonz-arch/README.md
  24. +2 −5 alfonz-arch/build.gradle
  25. +24 −54 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzActivity.java
  26. +5 −16 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzBindingActivity.java
  27. +4 −13 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzBindingFragment.java
  28. +5 −16 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzFragment.java
  29. +1 −3 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzView.java
  30. +12 −32 alfonz-arch/src/main/java/org/alfonz/arch/AlfonzViewModel.java
  31. +6 −18 alfonz-arch/src/main/java/org/alfonz/arch/bundle/AlfonzBundleViewModel.java
  32. +17 −49 alfonz-arch/src/main/java/org/alfonz/arch/bundle/AlfonzBundleViewModelFactory.java
  33. +1 −3 alfonz-arch/src/main/java/org/alfonz/arch/event/Event.java
  34. +1 −3 alfonz-arch/src/main/java/org/alfonz/arch/event/EventObserver.java
  35. +9 −24 alfonz-arch/src/main/java/org/alfonz/arch/event/LiveBus.java
  36. +7 −18 alfonz-arch/src/main/java/org/alfonz/arch/event/LiveEvent.java
  37. +8 −24 alfonz-arch/src/main/java/org/alfonz/arch/utility/BindingUtility.java
  38. +10 −29 alfonz-arch/src/main/java/org/alfonz/arch/widget/ToolbarIndicator.java
  39. +6 −3 alfonz-arch/src/main/res/layout/binding_variables.xml
  40. +0 −4 alfonz-graphics/build.gradle
  41. +5 −15 alfonz-graphics/src/main/java/org/alfonz/graphics/bitmap/BitmapBlur.java
  42. +3 −9 alfonz-graphics/src/main/java/org/alfonz/graphics/bitmap/BitmapReflection.java
  43. +5 −15 alfonz-graphics/src/main/java/org/alfonz/graphics/bitmap/BitmapScaler.java
  44. +15 −43 alfonz-graphics/src/main/java/org/alfonz/graphics/drawable/CircularDrawable.java
  45. +34 −92 alfonz-graphics/src/main/java/org/alfonz/graphics/drawable/PlaceholderDrawable.java
  46. +10 −30 alfonz-graphics/src/main/java/org/alfonz/graphics/drawable/RoundedDrawable.java
  47. +2 −4 alfonz-media/README.md
  48. +0 −4 alfonz-media/build.gradle
  49. +83 −221 alfonz-media/src/main/java/org/alfonz/media/ImagePicker.java
  50. +23 −55 alfonz-media/src/main/java/org/alfonz/media/SoundManager.java
  51. +19 −39 alfonz-rest/README.md
  52. +0 −4 alfonz-rest/build.gradle
  53. +3 −10 alfonz-rest/src/main/java/org/alfonz/rest/HttpException.java
  54. +1 −3 alfonz-rest/src/main/java/org/alfonz/rest/HttpLogger.java
  55. +1 −3 alfonz-rest/src/main/java/org/alfonz/rest/ResponseHandler.java
  56. +13 −35 alfonz-rest/src/main/java/org/alfonz/rest/call/BaseCallManager.java
  57. +8 −23 alfonz-rest/src/main/java/org/alfonz/rest/call/CallManager.java
  58. +12 −35 alfonz-rest/src/main/java/org/alfonz/rest/call/Callback.java
  59. +13 −33 alfonz-rest/src/main/java/org/alfonz/rest/http/GzipRequestInterceptor.java
  60. +34 −91 alfonz-rest/src/main/java/org/alfonz/rest/rx/RestRxManager.java
  61. +5 −10 alfonz-rx/README.md
  62. +0 −4 alfonz-rx/build.gradle
  63. +13 −33 alfonz-rx/src/main/java/org/alfonz/rx/AlfonzDisposableCompletableObserver.java
  64. +18 −45 alfonz-rx/src/main/java/org/alfonz/rx/AlfonzDisposableMaybeObserver.java
  65. +18 −45 alfonz-rx/src/main/java/org/alfonz/rx/AlfonzDisposableObserver.java
  66. +13 −33 alfonz-rx/src/main/java/org/alfonz/rx/AlfonzDisposableSingleObserver.java
  67. +9 −25 alfonz-rx/src/main/java/org/alfonz/rx/RxBus.java
  68. +32 −84 alfonz-rx/src/main/java/org/alfonz/rx/RxManager.java
  69. +11 −29 alfonz-rx/src/main/java/org/alfonz/rx/utility/SchedulersUtility.java
  70. +7 −14 alfonz-utility/README.md
  71. +0 −4 alfonz-utility/build.gradle
  72. +24 −52 alfonz-utility/src/main/java/org/alfonz/utility/ContentUtility.java
  73. +10 −27 alfonz-utility/src/main/java/org/alfonz/utility/DateConvertor.java
  74. +12 −30 alfonz-utility/src/main/java/org/alfonz/utility/DeviceUuidFactory.java
  75. +5 −15 alfonz-utility/src/main/java/org/alfonz/utility/DimensionUtility.java
  76. +2 −6 alfonz-utility/src/main/java/org/alfonz/utility/DownloadUtility.java
  77. +16 −42 alfonz-utility/src/main/java/org/alfonz/utility/HashUtility.java
  78. +52 −132 alfonz-utility/src/main/java/org/alfonz/utility/IntentUtility.java
  79. +3 −9 alfonz-utility/src/main/java/org/alfonz/utility/KeyboardUtility.java
  80. +43 −108 alfonz-utility/src/main/java/org/alfonz/utility/Logcat.java
  81. +8 −22 alfonz-utility/src/main/java/org/alfonz/utility/NetworkUtility.java
  82. +84 −224 alfonz-utility/src/main/java/org/alfonz/utility/PermissionManager.java
  83. +6 −18 alfonz-utility/src/main/java/org/alfonz/utility/ResourcesUtility.java
  84. +4 −10 alfonz-utility/src/main/java/org/alfonz/utility/ServiceUtility.java
  85. +41 −94 alfonz-utility/src/main/java/org/alfonz/utility/StorageUtility.java
  86. +5 −13 alfonz-utility/src/main/java/org/alfonz/utility/StringConvertor.java
  87. +6 −16 alfonz-utility/src/main/java/org/alfonz/utility/ValidationUtility.java
  88. +30 −63 alfonz-utility/src/main/java/org/alfonz/utility/VersionUtility.java
  89. +7 −17 alfonz-utility/src/main/java/org/alfonz/utility/ZipUtility.java
  90. +0 −4 alfonz-view/build.gradle
  91. +8 −21 alfonz-view/src/main/java/org/alfonz/view/AspectRatioImageView.java
  92. +39 −103 alfonz-view/src/main/java/org/alfonz/view/EllipsizingTextView.java
  93. +5 −14 alfonz-view/src/main/java/org/alfonz/view/MaxWidthLinearLayout.java
  94. +8 −23 alfonz-view/src/main/java/org/alfonz/view/ObservableScrollView.java
  95. +8 −25 alfonz-view/src/main/java/org/alfonz/view/RotatableImageView.java
  96. +15 −39 alfonz-view/src/main/java/org/alfonz/view/SelectorFrameLayout.java
  97. +15 −39 alfonz-view/src/main/java/org/alfonz/view/SelectorLinearLayout.java
  98. +15 −39 alfonz-view/src/main/java/org/alfonz/view/SelectorRelativeLayout.java
  99. +30 −79 alfonz-view/src/main/java/org/alfonz/view/StatefulLayout.java
  100. +39 −40 bintray.gradle
  101. +34 −34 install.gradle
  102. +0 −2 samples/build.gradle
  103. +3 −8 samples/src/main/java/org/alfonz/samples/SamplesActivity.java
  104. +6 −16 samples/src/main/java/org/alfonz/samples/SamplesApplication.java
  105. +1 −3 samples/src/main/java/org/alfonz/samples/SamplesConfig.java
  106. +8 −20 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleActivity.java
  107. +15 −39 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleDiffViewModel.java
  108. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleGridSimpleFragment.java
  109. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleListDiffFragment.java
  110. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleListMultiFragment.java
  111. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleListSimpleFragment.java
  112. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSamplePagerMultiFragment.java
  113. +9 −26 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSamplePagerSimpleFragment.java
  114. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleView.java
  115. +13 −34 samples/src/main/java/org/alfonz/samples/alfonzadapter/AdapterSampleViewModel.java
  116. +8 −20 samples/src/main/java/org/alfonz/samples/alfonzadapter/MessageListDiffAdapter.java
  117. +6 −16 samples/src/main/java/org/alfonz/samples/alfonzadapter/MessageListMultiAdapter.java
  118. +2 −5 samples/src/main/java/org/alfonz/samples/alfonzadapter/MessageListSimpleAdapter.java
  119. +6 −16 samples/src/main/java/org/alfonz/samples/alfonzadapter/MessagePagerMultiAdapter.java
  120. +2 −5 samples/src/main/java/org/alfonz/samples/alfonzadapter/MessagePagerSimpleAdapter.java
  121. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleActivity.java
  122. +5 −14 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleFragment.java
  123. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleView.java
  124. +16 −41 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleViewModel.java
  125. +7 −20 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleViewModelActivity.java
  126. +3 −9 samples/src/main/java/org/alfonz/samples/alfonzarch/ArchSampleViewModelFactory.java
  127. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzarch/BaseActivity.java
  128. +8 −20 samples/src/main/java/org/alfonz/samples/alfonzarch/BaseFragment.java
  129. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzarch/BaseViewModel.java
  130. +2 −6 samples/src/main/java/org/alfonz/samples/alfonzarch/event/SnackbarEvent.java
  131. +2 −6 samples/src/main/java/org/alfonz/samples/alfonzarch/event/ToastEvent.java
  132. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzgraphics/GraphicsSampleActivity.java
  133. +11 −32 samples/src/main/java/org/alfonz/samples/alfonzgraphics/GraphicsSampleFragment.java
  134. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzgraphics/GraphicsSampleView.java
  135. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzgraphics/GraphicsSampleViewModel.java
  136. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzmedia/MediaSampleActivity.java
  137. +13 −39 samples/src/main/java/org/alfonz/samples/alfonzmedia/MediaSampleFragment.java
  138. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzmedia/MediaSampleView.java
  139. +2 −6 samples/src/main/java/org/alfonz/samples/alfonzmedia/MediaSampleViewModel.java
  140. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzrest/RestSampleActivity.java
  141. +4 −11 samples/src/main/java/org/alfonz/samples/alfonzrest/RestSampleFragment.java
  142. +13 −34 samples/src/main/java/org/alfonz/samples/alfonzrest/RestSampleRxViewModel.java
  143. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzrest/RestSampleView.java
  144. +18 −46 samples/src/main/java/org/alfonz/samples/alfonzrest/RestSampleViewModel.java
  145. +6 −18 samples/src/main/java/org/alfonz/samples/alfonzrest/entity/ErrorEntity.java
  146. +8 −24 samples/src/main/java/org/alfonz/samples/alfonzrest/entity/OwnerEntity.java
  147. +36 −108 samples/src/main/java/org/alfonz/samples/alfonzrest/entity/RepoEntity.java
  148. +5 −13 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/RestHttpException.java
  149. +4 −11 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/RestHttpLogger.java
  150. +14 −23 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/RestResponseHandler.java
  151. +12 −34 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/RetrofitClient.java
  152. +2 −5 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/http/HeaderRequestInterceptor.java
  153. +6 −16 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/router/RepoRouter.java
  154. +6 −16 samples/src/main/java/org/alfonz/samples/alfonzrest/rest/router/RepoRxRouter.java
  155. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzrx/RxSampleActivity.java
  156. +7 −20 samples/src/main/java/org/alfonz/samples/alfonzrx/RxSampleFragment.java
  157. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzrx/RxSampleView.java
  158. +11 −33 samples/src/main/java/org/alfonz/samples/alfonzrx/RxSampleViewModel.java
  159. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzutility/UtilitySampleActivity.java
  160. +40 −119 samples/src/main/java/org/alfonz/samples/alfonzutility/UtilitySampleFragment.java
  161. +9 −23 samples/src/main/java/org/alfonz/samples/alfonzutility/UtilitySampleService.java
  162. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzutility/UtilitySampleView.java
  163. +19 −57 samples/src/main/java/org/alfonz/samples/alfonzutility/UtilitySampleViewModel.java
  164. +4 −10 samples/src/main/java/org/alfonz/samples/alfonzutility/utility/PermissionRationaleHandler.java
  165. +3 −8 samples/src/main/java/org/alfonz/samples/alfonzview/ViewSampleActivity.java
  166. +5 −14 samples/src/main/java/org/alfonz/samples/alfonzview/ViewSampleFragment.java
  167. +1 −3 samples/src/main/java/org/alfonz/samples/alfonzview/ViewSampleView.java
  168. +5 −12 samples/src/main/java/org/alfonz/samples/alfonzview/ViewSampleViewModel.java
  169. +4 −2 samples/src/main/res/layout/activity_arch_sample_view_model.xml
  170. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_grid.xml
  171. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_list.xml
  172. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_list_bit_item.xml
  173. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_list_diff.xml
  174. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_list_message_item.xml
  175. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_list_number_item.xml
  176. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_pager.xml
  177. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_pager_bit_item.xml
  178. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_pager_message_item.xml
  179. +4 −2 samples/src/main/res/layout/fragment_adapter_sample_pager_number_item.xml
  180. +4 −2 samples/src/main/res/layout/fragment_arch_sample.xml
  181. +4 −2 samples/src/main/res/layout/fragment_graphics_sample.xml
  182. +4 −2 samples/src/main/res/layout/fragment_media_sample.xml
  183. +4 −2 samples/src/main/res/layout/fragment_rest_sample.xml
  184. +4 −2 samples/src/main/res/layout/fragment_rx_sample.xml
  185. +4 −2 samples/src/main/res/layout/fragment_utility_sample.xml
  186. +4 −2 samples/src/main/res/layout/fragment_view_sample.xml
  187. +0 −1 utils.gradle
@@ -24,10 +24,8 @@ Choose an adapter which suits your needs:
Simple-type adapters can be used directly - just create a new instance. Multi-type adapters are abstract. Create a class, extend the generic adapter and call `super` in the constructor. Pass item layout, view (view layer in MVVM) and observable array collection in the `super`. Adapter will inflate the layout for an item and bind the view and the data into `BR.view` and `BR.data` variables.
```java
public class ProductListAdapter extends SimpleDataBoundRecyclerAdapter
{
public ProductListAdapter(ProductListView view, ProductListViewModel viewModel)
{
public class ProductListAdapter extends SimpleDataBoundRecyclerAdapter {
public ProductListAdapter(ProductListView view, ProductListViewModel viewModel) {
super(R.layout.fragment_product_list_item, view, viewModel.products);
}
}
@@ -63,36 +61,30 @@ Create an XML layout, define `view` and `data` variables, use `view` for invokin
Create a new instance of the adapter and set it in your RecyclerView. Implement event callbacks in the MVVM view layer - it is usually Fragment.
```java
public interface ProductListView extends AlfonzView, AdapterView
{
public interface ProductListView extends AlfonzView, AdapterView {
void onItemClick(ProductEntity product);
}
```
```java
public class ProductListFragment
extends BaseFragment<ProductListView, ProductListViewModel, FragmentProductListBinding>
implements ProductListView
{
implements ProductListView {
private ProductListAdapter mAdapter;
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupAdapter();
}
@Override
public void onItemClick(ProductEntity product)
{
public void onItemClick(ProductEntity product) {
startProductDetailActivity(product.getId());
}
private void setupAdapter()
{
if(mAdapter == null)
{
private void setupAdapter() {
if (mAdapter == null) {
mAdapter = new ProductListAdapter(this, getViewModel());
getBinding().fragmentProductListRecycler.setAdapter(mAdapter);
}
@@ -1,14 +1,12 @@
apply plugin: "com.android.library"
apply from: "../utils.gradle"
ext {
bintrayName = "alfonz-adapter"
libraryName = "Alfonz-Adapter"
artifact = "alfonz-adapter"
}
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
@@ -37,16 +35,15 @@ android {
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:support-compat:$androidSupportVersion"
implementation "com.android.support:support-core-ui:$androidSupportVersion"
implementation "com.android.support:recyclerview-v7:$androidSupportVersion"
implementation "com.android.support:support-annotations:$androidSupportVersion"
implementation "com.android.support:support-v4:$androidSupportVersion" // https://stackoverflow.com/questions/41568032/android-data-binding-dependency-conflict-with-the-support-library
implementation "com.android.support:support-v4:$androidSupportVersion"
// https://stackoverflow.com/questions/41568032/android-data-binding-dependency-conflict-with-the-support-library
}
apply from: "../install.gradle"
apply from: "../bintray.gradle"
@@ -2,7 +2,5 @@
import android.arch.lifecycle.LifecycleOwner;
public interface AdapterView extends LifecycleOwner
{
public interface AdapterView extends LifecycleOwner {
}
@@ -9,25 +9,18 @@
import android.view.View;
import android.view.ViewGroup;
public abstract class BaseDataBoundPagerAdapter<T extends ViewDataBinding> extends PagerAdapter
{
public abstract class BaseDataBoundPagerAdapter<T extends ViewDataBinding> extends PagerAdapter {
private LayoutInflater mLayoutInflater;
protected abstract void bindItem(T binding, int position);
@LayoutRes
public abstract int getItemLayoutId(int position);
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position)
{
if(mLayoutInflater == null)
{
public Object instantiateItem(@NonNull ViewGroup container, int position) {
if (mLayoutInflater == null) {
mLayoutInflater = LayoutInflater.from(container.getContext());
}
@@ -38,17 +31,13 @@ public Object instantiateItem(@NonNull ViewGroup container, int position)
return binding.getRoot();
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object)
{
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
{
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
}
@@ -28,7 +28,6 @@
import java.util.List;
/**
* A reference implementation for an adapter that wants to use data binding "the right way". It
* works with {@link BaseDataBoundRecyclerViewHolder}.
@@ -44,40 +43,33 @@
* @param <T> The type of the ViewDataBinding class. Can be omitted in multiple-binding-type use
* case.
*/
public abstract class BaseDataBoundRecyclerAdapter<T extends ViewDataBinding> extends RecyclerView.Adapter<BaseDataBoundRecyclerViewHolder<T>>
{
public abstract class BaseDataBoundRecyclerAdapter<T extends ViewDataBinding> extends RecyclerView.Adapter<BaseDataBoundRecyclerViewHolder<T>> {
private static final Object DB_PAYLOAD = new Object();
private LayoutInflater mLayoutInflater;
@Nullable
private RecyclerView mRecyclerView;
private LayoutInflater mLayoutInflater;
/**
* This is used to block items from updating themselves. RecyclerView wants to know when an
* item is invalidated and it prefers to refresh it via onRebind. It also helps with performance
* since data binding will not update views that are not changed.
*/
private final OnRebindCallback mOnRebindCallback = new OnRebindCallback()
{
private final OnRebindCallback mOnRebindCallback = new OnRebindCallback() {
@Override
public boolean onPreBind(@NonNull ViewDataBinding binding)
{
if(mRecyclerView == null || mRecyclerView.isComputingLayout())
{
public boolean onPreBind(@NonNull ViewDataBinding binding) {
if (mRecyclerView == null || mRecyclerView.isComputingLayout()) {
return true;
}
int childAdapterPosition = mRecyclerView.getChildAdapterPosition(binding.getRoot());
if(childAdapterPosition == RecyclerView.NO_POSITION)
{
if (childAdapterPosition == RecyclerView.NO_POSITION) {
return true;
}
notifyItemChanged(childAdapterPosition, DB_PAYLOAD);
return false;
}
};
/**
* Override this method to handle binding your items into views
*
@@ -87,18 +79,14 @@ public boolean onPreBind(@NonNull ViewDataBinding binding)
*/
protected abstract void bindItem(BaseDataBoundRecyclerViewHolder<T> holder, int position, List<Object> payloads);
@LayoutRes
public abstract int getItemLayoutId(int position);
@Override
@CallSuper
@NonNull
public BaseDataBoundRecyclerViewHolder<T> onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
if(mLayoutInflater == null)
{
public BaseDataBoundRecyclerViewHolder<T> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (mLayoutInflater == null) {
mLayoutInflater = LayoutInflater.from(parent.getContext());
}
@@ -107,54 +95,39 @@ public boolean onPreBind(@NonNull ViewDataBinding binding)
return vh;
}
@Override
public final void onBindViewHolder(@NonNull BaseDataBoundRecyclerViewHolder<T> holder, int position, @NonNull List<Object> payloads)
{
public final void onBindViewHolder(@NonNull BaseDataBoundRecyclerViewHolder<T> holder, int position, @NonNull List<Object> payloads) {
// when a VH is rebound to the same item, we don't have to call the setters
if(payloads.isEmpty() || hasNonDataBindingInvalidate(payloads))
{
if (payloads.isEmpty() || hasNonDataBindingInvalidate(payloads)) {
bindItem(holder, position, payloads);
}
holder.binding.executePendingBindings();
}
@Override
public final void onBindViewHolder(@NonNull BaseDataBoundRecyclerViewHolder<T> holder, int position)
{
public final void onBindViewHolder(@NonNull BaseDataBoundRecyclerViewHolder<T> holder, int position) {
throw new IllegalArgumentException("just overridden to make final.");
}
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView)
{
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
mRecyclerView = recyclerView;
}
@Override
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView)
{
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
mRecyclerView = null;
mLayoutInflater = null;
}
@Override
public final int getItemViewType(int position)
{
public final int getItemViewType(int position) {
return getItemLayoutId(position);
}
private boolean hasNonDataBindingInvalidate(@NonNull List<Object> payloads)
{
for(Object payload : payloads)
{
if(payload != DB_PAYLOAD)
{
private boolean hasNonDataBindingInvalidate(@NonNull List<Object> payloads) {
for (Object payload : payloads) {
if (payload != DB_PAYLOAD) {
return true;
}
}
@@ -25,24 +25,19 @@
import android.view.LayoutInflater;
import android.view.ViewGroup;
/**
* A generic ViewHolder that wraps a generated ViewDataBinding class.
*
* @param <T> The type of the ViewDataBinding class
*/
public class BaseDataBoundRecyclerViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder
{
public class BaseDataBoundRecyclerViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
@NonNull public final T binding;
public BaseDataBoundRecyclerViewHolder(@NonNull T binding)
{
public BaseDataBoundRecyclerViewHolder(@NonNull T binding) {
super(binding.getRoot());
this.binding = binding;
}
/**
* Creates a new ViewHolder for the given layout file.
* <p>
@@ -55,13 +50,11 @@ public BaseDataBoundRecyclerViewHolder(@NonNull T binding)
* @return A new ViewHolder that has a reference to the binding class
*/
@NonNull
public static <T extends ViewDataBinding> BaseDataBoundRecyclerViewHolder<T> create(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @LayoutRes int layoutId)
{
public static <T extends ViewDataBinding> BaseDataBoundRecyclerViewHolder<T> create(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @LayoutRes int layoutId) {
T binding = DataBindingUtil.inflate(inflater, layoutId, parent, false);
return new BaseDataBoundRecyclerViewHolder<>(binding);
}
/**
* Creates a new ViewHolder for the given layout file.
* <p>
@@ -75,8 +68,7 @@ public BaseDataBoundRecyclerViewHolder(@NonNull T binding)
* @return A new ViewHolder that has a reference to the binding class
*/
@NonNull
public static <T extends ViewDataBinding> BaseDataBoundRecyclerViewHolder<T> create(@NonNull LifecycleOwner lifecycleOwner, @NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @LayoutRes int layoutId)
{
public static <T extends ViewDataBinding> BaseDataBoundRecyclerViewHolder<T> create(@NonNull LifecycleOwner lifecycleOwner, @NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @LayoutRes int layoutId) {
T binding = DataBindingUtil.inflate(inflater, layoutId, parent, false);
binding.setLifecycleOwner(lifecycleOwner);
return new BaseDataBoundRecyclerViewHolder<>(binding);
Oops, something went wrong.

0 comments on commit c981c9d

Please sign in to comment.