11# LoadingStateView
22
3- English | [ 中文] ( README_ZH_CN .md)
3+ English | [ 中文] ( README_ZH .md)
44
55[ ![ ] ( 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 )
66
7- ` 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 and customized view** when loading network data, but also ** manages title bar.**
7+ ` LoadingStateView ` is a highly expandable Android library for showing loading status view on the low-coupling way, the core function is implemented with a [ Kotlin file] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/loadingstateview/src/main/java/com/dylanc/loadingstateview/LoadingStateView.kt ) of about 200 lines without comment statement . it not only shows different view like loading, content, error, empty and customized view when loading network data, but also manages title bar.
8+
9+ ** Major update: With the Kotlin feature, you can quickly add all functionality to the base class without affecting existing code. The overall usage is further simplified with removing the ` ViewHolder ` . It is recommended to upgrade!**
810
911## Feature
1012
1113- No need to add view code to the layout.
12- - Support for show custom views.
14+ - Quickly add all functionality to the base class without affecting existing code. (Kotlin)
1315- Support for use for Activity, Fragment, RecyclerView, View.
16+ - Support for show custom views.
1417- Support for managing the title bar and add multiple headers.
1518- Support for set reload event.
1619- Support for update views anytime.
@@ -20,25 +23,28 @@ English | [中文](README_ZH_CN.md)
2023
2124Click or scan QR code to download
2225
23- [ ![ QR code] ( img/app_download_qr_code.png )] ( https://www.pgyer.com/loadinghelper )
26+ [ ![ QR code] ( docs/ img/app_download_qr_code.png)] ( https://www.pgyer.com/loadinghelper )
2427
25- | [ 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) |
28+ | [ Activity(error)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/ActErrorActivity.java) | [ View(placeholder)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/ViewPlaceholderActivity.java) | [ ViewPager(timeout)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/ViewPagerActivity.java) | [ RecyclerView(cool loading)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java /ui/RecyclerViewActivity.java) |
2629| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
27- | ![ ] ( gif/activity_error.gif ) | ![ ] ( gif/view_placeholder.gif ) | ![ ] ( gif/viewpager_timeout.gif ) | ![ ] ( gif/recyclerview_loading.gif ) |
30+ | ![ ] ( docs/ gif/activity_error.gif) | ![ ] ( docs/ gif/view_placeholder.gif) | ![ ] ( docs/ gif/viewpager_timeout.gif) | ![ ] ( docs/ gif/recyclerview_loading.gif) |
2831
29- | [ 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) |
32+ | [ SpecialHeader(custom)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/CustomHeaderActivity.java) | [ MultipleHeader(search)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/MultipleHeaderActivity.java) | [ SpecialDecorView(scrolling)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java/ ui/ScrollingToolbarActivity.java) | [ BottomDecorView(editor)] ( https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/ src/main/java/com/dylanc/loadingstateview/sample/java /ui/BottomEditorActivity.java) |
3033| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
31- | ![ ] ( gif/special_header_custom.gif ) | ![ ] ( gif/multiple_header_search.gif ) | ![ ] ( gif/special_decor_scrolling.gif ) | ![ ] ( gif/bottom_decor_editor.gif ) |
34+ | ![ ] ( docs/ gif/special_header_custom.gif) | ![ ] ( docs/ gif/multiple_header_search.gif) | ![ ] ( docs/ gif/special_decor_scrolling.gif) | ![ ] ( docs/ gif/bottom_decor_editor.gif) |
3235
36+ ## Usage
3337
34- ## Getting started
38+ :pencil : ** [ >> Usage documentation <<] ( https://dylancaicoding.github.io/LoadingStateView ) **
39+
40+ ## Gradle
3541
3642Add it in your root ` build.gradle ` at the end of repositories:
3743
3844``` groovy
3945allprojects {
4046 repositories {
41- ...
47+ // ...
4248 maven { url 'https://www.jitpack.io' }
4349 }
4450}
@@ -48,124 +54,27 @@ Add dependencies in your module `build.gradle` :
4854
4955``` groovy
5056dependencies {
51- implementation 'com.github.DylanCaiCoding:LoadingStateView:3.0.1'
52- }
53- ```
54-
55- ### Usage
56-
57- #### Step 1. Create a class extends ` LoadingStateView.ViewDelegate<VH extends ViewHolder> ` , for example:
58-
59- ``` java
60- public class LoadingViewDelegate extends LoadingStateView .ViewDelegate<LoadingStateView .ViewHolder > {
61-
62- @NonNull
63- @Override
64- public LoadingStateView .ViewHolder onCreateViewHolder (@NonNull LayoutInflater inflater , @NonNull ViewGroup parent ) {
65- return new LoadingStateView .ViewHolder (inflater. inflate(R . layout. layout_loading_view, parent, false ));
66- }
67-
68- @Override
69- public void onBindViewHolder (@NonNull LoadingStateView .ViewHolder holder ) {
70- }
71- }
72- ```
73-
74- #### Step 2. Register ` ViewDelegate ` with a view type, for example:
75-
76- ``` java
77- LoadingStateView loadingStateView = new LoadingStateView (this );
78- loadingStateView. register(ViewType . LOADING , new LoadingViewDelegate ());
79- ```
80-
81- ##### Or if you want to register a global ` ViewDelegate ` .
82-
83- ``` java
84- loadingStateView. setViewDelegatePool(pool - > {
85- pool. register(ViewType . LOADING , new LoadingViewDelegate ());
86- });
87- ```
88-
89- #### Step 3. Show view by view type, for example:
57+ // java
58+ implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview:4.0.0'
9059
91- ``` java
92- loadingStateView. showView(viewType);
93- loadingStateView. showLoadingView(); // view type is ViewType.LOADING
94- loadingStateView. showContentView(); // view type is ViewType.CONTENT
95- loadingStateView. showErrorView(); // view type is ViewType.ERROR
96- loadingStateView. showEmptyView(); // view type is ViewType.EMPTY
97- ```
98-
99- #### When you need to reload data.
100-
101- ``` java
102- loadingStateView. setOnReloadListener(new LoadingStateView .OnReloadListener () {
103- @Override
104- public void onReload () {
105- // request data again
106- }
107- });
108-
109- // In the adapter
110- holder. getOnReloadListener. onReload();
111- ```
112-
113- #### When you need to change view after view showed.
114-
115- ``` java
116- loadingStateView. updateView(ViewType . ERROR , (ErrorViewDelegate delegate) - > {
117- delegate. msg = " Fail to load, please wait" ;
118- });
119- ```
120-
121- ### Advanced usage
122-
123- #### Add title view
124-
125- If you want to add an ordinary title bar above the content.
126-
127- Similar to the previous usage, create a class extends ` LoadingStateView.ViewDelegate<VH extends ViewHolder> ` and set header.
128-
129- ``` java
130- loadingStateView. setDecorHeader(new TitleViewDelegate (" title" ), new SearchHeaderViewDelegate ());
131- ```
132-
133- If you want to add an special title bar with linkage effect.
134-
135- Create a class extends ` LoadingStateView.DecorViewDelegate ` to create a decorated view and specify a loading container.
136-
137- ``` java
138- class ScrollingDecorViewDelegate : LoadingStateView.DecorViewDelegate() {
139- @NotNull
140- override fun onCreateDecorView (@NotNull inflater : LayoutInflater ): View {
141- return inflater. inflate(R . layout. layout_scrolling, null )
142- }
143-
144- @NotNull
145- fun getContentParent (@NotNull decorView : View ): ViewGroup {
146- return decorView. findViewById(R . id. content_parent)
147- }
60+ // kotlin
61+ implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview-ktx:4.0.0'
14862}
14963```
15064
151- Then set it up.
152-
153- ``` java
154- loadingStateView. setDecorView(new ScrollingDecorViewDelegate ());
155- ```
15665
157- ## LoadingHelper's migration Guide
66+ ## Change log
15867
159- The original name of this library is ` LoadingHelper ` , and some class and method names should be changed later. Old users can check the [ migration guide ] ( https://github.com/DylanCaiCoding/LoadingHelper ) and change it to the latest usage. If you feel troublesome and are not obsessive-compulsive, you can also not migrate.
68+ [ Releases ] ( https://github.com/DylanCaiCoding/LoadingStateView/releases )
16069
16170## Author's other libraries
16271
16372| Library | Description |
16473| ------------------------------------------------------------ | ------------------------------------------------------------ |
165- | [ Longan] ( https://github.com/DylanCaiCoding/Longan ) | A collection of Kotlin utils which makes Android application development faster and easier. |
74+ | [ Longan] ( https://github.com/DylanCaiCoding/Longan ) | Probably the best Kotlin utils library for Android. |
16675| [ ViewBindingKTX] ( https://github.com/DylanCaiCoding/ViewBindingKTX ) | The most comprehensive utils of ViewBinding. |
167- | [ MMKV-KTX] ( https://github.com/DylanCaiCoding/MMKV-KTX ) | Easier to use the MMKV . |
168- | [ ActivityResultLauncher ] ( https://github.com/DylanCaiCoding/ActivityResultLauncher ) | Perfect replacement for ` startActivityForResult() ` |
76+ | [ MMKV-KTX] ( https://github.com/DylanCaiCoding/MMKV-KTX ) | Use MMKV with property delegates . |
77+ | [ Tracker ] ( https://github.com/DylanCaiCoding/Tracker ) | A lightweight tracking framework based on the tracking idea of Buzzvideo. |
16978
17079## Thanks
17180
0 commit comments