1
1
# LoadingStateView
2
2
3
- English | [ 中文] ( README_ZH_CN .md)
3
+ English | [ 中文] ( README_ZH .md)
4
4
5
5
[ ![ ] ( 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 )
6
6
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!**
8
10
9
11
## Feature
10
12
11
13
- 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)
13
15
- Support for use for Activity, Fragment, RecyclerView, View.
16
+ - Support for show custom views.
14
17
- Support for managing the title bar and add multiple headers.
15
18
- Support for set reload event.
16
19
- Support for update views anytime.
@@ -20,25 +23,28 @@ English | [中文](README_ZH_CN.md)
20
23
21
24
Click or scan QR code to download
22
25
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 )
24
27
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) |
26
29
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
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) |
28
31
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) |
30
33
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
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) |
32
35
36
+ ## Usage
33
37
34
- ## Getting started
38
+ :pencil : ** [ >> Usage documentation <<] ( https://dylancaicoding.github.io/LoadingStateView ) **
39
+
40
+ ## Gradle
35
41
36
42
Add it in your root ` build.gradle ` at the end of repositories:
37
43
38
44
``` groovy
39
45
allprojects {
40
46
repositories {
41
- ...
47
+ // ...
42
48
maven { url 'https://www.jitpack.io' }
43
49
}
44
50
}
@@ -48,124 +54,27 @@ Add dependencies in your module `build.gradle` :
48
54
49
55
``` groovy
50
56
dependencies {
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'
90
59
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'
148
62
}
149
63
```
150
64
151
- Then set it up.
152
-
153
- ``` java
154
- loadingStateView. setDecorView(new ScrollingDecorViewDelegate ());
155
- ```
156
65
157
- ## LoadingHelper's migration Guide
66
+ ## Change log
158
67
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 )
160
69
161
70
## Author's other libraries
162
71
163
72
| Library | Description |
164
73
| ------------------------------------------------------------ | ------------------------------------------------------------ |
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. |
166
75
| [ 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. |
169
78
170
79
## Thanks
171
80
0 commit comments