Skip to content

Commit

Permalink
Prepare for release 3.0.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCaiCoding committed Sep 26, 2021
1 parent f6ee86e commit d21fcc5
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 171 deletions.
106 changes: 41 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# LoadingHelper
# LoadingStateView

English | [中文](README_ZH_CN.md)

[![](https://www.jitpack.io/v/DylanCaiCoding/LoadingHelper.svg)](https://www.jitpack.io/#DylanCaiCoding/LoadingHelper) [![](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](https://github.com/DylanCaiCoding/LoadingHelper/blob/master/LICENSE)
[![](https://www.jitpack.io/v/DylanCaiCoding/LoadingStateView.svg)](https://www.jitpack.io/#DylanCaiCoding/LoadingLoadingStateView) [![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/LICENSE)

`LoadingHelper` is a highly expandable Android library for showing loading status view on the low-coupling way, it is implemented with a Kotlin code of less than 300 lines without comment statement . it not only **shows different view like loading, content, error, empty or customized view** when loading network data, but also **manages title bar.**
`LoadingStateView` is a highly expandable Android library for showing loading status view on the low-coupling way, it is implemented with a Kotlin code of less than 300 lines without comment statement . it not only **shows different view like loading, content, error, empty or customized view** when loading network data, but also **manages title bar.**

## Feature

Expand All @@ -22,18 +22,19 @@ Click or scan QR code to download

[![QR code](img/app_download_qr_code.png)](https://www.pgyer.com/loadinghelper)

| [Activity(error)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/ActErrorActivity.java) | [View(placeholder)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/ViewPlaceholderActivity.java) | [ViewPager(timeout)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/ViewPagerActivity.java) | [RecyclerView(cool loading)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/RecyclerViewActivity.java) |
| :---: | :----: | :---: | :---: |
| ![](gif/activity_error.gif) | ![](gif/view_placeholder.gif) | ![](gif/viewpager_timeout.gif) | ![](gif/recyclerview_loading.gif) |
| [Activity(error)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/ActErrorActivity.java) | [View(placeholder)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/ViewPlaceholderActivity.java) | [ViewPager(timeout)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/ViewPagerActivity.java) | [RecyclerView(cool loading)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/RecyclerViewActivity.java) |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](gif/activity_error.gif) | ![](gif/view_placeholder.gif) | ![](gif/viewpager_timeout.gif) | ![](gif/recyclerview_loading.gif) |

| [SpecialHeader(custom)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/CustomHeaderActivity.java) | [MultipleHeader(search)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/MultipleHeaderActivity.java) | [SpecialDecorView(scrolling)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/ScrollingToolbarActivity.java) | [BottomDecorView(editor)](app/src/main/java/com/dylanc/loadinghelper/sample/ui/BottomEditorActivity.java) |
| :---: | :---: | :---: | :---: |
| ![](gif/special_header_custom.gif) | ![](gif/multiple_header_search.gif) | ![](gif/special_decor_scrolling.gif) | ![](gif/bottom_decor_editor.gif) |
| [SpecialHeader(custom)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/CustomHeaderActivity.java) | [MultipleHeader(search)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/MultipleHeaderActivity.java) | [SpecialDecorView(scrolling)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/ScrollingToolbarActivity.java) | [BottomDecorView(editor)](app/src/main/java/com/dylanc/loadingstateview/sample/ui/BottomEditorActivity.java) |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](gif/special_header_custom.gif) | ![](gif/multiple_header_search.gif) | ![](gif/special_decor_scrolling.gif) | ![](gif/bottom_decor_editor.gif) |


## Getting started

Add it in your root `build.gradle` at the end of repositories:

```groovy
allprojects {
repositories {
Expand All @@ -45,62 +46,61 @@ allprojects {

Add dependencies in your module `build.gradle` :

```
```groovy
dependencies {
implementation 'com.github.DylanCaiCoding:LoadingHelper:2.3.0'
implementation 'com.github.DylanCaiCoding:LoadingStateView:3.0.0-alpha'
}
```

### Usage

#### Step 1. Create a class extends `LoadingHelper.Adapter<VH extends ViewHolder>`, for example:
#### Step 1. Create a class extends `LoadingStateView.ViewDelegate<VH extends ViewHolder>`, for example:

```java
public class LoadingAdapter extends LoadingHelper.Adapter<LoadingHelper.ViewHolder> {
public class LoadingViewDelegate extends LoadingStateView.ViewDelegate<LoadingStateView.ViewHolder> {

@NonNull
@Override
public LoadingHelper.ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return new LoadingHelper.ViewHolder(inflater.inflate(R.layout.layout_loading_view, parent, false));
public LoadingStateView.ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return new LoadingStateView.ViewHolder(inflater.inflate(R.layout.layout_loading_view, parent, false));
}

@Override
public void onBindViewHolder(@NonNull LoadingHelper.ViewHolder holder) {

public void onBindViewHolder(@NonNull LoadingStateView.ViewHolder holder) {
}
}
```

#### Step 2. Register your adapter with a view type, for example:
#### Step 2. Register `ViewDelegate` with a view type, for example:

```java
LoadingHelper loadingHelper = new LoadingHelper(this);
loadingHelper.register(ViewType.LOADING, new LoadingAdapter());
LoadingStateView loadingStateView = new LoadingStateView(this);
loadingStateView.register(ViewType.LOADING, new LoadingViewDelegate());
```

##### Or if you want to register a global adapter.
##### Or if you want to register a global `ViewDelegate`.

```java
LoadingHelper.setDefaultAdapterPool(adapterPool -> {
adapterPool.register(ViewType.LOADING, new LoadingAdapter());
return Unit.INSTANCE;
loadingStateView.setViewDelegatePool(pool -> {
pool.register(ViewType.LOADING, new LoadingViewDelegate());
return null;
});
```

#### Step 3. Show view by view type, for example:

```java
loadingHelper.showView(viewType);
loadingHelper.showLoadingView(); // view type is ViewType.LOADING
loadingHelper.showContentView(); // view type is ViewType.CONTENT
loadingHelper.showErrorView(); // view type is ViewType.ERROR
loadingHelper.showEmptyView(); // view type is ViewType.EMPTY
loadingStateView.showView(viewType);
loadingStateView.showLoadingView(); // view type is ViewType.LOADING
loadingStateView.showContentView(); // view type is ViewType.CONTENT
loadingStateView.showErrorView(); // view type is ViewType.ERROR
loadingStateView.showEmptyView(); // view type is ViewType.EMPTY
```

#### When you need to reload data.

```java
loadingHelper.setOnReloadListener(new LoadingHelper.OnReloadListener() {
loadingStateView.setOnReloadListener(new LoadingStateView.OnReloadListener() {
@Override
public void onReload() {
// request data again
Expand All @@ -114,9 +114,9 @@ holder.getOnReloadListener.onReload();
#### When you need to change view after view showed.

```java
ErrorAdapter adapter = loadingHelper.getAdapter(ViewType.Error);
adapter.errorText = "Fail to load, please wait";
adapter.notifyDataSetChanged();
ErrorViewDelegate errorViewDelegate = loadingStateView.getViewDelegate(ViewType.ERROR);
errorViewDelegate.errorText = "Fail to load, please wait";
loadingStateView.notifyDataSetChanged(ViewType.ERROR);
```

### Advanced usage
Expand All @@ -125,42 +125,30 @@ adapter.notifyDataSetChanged();

If you want to add an ordinary title bar above the content.

Similar to the previous usage, create a class extends `LoadingHelper.Adapter<VH extends ViewHolder>` and set header.
Similar to the previous usage, create a class extends `LoadingStateView.ViewDelegate<VH extends ViewHolder>` and set header.

```java
loadingHelper.setDecorHeader(new TitleAdapter("title"), new SearchHeaderAdapter(onSearchListener));
loadingStateView.setDecorHeader(new TitleViewDelegate("title"), new SearchHeaderViewDelegate());
```

If you want to add an special title bar with linkage effect.

Create a class extends `LoadingHelper.DecorAdapter` to create a decorated view and specify a loading container.
Create a class extends `LoadingStateView.DecorViewDelegate` to create a decorated view and specify a loading container.

```java
public class ScrollDecorAdapter extends LoadingHelper.DecorAdapter {
@NotNull
@Override
public View onCreateDecorView(@NotNull LayoutInflater inflater) {
return inflater.inflate(R.layout.layout_scrolling, null);
}

@NotNull
@Override
public ViewGroup getContentParent(@NotNull View decorView) {
return decorView.findViewById(R.id.content_parent);
}
}
public class ScrollingDecorViewDelegate extends LoadingStateView.DecorViewDelegate { @NotNull @Override public View onCreateDecorView(@NotNull LayoutInflater inflater) { return inflater.inflate(R.layout.layout_scrolling, null); } @NotNull @Override public ViewGroup getContentParent(@NotNull View decorView) { return decorView.findViewById(R.id.content_parent); }}
```

Then set it up.

```java
loadingHelper.setDecorAdapter(new ScrollDecorAdapter());
loadingStateView.setDecorView(new ScrollingDecorViewDelegate());
```

## Author's other libraries

- [LoadingHelper](https://github.com/DylanCaiCoding/LoadingHelper), a highly expandable Android library for decoupling the code of toolbar or loading status view.
- [ViewBindingKTX](https://github.com/DylanCaiCoding/ViewBindingKTX), the most comprehensive utils of ViewBinding.
- [ActivityResultLauncher](https://github.com/DylanCaiCoding/ActivityResultLauncher), perfect replacement for `startActivityForResult()`

## Thanks

Expand All @@ -171,17 +159,5 @@ loadingHelper.setDecorAdapter(new ScrollDecorAdapter());