1
- # LoadingHelper
1
+ # LoadingStateView
2
2
3
3
English | [ 中文] ( README_ZH_CN.md )
4
4
5
- [ ![ ] ( 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 )
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
- ` 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.**
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 or customized view** when loading network data, but also ** manages title bar.**
8
8
9
9
## Feature
10
10
@@ -22,18 +22,19 @@ Click or scan QR code to download
22
22
23
23
[ ![ QR code] ( img/app_download_qr_code.png )] ( https://www.pgyer.com/loadinghelper )
24
24
25
- | [ 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 ) |
26
- | :---: | :----: | :---: | :---: |
27
- | ![ ] ( gif/activity_error.gif ) | ![ ] ( gif/view_placeholder.gif ) | ![ ] ( gif/viewpager_timeout.gif ) | ![ ] ( gif/recyclerview_loading.gif ) |
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 ) |
26
+ | :---------------------------------------------------------- : | :---------------------------------------------------------- : | :---------------------------------------------------------- : | :------------------------------------------------------- ---: |
27
+ | ![ ] ( gif/activity_error.gif ) | ![ ] ( gif/view_placeholder.gif ) | ![ ] ( gif/viewpager_timeout.gif ) | ![ ] ( gif/recyclerview_loading.gif ) |
28
28
29
- | [ 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 ) |
30
- | :---: | :---: | :---: | :---: |
31
- | ![ ] ( gif/special_header_custom.gif ) | ![ ] ( gif/multiple_header_search.gif ) | ![ ] ( gif/special_decor_scrolling.gif ) | ![ ] ( gif/bottom_decor_editor.gif ) |
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 ) |
30
+ | :---------------------------------------------------------- : | :---------------------------------------------------------- : | :---------------------------------------------------------- : | :------------------------------------------------------- ---: |
31
+ | ![ ] ( gif/special_header_custom.gif ) | ![ ] ( gif/multiple_header_search.gif ) | ![ ] ( gif/special_decor_scrolling.gif ) | ![ ] ( gif/bottom_decor_editor.gif ) |
32
32
33
33
34
34
## Getting started
35
35
36
36
Add it in your root ` build.gradle ` at the end of repositories:
37
+
37
38
``` groovy
38
39
allprojects {
39
40
repositories {
@@ -45,62 +46,61 @@ allprojects {
45
46
46
47
Add dependencies in your module ` build.gradle ` :
47
48
48
- ```
49
+ ``` groovy
49
50
dependencies {
50
- implementation 'com.github.DylanCaiCoding:LoadingHelper:2. 3.0'
51
+ implementation 'com.github.DylanCaiCoding:LoadingStateView: 3.0.0-alpha '
51
52
}
52
53
```
53
54
54
55
### Usage
55
56
56
- #### Step 1. Create a class extends ` LoadingHelper.Adapter <VH extends ViewHolder>` , for example:
57
+ #### Step 1. Create a class extends ` LoadingStateView.ViewDelegate <VH extends ViewHolder>` , for example:
57
58
58
59
``` java
59
- public class LoadingAdapter extends LoadingHelper . Adapter< LoadingHelper .ViewHolder > {
60
+ public class LoadingViewDelegate extends LoadingStateView . ViewDelegate< LoadingStateView .ViewHolder > {
60
61
61
62
@NonNull
62
63
@Override
63
- public LoadingHelper .ViewHolder onCreateViewHolder (@NonNull LayoutInflater inflater , @NonNull ViewGroup parent ) {
64
- return new LoadingHelper .ViewHolder (inflater. inflate(R . layout. layout_loading_view, parent, false ));
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 ));
65
66
}
66
67
67
68
@Override
68
- public void onBindViewHolder (@NonNull LoadingHelper .ViewHolder holder ) {
69
-
69
+ public void onBindViewHolder (@NonNull LoadingStateView .ViewHolder holder ) {
70
70
}
71
71
}
72
72
```
73
73
74
- #### Step 2. Register your adapter with a view type, for example:
74
+ #### Step 2. Register ` ViewDelegate ` with a view type, for example:
75
75
76
76
``` java
77
- LoadingHelper loadingHelper = new LoadingHelper (this );
78
- loadingHelper . register(ViewType . LOADING , new LoadingAdapter ());
77
+ LoadingStateView loadingStateView = new LoadingStateView (this );
78
+ loadingStateView . register(ViewType . LOADING , new LoadingViewDelegate ());
79
79
```
80
80
81
- ##### Or if you want to register a global adapter .
81
+ ##### Or if you want to register a global ` ViewDelegate ` .
82
82
83
83
``` java
84
- LoadingHelper . setDefaultAdapterPool(adapterPool - > {
85
- adapterPool . register(ViewType . LOADING , new LoadingAdapter ());
86
- return Unit . INSTANCE ;
84
+ loadingStateView . setViewDelegatePool(pool - > {
85
+ pool . register(ViewType . LOADING , new LoadingViewDelegate ());
86
+ return null ;
87
87
});
88
88
```
89
89
90
90
#### Step 3. Show view by view type, for example:
91
91
92
92
``` java
93
- loadingHelper . showView(viewType);
94
- loadingHelper . showLoadingView(); // view type is ViewType.LOADING
95
- loadingHelper . showContentView(); // view type is ViewType.CONTENT
96
- loadingHelper . showErrorView(); // view type is ViewType.ERROR
97
- loadingHelper . showEmptyView(); // view type is ViewType.EMPTY
93
+ loadingStateView . showView(viewType);
94
+ loadingStateView . showLoadingView(); // view type is ViewType.LOADING
95
+ loadingStateView . showContentView(); // view type is ViewType.CONTENT
96
+ loadingStateView . showErrorView(); // view type is ViewType.ERROR
97
+ loadingStateView . showEmptyView(); // view type is ViewType.EMPTY
98
98
```
99
99
100
100
#### When you need to reload data.
101
101
102
102
``` java
103
- loadingHelper . setOnReloadListener(new LoadingHelper .OnReloadListener () {
103
+ loadingStateView . setOnReloadListener(new LoadingStateView .OnReloadListener () {
104
104
@Override
105
105
public void onReload () {
106
106
// request data again
@@ -114,9 +114,9 @@ holder.getOnReloadListener.onReload();
114
114
#### When you need to change view after view showed.
115
115
116
116
``` java
117
- ErrorAdapter adapter = loadingHelper . getAdapter (ViewType . Error );
118
- adapter . errorText = " Fail to load, please wait" ;
119
- adapter . notifyDataSetChanged();
117
+ ErrorViewDelegate errorViewDelegate = loadingStateView . getViewDelegate (ViewType . ERROR );
118
+ errorViewDelegate . errorText = " Fail to load, please wait" ;
119
+ loadingStateView . notifyDataSetChanged(ViewType . ERROR );
120
120
```
121
121
122
122
### Advanced usage
@@ -125,42 +125,30 @@ adapter.notifyDataSetChanged();
125
125
126
126
If you want to add an ordinary title bar above the content.
127
127
128
- Similar to the previous usage, create a class extends ` LoadingHelper.Adapter <VH extends ViewHolder>` and set header.
128
+ Similar to the previous usage, create a class extends ` LoadingStateView.ViewDelegate <VH extends ViewHolder>` and set header.
129
129
130
130
``` java
131
- loadingHelper . setDecorHeader(new TitleAdapter (" title" ), new SearchHeaderAdapter (onSearchListener ));
131
+ loadingStateView . setDecorHeader(new TitleViewDelegate (" title" ), new SearchHeaderViewDelegate ( ));
132
132
```
133
133
134
134
If you want to add an special title bar with linkage effect.
135
135
136
- Create a class extends ` LoadingHelper.DecorAdapter ` to create a decorated view and specify a loading container.
136
+ Create a class extends ` LoadingStateView.DecorViewDelegate ` to create a decorated view and specify a loading container.
137
137
138
138
``` java
139
- public class ScrollDecorAdapter extends LoadingHelper .DecorAdapter {
140
- @NotNull
141
- @Override
142
- public View onCreateDecorView (@NotNull LayoutInflater inflater ) {
143
- return inflater. inflate(R . layout. layout_scrolling, null );
144
- }
145
-
146
- @NotNull
147
- @Override
148
- public ViewGroup getContentParent (@NotNull View decorView ) {
149
- return decorView. findViewById(R . id. content_parent);
150
- }
151
- }
139
+ 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); }}
152
140
```
153
141
154
142
Then set it up.
155
143
156
144
``` java
157
- loadingHelper . setDecorAdapter (new ScrollDecorAdapter ());
145
+ loadingStateView . setDecorView (new ScrollingDecorViewDelegate ());
158
146
```
159
147
160
148
## Author's other libraries
161
149
162
- - [ LoadingHelper] ( https://github.com/DylanCaiCoding/LoadingHelper ) , a highly expandable Android library for decoupling the code of toolbar or loading status view.
163
150
- [ ViewBindingKTX] ( https://github.com/DylanCaiCoding/ViewBindingKTX ) , the most comprehensive utils of ViewBinding.
151
+ - [ ActivityResultLauncher] ( https://github.com/DylanCaiCoding/ActivityResultLauncher ) , perfect replacement for ` startActivityForResult() `
164
152
165
153
## Thanks
166
154
@@ -171,17 +159,5 @@ loadingHelper.setDecorAdapter(new ScrollDecorAdapter());
171
159
## License
172
160
173
161
```
174
- Copyright (C) 2019. Dylan Cai
175
-
176
- Licensed under the Apache License, Version 2.0 (the "License");
177
- you may not use this file except in compliance with the License.
178
- You may obtain a copy of the License at
179
-
180
- http://www.apache.org/licenses/LICENSE-2.0
181
-
182
- Unless required by applicable law or agreed to in writing, software
183
- distributed under the License is distributed on an "AS IS" BASIS,
184
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185
- See the License for the specific language governing permissions and
186
- limitations under the License.
187
- ```
162
+ Copyright (C) 2019. Dylan CaiLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
163
+ ```
0 commit comments