├── .gitignore
├── README-en.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── lottie_empty.json
│ └── lottie_loading.json
│ ├── ic_launcher-web.png
│ ├── java
│ └── sample
│ │ └── kingja
│ │ └── loadsir
│ │ ├── App.java
│ │ ├── MainActivity.java
│ │ ├── PostUtil.java
│ │ ├── base
│ │ ├── BaseFragment.java
│ │ └── BaseTitleActivity.java
│ │ ├── callback
│ │ ├── AnimateCallback.java
│ │ ├── CustomCallback.java
│ │ ├── EmptyCallback.java
│ │ ├── ErrorCallback.java
│ │ ├── LoadingCallback.java
│ │ ├── LottieEmptyCallback.java
│ │ ├── LottieLoadingCallback.java
│ │ ├── PlaceholderCallback.java
│ │ ├── TimeoutCallback.java
│ │ └── XCallback.java
│ │ └── target
│ │ ├── AnimateActivity.java
│ │ ├── BestPracticesActivity.java
│ │ ├── ConstraintLayoutActivity.java
│ │ ├── ConvertorActivity.java
│ │ ├── DefaultCallbackActivity.java
│ │ ├── FragmentA.java
│ │ ├── FragmentB.java
│ │ ├── FragmentSingleActivity.java
│ │ ├── KeepTitleActivity.java
│ │ ├── KeepTitleFragment.java
│ │ ├── KeepTitleFragmentActivity.java
│ │ ├── LottieActivity.java
│ │ ├── MultiFragmentActivity.java
│ │ ├── MultiFragmentWithViewPagerActivity.java
│ │ ├── NormalActivity.java
│ │ ├── NormalFragment.java
│ │ ├── PlaceholderActivity.java
│ │ └── ViewTargetActivity.java
│ └── res
│ ├── drawable
│ ├── awkward.png
│ ├── custom.png
│ ├── empty.png
│ ├── error.png
│ ├── img.jpg
│ ├── music.png
│ └── timeout.png
│ ├── layout
│ ├── activity_activity_convertor.xml
│ ├── activity_best_practices.xml
│ ├── activity_constraintlayout.xml
│ ├── activity_content.xml
│ ├── activity_fragment.xml
│ ├── activity_fragment_mutil.xml
│ ├── activity_fragment_viewpager.xml
│ ├── activity_main.xml
│ ├── activity_placeholder.xml
│ ├── activity_title.xml
│ ├── activity_view.xml
│ ├── fragment_a_content.xml
│ ├── fragment_b_content.xml
│ ├── include_title.xml
│ ├── layout_animate.xml
│ ├── layout_custom.xml
│ ├── layout_custom_error.xml
│ ├── layout_empty.xml
│ ├── layout_error.xml
│ ├── layout_loading.xml
│ ├── layout_lottie_empty.xml
│ ├── layout_lottie_loading.xml
│ ├── layout_placeholder.xml
│ ├── layout_timeout.xml
│ ├── layout_x.xml
│ └── title_title_bar.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── back.png
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── docs
├── BestPractice-cn.md
├── BestPractice.md
├── FAQ-cn.md
├── FAQ.md
├── NextVersion.md
└── changelog.md
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── imgs
├── LoadSir.jpg
├── LoadSir_flow.jpg
├── muitl_fragment.gif
├── normal_activity.gif
├── placeholder_activity.gif
├── qcode_1.3.2.png
├── qcode_1.3.8.png
├── single_fragment.gif
├── view_activity.gif
└── viewpage_fragment.gif
├── loadsir
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── kingja
│ └── loadsir
│ ├── LoadSirUtil.java
│ ├── callback
│ ├── Callback.java
│ ├── HintCallback.java
│ ├── ProgressCallback.java
│ └── SuccessCallback.java
│ ├── core
│ ├── Convertor.java
│ ├── LoadLayout.java
│ ├── LoadService.java
│ ├── LoadSir.java
│ └── Transport.java
│ └── target
│ ├── ActivityTarget.java
│ ├── ITarget.java
│ └── ViewTarget.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
11 |
--------------------------------------------------------------------------------
/README-en.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | English | [中文](README-cn.md)
4 |
5 | What's LoadSir?
6 | ---
7 |
8 | [](https://android-arsenal.com/details/1/6227)
9 | [](https://bintray.com/kingja/maven/loadsir#files/com%2Fkingja%2Floadsir%2Floadsir%2F1.2.0)
10 | :point_right:[](https://github.com/KingJA/LoadSir/releases):point_left:
11 |
12 |
13 | ***LoadSir*** is a lightweight, good expandable Android library used for displaying different pages like **loading**,
14 | **error**, **empty**, **timeout** or even your **custom page** when you load data from database or a REST service. LoadSir is very different from
15 | other similar libraries. I mean... ***better***.
16 |
17 | Preview - samples
18 | ---
19 | | **in [Activity](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/NormalActivity.java)**|**in [View](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/ViewTargetActivity.java)**|**in [Fragment](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/NormalFragment.java)**|
20 | |:---:|:----:|:----:|
21 | ||||
22 |
23 | | **[Placeholder](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/PlaceholderActivity.java)**|**[Multi-Fragment](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentActivity.java)**|**[ViewPager+Fragment](https://github.com/KingJA/LoadSir/blob/master/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentWithViewPagerActivity.java)**|
24 | |:---:|:----:|:----:|
25 | ||||
26 |
27 | Download Demo
28 | ---
29 | 
30 | ###### (password:9517)
31 |
32 | Feature
33 | ---
34 | * :star: support for Activity, Fragment, Fragment(v4), View
35 | * :star: support for Multi-Fragment, Fragment+ViewPager
36 | * :star: convert http result structure into a Callback
37 | * :star: no need to modify the layout
38 | * :star: only load one layout once
39 | * :star: no need to set enum or constant for status code
40 | * :star: set your own onClick logic in custom Callback
41 | * :star: no preloaded load page
42 | * :star: support for keeping the toolbar, titleview
43 | * allow to customize your own load page
44 | * set the retry onClick listener `OnReloadListener`
45 | * set the default load page
46 | * add multi load pages
47 | * thread-safety
48 |
49 | How does LoadSir work?
50 | ---
51 | <div align="center"><img src="imgs/LoadSir_flow.jpg"/></div>
52 |
53 | 🚀 Getting started
54 | ---
55 |
56 | LoadSir only needs 3 steps: **1. Config** -> **2. Register** -> **3. Display**
57 |
58 | ### Download
59 |
60 | ```groovy
61 | compile 'com.kingja.loadsir:loadsir:1.3.8'
62 | ```
63 |
64 | ### Step 1: Config
65 | There are two ways to set the config. Add your custom pages and set the default page.
66 |
67 | * ###### Global Config
68 | Set config with singleton pattern, you can do it in your Application. No matter where you do this job, you could get the
69 | unique LoadSir everywhere.
70 |
71 | ```java
72 | public class App extends Application {
73 | @Override
74 | public void onCreate() {
75 | super.onCreate();
76 | LoadSir.beginBuilder()
77 | .addCallback(new ErrorCallback())
78 | .addCallback(new EmptyCallback())
79 | .addCallback(new LoadingCallback())
80 | .addCallback(new TimeoutCallback())
81 | .addCallback(new CustomCallback())
82 | .setDefaultCallback(LoadingCallback.class)
83 | .commit();
84 | }
85 | }
86 | ```
87 | * ###### Single Config
88 | If you want to create another specific LoadSir, you can set config like this.
89 |
90 | ```java
91 | LoadSir loadSir = new LoadSir.Builder()
92 | .addCallback(new LoadingCallback())
93 | .addCallback(new EmptyCallback())
94 | .addCallback(new ErrorCallback())
95 | .build();
96 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
97 | @Override
98 | public void onReload(View v) {
99 | // retry logic
100 | }
101 | });
102 | ```
103 | ### Step 2: Register
104 |
105 | Tell LoadSir which "layout" you want to be replaced with LoadLayout.
106 |
107 | * ###### Register an Activity
108 | The registered `Activity` will be handled by LoadSir.
109 | ```java
110 | @Override
111 | protected void onCreate(@Nullable Bundle savedInstanceState) {
112 | super.onCreate(savedInstanceState);
113 | setContentView(R.layout.activity_content);
114 |
115 | // You can change the callback on sub thread directly.
116 | LoadService loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
117 | @Override
118 | public void onReload(View v) {
119 | // your retry logic
120 | }
121 | });
122 | }
123 | ```
124 |
125 | * ###### Register a View
126 | The registered `ImageView` will be handled by LoadSir.
127 | ```java
128 | ImageView imageView = (ImageView) findViewById(R.id.iv_img);
129 | LoadSir loadSir = new LoadSir.Builder()
130 | .addCallback(new TimeoutCallback())
131 | .setDefaultCallback(LoadingCallback.class)
132 | .build();
133 | loadService = loadSir.register(imageView, new Callback.OnReloadListener() {
134 | @Override
135 | public void onReload(View v) {
136 | loadService.showCallback(LoadingCallback.class);
137 | // your retry logic
138 | }
139 | });
140 | ```
141 |
142 | * ###### Register a Fragment
143 | The registered `Fragment` will be handled by LoadSir.
144 | Use it in Fragment is a bit different from the other two, follow the template code.
145 | ```java
146 | @Nullable
147 | @Override
148 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
149 | //step 1:obtain root view
150 | rootView = View.inflate(getActivity(), R.layout.fragment_a_content, null);
151 |
152 | //step 2:obtain the LoadService
153 | LoadService loadService = LoadSir.getDefault().register(rootView, new Callback.OnReloadListener() {
154 | @Override
155 | public void onReload(View v) {
156 | // your retry logic
157 | }
158 | });
159 |
160 | //step 3:return the LoadLayout from LoadService
161 | return loadService.getLoadLayout();
162 | }
163 | ```
164 |
165 | ### Step 3: Display
166 | What to show after fetching data (from REST service or database...)?
167 | * ###### Direct Display
168 | ```java
169 | protected void loadFromNet() {
170 | // do net job/load data...
171 |
172 | // callback after finish
173 | loadService.showSuccess(); // successful case -> show the data, eg RecyclerView,...
174 | --- OR ---
175 | loadService.showCallback(EmptyCallback.class); // do/show something else
176 | }
177 | ```
178 | **Info:** `showSuccess()` calls the `SuccessCallback` to "hide" LoadSir and show the content.
179 |
180 | * ###### Convertor Display (recommended)
181 | If you want LoadSir to do callback automatically, you can pass a Convertor when you register.
182 |
183 | ```java
184 | LoadService loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
185 | @Override
186 | public void onReload(View v) {
187 | // retry logic
188 | }}, new Convertor<HttpResult>() {
189 | @Override
190 | public Class<? extends Callback> map(HttpResult httpResult) {
191 | Class<? extends Callback> resultCode = SuccessCallback.class;
192 | switch (httpResult.getResultCode()) {
193 | case SUCCESS_CODE:
194 | if (httpResult.getData().size() == 0) {
195 | resultCode = EmptyCallback.class;
196 | }else{
197 | resultCode = SuccessCallback.class;
198 | }
199 | break;
200 | case ERROR_CODE:
201 | resultCode = ErrorCallback.class;
202 | break;
203 | }
204 | return resultCode;
205 | }
206 | });
207 | ```
208 | Pass a HttpResult, now you start up a robot LoadSir.
209 | ```java
210 | loadService.showWithConvertor(httpResult);
211 | ```
212 |
213 | ### Customize
214 | You can customize your own load page like loading, empty, error, timeout, etc. Provide the layout and fill the retry
215 | logic (if necessarily).
216 |
217 | ```java
218 | public class CustomCallback extends Callback {
219 |
220 | @Override
221 | protected int onCreateView() {
222 | return R.layout.layout_custom;
223 | }
224 |
225 | @Override
226 | protected boolean onReloadEvent(final Context context, View view) {
227 | Toast.makeText(context.getApplicationContext(), "Hello buddy! :p", Toast.LENGTH_SHORT).show();
228 | (view.findViewById(R.id.iv_gift)).setOnClickListener(new View.OnClickListener() {
229 | @Override
230 | public void onClick(View v) {
231 | Toast.makeText(context.getApplicationContext(), "It's your gift! :p", Toast.LENGTH_SHORT).show();
232 | }
233 | });
234 | return true;
235 | }
236 |
237 | //set visibility of SuccessView when callback is attach to Layout,true:visible, false: invisible
238 | @Override
239 | public boolean getSuccessVisible() {
240 | return super.getSuccessVisible();
241 | }
242 |
243 | //Called when the view of Callback is attached to LoadLayout.
244 | @Override
245 | public void onAttach(Context context, View view) {
246 | super.onAttach(context, view);
247 | }
248 |
249 | //Called when the view of Callback was detached from LoadLayout.
250 | @Override
251 | public void onDetach() {
252 | super.onDetach(context, view);
253 | }
254 |
255 | }
256 | ```
257 |
258 | ### Modify Callback Dynamically
259 | Access the view of a `Callback`.
260 | ```java
261 | loadService = LoadSir.getDefault().register(...);
262 | loadService.setCallBack(EmptyCallback.class, new Transport() {
263 | @Override
264 | public void order(Context context, View view) {
265 | TextView mTvEmpty = (TextView) view.findViewById(R.id.tv_empty);
266 | mTvEmpty.setText("Fine, no data. You must fill it!");
267 | }
268 | });
269 | ```
270 | ### Default Callback in LoadSir
271 |
272 | ```java
273 | ProgressCallback loadingCallback = new ProgressCallback.Builder()
274 | .setTitle("Loading", R.style.Hint_Title)
275 | .build();
276 |
277 | HintCallback hintCallback = new HintCallback.Builder()
278 | .setTitle("Error", R.style.Hint_Title)
279 | .setSubTitle("Sorry, buddy, I will try it again.")
280 | .setHintImg(R.drawable.error)
281 | .build();
282 |
283 | LoadSir loadSir = new LoadSir.Builder()
284 | .addCallback(loadingCallback)
285 | .addCallback(hintCallback)
286 | .setDefaultCallback(ProgressCallback.class)
287 | .build();
288 | ```
289 |
290 |
291 |
292 |
293 |
294 | ### :bulb: About placeholder effect
295 | The effect of placeholder is just like the library [ShimmerRecyclerView](https://github.com/sharish/ShimmerRecyclerView)
296 | works. LoadSir do the similar job only through a PlaceHolderCallback, just a custom ***Callback***. That feeling was
297 | amazing. :ghost:
298 |
299 | ## Docs
300 | * :point_right: [FAQ](docs/FAQ.md)
301 | * 📌 [Version changelog](docs/changelog.md)
302 | * [Best Practice](docs/BestPractice.md)
303 | * [What will the next version include?](docs/NextVersion.md)
304 |
305 | ## ProGuard
306 |
307 | ```xml
308 | -dontwarn com.kingja.loadsir.**
309 | -keep class com.kingja.loadsir.** {*;}
310 | ```
311 | ## Contact Me
312 | Any questions: Welcome to contact me.
313 | * Email: kingjavip@gmail.com
314 |
315 | ## License
316 |
317 | Copyright 2017 KingJA
318 |
319 | Licensed under the Apache License, Version 2.0 (the "License");
320 | you may not use this file except in compliance with the License.
321 | You may obtain a copy of the License at
322 |
323 | http://www.apache.org/licenses/LICENSE-2.0
324 |
325 | Unless required by applicable law or agreed to in writing, software
326 | distributed under the License is distributed on an "AS IS" BASIS,
327 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
328 | See the License for the specific language governing permissions and
329 | limitations under the License.
330 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | 中文 | [English](README-en.md)
4 |
5 | LoadSir
6 | ---
7 |
8 | [](https://android-arsenal.com/details/1/6227)
9 | [](https://bintray.com/kingja/maven/loadsir#files/com%2Fkingja%2Floadsir%2Floadsir%2F1.2.0)
10 | :point_right:[](https://github.com/KingJA/LoadSir/releases):point_left:
11 |
12 | `LoadSir`是一个高效易用,低碳环保,扩展性良好的加载反馈页管理框架,在加载网络或其他数据时候,根据需求切换状态页面,
13 | 可添加自定义状态页面,如加载中,加载失败,无数据,网络超时,如占位图,登录失效等常用页面。可配合网络加载框架,结合返回
14 | 状态码,错误码,数据进行状态页自动切换,封装使用效果更佳。
15 |
16 | 使用场景
17 | ---
18 | | **in Activity**|**in View**|**in Fragment**|
19 | |:---:|:----:|:----:|
20 | ||||
21 |
22 | | **Placeholder**|**Muitl-Fragment**|**ViewPage+Fragment**|
23 | |:---:|:----:|:----:|
24 | ||||
25 |
26 | 下载 Demo
27 | ---
28 | 
29 | ###### (密码:9517)
30 |
31 | 流程图
32 | ---
33 | <div align="center"><img src="imgs/LoadSir_flow.jpg"/></div>
34 |
35 | LoadSir的功能及特点
36 | ---
37 | * :star:支持Activity,Fragment,Fragment(v4),View状态回调
38 | * :star:适配多个Fragment切换,及Fragment+ViewPager切换,不会布局叠加或者布局错乱
39 | * :star:利用泛型转换输入信号和输出状态,可根据网络返回体的状态码或者数据返回自动适配状态页,实现全局自动状态切换
40 | * :star:无需修改布局文件
41 | * :star:只加载唯一一个状态视图,不会预加载全部视图
42 | * :star:不需要设置枚举或者常量状态值,直接用状态页类类型(xxx.class)作为状态码
43 | * :star:可对单个状态页单独设置点击事件,根据返回boolean值覆盖或者结合OnReloadListener使用,如网络错误可跳转设置页
44 | * :star:无预设页面,低耦合,开发者随心配置
45 | * :star:可保留标题栏(Toolbar,titile view等)
46 | * 可设置重新加载点击事件(OnReloadListener)
47 | * 可自定义状态页(继承Callback类)
48 | * 可在子线程直接切换状态
49 | * 可设置初始状态页(常用进度页作为初始状态)
50 | * 可扩展状态页面,在配置中添加自定义状态页
51 | * 可全局单例配置,也可以单独配置
52 |
53 |
54 |
55 | 开始使用LoadSir
56 | ---
57 |
58 | LoadSir的使用,只需要简单的三步
59 |
60 | ### 添加依赖
61 |
62 | ```groovy
63 | compile 'com.kingja.loadsir:loadsir:1.3.8'
64 | ```
65 |
66 | ### 第一步:配置
67 |
68 | ###### 全局配置方式
69 | 全局配置方式,使用的是单例模式,即获取的配置都是一样的。可在Application中配置,添加状态页,设置默认状态页
70 |
71 | ```java
72 | public class App extends Application {
73 | @Override
74 | public void onCreate() {
75 | super.onCreate();
76 | LoadSir.beginBuilder()
77 | .addCallback(new ErrorCallback())//添加各种状态页
78 | .addCallback(new EmptyCallback())
79 | .addCallback(new LoadingCallback())
80 | .addCallback(new TimeoutCallback())
81 | .addCallback(new CustomCallback())
82 | .setDefaultCallback(LoadingCallback.class)//设置默认状态页
83 | .commit();
84 | }
85 | }
86 | ```
87 | ###### 单独配置方式
88 | 如果你即想保留全局配置,又想在某个特殊页面加点不同的配置,可采用该方式。
89 |
90 | ```java
91 | LoadSir loadSir = new LoadSir.Builder()
92 | .addCallback(new LoadingCallback())
93 | .addCallback(new EmptyCallback())
94 | .addCallback(new ErrorCallback())
95 | .build();
96 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
97 | @Override
98 | public void onReload(View v) {
99 | // 重新加载逻辑
100 | }
101 | });
102 | ```
103 | ### 第二步:注册
104 |
105 | ###### 在Activity中使用
106 |
107 | ```java
108 | @Override
109 | protected void onCreate(@Nullable Bundle savedInstanceState) {
110 | super.onCreate(savedInstanceState);
111 | setContentView(R.layout.activity_content);
112 | // Your can change the callback on sub thread directly.
113 | LoadService loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
114 | @Override
115 | public void onReload(View v) {
116 | // 重新加载逻辑
117 | }
118 | });
119 | }}
120 | ```
121 |
122 | ###### 在View 中使用
123 | ```java
124 | ImageView imageView = (ImageView) findViewById(R.id.iv_img);
125 | LoadSir loadSir = new LoadSir.Builder()
126 | .addCallback(new TimeoutCallback())
127 | .setDefaultCallback(LoadingCallback.class)
128 | .build();
129 | loadService = loadSir.register(imageView, new Callback.OnReloadListener() {
130 | @Override
131 | public void onReload(View v) {
132 | loadService.showCallback(LoadingCallback.class);
133 | // 重新加载逻辑
134 | }
135 | });
136 | Ps:
137 | [1]要注册RelativeLayout或ConstraintLayout的子View,如果该子View被其它子View约束,建议在子View外层再包一层布局,参考
138 | acitivy_view.xm和activity_constraintlayout.xml
139 | ```
140 | ###### 在Fragment 中使用
141 | 由于Fragment添加到Activitiy方式多样,比较特别,所以在Fragment注册方式不同于上面两种,大家先看模板代码:
142 | ```java
143 | @Nullable
144 | @Override
145 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
146 | savedInstanceState) {
147 | //第一步:获取布局View
148 | rootView = View.inflate(getActivity(), R.layout.fragment_a_content, null);
149 | //第二步:注册布局View
150 | LoadService loadService = LoadSir.getDefault().register(rootView, new Callback.OnReloadListener() {
151 | @Override
152 | public void onReload(View v) {
153 | // 重新加载逻辑
154 | }
155 | });
156 | //第三步:返回LoadSir生成的LoadLayout
157 | return loadService.getLoadLayout();
158 | }
159 | ```
160 |
161 | ### 第三步: 回调
162 |
163 | ###### 直接回调
164 | ```java
165 | protected void loadNet() {
166 | // 进行网络访问...
167 | // 进行回调
168 | loadService.showSuccess();//成功回调
169 | loadService.showCallback(EmptyCallback.class);//其他回调
170 | }
171 | ```
172 | ###### 转换器回调 (推荐使用)
173 | 如果你不想再每次回调都要手动进行的话,可以选择注册的时候加入转换器,可根据返回的数据,适配对应的状态页。
174 |
175 | ```java
176 | LoadService loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
177 | @Override
178 | public void onReload(View v) {
179 | // 重新加载逻辑
180 | }}, new Convertor<HttpResult>() {
181 | @Override
182 | public Class<? extends Callback> map(HttpResult httpResult) {
183 | Class<? extends Callback> resultCode = SuccessCallback.class;
184 | switch (httpResult.getResultCode()) {
185 | case SUCCESS_CODE://成功回调
186 | if (httpResult.getData().size() == 0) {
187 | resultCode = EmptyCallback.class;
188 | }else{
189 | resultCode = SuccessCallback.class;
190 | }
191 | break;
192 | case ERROR_CODE:
193 | resultCode = ErrorCallback.class;
194 | break;
195 | }
196 | return resultCode;
197 | }
198 | });
199 | ```
200 | 回调的时候直接传入转换器指定的数据类型。
201 | ```java
202 | loadService.showWithConvertor(httpResult);
203 | ```
204 |
205 | ### 自定义回调页
206 | LoadSir为了完全解耦,没有预设任何状态页,需要自己实现,开发者自定义自己的回调页面,比如加载中,没数据,错误,超时等常用页面,
207 | 设置布局及自定义点击逻辑
208 |
209 | ```java
210 | public class CustomCallback extends Callback {
211 |
212 | //填充布局
213 | @Override
214 | protected int onCreateView() {
215 | return R.layout.layout_custom;
216 | }
217 | //当前Callback的点击事件,如果返回true则覆盖注册时的onReloa(),如果返回false则两者都执行,先执行onReloadEvent()。
218 | @Override
219 | protected boolean onReloadEvent(final Context context, View view) {
220 | Toast.makeText(context.getApplicationContext(), "Hello buddy! :p", Toast.LENGTH_SHORT).show();
221 | (view.findViewById(R.id.iv_gift)).setOnClickListener(new View.OnClickListener() {
222 | @Override
223 | public void onClick(View v) {
224 | Toast.makeText(context.getApplicationContext(), "It's your gift! :p", Toast.LENGTH_SHORT).show();
225 | }
226 | });
227 | return true;
228 | }
229 |
230 | //是否在显示Callback视图的时候显示原始图(SuccessView),返回true显示,false隐藏
231 | @Override
232 | public boolean getSuccessVisible() {
233 | return super.getSuccessVisible();
234 | }
235 |
236 | //将Callback添加到当前视图时的回调,View为当前Callback的布局View
237 | @Override
238 | public void onAttach(Context context, View view) {
239 | super.onAttach(context, view);
240 | }
241 |
242 | //将Callback从当前视图删除时的回调,View为当前Callback的布局View
243 | @Override
244 | public void onDetach() {
245 | super.onDetach(context, view);
246 | }
247 |
248 | }
249 | ```
250 | ### 动态修改Callback
251 |
252 | ```java
253 | loadService = LoadSir.getDefault().register(...);
254 | loadService.setCallBack(EmptyCallback.class, new Transport() {
255 | @Override
256 | public void order(Context context, View view) {
257 | TextView mTvEmpty = (TextView) view.findViewById(R.id.tv_empty);
258 | mTvEmpty.setText("fine, no data. You must fill it!");
259 | }
260 | });
261 | ```
262 |
263 | ### LoadSir自带便携式Callback
264 |
265 | ```java
266 | ProgressCallback loadingCallback = new ProgressCallback.Builder()
267 | .setTitle("Loading", R.style.Hint_Title)
268 | .build();
269 |
270 | HintCallback hintCallback = new HintCallback.Builder()
271 | .setTitle("Error", R.style.Hint_Title)
272 | .setSubTitle("Sorry, buddy, I will try it again.")
273 | .setHintImg(R.drawable.error)
274 | .build();
275 |
276 | LoadSir loadSir = new LoadSir.Builder()
277 | .addCallback(loadingCallback)
278 | .addCallback(hintCallback)
279 | .setDefaultCallback(ProgressCallback.class)
280 | .build();
281 | ```
282 |
283 | 在使用过程中,遇到问题可以先去[FAQ](docs/FAQ.md)和Issues看看有没解决方案,如果没有的话,请给我提Issue吧。
284 |
285 |
286 | ### :bulb: About placeholder effect
287 | placeholder效果状态页类似[ShimmerRecyclerView](https://github.com/sharish/ShimmerRecyclerView)的效果. LoadSir只用了一个
288 | 自定义状态页PlaceHolderCallback就完成类似的效果,是不是很棒 :ghost:
289 |
290 | ## Docs
291 | * :point_right: [常见问题](docs/FAQ-cn.md)
292 | * 📌 [更新日志](docs/changelog.md)
293 | * [最佳实践](docs/BestPractice-cn.md)
294 | * [下个版本开发计划](docs/NextVersion.md)
295 |
296 | ## 代码混淆
297 |
298 | ```xml
299 | -dontwarn com.kingja.loadsir.**
300 | -keep class com.kingja.loadsir.** {*;}
301 | ```
302 |
303 | ## Contact Me
304 | Any questions,Welcome to contact me.
305 | * Email:kingjavip@gmail.com
306 | * QQ群(818251143)
307 |
308 | ## License
309 |
310 | Copyright 2017 KingJA
311 |
312 | Licensed under the Apache License, Version 2.0 (the "License");
313 | you may not use this file except in compliance with the License.
314 | You may obtain a copy of the License at
315 |
316 | http://www.apache.org/licenses/LICENSE-2.0
317 |
318 | Unless required by applicable law or agreed to in writing, software
319 | distributed under the License is distributed on an "AS IS" BASIS,
320 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
321 | See the License for the specific language governing permissions and
322 | limitations under the License.
323 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .idea
3 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION
6 | defaultConfig {
7 | applicationId "sample.kingja.loadsir"
8 | minSdkVersion MIN_SDK_VERSION as int
9 | targetSdkVersion TARGET_SDK_VERSION as int
10 | versionCode VERSION_CODE as int
11 | versionName VERSION_NAME
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled true
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | debug {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 |
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(include: ['*.jar'], dir: 'libs')
32 | implementation 'com.google.android.material:material:1.2.0-alpha05'
33 | implementation 'androidx.appcompat:appcompat:1.1.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 |
36 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
37 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
38 |
39 | implementation 'com.jakewharton:butterknife:10.2.1'
40 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
41 |
42 | // implementation('com.airbnb.android:lottie:3.3.0') { exclude group: 'com.android.support' }
43 | implementation 'com.airbnb.android:lottie:2.8.0'
44 | // implementation project(':loadsir')
45 | implementation 'com.kingja.loadsir:loadsir:1.3.8'
46 | }
47 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | -dontwarn com.kingja.loadsir.**
28 | -keep class com.kingja.loadsir.** {*;}
29 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 | package="sample.kingja.loadsir">
4 |
5 | <application
6 | android:name=".App"
7 | android:icon="@mipmap/ic_launcher"
8 | android:label="@string/app_name"
9 | android:roundIcon="@mipmap/ic_launcher_round"
10 | android:supportsRtl="true"
11 | android:theme="@style/AppTheme">
12 | <activity android:name=".MainActivity">
13 | <intent-filter>
14 | <action android:name="android.intent.action.MAIN"/>
15 |
16 | <category android:name="android.intent.category.LAUNCHER"/>
17 | </intent-filter>
18 |
19 | </activity>
20 | <activity android:name=".target.NormalActivity"/>
21 | <activity android:name=".target.ConvertorActivity"/>
22 | <activity android:name=".target.FragmentSingleActivity"/>
23 | <activity android:name=".target.ViewTargetActivity"/>
24 | <activity android:name=".target.DefaultCallbackActivity"/>
25 | <activity android:name=".target.MultiFragmentWithViewPagerActivity"/>
26 | <activity android:name=".target.MultiFragmentActivity"/>
27 | <activity android:name=".target.PlaceholderActivity"/>
28 | <activity android:name=".target.AnimateActivity"/>
29 | <activity android:name=".target.KeepTitleFragmentActivity"/>
30 | <activity android:name=".target.BestPracticesActivity"/>
31 | <activity android:name=".target.LottieActivity"/>
32 | <activity
33 | android:name=".target.KeepTitleActivity"
34 | android:theme="@style/NoTitle"/>
35 | <activity android:name=".target.ConstraintLayoutActivity"/>
36 | </application>
37 |
38 | </manifest>
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/App.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.app.Application;
4 |
5 | import com.kingja.loadsir.core.LoadSir;
6 | import com.squareup.leakcanary.LeakCanary;
7 |
8 | import sample.kingja.loadsir.callback.CustomCallback;
9 | import sample.kingja.loadsir.callback.EmptyCallback;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 | import sample.kingja.loadsir.callback.TimeoutCallback;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/3 14:02
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 |
21 | public class App extends Application {
22 | @Override
23 | public void onCreate() {
24 | super.onCreate();
25 | if (setupLeakCanary()) {
26 | return;
27 | }
28 |
29 | LoadSir.beginBuilder()
30 | .addCallback(new ErrorCallback())
31 | .addCallback(new EmptyCallback())
32 | .addCallback(new LoadingCallback())
33 | .addCallback(new TimeoutCallback())
34 | .addCallback(new CustomCallback())
35 | .setDefaultCallback(LoadingCallback.class)
36 | .commit();
37 | }
38 |
39 | private boolean setupLeakCanary() {
40 | if (LeakCanary.isInAnalyzerProcess(this)) {
41 | // This process is dedicated to LeakCanary for heap analysis.
42 | // You should not init your app in this process.
43 | return true;
44 | }
45 | LeakCanary.install(this);
46 | return false;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/MainActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import sample.kingja.loadsir.target.AnimateActivity;
9 | import sample.kingja.loadsir.target.BestPracticesActivity;
10 | import sample.kingja.loadsir.target.ConstraintLayoutActivity;
11 | import sample.kingja.loadsir.target.DefaultCallbackActivity;
12 | import sample.kingja.loadsir.target.KeepTitleActivity;
13 | import sample.kingja.loadsir.target.KeepTitleFragmentActivity;
14 | import sample.kingja.loadsir.target.MultiFragmentActivity;
15 | import sample.kingja.loadsir.target.FragmentSingleActivity;
16 | import sample.kingja.loadsir.target.NormalActivity;
17 | import sample.kingja.loadsir.target.ConvertorActivity;
18 | import sample.kingja.loadsir.target.MultiFragmentWithViewPagerActivity;
19 | import sample.kingja.loadsir.target.PlaceholderActivity;
20 | import sample.kingja.loadsir.target.ViewTargetActivity;
21 |
22 | /**
23 | * Description:TODO
24 | * Create Time:2017/9/2 16:02
25 | * Author:KingJA
26 | * Email:kingjavip@gmail.com
27 | */
28 |
29 | public class MainActivity extends AppCompatActivity {
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | }
36 |
37 | public void inActivity(View view) {
38 | startActivity(new Intent(this, NormalActivity.class));
39 | }
40 |
41 | public void showPlaceholder(View view) {
42 | startActivity(new Intent(this, PlaceholderActivity.class));
43 | }
44 |
45 | public void inActivityWithConvertor(View view) {
46 | startActivity(new Intent(this, ConvertorActivity.class));
47 | }
48 |
49 | public void inFragment(View view) {
50 | startActivity(new Intent(this, FragmentSingleActivity.class));
51 | }
52 |
53 | public void inFragmentMutil(View view) {
54 | startActivity(new Intent(this, MultiFragmentActivity.class));
55 | }
56 |
57 | public void inFragmentViewSirPager(View view) {
58 | startActivity(new Intent(this, MultiFragmentWithViewPagerActivity.class));
59 | }
60 |
61 | public void inView(View view) {
62 | startActivity(new Intent(this, ViewTargetActivity.class));
63 | }
64 |
65 | public void defaultCallback(View view) {
66 | startActivity(new Intent(this, DefaultCallbackActivity.class));
67 | }
68 |
69 | public void animatCallback(View view) {
70 | startActivity(new Intent(this, AnimateActivity.class));
71 | }
72 |
73 | public void keepTitleInFragment(View view) {
74 | startActivity(new Intent(this, KeepTitleFragmentActivity.class));
75 | }
76 |
77 | public void bestPractices(View view) {
78 | startActivity(new Intent(this, BestPracticesActivity.class));
79 | }
80 |
81 | public void keepTitleInActivity(View view) {
82 | startActivity(new Intent(this, KeepTitleActivity.class));
83 | }
84 |
85 | public void inConstraintLayoutActivity(View view) {
86 | startActivity(new Intent(this, ConstraintLayoutActivity.class));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/PostUtil.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.core.LoadService;
8 |
9 | /**
10 | * Description:TODO
11 | * Create Time:2017/9/4 15:21
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 | public class PostUtil {
16 | private static final int DELAY_TIME = 1000;
17 |
18 | public static void postCallbackDelayed(final LoadService loadService, final Class<? extends Callback> clazz) {
19 | postCallbackDelayed(loadService, clazz, DELAY_TIME);
20 | }
21 |
22 | public static void postCallbackDelayed(final LoadService loadService, final Class<? extends Callback> clazz, long
23 | delay) {
24 | new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
25 | @Override
26 | public void run() {
27 | loadService.showCallback(clazz);
28 | }
29 | }, delay);
30 | }
31 |
32 | public static void postSuccessDelayed(final LoadService loadService) {
33 | postSuccessDelayed(loadService, DELAY_TIME);
34 | }
35 |
36 | public static void postSuccessDelayed(final LoadService loadService, long delay) {
37 | new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
38 | @Override
39 | public void run() {
40 | loadService.showSuccess();
41 | }
42 | }, delay);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.base;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.core.LoadService;
10 | import com.kingja.loadsir.core.LoadSir;
11 |
12 | import androidx.annotation.Nullable;
13 | import androidx.fragment.app.Fragment;
14 | import butterknife.ButterKnife;
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/9/6 14:34
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 | public abstract class BaseFragment extends Fragment {
23 |
24 | protected LoadService mBaseLoadService;
25 |
26 | @Nullable
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
29 | savedInstanceState) {
30 | View rootView = inflater.inflate(onCreateFragmentView(), container, false);
31 | ButterKnife.bind(this, rootView);
32 | mBaseLoadService = LoadSir.getDefault().register(rootView, new Callback.OnReloadListener() {
33 | @Override
34 | public void onReload(View v) {
35 | onNetReload(v);
36 | }
37 | });
38 | return mBaseLoadService.getLoadLayout();
39 | }
40 |
41 | protected abstract int onCreateFragmentView();
42 |
43 | @Override
44 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
45 | super.onViewCreated(view, savedInstanceState);
46 |
47 | loadNet();
48 | }
49 |
50 | protected abstract void loadNet();
51 |
52 | protected abstract void onNetReload(View v);
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/base/BaseTitleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.base;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.FrameLayout;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.kingja.loadsir.callback.Callback;
10 | import com.kingja.loadsir.core.LoadService;
11 | import com.kingja.loadsir.core.LoadSir;
12 |
13 | import androidx.annotation.Nullable;
14 | import androidx.appcompat.app.AppCompatActivity;
15 | import butterknife.ButterKnife;
16 | import sample.kingja.loadsir.R;
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/3/20 14:17
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 | public abstract class BaseTitleActivity extends AppCompatActivity {
25 | protected View rootView;
26 | protected LoadService mBaseLoadService;
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | rootView = View.inflate(this, R.layout.activity_title, null);
32 | addContent();
33 | setContentView(rootView);
34 | initView();
35 | initNet();
36 | }
37 |
38 |
39 | private void addContent() {
40 | FrameLayout flContent = rootView.findViewById(R.id.fl_content);
41 | TextView tvTitleTitle = rootView.findViewById(R.id.tv_title_title);
42 | LinearLayout llTitleBack = rootView.findViewById(R.id.ll_title_back);
43 | tvTitleTitle.setText(getContentTitle() == null ? "" : getContentTitle());
44 | llTitleBack.setOnClickListener(v -> backClick());
45 | View content = View.inflate(this, getContentView(), null);
46 | if (content != null) {
47 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
48 | FrameLayout.LayoutParams.MATCH_PARENT);
49 | flContent.addView(content, params);
50 | ButterKnife.bind(this, rootView);
51 | mBaseLoadService = LoadSir.getDefault().register(content, (Callback.OnReloadListener) this::onNetReload);
52 | }
53 | }
54 |
55 | private void backClick() {
56 | finish();
57 | }
58 |
59 | protected abstract String getContentTitle();
60 |
61 | protected abstract int getContentView();
62 |
63 | protected abstract void initView();
64 |
65 | protected abstract void initNet();
66 |
67 | protected abstract void onNetReload(View v);
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/AnimateCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.animation.Animation;
6 | import android.view.animation.LinearInterpolator;
7 | import android.view.animation.RotateAnimation;
8 | import android.widget.Toast;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 |
12 | import sample.kingja.loadsir.R;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/3 10:22
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 | public class AnimateCallback extends Callback {
21 |
22 | private Context context;
23 | private View animateView;
24 |
25 | @Override
26 | protected int onCreateView() {
27 | return R.layout.layout_animate;
28 | }
29 |
30 | @Override
31 | protected void onViewCreate(Context context, View view) {
32 | super.onViewCreate(context, view);
33 | }
34 |
35 | @Override
36 | public void onAttach(Context context, View view) {
37 | this.context = context;
38 | animateView = view.findViewById(R.id.view_animate);
39 | Animation animation = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF,
40 | 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
41 | animation.setDuration(1000);
42 | animation.setRepeatCount(Integer.MAX_VALUE);
43 | animation.setFillAfter(true);
44 | animation.setInterpolator(new LinearInterpolator());
45 | animateView.startAnimation(animation);
46 | Toast.makeText(context.getApplicationContext(), "start animation", Toast.LENGTH_SHORT).show();
47 | }
48 |
49 | @Override
50 | public void onDetach() {
51 | super.onDetach();
52 | if (animateView != null) {
53 | animateView.clearAnimation();
54 | }
55 | Toast.makeText(context.getApplicationContext(), "stop animation", Toast.LENGTH_SHORT).show();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/CustomCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 |
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/3 10:22
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class CustomCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_custom;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(final Context context, View view) {
26 | Toast.makeText(context.getApplicationContext(), "Hello buddy, how r u! :p", Toast.LENGTH_SHORT).show();
27 | (view.findViewById(R.id.iv_gift)).setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | Toast.makeText(context.getApplicationContext(), "It's your gift! :p", Toast.LENGTH_SHORT).show();
31 | }
32 | });
33 | return true;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/EmptyCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | import sample.kingja.loadsir.R;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 10:22
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 |
14 | public class EmptyCallback extends Callback {
15 |
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_empty;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/ErrorCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 |
4 | import com.kingja.loadsir.callback.Callback;
5 |
6 | import sample.kingja.loadsir.R;
7 |
8 | /**
9 | * Description:TODO
10 | * Create Time:2017/9/4 10:20
11 | * Author:KingJA
12 | * Email:kingjavip@gmail.com
13 | */
14 |
15 | public class ErrorCallback extends Callback {
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_error;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LoadingCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class LoadingCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_loading;
22 | }
23 |
24 |
25 | @Override
26 | protected boolean onReloadEvent(Context context, View view) {
27 | return true;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LottieEmptyCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | import sample.kingja.loadsir.R;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 10:22
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 |
14 | public class LottieEmptyCallback extends Callback {
15 |
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_lottie_empty;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LottieLoadingCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class LottieLoadingCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_lottie_loading;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(Context context, View view) {
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/PlaceholderCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class PlaceholderCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_placeholder;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(Context context, View view) {
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/TimeoutCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 |
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/2 16:17
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 |
18 | public class TimeoutCallback extends Callback {
19 |
20 | @Override
21 | protected int onCreateView() {
22 | return R.layout.layout_timeout;
23 | }
24 |
25 | @Override
26 | protected boolean onReloadEvent(Context context, View view) {
27 | Toast.makeText(context.getApplicationContext(),"Connecting to the network again!",Toast.LENGTH_SHORT).show();
28 | return false;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/XCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | import sample.kingja.loadsir.R;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 10:22
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 |
14 | public class XCallback extends Callback {
15 |
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_empty;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/AnimateActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.os.SystemClock;
5 | import android.view.View;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 | import com.kingja.loadsir.core.LoadService;
9 | import com.kingja.loadsir.core.LoadSir;
10 |
11 | import androidx.annotation.Nullable;
12 | import androidx.appcompat.app.AppCompatActivity;
13 | import sample.kingja.loadsir.PostUtil;
14 | import sample.kingja.loadsir.R;
15 | import sample.kingja.loadsir.callback.AnimateCallback;
16 | import sample.kingja.loadsir.callback.EmptyCallback;
17 |
18 |
19 | /**
20 | * Description:TODO
21 | * Create Time:2017/9/4 10:12
22 | * Author:KingJA
23 | * Email:kingjavip@gmail.com
24 | */
25 |
26 | public class AnimateActivity extends AppCompatActivity {
27 |
28 |
29 | private LoadService loadService;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_content);
35 | // Your can change the callback on sub thread directly.
36 | LoadSir loadSir = new LoadSir.Builder()
37 | .addCallback(new EmptyCallback())
38 | .addCallback(new AnimateCallback())
39 | .setDefaultCallback(AnimateCallback.class)
40 | .build();
41 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
42 | @Override
43 | public void onReload(View v) {
44 | // Your can change the status out of Main thread.
45 | new Thread(new Runnable() {
46 | @Override
47 | public void run() {
48 | loadService.showCallback(AnimateCallback.class);
49 | //do retry logic...
50 | SystemClock.sleep(500);
51 | //callback on sub thread
52 | loadService.showSuccess();
53 | }
54 | }).start();
55 | }
56 | });
57 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1000);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/BestPracticesActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import androidx.annotation.Nullable;
8 | import androidx.appcompat.app.AppCompatActivity;
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/29 13:54
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class BestPracticesActivity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_best_practices);
22 | }
23 |
24 | public void mvpActivity(View view) {
25 | }
26 |
27 | public void onLottie(View view) {
28 | startActivity(new Intent(this, LottieActivity.class));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/ConstraintLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.os.SystemClock;
5 | import android.view.View;
6 | import android.widget.TextView;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.core.LoadService;
10 | import com.kingja.loadsir.core.LoadSir;
11 |
12 | import androidx.annotation.Nullable;
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import sample.kingja.loadsir.PostUtil;
15 | import sample.kingja.loadsir.R;
16 | import sample.kingja.loadsir.callback.EmptyCallback;
17 | import sample.kingja.loadsir.callback.LoadingCallback;
18 |
19 |
20 | /**
21 | * Description:TODO
22 | * Create Time:2017/9/4 10:12
23 | * Author:KingJA
24 | * Email:kingjavip@gmail.com
25 | */
26 |
27 | public class ConstraintLayoutActivity extends AppCompatActivity {
28 |
29 | private LoadService loadService;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_constraintlayout);
35 | initLoadSir();
36 | }
37 |
38 | private void initLoadSir() {
39 | TextView tv_center = findViewById(R.id.tv_center);
40 | loadService = LoadSir.getDefault().register(tv_center, new Callback.OnReloadListener() {
41 | @Override
42 | public void onReload(View v) {
43 | // Your can change the status out of Main thread.
44 | new Thread(new Runnable() {
45 | @Override
46 | public void run() {
47 | loadService.showCallback(LoadingCallback.class);
48 | //do retry logic...
49 | SystemClock.sleep(500);
50 | //callback
51 | loadService.showSuccess();
52 | }
53 | }).start();
54 | }
55 | });
56 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1000);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/ConvertorActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.view.View;
6 |
7 | import androidx.annotation.Nullable;
8 | import androidx.appcompat.app.AppCompatActivity;
9 | import sample.kingja.loadsir.callback.EmptyCallback;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 |
13 | import com.kingja.loadsir.callback.Callback;
14 | import com.kingja.loadsir.callback.SuccessCallback;
15 | import com.kingja.loadsir.core.LoadService;
16 | import com.kingja.loadsir.core.LoadSir;
17 |
18 | import com.kingja.loadsir.core.Convertor;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.Random;
23 |
24 | import sample.kingja.loadsir.R;
25 | import sample.kingja.loadsir.PostUtil;
26 |
27 |
28 | /**
29 | * Description:TODO
30 | * Create Time:2017/9/4 10:35
31 | * Author:KingJA
32 | * Email:kingjavip@gmail.com
33 | */
34 |
35 | public class ConvertorActivity extends AppCompatActivity {
36 |
37 | private LoadService loadService;
38 | private HttpResult mHttpResult = new HttpResult(new Random().nextInt(2), new ArrayList<>());
39 | private static final int SUCCESS_CODE = 0x00;
40 | private static final int ERROR_CODE = 0x01;
41 |
42 | @Override
43 | protected void onCreate(@Nullable Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_activity_convertor);
46 | LoadSir loadSir = new LoadSir.Builder()
47 | .addCallback(new LoadingCallback())
48 | .addCallback(new EmptyCallback())
49 | .addCallback(new ErrorCallback())
50 | .setDefaultCallback(LoadingCallback.class)
51 | .build();
52 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | loadService.showCallback(LoadingCallback.class);
56 | PostUtil.postCallbackDelayed(loadService, SuccessCallback.class);
57 | }
58 | }, new Convertor<HttpResult>() {
59 | @Override
60 | public Class<? extends Callback> map(HttpResult httpResult) {
61 | Class<? extends Callback> resultCode = SuccessCallback.class;
62 | switch (httpResult.getResultCode()) {
63 | //success
64 | case SUCCESS_CODE:
65 | if (httpResult.getData().size() == 0) {
66 | resultCode = EmptyCallback.class;
67 | } else {
68 | resultCode = SuccessCallback.class;
69 | }
70 | break;
71 | case ERROR_CODE:
72 | resultCode = ErrorCallback.class;
73 | break;
74 | default:
75 | resultCode = ErrorCallback.class;
76 | }
77 | return resultCode;
78 | }
79 | });
80 | new Handler().postDelayed(new Runnable() {
81 | @Override
82 | public void run() {
83 | // do net here...
84 |
85 | //callback
86 | loadService.showWithConvertor(mHttpResult);
87 | }
88 | }, 500);
89 | }
90 |
91 | private class HttpResult {
92 | private int resultCode;
93 | private List<Object> data;
94 |
95 | HttpResult(int resultCode, List<Object> data) {
96 | this.resultCode = resultCode;
97 | this.data = data;
98 | }
99 |
100 | int getResultCode() {
101 | return resultCode;
102 | }
103 |
104 | public List<Object> getData() {
105 | return data;
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/DefaultCallbackActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.callback.HintCallback;
8 | import com.kingja.loadsir.callback.ProgressCallback;
9 | import com.kingja.loadsir.core.LoadService;
10 | import com.kingja.loadsir.core.LoadSir;
11 |
12 | import androidx.annotation.Nullable;
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import sample.kingja.loadsir.PostUtil;
15 | import sample.kingja.loadsir.R;
16 |
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/4 10:12
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class DefaultCallbackActivity extends AppCompatActivity {
26 |
27 | private LoadService loadService;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_content);
33 |
34 | ProgressCallback loadingCallback = new ProgressCallback.Builder()
35 | .setTitle("Loading", R.style.Hint_Title)
36 | // .setAboveSuccess(true)// attach loadingView above successView
37 | .build();
38 |
39 | HintCallback hintCallback = new HintCallback.Builder()
40 | .setTitle("Error", R.style.Hint_Title)
41 | .setSubTitle("Sorry, buddy, I will try it again.")
42 | .setHintImg(R.drawable.error)
43 | .build();
44 |
45 | LoadSir loadSir = new LoadSir.Builder()
46 | .addCallback(loadingCallback)
47 | .addCallback(hintCallback)
48 | .setDefaultCallback(ProgressCallback.class)
49 | .build();
50 |
51 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
52 | @Override
53 | public void onReload(View v) {
54 | loadService.showCallback(ProgressCallback.class);
55 | PostUtil.postSuccessDelayed(loadService);
56 |
57 | }
58 | });
59 | PostUtil.postCallbackDelayed(loadService, HintCallback.class);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentA.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 | import android.widget.Toast;
6 |
7 | import butterknife.BindView;
8 | import sample.kingja.loadsir.PostUtil;
9 | import sample.kingja.loadsir.R;
10 | import sample.kingja.loadsir.base.BaseFragment;
11 | import sample.kingja.loadsir.callback.ErrorCallback;
12 | import sample.kingja.loadsir.callback.LoadingCallback;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/5 13:28
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 | public class FragmentA extends BaseFragment {
21 | @BindView(R.id.tv_result_a)
22 | TextView mTvResultA;
23 | @Override
24 | protected int onCreateFragmentView() {
25 | return R.layout.fragment_a_content;
26 | }
27 |
28 | @Override
29 | protected void loadNet() {
30 | // do net here...
31 | // call back
32 | PostUtil.postCallbackDelayed(mBaseLoadService, ErrorCallback.class);
33 | }
34 |
35 | @Override
36 | protected void onNetReload(View v) {
37 | mTvResultA.setText("Oh, Yes.");
38 | Toast.makeText(getContext(),"reload in Fragment A",Toast.LENGTH_SHORT).show();
39 | mBaseLoadService.showCallback(LoadingCallback.class);
40 | //do retry logic...
41 |
42 | //callback
43 | PostUtil.postSuccessDelayed(mBaseLoadService);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentB.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 | import android.widget.Toast;
6 |
7 | import butterknife.BindView;
8 | import sample.kingja.loadsir.callback.EmptyCallback;
9 | import sample.kingja.loadsir.callback.LoadingCallback;
10 |
11 | import sample.kingja.loadsir.PostUtil;
12 | import sample.kingja.loadsir.R;
13 | import sample.kingja.loadsir.base.BaseFragment;
14 |
15 | /**
16 | * Description:TODO
17 | * Create Time:2017/9/5 13:27
18 | * Author:KingJA
19 | * Email:kingjavip@gmail.com
20 | */
21 | public class FragmentB extends BaseFragment {
22 | @BindView(R.id.tv_result_b)
23 | TextView mTvResultB;
24 | @Override
25 | protected int onCreateFragmentView() {
26 | return R.layout.fragment_b_content;
27 | }
28 |
29 | @Override
30 | protected void loadNet() {
31 | // do net here...
32 | // call back
33 | PostUtil.postCallbackDelayed(mBaseLoadService, EmptyCallback.class);
34 | }
35 | @Override
36 | protected void onNetReload(View v) {
37 | mTvResultB.setText("Oh, Yes too.");
38 | Toast.makeText(getContext(),"reload in Fragment B",Toast.LENGTH_SHORT).show();
39 | mBaseLoadService.showCallback(LoadingCallback.class);
40 | //do retry logic...
41 |
42 | //callback
43 | PostUtil.postSuccessDelayed(mBaseLoadService);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentSingleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import sample.kingja.loadsir.R;
7 |
8 | /**
9 | * Description:TODO
10 | * Create Time:2017/9/4 10:56
11 | * Author:KingJA
12 | * Email:kingjavip@gmail.com
13 | */
14 |
15 | public class FragmentSingleActivity extends AppCompatActivity {
16 | private static final String TAG ="FragmentSingleActivity" ;
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_fragment);
21 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new NormalFragment()).commit();
22 |
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import butterknife.BindView;
7 | import sample.kingja.loadsir.PostUtil;
8 | import sample.kingja.loadsir.R;
9 | import sample.kingja.loadsir.base.BaseTitleActivity;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 |
13 | /**
14 | * Description:
15 | * Create Time:2017/9/4 10:56
16 | * Author:KingJA
17 | * Email:kingjavip@gmail.com
18 | */
19 |
20 | public class KeepTitleActivity extends BaseTitleActivity {
21 | @BindView(R.id.tv_title)
22 | TextView mTvTitle;
23 |
24 |
25 | @Override
26 | protected String getContentTitle() {
27 | return "Title";
28 | }
29 |
30 | @Override
31 | protected int getContentView() {
32 | return R.layout.activity_content;
33 | }
34 |
35 | @Override
36 | protected void initView() {
37 | TextView mTvMsg = findViewById(R.id.tv_subTitle);
38 | mTvMsg.setText("Keep Title In Activity");
39 | mTvTitle.setText("Yes, Success");
40 | }
41 |
42 | @Override
43 | protected void initNet() {
44 | PostUtil.postCallbackDelayed(mBaseLoadService, ErrorCallback.class);
45 | }
46 |
47 | @Override
48 | protected void onNetReload(View v) {
49 | mBaseLoadService.showCallback(LoadingCallback.class);
50 | PostUtil.postSuccessDelayed(mBaseLoadService);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.LinearLayout;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 | import com.kingja.loadsir.core.LoadService;
12 | import com.kingja.loadsir.core.LoadSir;
13 |
14 | import androidx.annotation.Nullable;
15 | import androidx.fragment.app.Fragment;
16 | import butterknife.BindView;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 | import butterknife.Unbinder;
20 | import sample.kingja.loadsir.PostUtil;
21 | import sample.kingja.loadsir.R;
22 | import sample.kingja.loadsir.callback.EmptyCallback;
23 | import sample.kingja.loadsir.callback.LoadingCallback;
24 |
25 | /**
26 | * Description:
27 | * Create Time:2017/9/26 14:33
28 | * Author:KingJA
29 | * Email:kingjavip@gmail.com
30 | */
31 | public class KeepTitleFragment extends Fragment {
32 |
33 | private LoadService loadService;
34 | @BindView(R.id.iv_back)
35 | ImageView mIvBack;
36 | private Unbinder unBinder;
37 | private ViewGroup rootView;
38 |
39 | @OnClick(R.id.iv_back)
40 | public void onBack() {
41 | getActivity().finish();
42 | }
43 |
44 | @Override
45 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
46 | super.onViewCreated(view, savedInstanceState);
47 | LinearLayout contentView = rootView.findViewById(R.id.ll_content);
48 | LoadSir loadSir = new LoadSir.Builder()
49 | .addCallback(new EmptyCallback())
50 | .addCallback(new LoadingCallback())
51 | .setDefaultCallback(LoadingCallback.class)
52 | .build();
53 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
54 | @Override
55 | public void onReload(View v) {
56 | loadService.showSuccess();
57 | }
58 | });
59 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
60 | }
61 |
62 | @Nullable
63 | @Override
64 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
65 | savedInstanceState) {
66 | rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
67 | unBinder = ButterKnife.bind(this, rootView);
68 | return rootView;
69 | }
70 |
71 | @Override
72 | public void onDetach() {
73 | super.onDetach();
74 | unBinder.unbind();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.view.Window;
5 |
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import sample.kingja.loadsir.R;
8 |
9 | /**
10 | * Description:
11 | * Create Time:2017/9/4 10:56
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 |
16 | public class KeepTitleFragmentActivity extends AppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | requestWindowFeature(Window.FEATURE_NO_TITLE);
22 | setContentView(R.layout.activity_fragment);
23 | if (getSupportActionBar() != null) {
24 | getSupportActionBar().hide();
25 | }
26 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new KeepTitleFragment()).commit();
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/LottieActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.core.LoadService;
8 | import com.kingja.loadsir.core.LoadSir;
9 |
10 | import androidx.annotation.Nullable;
11 | import androidx.appcompat.app.AppCompatActivity;
12 | import sample.kingja.loadsir.PostUtil;
13 | import sample.kingja.loadsir.R;
14 | import sample.kingja.loadsir.callback.LottieEmptyCallback;
15 | import sample.kingja.loadsir.callback.LottieLoadingCallback;
16 |
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/4 10:12
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class LottieActivity extends AppCompatActivity {
26 |
27 | private LoadService loadService;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_content);
33 | LoadSir loadSir = new LoadSir.Builder()
34 | .addCallback(new LottieLoadingCallback())
35 | .addCallback(new LottieEmptyCallback())
36 | .setDefaultCallback(LottieLoadingCallback.class)
37 | .build();
38 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
39 | @Override
40 | public void onReload(View v) {
41 | loadService.showCallback(LottieLoadingCallback.class);
42 | PostUtil.postSuccessDelayed(loadService, 1500);
43 | }
44 | });
45 | PostUtil.postCallbackDelayed(loadService, LottieEmptyCallback.class);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import sample.kingja.loadsir.R;
8 |
9 | /**
10 | * Description:TODO
11 | * Create Time:2017/9/4 10:56
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 |
16 | public class MultiFragmentActivity extends AppCompatActivity {
17 | private static final String TAG = "FragmentSingleActivity";
18 | private FragmentA fragmentA;
19 | private FragmentB fragmentB;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_fragment_mutil);
25 | fragmentA = new FragmentA();
26 | fragmentB = new FragmentB();
27 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, fragmentA).commit();
28 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, fragmentB).commit();
29 | getSupportFragmentManager().beginTransaction().show(fragmentA).hide(fragmentB).commit();
30 | }
31 |
32 |
33 | public void showFragmentA(View view) {
34 | getSupportFragmentManager().beginTransaction().show(fragmentA).hide(fragmentB).commit();
35 | }
36 |
37 | public void showFragmentB(View view) {
38 | getSupportFragmentManager().beginTransaction().show(fragmentB).hide(fragmentA).commit();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentWithViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | import com.google.android.material.tabs.TabLayout;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import androidx.fragment.app.Fragment;
13 | import androidx.fragment.app.FragmentManager;
14 | import androidx.fragment.app.FragmentPagerAdapter;
15 | import androidx.viewpager.widget.ViewPager;
16 | import sample.kingja.loadsir.R;
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/4 10:56
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class MultiFragmentWithViewPagerActivity extends AppCompatActivity {
26 | private List<Fragment>fragments=new ArrayList<>();
27 | private String[]tabTitles={"Fragment A","Fragment B"};
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_fragment_viewpager);
32 | ViewPager viewpager = findViewById(R.id.viewpager);
33 | TabLayout tablayout = findViewById(R.id.tablayout);
34 |
35 | fragments.add(new FragmentA());
36 | fragments.add(new FragmentB());
37 | viewpager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
38 |
39 | tablayout.setupWithViewPager(viewpager);
40 | tablayout.setTabMode(TabLayout.MODE_FIXED);
41 |
42 | }
43 |
44 | private class PagerAdapter extends FragmentPagerAdapter {
45 |
46 | PagerAdapter(FragmentManager fm) {
47 | super(fm);
48 | }
49 |
50 | @Override
51 | public Fragment getItem(int position) {
52 | return fragments.get(position);
53 | }
54 |
55 | @Override
56 | public int getCount() {
57 | return fragments.size();
58 | }
59 |
60 | @Override
61 | public CharSequence getPageTitle(int position) {
62 | return tabTitles[position];
63 | }
64 | }
65 |
66 |
67 |
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/NormalActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.SystemClock;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.Nullable;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import sample.kingja.loadsir.callback.EmptyCallback;
12 | import sample.kingja.loadsir.callback.LoadingCallback;
13 |
14 | import com.kingja.loadsir.callback.Callback;
15 | import com.kingja.loadsir.core.LoadService;
16 | import com.kingja.loadsir.core.LoadSir;
17 | import com.kingja.loadsir.core.Transport;
18 |
19 | import sample.kingja.loadsir.R;
20 | import sample.kingja.loadsir.PostUtil;
21 |
22 |
23 | /**
24 | * Description:TODO
25 | * Create Time:2017/9/4 10:12
26 | * Author:KingJA
27 | * Email:kingjavip@gmail.com
28 | */
29 |
30 | public class NormalActivity extends AppCompatActivity {
31 |
32 | private LoadService loadService;
33 |
34 | @Override
35 | protected void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_content);
38 | // Your can change the callback on sub thread directly.
39 | loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
40 | @Override
41 | public void onReload(View v) {
42 | // Your can change the status out of Main thread.
43 | new Thread(new Runnable() {
44 | @Override
45 | public void run() {
46 | loadService.showCallback(LoadingCallback.class);
47 | //do retry logic...
48 | SystemClock.sleep(500);
49 | //callback
50 | loadService.showSuccess();
51 | }
52 | }).start();
53 | }
54 | }).setCallBack(EmptyCallback.class, new Transport() {
55 | @Override
56 | public void order(Context context, View view) {
57 | TextView mTvEmpty = view.findViewById(R.id.tv_empty);
58 | mTvEmpty.setText("fine, no data. You must fill it!");
59 | }
60 | });
61 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/NormalFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 |
5 | import android.os.SystemClock;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 | import com.kingja.loadsir.core.LoadService;
12 | import com.kingja.loadsir.core.LoadSir;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 | import androidx.fragment.app.Fragment;
17 | import butterknife.ButterKnife;
18 | import sample.kingja.loadsir.PostUtil;
19 | import sample.kingja.loadsir.R;
20 | import sample.kingja.loadsir.callback.CustomCallback;
21 | import sample.kingja.loadsir.callback.ErrorCallback;
22 | import sample.kingja.loadsir.callback.LoadingCallback;
23 |
24 | /**
25 | * Description:TODO
26 | * Create Time:2017/9/5 13:28
27 | * Author:KingJA
28 | * Email:kingjavip@gmail.com
29 | */
30 | public class NormalFragment extends Fragment {
31 |
32 | private LoadService loadService;
33 |
34 | @Nullable
35 | @Override
36 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
37 | @Nullable Bundle savedInstanceState) {
38 | LoadSir loadSir = new LoadSir.Builder()
39 | .addCallback(new CustomCallback())
40 | .addCallback(new LoadingCallback())
41 | .addCallback(new ErrorCallback())
42 | .setDefaultCallback(LoadingCallback.class)
43 | .build();
44 | View rootView = inflater.inflate(R.layout.fragment_a_content, container, false);
45 | ButterKnife.bind(this, rootView);
46 | loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
47 | @Override
48 | public void onReload(View v) {
49 | // Your can change the status out of Main thread.
50 | new Thread(new Runnable() {
51 | @Override
52 | public void run() {
53 | loadService.showCallback(LoadingCallback.class);
54 | //do retry logic...
55 | SystemClock.sleep(500);
56 | //callback
57 | loadService.showCallback(CustomCallback.class);
58 | }
59 | }).start();
60 | }
61 | });
62 | return loadService.getLoadLayout();
63 | }
64 |
65 | @Override
66 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
67 | super.onViewCreated(view, savedInstanceState);
68 | PostUtil.postCallbackDelayed(loadService, ErrorCallback.class);
69 | }
70 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/PlaceholderActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.kingja.loadsir.callback.Callback;
6 | import com.kingja.loadsir.core.LoadService;
7 | import com.kingja.loadsir.core.LoadSir;
8 |
9 | import androidx.annotation.Nullable;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import sample.kingja.loadsir.PostUtil;
12 | import sample.kingja.loadsir.R;
13 | import sample.kingja.loadsir.callback.PlaceholderCallback;
14 |
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/9/3 11:22
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 |
23 | public class PlaceholderActivity extends AppCompatActivity {
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_placeholder);
29 | LoadSir loadSir = new LoadSir.Builder()
30 | .addCallback(new PlaceholderCallback())
31 | .setDefaultCallback(PlaceholderCallback.class)
32 | .build();
33 | //do retry logic...
34 | LoadService loadService = loadSir.register(this, (Callback.OnReloadListener) v -> {
35 | //do retry logic...
36 | });
37 | PostUtil.postSuccessDelayed(loadService, 1000);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/ViewTargetActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.widget.ImageView;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.core.LoadService;
8 | import com.kingja.loadsir.core.LoadSir;
9 |
10 | import androidx.annotation.Nullable;
11 | import androidx.appcompat.app.AppCompatActivity;
12 | import sample.kingja.loadsir.PostUtil;
13 | import sample.kingja.loadsir.R;
14 | import sample.kingja.loadsir.callback.LoadingCallback;
15 | import sample.kingja.loadsir.callback.TimeoutCallback;
16 |
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/3 11:22
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class ViewTargetActivity extends AppCompatActivity {
26 |
27 | private LoadService loadService;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_view);
33 | ImageView imageView = findViewById(R.id.iv_img);
34 | LoadSir loadSir = new LoadSir.Builder()
35 | .addCallback(new TimeoutCallback())
36 | .addCallback(new LoadingCallback())
37 | .setDefaultCallback(LoadingCallback.class)
38 | .build();
39 | loadService = loadSir.register(imageView, (Callback.OnReloadListener) v -> {
40 | loadService.showCallback(LoadingCallback.class);
41 | //do retry logic...
42 |
43 | //callback
44 | PostUtil.postSuccessDelayed(loadService);
45 | });
46 | PostUtil.postCallbackDelayed(loadService, TimeoutCallback.class);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/awkward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/awkward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/custom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/custom.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/empty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/error.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/img.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/music.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/music.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/timeout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/drawable/timeout.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_activity_convertor.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | xmlns:tools="http://schemas.android.com/tools"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent"
7 | android:gravity="center"
8 | android:orientation="vertical"
9 | tools:context="sample.kingja.loadsir.MainActivity">
10 |
11 | <TextView
12 | android:layout_width="wrap_content"
13 | android:layout_height="wrap_content"
14 | android:text="Success"
15 | android:textColor="#358c69"
16 | android:textSize="30sp"/>
17 |
18 | <TextView
19 | android:layout_width="wrap_content"
20 | android:layout_height="wrap_content"
21 | android:text="Content in Activity with convertor"/>
22 |
23 | </LinearLayout>
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_best_practices.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <ScrollView
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | xmlns:tools="http://schemas.android.com/tools"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent">
7 |
8 | <LinearLayout
9 | android:layout_width="match_parent"
10 | android:layout_height="wrap_content"
11 | android:orientation="vertical"
12 | android:padding="12dp"
13 | tools:context="sample.kingja.loadsir.MainActivity">
14 |
15 |
16 | <Button
17 | android:layout_width="match_parent"
18 | android:layout_height="wrap_content"
19 | android:onClick="onLottie"
20 | android:text="LoadSir + Lottie"
21 | android:textAllCaps="false"/>
22 |
23 | <Button
24 | android:onClick="mvpActivity"
25 | android:layout_width="match_parent"
26 | android:layout_height="wrap_content"
27 | android:text="..."
28 | android:textAllCaps="false"/>
29 |
30 | <Button
31 | android:layout_width="match_parent"
32 | android:layout_height="wrap_content"
33 | android:text="..."
34 | android:textAllCaps="false"/>
35 |
36 |
37 | </LinearLayout>
38 | </ScrollView>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_constraintlayout.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | xmlns:app="http://schemas.android.com/apk/res-auto"
4 | android:id="@+id/constraintLayout"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent"
7 | android:background="#11ff0000">
8 |
9 |
10 | <TextView
11 | android:id="@+id/tv_img"
12 | android:layout_width="140dp"
13 | android:layout_height="86dp"
14 | android:layout_marginLeft="12dp"
15 | android:layout_marginTop="12dp"
16 | android:background="#fd3"
17 | app:layout_constraintLeft_toLeftOf="parent"
18 | app:layout_constraintTop_toTopOf="parent" />
19 |
20 |
21 | <FrameLayout
22 | android:id="@+id/fl_wrap"
23 | android:layout_width="match_parent"
24 | android:layout_height="wrap_content"
25 | android:layout_margin="16dp"
26 | app:layout_constraintDimensionRatio="16:6"
27 | app:layout_constraintEnd_toEndOf="parent"
28 | app:layout_constraintLeft_toLeftOf="parent"
29 | app:layout_constraintRight_toRightOf="parent"
30 | app:layout_constraintStart_toStartOf="parent"
31 | app:layout_constraintTop_toBottomOf="@id/tv_img">
32 |
33 | <TextView
34 | android:id="@+id/tv_center"
35 | android:layout_width="match_parent"
36 | android:layout_height="170dp"
37 | android:background="#7FA7CB"
38 | android:gravity="center"
39 | android:text="successView"
40 | android:textSize="20sp" />
41 | </FrameLayout>
42 |
43 | <TextView
44 | android:id="@+id/ll_child"
45 | android:layout_width="match_parent"
46 | android:layout_height="200dp"
47 | android:layout_margin="16dp"
48 | android:background="#00BCD4"
49 | android:gravity="center"
50 | android:text="Top_toBottomOf successView"
51 | app:layout_constraintEnd_toEndOf="parent"
52 | app:layout_constraintLeft_toLeftOf="parent"
53 | app:layout_constraintRight_toRightOf="parent"
54 | app:layout_constraintStart_toStartOf="parent"
55 | app:layout_constraintTop_toBottomOf="@id/fl_wrap" />
56 |
57 |
58 | <TextView
59 | android:id="@+id/tv_title"
60 | android:layout_width="0dp"
61 | android:layout_height="wrap_content"
62 | android:layout_marginLeft="8dp"
63 | android:layout_marginRight="12dp"
64 | android:lines="3"
65 | android:text="LoadSir is a lightweight, good expandable Android library used for displaying different pages like loading, error, empty, timeout or even your custom page when you load data from database or a REST service. LoadSir is very different from other similar libraries. I mean... better."
66 | android:textColor="#000000"
67 | android:textSize="16dp"
68 | app:layout_constraintLeft_toRightOf="@id/tv_img"
69 | app:layout_constraintRight_toRightOf="parent"
70 | app:layout_constraintTop_toTopOf="@id/tv_img"
71 | android:layout_marginStart="8dp"
72 | android:layout_marginEnd="12dp" />
73 |
74 | <TextView
75 | android:id="@+id/tv_time"
76 | android:layout_width="wrap_content"
77 | android:layout_height="wrap_content"
78 | android:layout_marginLeft="8dp"
79 | android:layout_marginTop="12dp"
80 | android:text="2 hours ago"
81 | android:textColor="#333"
82 | android:textSize="12dp"
83 | app:layout_constraintBottom_toBottomOf="@id/tv_img"
84 | app:layout_constraintLeft_toRightOf="@id/tv_img" />
85 |
86 |
87 | </androidx.constraintlayout.widget.ConstraintLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_content.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | xmlns:tools="http://schemas.android.com/tools"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent"
7 | tools:context="sample.kingja.loadsir.MainActivity"
8 | android:gravity="center"
9 | android:orientation="vertical"
10 | android:id="@+id/ll_root_activity">
11 |
12 | <TextView
13 | android:id="@+id/tv_title"
14 | android:textSize="30sp"
15 | android:textColor="#358c69"
16 | android:text="Success"
17 | android:layout_width="wrap_content"
18 | android:layout_height="wrap_content"/>
19 |
20 | <TextView
21 | android:id="@+id/tv_subTitle"
22 | android:layout_width="wrap_content"
23 | android:layout_height="wrap_content"
24 | android:text="Content in Activity"/>
25 |
26 | </LinearLayout>
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <FrameLayout
3 | android:id="@+id/fl_content"
4 | xmlns:android="http://schemas.android.com/apk/res/android"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent">
7 |
8 | </FrameLayout>
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_mutil.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:orientation="vertical">
7 | <LinearLayout
8 | android:layout_width="match_parent"
9 | android:layout_height="wrap_content">
10 |
11 | <Button
12 | android:textAllCaps="false"
13 | android:onClick="showFragmentA"
14 | android:text="Fragment A"
15 | android:layout_width="0dp"
16 | android:layout_height="wrap_content"
17 | android:layout_weight="1"/>
18 |
19 | <Button
20 | android:textAllCaps="false"
21 | android:onClick="showFragmentB"
22 | android:text="Fragment B"
23 | android:layout_width="0dp"
24 | android:layout_height="wrap_content"
25 | android:layout_weight="1"/>
26 | </LinearLayout>
27 | <FrameLayout
28 | android:id="@+id/fl_content"
29 | android:layout_width="match_parent"
30 | android:layout_height="0dp"
31 | android:layout_weight="1">
32 |
33 |
34 | </FrameLayout>
35 |
36 |
37 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_viewpager.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:orientation="vertical">
7 |
8 | <com.google.android.material.tabs.TabLayout
9 | android:id="@+id/tablayout"
10 | android:layout_width="match_parent"
11 | android:layout_height="48dp"/>
12 |
13 |
14 | <androidx.viewpager.widget.ViewPager
15 | android:id="@+id/viewpager"
16 | android:layout_width="match_parent"
17 | android:layout_height="match_parent">
18 |
19 | </androidx.viewpager.widget.ViewPager>
20 | </LinearLayout>
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <ScrollView
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | xmlns:tools="http://schemas.android.com/tools"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent">
7 |
8 | <LinearLayout
9 | android:layout_width="match_parent"
10 | android:layout_height="wrap_content"
11 | android:orientation="vertical"
12 | android:padding="12dp"
13 | tools:context="sample.kingja.loadsir.MainActivity">
14 |
15 | <Button
16 | android:layout_width="match_parent"
17 | android:layout_height="wrap_content"
18 | android:onClick="inActivity"
19 | android:text="@string/activity_empty"
20 | android:textAllCaps="false"/>
21 | <Button
22 | android:layout_width="match_parent"
23 | android:layout_height="wrap_content"
24 | android:onClick="inConstraintLayoutActivity"
25 | android:text="@string/activity_constraintLayout"
26 | android:textAllCaps="false"/>
27 |
28 | <Button
29 | android:layout_width="match_parent"
30 | android:layout_height="wrap_content"
31 | android:onClick="showPlaceholder"
32 | android:text="@string/activity_placeholder"
33 | android:textAllCaps="false"/>
34 |
35 | <Button
36 | android:layout_width="match_parent"
37 | android:layout_height="wrap_content"
38 | android:onClick="inActivityWithConvertor"
39 | android:text="@string/activity_with_convertor"
40 | android:textAllCaps="false"/>
41 |
42 | <Button
43 | android:layout_width="match_parent"
44 | android:layout_height="wrap_content"
45 | android:onClick="inFragment"
46 | android:text="@string/single_fragment_custom"
47 | android:textAllCaps="false"/>
48 |
49 | <Button
50 | android:layout_width="match_parent"
51 | android:layout_height="wrap_content"
52 | android:onClick="inFragmentMutil"
53 | android:text="@string/multiple_fragment"
54 | android:textAllCaps="false"/>
55 |
56 | <Button
57 | android:layout_width="match_parent"
58 | android:layout_height="wrap_content"
59 | android:onClick="inFragmentViewSirPager"
60 | android:text="@string/multiple_fragment_viewpager"
61 | android:textAllCaps="false"/>
62 |
63 | <Button
64 | android:layout_width="match_parent"
65 | android:layout_height="wrap_content"
66 | android:onClick="inView"
67 | android:text="@string/view_timeout"
68 | android:textAllCaps="false"/>
69 |
70 | <Button
71 | android:layout_width="match_parent"
72 | android:layout_height="wrap_content"
73 | android:onClick="defaultCallback"
74 | android:text="@string/default_loadsir_callback"
75 | android:textAllCaps="false"/>
76 |
77 | <Button
78 | android:layout_width="match_parent"
79 | android:layout_height="wrap_content"
80 | android:onClick="animatCallback"
81 | android:text="@string/animat_callback"
82 | android:textAllCaps="false"/>
83 |
84 | <Button
85 | android:layout_width="match_parent"
86 | android:layout_height="wrap_content"
87 | android:onClick="keepTitleInActivity"
88 | android:text="@string/keep_title_bar_in_activity"
89 | android:textAllCaps="false"/>
90 |
91 | <Button
92 | android:layout_width="match_parent"
93 | android:layout_height="wrap_content"
94 | android:onClick="keepTitleInFragment"
95 | android:text="@string/keep_title_bar_in_fragment"
96 | android:textAllCaps="false"/>
97 |
98 | <Button
99 | android:background="#d77213"
100 | android:layout_width="match_parent"
101 | android:layout_height="wrap_content"
102 | android:onClick="bestPractices"
103 | android:text="@string/best_practices"
104 | android:textAllCaps="false"/>
105 |
106 |
107 | </LinearLayout>
108 | </ScrollView>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_placeholder.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:orientation="vertical"
6 | android:id="@+id/ll_root_placeholder">
7 |
8 |
9 | <LinearLayout
10 | android:layout_width="match_parent"
11 | android:layout_height="wrap_content"
12 | android:gravity="center_vertical"
13 | android:padding="12dp">
14 |
15 | <ImageView
16 | android:layout_width="80dp"
17 | android:layout_height="80dp"
18 | android:layout_marginRight="12dp"
19 | android:background="@drawable/music" />
20 |
21 | <LinearLayout
22 |
23 | android:layout_width="match_parent"
24 | android:layout_height="wrap_content"
25 | android:orientation="vertical">
26 |
27 | <TextView
28 | android:layout_width="match_parent"
29 | android:layout_height="wrap_content"
30 | android:layout_marginBottom="8dp"
31 | android:text="Something To Tell You"
32 | android:textColor="#333333" />
33 |
34 | <TextView
35 | android:layout_width="match_parent"
36 | android:layout_height="wrap_content"
37 | android:text="HAIM" />
38 |
39 |
40 | </LinearLayout>
41 |
42 |
43 | </LinearLayout>
44 |
45 |
46 | <TextView
47 | android:layout_width="match_parent"
48 | android:layout_height="wrap_content"
49 | android:background="#d5efe1"
50 | android:padding="6dp"
51 | android:text="Lyric"
52 | android:textColor="#484848"
53 | android:textSize="12sp" />
54 |
55 | <TextView
56 | android:layout_width="match_parent"
57 | android:layout_height="match_parent"
58 | android:layout_marginTop="8dp"
59 | android:padding="12dp"
60 | android:text="On the way down, a fall from grace
61 | I was in for a heavy one when I could feel you pull away
62 | On the way down, it almost was too much to take
63 | Even though I tried, it was never enough for running in the same damn place"
64 |
65 | />
66 |
67 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_title.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:orientation="vertical">
6 |
7 | <RelativeLayout
8 | android:layout_width="match_parent"
9 | android:layout_height="48dp"
10 | android:background="@color/black">
11 |
12 | <LinearLayout
13 | android:id="@+id/ll_title_back"
14 | android:layout_width="48dp"
15 | android:layout_height="48dp"
16 | android:gravity="center">
17 |
18 | <ImageView
19 | android:layout_width="wrap_content"
20 | android:layout_height="wrap_content"
21 | android:src="@mipmap/back"
22 | android:tint="@color/white"/>
23 | </LinearLayout>
24 |
25 |
26 | <TextView
27 | android:id="@+id/tv_title_title"
28 | style="@style/font_f_18"
29 | android:text="标题"
30 | android:layout_centerInParent="true"
31 | android:layout_width="wrap_content"
32 | android:layout_height="wrap_content"/>
33 |
34 | </RelativeLayout>
35 |
36 | <FrameLayout
37 | android:id="@+id/fl_content"
38 | android:layout_width="match_parent"
39 | android:layout_height="match_parent"/>
40 |
41 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <RelativeLayout
3 | xmlns:android="http://schemas.android.com/apk/res/android"
4 | xmlns:tools="http://schemas.android.com/tools"
5 | android:id="@+id/fl_content"
6 | android:layout_width="match_parent"
7 | android:layout_height="match_parent"
8 | android:orientation="vertical"
9 | tools:ignore="ContentDescription">
10 |
11 | <TextView
12 | android:id="@+id/tv_text"
13 | android:layout_width="match_parent"
14 | android:layout_height="wrap_content"
15 | android:background="#ff7b00"
16 | android:gravity="center"
17 | android:padding="12dp"
18 | android:text="@string/hey_guys_what_are_you_looking_for"/>
19 |
20 | <FrameLayout
21 | android:layout_below="@id/tv_text"
22 | android:layout_margin="20dp"
23 | android:id="@+id/fl_wrap"
24 | android:layout_width="wrap_content"
25 | android:layout_height="wrap_content">
26 | <ImageView
27 | android:id="@+id/iv_img"
28 | android:layout_width="match_parent"
29 | android:layout_height="200dp"
30 | android:scaleType="centerCrop"
31 | android:src="@drawable/img"/>
32 |
33 | </FrameLayout>
34 |
35 | <TextView
36 | android:layout_below="@id/fl_wrap"
37 | android:layout_width="20dp"
38 | android:layout_height="20dp"
39 | android:background="#2196F3"/>
40 |
41 | </RelativeLayout>
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_a_content.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_root_a"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center"
7 | android:background="#eae8c7"
8 | android:orientation="vertical">
9 |
10 | <TextView
11 | android:id="@+id/tv_result_a"
12 | android:layout_width="wrap_content"
13 | android:layout_height="wrap_content"
14 | android:text="Success"
15 | android:textColor="#358c69"
16 | android:textSize="30sp"/>
17 |
18 | <TextView
19 | android:layout_width="wrap_content"
20 | android:layout_height="wrap_content"
21 | android:text="Fragment A content"/>
22 |
23 | </LinearLayout>
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_b_content.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_root_b"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center"
7 | android:orientation="vertical">
8 |
9 | <TextView
10 | android:id="@+id/tv_result_b"
11 | android:layout_width="wrap_content"
12 | android:layout_height="wrap_content"
13 | android:text="Success"
14 | android:textColor="#358c69"
15 | android:textSize="30sp"/>
16 |
17 | <TextView
18 | android:layout_width="wrap_content"
19 | android:layout_height="wrap_content"
20 | android:text="Fragment B content"/>
21 |
22 | </LinearLayout>
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_title.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/rl_titleBar"
4 | android:layout_width="match_parent"
5 | android:layout_height="wrap_content"
6 | android:background="#000000"
7 | android:orientation="vertical"
8 | android:padding="10dp">
9 |
10 | <ImageView
11 | android:id="@+id/iv_back"
12 | android:layout_width="24dp"
13 | android:layout_height="24dp"
14 | android:background="@mipmap/back"/>
15 |
16 | <TextView
17 | android:layout_width="wrap_content"
18 | android:layout_height="wrap_content"
19 | android:layout_centerInParent="true"
20 | android:gravity="center"
21 | android:text="@string/loadsir"
22 | android:textColor="#ffffff"
23 | android:textSize="20sp"
24 | />
25 |
26 | </RelativeLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_animate.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:gravity="center"
6 | android:orientation="vertical">
7 |
8 | <View
9 | android:id="@+id/view_animate"
10 | android:background="#1b81d4"
11 | android:layout_width="60dp"
12 | android:layout_height="60dp"/>
13 |
14 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_custom"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center"
7 | android:orientation="vertical">
8 |
9 | <ImageView
10 | android:id="@+id/iv_gift"
11 | android:layout_width="80dp"
12 | android:layout_height="80dp"
13 | android:layout_marginBottom="4dp"
14 | android:background="@drawable/custom" />
15 |
16 | <TextView
17 | android:layout_width="wrap_content"
18 | android:layout_height="wrap_content"
19 | android:text="custom page(Callback)"
20 | android:textColor="#333333"
21 | android:textSize="18sp" />
22 |
23 | <TextView
24 | android:layout_width="wrap_content"
25 | android:layout_height="wrap_content"
26 | android:text="You can declare your own retry logic!" />
27 | </LinearLayout>
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom_error.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:gravity="center"
6 | android:orientation="vertical">
7 |
8 | <TextView
9 | android:textSize="18sp"
10 | android:textColor="#333333"
11 | android:layout_width="wrap_content"
12 | android:layout_height="wrap_content"
13 | android:text="OMG! What's wrong?!"/>
14 | <TextView
15 | android:layout_width="wrap_content"
16 | android:layout_height="wrap_content"
17 | android:text="click me to retry!"/>
18 | </LinearLayout>
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_empty.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_empty"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center"
7 | android:orientation="vertical">
8 |
9 | <ImageView
10 | android:layout_width="80dp"
11 | android:layout_height="80dp"
12 | android:background="@drawable/empty"/>
13 |
14 | <TextView
15 | android:id="@+id/tv_empty"
16 | android:layout_width="wrap_content"
17 | android:layout_height="wrap_content"
18 | android:text="@string/fine_no_data"
19 | android:textColor="#333333"
20 | android:textSize="18sp"/>
21 |
22 | <TextView
23 | android:layout_width="wrap_content"
24 | android:layout_height="wrap_content"
25 | android:text="@string/click_me_to_retry"/>
26 | </LinearLayout>
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_error.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:gravity="center"
6 | android:id="@+id/ll_error"
7 | android:orientation="vertical">
8 |
9 | <ImageView
10 | android:layout_marginBottom="4dp"
11 | android:layout_width="100dp"
12 | android:layout_height="80dp"
13 | android:background="@drawable/error"/>
14 |
15 | <TextView
16 | android:textSize="18sp"
17 | android:textColor="#333333"
18 | android:layout_width="wrap_content"
19 | android:layout_height="wrap_content"
20 | android:text="Boss! something is wrong."/>
21 | <TextView
22 | android:layout_width="wrap_content"
23 | android:layout_height="wrap_content"
24 | android:text="click me to retry!"/>
25 | </LinearLayout>
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_loading.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_loading"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center">
7 |
8 | <ProgressBar
9 | android:layout_width="wrap_content"
10 | android:layout_height="wrap_content"/>
11 |
12 | </LinearLayout>
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_lottie_empty.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | xmlns:app="http://schemas.android.com/apk/res-auto"
4 | android:id="@+id/ll_loading"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent"
7 | android:gravity="center">
8 |
9 | <com.airbnb.lottie.LottieAnimationView
10 | android:id="@+id/animation_view"
11 | android:layout_width="wrap_content"
12 | android:layout_height="wrap_content"
13 | app:lottie_fileName="lottie_empty.json"
14 | app:lottie_loop="true"
15 | app:lottie_autoPlay="true"/>
16 | </LinearLayout>
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_lottie_loading.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | xmlns:app="http://schemas.android.com/apk/res-auto"
4 | android:id="@+id/ll_loading"
5 | android:layout_width="match_parent"
6 | android:layout_height="match_parent"
7 | android:gravity="center">
8 |
9 | <com.airbnb.lottie.LottieAnimationView
10 | android:id="@+id/animation_view"
11 | android:layout_width="wrap_content"
12 | android:layout_height="wrap_content"
13 | app:lottie_fileName="lottie_loading.json"
14 | app:lottie_loop="true"
15 | app:lottie_autoPlay="true"/>
16 | </LinearLayout>
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_placeholder.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:orientation="vertical"
6 | android:id="@+id/ll_placeholder">
7 | <LinearLayout
8 | android:layout_width="match_parent"
9 | android:layout_height="wrap_content"
10 | android:gravity="center_vertical"
11 | android:padding="12dp">
12 |
13 | <ImageView
14 | android:layout_width="80dp"
15 | android:layout_height="80dp"
16 | android:layout_marginRight="12dp"
17 | android:background="#dedede" />
18 |
19 | <LinearLayout
20 |
21 | android:layout_width="match_parent"
22 | android:layout_height="wrap_content"
23 | android:orientation="vertical">
24 |
25 | <TextView
26 | android:layout_width="match_parent"
27 | android:layout_height="wrap_content"
28 | android:layout_marginBottom="8dp"
29 | android:background="#dedede" />
30 |
31 | <TextView
32 | android:layout_width="match_parent"
33 | android:layout_height="wrap_content"
34 | android:background="#dedede" />
35 |
36 |
37 | </LinearLayout>
38 |
39 |
40 | </LinearLayout>
41 |
42 |
43 | <LinearLayout
44 |
45 | android:layout_width="match_parent"
46 | android:layout_height="match_parent"
47 | android:orientation="vertical"
48 | android:padding="12dp">
49 |
50 | <TextView
51 | android:layout_width="match_parent"
52 | android:layout_height="wrap_content"
53 | android:layout_marginBottom="12dp"
54 | android:background="#dedede" />
55 |
56 | <TextView
57 | android:layout_width="match_parent"
58 | android:layout_height="100dp"
59 | android:layout_marginBottom="16dp"
60 | android:background="#dedede" />
61 |
62 | <TextView
63 | android:layout_width="match_parent"
64 | android:layout_height="100dp"
65 | android:layout_marginBottom="16dp"
66 | android:background="#dedede" />
67 |
68 | <TextView
69 | android:layout_width="match_parent"
70 | android:layout_height="100dp"
71 | android:layout_marginBottom="16dp"
72 | android:background="#dedede" />
73 |
74 |
75 | </LinearLayout>
76 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_timeout.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:id="@+id/ll_timeout"
4 | android:layout_width="match_parent"
5 | android:layout_height="match_parent"
6 | android:gravity="center"
7 | android:orientation="vertical">
8 |
9 | <ImageView
10 | android:layout_width="80dp"
11 | android:layout_height="80dp"
12 | android:layout_marginBottom="4dp"
13 | android:background="@drawable/timeout" />
14 |
15 | <TextView
16 | android:layout_width="wrap_content"
17 | android:layout_height="wrap_content"
18 | android:text="Oh no, timeout."
19 | android:textColor="#333333"
20 | android:textSize="18sp" />
21 |
22 | <TextView
23 | android:layout_width="wrap_content"
24 | android:layout_height="wrap_content"
25 | android:text="click me to retry!" />
26 | </LinearLayout>
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_x.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:gravity="center"
6 | android:orientation="vertical">
7 | </LinearLayout>
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/title_title_bar.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 | android:layout_width="match_parent"
4 | android:layout_height="match_parent"
5 | android:orientation="vertical">
6 |
7 | <include layout="@layout/include_title"/>
8 |
9 | <LinearLayout
10 | android:id="@+id/ll_content"
11 | android:layout_width="match_parent"
12 | android:layout_height="match_parent"
13 | android:background="#eae8c7"
14 | android:gravity="center"
15 | android:orientation="vertical">
16 |
17 | <TextView
18 | android:layout_width="wrap_content"
19 | android:layout_height="wrap_content"
20 | android:text="@string/success"
21 | android:textColor="#358c69"
22 | android:textSize="30sp"/>
23 |
24 | <TextView
25 | android:layout_width="wrap_content"
26 | android:layout_height="wrap_content"
27 | android:text="@string/keep_title_bar"/>
28 |
29 | </LinearLayout>
30 |
31 | </LinearLayout>
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xxhdpi/back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <resources>
3 | <color name="colorPrimary">#000000</color>
4 | <color name="colorPrimaryDark">#787878</color>
5 | <color name="colorAccent">#FF4081</color>
6 |
7 | <color name="black">#000000</color>
8 | <color name="white">#ffffff</color>
9 | <color name="red">#bb2c28</color>
10 | </resources>
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 | <resources>
2 | <string name="app_name">LoadSir</string>
3 | <string name="activity_empty">Activity(empty)</string>
4 | <string name="activity_constraintLayout">Activity(constraintLayout)</string>
5 | <string name="activity_placeholder">Activity(placeholder)</string>
6 | <string name="activity_with_convertor">Activity with Convertor</string>
7 | <string name="single_fragment_custom">single Fragment(custom)</string>
8 | <string name="multiple_fragment">multiple Fragment</string>
9 | <string name="multiple_fragment_viewpager">multiple Fragment+ViewPager</string>
10 | <string name="view_timeout">View(timeout)</string>
11 | <string name="animat_callback">Animat Callback</string>
12 | <string name="keep_title_bar_in_fragment">keep title bar in Fragment</string>
13 | <string name="loadsir">LoadSir</string>
14 | <string name="success">Success</string>
15 | <string name="keep_title_bar">keep title bar</string>
16 | <string name="fine_no_data">fine, no data.</string>
17 | <string name="click_me_to_retry">click me to retry!</string>
18 | <string name="best_practices">best practices</string>
19 | <string name="default_loadsir_callback">default LoadSir Callback</string>
20 | <string name="keep_title_bar_in_activity">keep title bar in Activity</string>
21 | <string name="hey_guys_what_are_you_looking_for">Hey guys, What are you looking for?</string>
22 | </resources>
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 | <resources>
2 |
3 | <!-- Base application theme. -->
4 | <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5 | <!-- Customize your theme here. -->
6 | <item name="colorPrimary">@color/colorPrimary</item>
7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8 | <item name="colorAccent">@color/colorAccent</item>
9 | </style>
10 |
11 | <style name="NoTitle" parent="Theme.AppCompat.Light.NoActionBar"/>
12 |
13 | <style name="Hint_Title">
14 | <item name="android:textColor">@color/colorAccent</item>
15 | <item name="android:textSize">20sp</item>
16 | </style>
17 |
18 | <style name="Hint_SubTitle">
19 | <item name="android:textColor">#666666</item>
20 | </style>
21 |
22 | <style name="font_f_18">
23 | <item name="android:singleLine">true</item>
24 | <item name="android:textSize">18sp</item>
25 | <item name="android:textColor">@color/white</item>
26 | </style>
27 | </resources>
28 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.5.3'
9 | classpath 'com.novoda:bintray-release:0.9.2'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | google()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/docs/BestPractice-cn.md:
--------------------------------------------------------------------------------
1 | 最佳实践
2 | ---
3 |
4 | 如果有你关于LoadSir好的使用场景或者封装方式,欢迎发起`pull request`.
5 |
6 | ### #1 xxx
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/BestPractice.md:
--------------------------------------------------------------------------------
1 | Best Practice
2 | ---
3 |
4 | In this documentation I collect good examples how to use LoadSir - and how to use LoadSir with other common open-source libs.
5 |
6 | If you have any wishes or ideas, please make a PR or an issue.
7 | Thank you for your help.
8 |
9 | ### #1 xxx
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/docs/FAQ-cn.md:
--------------------------------------------------------------------------------
1 | 常见问题
2 | ---
3 |
4 | 如果下列问题中,你有更好的解决方法,欢迎对docs/FAQ-cn.md 发起pull request。
5 |
6 | ### #1 如何和ButterKnife配合使用?
7 |
8 | in Activity
9 |
10 | ```java
11 |
12 | public class BufferKnifeActivity extends AppCompatActivity {
13 | @BindView(R.id.tv_msg)
14 | TextView mTv_msg;
15 | private LoadService loadService;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ButterKnife.bind(this);
22 |
23 | LoadSir loadSir = new LoadSir.Builder()
24 | .addCallback(new EmptyCallback())
25 | .build();
26 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
27 | @Override
28 | public void onReload(View v) {
29 | //TODO
30 | }
31 |
32 | });
33 | loadService.showCallback(EmptyCallback.class);
34 | }
35 | }
36 |
37 | ```
38 |
39 | in Fragment
40 |
41 | ```java
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
45 | savedInstanceState) {
46 | View rootView = View.inflate(getActivity(), R.layout.fragment_bk, null);
47 | ButterKnife.bind(this, rootView);
48 |
49 | LoadSir loadSir = new LoadSir.Builder()
50 | .addCallback(new EmptyCallback())
51 | .build();
52 | loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | //TODO
56 | }
57 |
58 | });
59 | return loadService.getLoadLayout();
60 | }
61 | ```
62 |
63 | ### #2 如果保留原布局的标题栏(toolbar,或者titileView)?
64 | 在Activity,在Fragment中,只要注册toolbar,或者titileView以下的布局View即可,这样LoadSir就会保留标题栏。
65 | 在Fragment,请看参考代码:
66 | ```java
67 | @Override
68 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
69 | super.onViewCreated(view, savedInstanceState);
70 | LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
71 | LoadSir loadSir = new LoadSir.Builder()
72 | .addCallback(new EmptyCallback())
73 | .addCallback(new LoadingCallback())
74 | .setDefaultCallback(LoadingCallback.class)
75 | .build();
76 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
77 | @Override
78 | public void onReload(View v) {
79 | loadService.showSuccess();
80 | }
81 | });
82 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
83 | }
84 | ```
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/docs/FAQ.md:
--------------------------------------------------------------------------------
1 | FAQ
2 | ---
3 |
4 | If you have better solutions about the questions below, welcome to push pull requests to me.
5 |
6 | ### #1 How to use with ButterKnife?
7 |
8 | * ###### in Activity
9 |
10 | ```java
11 |
12 | public class BufferKnifeActivity extends AppCompatActivity {
13 | @BindView(R.id.tv_msg)
14 | TextView mTv_msg;
15 | private LoadService loadService;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ButterKnife.bind(this);
22 |
23 | LoadSir loadSir = new LoadSir.Builder()
24 | .addCallback(new EmptyCallback())
25 | .build();
26 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
27 | @Override
28 | public void onReload(View v) {
29 | //TODO
30 | }
31 |
32 | });
33 | loadService.showCallback(EmptyCallback.class);
34 | }
35 | }
36 |
37 | ```
38 |
39 | * ###### in Fragment
40 |
41 | ```java
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
45 | savedInstanceState) {
46 | View rootView = View.inflate(getActivity(), R.layout.fragment_bk, null);
47 | ButterKnife.bind(this, rootView);
48 |
49 | LoadSir loadSir = new LoadSir.Builder()
50 | .addCallback(new EmptyCallback())
51 | .build();
52 | loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | //TODO
56 | }
57 |
58 | });
59 | return loadService.getLoadLayout();
60 | }
61 | ```
62 |
63 | ### #2 How to keep the toolbar in Fragment?
64 | ```java
65 | @Override
66 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
67 | super.onViewCreated(view, savedInstanceState);
68 | //fetch contentView View,the View except toolbar or titleView.
69 | LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
70 | LoadSir loadSir = new LoadSir.Builder()
71 | .addCallback(new EmptyCallback())
72 | .addCallback(new LoadingCallback())
73 | .setDefaultCallback(LoadingCallback.class)
74 | .build();
75 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
76 | @Override
77 | public void onReload(View v) {
78 | loadService.showSuccess();
79 | }
80 | });
81 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
82 | }
83 | ```
84 |
85 | If you have a better idea, please let me know. I'm very interested to improve LoadSir in any way. Thanks for your help.
86 |
87 |
88 | ### #3 `setDefaultCallback(...)` vs `addCallback(...)`
89 | What's the purpose of a `DefaultCallback`?
90 |
91 | With `setDefaultCallback(...)` you set the **first** visible "view" for LoadSir.
92 | With `addCallback(...)` you could set other "views" for different purposes.
93 | Normally you have the use case to show a loading view/ProgressBar, therefore you should use `setDefaultCallback("your LoadingCallback")`.
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/docs/NextVersion.md:
--------------------------------------------------------------------------------
1 | The Next Version
2 | ---
3 |
4 | The next version will include:
5 |
6 | **1.3.x**
7 | - [ ] Samples how to use LoadSir with other common open-source libs.
8 | - [ ] you tell me
9 |
--------------------------------------------------------------------------------
/docs/changelog.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | ---
3 | **1.3.8**
4 | - [x] 适配Android X
5 | - [x] 支持ConstraintLayout的子View注册(详见Ps[1])
6 | - [x] 修复子view有margin,注册后出现双倍margin问题
7 |
8 | Ps:
9 | [1]要注册RelativeLayout或ConstraintLayout的子View,如果该子View被其它子View约束,建议在子View外层再包一层布局,参考
10 | acitivy_view.xm和activity_constraintlayout.xml
11 |
12 | **1.3.6**
13 | - [x] modify code in`showWithCallback(boolean successVisible)`, use INVISIBLE instead of GONE thanks @X
14 |
15 | **1.3.5**
16 | - [x] add API `public Class<? extends Callback> getCurrentCallback()`X
17 | - [x] deprecated API `public LinearLayout getTitleLoadLayout(Context context, ViewGroup rootView, View titleView)`
18 |
19 | **1.3.2**
20 | - [x] add API `public boolean getSuccessVisible()` used for displaying callback above successView.
21 | - [x] fix layout fault when register in View.
22 |
23 | **1.3.0**
24 | - [x] in default, addView(SuccessfulView). Hide SuccessfulView instead of removeView(SuccessfulView).
25 | - [x] add default Callback `ProgressCallback`, `HintCallback`.
26 |
27 | **v1.2.2**
28 | - [x] change minSdkVersion 16 to 14 [issues #8](https://github.com/KingJA/LoadSir/issues/8)
29 | - [x] modify callback dynamically [issues #11](https://github.com/KingJA/LoadSir/issues/11) [issues #7](https://github.com/KingJA/LoadSir/issues/7)
30 | - [x] add TitleBar sample [issues #12](https://github.com/KingJA/LoadSir/issues/12)
31 | - [x] add API in Callback [issues #10](https://github.com/KingJA/LoadSir/issues/10)
32 | * protected abstract int onCreateView()
33 | * public void onDetach()
34 | * public void onAttach(Context context, View view)
35 | - [x] make LoadLayout public
36 |
37 | **v1.2.0**
38 | - [x] Improve API naming notations.
39 |
40 | **v1.1.1**
41 | - [x] Initial release .
42 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.3.8
2 | VERSION_CODE=2020030801
3 | COMPILE_SDK_VERSION = 28
4 | BUILD_TOOLS_VERSION = 28.0.3
5 | MIN_SDK_VERSION = 16
6 | TARGET_SDK_VERSION = 28
7 | SUPPORT_VERSION = 28.1.0
8 | android.useAndroidX=true
9 | android.enableJetifier=true
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 08 22:08:06 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)#39;`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/imgs/LoadSir.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/LoadSir.jpg
--------------------------------------------------------------------------------
/imgs/LoadSir_flow.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/LoadSir_flow.jpg
--------------------------------------------------------------------------------
/imgs/muitl_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/muitl_fragment.gif
--------------------------------------------------------------------------------
/imgs/normal_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/normal_activity.gif
--------------------------------------------------------------------------------
/imgs/placeholder_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/placeholder_activity.gif
--------------------------------------------------------------------------------
/imgs/qcode_1.3.2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/qcode_1.3.2.png
--------------------------------------------------------------------------------
/imgs/qcode_1.3.8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/qcode_1.3.8.png
--------------------------------------------------------------------------------
/imgs/single_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/single_fragment.gif
--------------------------------------------------------------------------------
/imgs/view_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/view_activity.gif
--------------------------------------------------------------------------------
/imgs/viewpage_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/LoadSir/7ff786c73b019997bccdb96a69f68e6c947e384b/imgs/viewpage_fragment.gif
--------------------------------------------------------------------------------
/loadsir/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/loadsir/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion COMPILE_SDK_VERSION as int
6 | buildToolsVersion BUILD_TOOLS_VERSION
7 |
8 | defaultConfig {
9 | minSdkVersion MIN_SDK_VERSION as int
10 | targetSdkVersion TARGET_SDK_VERSION as int
11 | versionCode VERSION_CODE as int
12 | versionName VERSION_NAME
13 | }
14 | buildTypes {
15 | release {
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(include: ['*.jar'], dir: 'libs')
22 | implementation "androidx.annotation:annotation:1.1.0"
23 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
24 | implementation 'androidx.fragment:fragment:1.2.2'
25 |
26 | }
27 |
28 | publish {
29 | artifactId = 'loadsir'
30 | userOrg = 'kingja'
31 | groupId = 'com.kingja.loadsir'
32 | publishVersion = '1.3.8'
33 | desc = 'Android library to show most common state templates like loading, empty, error etc.'
34 | website = 'https://github.com/KingJA/LoadSir'
35 | }
36 |
--------------------------------------------------------------------------------
/loadsir/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | #-dontwarn com.kingja.loadsir.**
28 | #-keep class com.kingja.loadsir.** {*;}
29 |
--------------------------------------------------------------------------------
/loadsir/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 | <manifest package="com.kingja.loadsir"/>
2 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/LoadSirUtil.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir;
2 |
3 | import android.os.Looper;
4 | import android.util.Log;
5 |
6 | import com.kingja.loadsir.target.ITarget;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 16:24
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 | public class LoadSirUtil {
17 |
18 | public static boolean isMainThread() {
19 | return Looper.myLooper() == Looper.getMainLooper();
20 | }
21 |
22 | public static ITarget getTargetContext(Object target, List<ITarget> targetContextList) {
23 | for (ITarget targetContext : targetContextList) {
24 | if (targetContext.equals(target)) {
25 | return targetContext;
26 | }
27 |
28 | }
29 | throw new IllegalArgumentException("No TargetContext fit it");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/callback/Callback.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import java.io.ByteArrayInputStream;
7 | import java.io.ByteArrayOutputStream;
8 | import java.io.ObjectInputStream;
9 | import java.io.ObjectOutputStream;
10 | import java.io.Serializable;
11 |
12 |
13 | /**
14 | * Description:TODO
15 | * Create Time:2017/9/2 17:04
16 | * Author:KingJA
17 | * Email:kingjavip@gmail.com
18 | */
19 | public abstract class Callback implements Serializable {
20 | private View rootView;
21 | private Context context;
22 | private OnReloadListener onReloadListener;
23 | private boolean successViewVisible;
24 |
25 | public Callback() {
26 | }
27 |
28 | Callback(View view, Context context, OnReloadListener onReloadListener) {
29 | this.rootView = view;
30 | this.context = context;
31 | this.onReloadListener = onReloadListener;
32 | }
33 |
34 | public Callback setCallback(Context context, OnReloadListener onReloadListener) {
35 | this.context = context;
36 | this.onReloadListener = onReloadListener;
37 | return this;
38 | }
39 |
40 | public View getRootView() {
41 | int resId = onCreateView();
42 | if (resId == 0 && rootView != null) {
43 | return rootView;
44 | }
45 |
46 | if (onBuildView(context) != null) {
47 | rootView = onBuildView(context);
48 | }
49 |
50 | if (rootView == null) {
51 | rootView = View.inflate(context, onCreateView(), null);
52 | }
53 | rootView.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | if (onReloadEvent(context, rootView)) {
57 | return;
58 | }
59 | if (onReloadListener != null) {
60 | onReloadListener.onReload(v);
61 | }
62 | }
63 | });
64 | onViewCreate(context, rootView);
65 | return rootView;
66 | }
67 |
68 | protected View onBuildView(Context context) {
69 | return null;
70 | }
71 |
72 | /**
73 | * if return true, the successView will be visible when the view of callback is attached.
74 | */
75 | public boolean getSuccessVisible() {
76 | return successViewVisible;
77 | }
78 |
79 | void setSuccessVisible(boolean visible) {
80 | this.successViewVisible = visible;
81 | }
82 |
83 | /**
84 | * @deprecated Use {@link #onReloadEvent(Context context, View view)} instead.
85 | */
86 | protected boolean onRetry(Context context, View view) {
87 | return false;
88 | }
89 |
90 | protected boolean onReloadEvent(Context context, View view) {
91 | return false;
92 | }
93 |
94 | public Callback copy() {
95 | ByteArrayOutputStream bao = new ByteArrayOutputStream();
96 | ObjectOutputStream oos;
97 | Object obj = null;
98 | try {
99 | oos = new ObjectOutputStream(bao);
100 | oos.writeObject(this);
101 | oos.close();
102 | ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
103 | ObjectInputStream ois = new ObjectInputStream(bis);
104 | obj = ois.readObject();
105 | ois.close();
106 | } catch (Exception e) {
107 | e.printStackTrace();
108 | }
109 | return (Callback) obj;
110 | }
111 |
112 | /**
113 | * @since 1.2.2
114 | */
115 | public View obtainRootView() {
116 | if (rootView == null) {
117 | rootView = View.inflate(context, onCreateView(), null);
118 | }
119 | return rootView;
120 | }
121 |
122 | public interface OnReloadListener extends Serializable {
123 | void onReload(View v);
124 | }
125 |
126 | protected abstract int onCreateView();
127 |
128 | /**
129 | * Called immediately after {@link #onCreateView()}
130 | *
131 | * @since 1.2.2
132 | */
133 | protected void onViewCreate(Context context, View view) {
134 | }
135 |
136 | /**
137 | * Called when the rootView of Callback is attached to its LoadLayout.
138 | *
139 | * @since 1.2.2
140 | */
141 | public void onAttach(Context context, View view) {
142 | }
143 |
144 | /**
145 | * Called when the rootView of Callback is removed from its LoadLayout.
146 | *
147 | * @since 1.2.2
148 | */
149 | public void onDetach() {
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/callback/HintCallback.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.DrawableRes;
13 | import androidx.annotation.StyleRes;
14 |
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/10/9 14:12
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 | public class HintCallback extends Callback {
23 |
24 | private String title;
25 | private String subTitle;
26 | private int imgResId;
27 | private int titleStyleRes;
28 | private int subTitleStyleRes;
29 |
30 | public HintCallback(Builder builder) {
31 | this.title = builder.title;
32 | this.subTitle = builder.subTitle;
33 | this.imgResId = builder.imgResId;
34 | this.subTitleStyleRes = builder.subTitleStyleRes;
35 | this.titleStyleRes = builder.titleStyleRes;
36 | }
37 |
38 | @Override
39 | protected int onCreateView() {
40 | return 0;
41 | }
42 |
43 | @Override
44 | protected View onBuildView(Context context) {
45 | return new LinearLayout(context);
46 | }
47 |
48 | @Override
49 | protected void onViewCreate(Context context, View view) {
50 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
51 | ViewGroup.LayoutParams.WRAP_CONTENT);
52 | lp.gravity = Gravity.CENTER;
53 | LinearLayout ll = (LinearLayout) view;
54 | ll.setOrientation(LinearLayout.VERTICAL);
55 | ll.setGravity(Gravity.CENTER);
56 | if (imgResId != -1) {
57 | ImageView ivImage = new ImageView(context);
58 | ivImage.setBackgroundResource(imgResId);
59 | ll.addView(ivImage, lp);
60 | }
61 | if (!TextUtils.isEmpty(title)) {
62 | TextView tvTitle = new TextView(context);
63 | tvTitle.setText(title);
64 | if (titleStyleRes == -1) {
65 | tvTitle.setTextAppearance(context, android.R.style.TextAppearance_Large);
66 | } else {
67 | tvTitle.setTextAppearance(context, titleStyleRes);
68 | }
69 | ll.addView(tvTitle, lp);
70 | }
71 | if (!TextUtils.isEmpty(subTitle)) {
72 | TextView tvSubtitle = new TextView(context);
73 | tvSubtitle.setText(subTitle);
74 | if (subTitleStyleRes == -1) {
75 | tvSubtitle.setTextAppearance(context, android.R.style.TextAppearance_Small);
76 | } else {
77 | tvSubtitle.setTextAppearance(context, subTitleStyleRes);
78 | }
79 | ll.addView(tvSubtitle, lp);
80 | }
81 | }
82 |
83 | public static class Builder {
84 | private String title;
85 | private String subTitle;
86 | private int imgResId = -1;
87 | private int subTitleStyleRes = -1;
88 | private int titleStyleRes = -1;
89 |
90 | public Builder setHintImg(@DrawableRes int imgResId) {
91 | this.imgResId = imgResId;
92 | return this;
93 | }
94 |
95 | public Builder setTitle(String title) {
96 | return setTitle(title, -1);
97 | }
98 |
99 | public Builder setTitle(String title, @StyleRes int titleStyleRes) {
100 | this.title = title;
101 | this.titleStyleRes = titleStyleRes;
102 | return this;
103 | }
104 |
105 | public Builder setSubTitle(String subTitle) {
106 | return setSubTitle(subTitle, -1);
107 | }
108 |
109 | public Builder setSubTitle(String subTitle, @StyleRes int subTitleStyleRes) {
110 | this.subTitle = subTitle;
111 | this.subTitleStyleRes = subTitleStyleRes;
112 | return this;
113 | }
114 |
115 | public HintCallback build() {
116 | return new HintCallback(this);
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/callback/ProgressCallback.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.LinearLayout;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.StyleRes;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/10/9 14:12
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 | public class ProgressCallback extends Callback {
21 |
22 | private String title;
23 | private String subTitle;
24 | private int subTitleStyleRes = -1;
25 | private int titleStyleRes = -1;
26 |
27 | private ProgressCallback(Builder builder) {
28 | this.title = builder.title;
29 | this.subTitle = builder.subTitle;
30 | this.subTitleStyleRes = builder.subTitleStyleRes;
31 | this.titleStyleRes = builder.titleStyleRes;
32 | setSuccessVisible(builder.aboveable);
33 | }
34 |
35 | @Override
36 | protected int onCreateView() {
37 | return 0;
38 | }
39 |
40 | @Override
41 | protected View onBuildView(Context context) {
42 | return new LinearLayout(context);
43 | }
44 |
45 | @Override
46 | protected void onViewCreate(Context context, View view) {
47 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
48 | ViewGroup.LayoutParams.WRAP_CONTENT);
49 | lp.gravity = Gravity.CENTER;
50 | LinearLayout ll = (LinearLayout) view;
51 | ll.setOrientation(LinearLayout.VERTICAL);
52 | ll.setGravity(Gravity.CENTER);
53 |
54 | ProgressBar progressBar = new ProgressBar(context);
55 | ll.addView(progressBar, lp);
56 |
57 | if (!TextUtils.isEmpty(title)) {
58 | TextView tvTitle = new TextView(context);
59 | tvTitle.setText(title);
60 | if (titleStyleRes == -1) {
61 | tvTitle.setTextAppearance(context, android.R.style.TextAppearance_Large);
62 | } else {
63 | tvTitle.setTextAppearance(context, titleStyleRes);
64 | }
65 | ll.addView(tvTitle, lp);
66 | }
67 | if (!TextUtils.isEmpty(subTitle)) {
68 | TextView tvSubtitle = new TextView(context);
69 | tvSubtitle.setText(subTitle);
70 | if (subTitleStyleRes == -1) {
71 | tvSubtitle.setTextAppearance(context, android.R.style.TextAppearance_Medium);
72 | } else {
73 | tvSubtitle.setTextAppearance(context, subTitleStyleRes);
74 | }
75 | ll.addView(tvSubtitle, lp);
76 | }
77 | }
78 |
79 | public static class Builder {
80 |
81 | private String title;
82 | private String subTitle;
83 | private int subTitleStyleRes = -1;
84 | private int titleStyleRes = -1;
85 | private boolean aboveable;
86 |
87 | public Builder setTitle(String title) {
88 | return setTitle(title, -1);
89 | }
90 |
91 | public Builder setTitle(String title, @StyleRes int titleStyleRes) {
92 | this.title = title;
93 | this.titleStyleRes = titleStyleRes;
94 | return this;
95 | }
96 |
97 | public Builder setSubTitle(String subTitle) {
98 | return setSubTitle(subTitle, -1);
99 | }
100 |
101 | public Builder setSubTitle(String subTitle, @StyleRes int subTitleStyleRes) {
102 | this.subTitle = subTitle;
103 | this.subTitleStyleRes = subTitleStyleRes;
104 | return this;
105 | }
106 |
107 | public Builder setAboveSuccess(boolean aboveable) {
108 | this.aboveable = aboveable;
109 | return this;
110 | }
111 |
112 | public ProgressCallback build() {
113 | return new ProgressCallback(this);
114 | }
115 | }
116 | }
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/callback/SuccessCallback.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | /**
7 | * Description:TODO
8 | * Create Time:2017/9/4 10:22
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 |
13 | public class SuccessCallback extends Callback {
14 | public SuccessCallback(View view, Context context, OnReloadListener onReloadListener) {
15 | super(view, context, onReloadListener);
16 | }
17 |
18 | @Override
19 | protected int onCreateView() {
20 | return 0;
21 | }
22 |
23 | /**
24 | * @deprecated Use {@link #showWithCallback(boolean successVisible)} instead.
25 | */
26 | public void hide() {
27 | obtainRootView().setVisibility(View.INVISIBLE);
28 | }
29 |
30 | public void show() {
31 | obtainRootView().setVisibility(View.VISIBLE);
32 | }
33 |
34 | public void showWithCallback(boolean successVisible) {
35 | obtainRootView().setVisibility(successVisible ? View.VISIBLE : View.INVISIBLE);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/Convertor.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | /**
6 | * Description:TODO
7 | * Create Time:2017/9/4 8:58
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public interface Convertor<T> {
12 | Class<?extends Callback> map(T t);
13 | }
14 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/LoadLayout.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.FrameLayout;
8 |
9 | import com.kingja.loadsir.LoadSirUtil;
10 | import com.kingja.loadsir.callback.Callback;
11 | import com.kingja.loadsir.callback.SuccessCallback;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | import androidx.annotation.NonNull;
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/2 17:02
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class LoadLayout extends FrameLayout {
26 | private final String TAG = getClass().getSimpleName();
27 | private Map<Class<? extends Callback>, Callback> callbacks = new HashMap<>();
28 | private Context context;
29 | private Callback.OnReloadListener onReloadListener;
30 | private Class<? extends Callback> preCallback;
31 | private Class<? extends Callback> curCallback;
32 | private static final int CALLBACK_CUSTOM_INDEX = 1;
33 |
34 | public LoadLayout(@NonNull Context context) {
35 | super(context);
36 | }
37 |
38 | public LoadLayout(@NonNull Context context, Callback.OnReloadListener onReloadListener) {
39 | this(context);
40 | this.context = context;
41 | this.onReloadListener = onReloadListener;
42 | }
43 |
44 | public void setupSuccessLayout(Callback callback) {
45 | addCallback(callback);
46 | View successView = callback.getRootView();
47 | successView.setVisibility(View.INVISIBLE);
48 | addView(successView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
49 | ViewGroup.LayoutParams.MATCH_PARENT));
50 | curCallback = SuccessCallback.class;
51 | }
52 |
53 | public void setupCallback(Callback callback) {
54 | Callback cloneCallback = callback.copy();
55 | cloneCallback.setCallback(context, onReloadListener);
56 | addCallback(cloneCallback);
57 | }
58 |
59 | public void addCallback(Callback callback) {
60 | if (!callbacks.containsKey(callback.getClass())) {
61 | callbacks.put(callback.getClass(), callback);
62 | }
63 | }
64 |
65 | public void showCallback(final Class<? extends Callback> callback) {
66 | checkCallbackExist(callback);
67 | if (LoadSirUtil.isMainThread()) {
68 | showCallbackView(callback);
69 | } else {
70 | postToMainThread(callback);
71 | }
72 | }
73 |
74 | public Class<? extends Callback> getCurrentCallback() {
75 | return curCallback;
76 | }
77 |
78 | private void postToMainThread(final Class<? extends Callback> status) {
79 | post(new Runnable() {
80 | @Override
81 | public void run() {
82 | showCallbackView(status);
83 | }
84 | });
85 | }
86 |
87 | private void showCallbackView(Class<? extends Callback> status) {
88 | if (preCallback != null) {
89 | if (preCallback == status) {
90 | return;
91 | }
92 | callbacks.get(preCallback).onDetach();
93 | }
94 | if (getChildCount() > 1) {
95 | removeViewAt(CALLBACK_CUSTOM_INDEX);
96 | }
97 | for (Class key : callbacks.keySet()) {
98 | if (key == status) {
99 | SuccessCallback successCallback = (SuccessCallback) callbacks.get(SuccessCallback.class);
100 | if (key == SuccessCallback.class) {
101 | successCallback.show();
102 | } else {
103 | successCallback.showWithCallback(callbacks.get(key).getSuccessVisible());
104 | View rootView = callbacks.get(key).getRootView();
105 | addView(rootView);
106 | callbacks.get(key).onAttach(context, rootView);
107 | }
108 | preCallback = status;
109 | }
110 | }
111 | curCallback = status;
112 | }
113 |
114 | public void setCallBack(Class<? extends Callback> callback, Transport transport) {
115 | if (transport == null) {
116 | return;
117 | }
118 | checkCallbackExist(callback);
119 | transport.order(context, callbacks.get(callback).obtainRootView());
120 | }
121 |
122 | private void checkCallbackExist(Class<? extends Callback> callback) {
123 | if (!callbacks.containsKey(callback)) {
124 | throw new IllegalArgumentException(String.format("The Callback (%s) is nonexistent.", callback
125 | .getSimpleName()));
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/LoadService.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 |
9 | import com.kingja.loadsir.callback.Callback;
10 | import com.kingja.loadsir.callback.SuccessCallback;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/6 10:05
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 | public class LoadService<T> {
21 | private final String TAG = getClass().getSimpleName();
22 | private LoadLayout loadLayout;
23 | private Convertor<T> convertor;
24 |
25 | LoadService(Convertor<T> convertor,LoadLayout loadLayout,LoadSir.Builder builder) {
26 | this.convertor = convertor;
27 | this.loadLayout = loadLayout;
28 | initCallback(builder);
29 | }
30 |
31 | private void initCallback(LoadSir.Builder builder) {
32 | List<Callback> callbacks = builder.getCallbacks();
33 | final Class<? extends Callback> defalutCallback = builder.getDefaultCallback();
34 | if (callbacks != null && callbacks.size() > 0) {
35 | for (Callback callback : callbacks) {
36 | loadLayout.setupCallback(callback);
37 | }
38 | }
39 | new Handler().post(new Runnable() {
40 | @Override
41 | public void run() {
42 | if (defalutCallback != null) {
43 | loadLayout.showCallback(defalutCallback);
44 | }
45 | }
46 | });
47 |
48 | }
49 |
50 | public void showSuccess() {
51 | loadLayout.showCallback(SuccessCallback.class);
52 | }
53 |
54 | public void showCallback(Class<? extends Callback> callback) {
55 | loadLayout.showCallback(callback);
56 | }
57 |
58 | public void showWithConvertor(T t) {
59 | if (convertor == null) {
60 | throw new IllegalArgumentException("You haven't set the Convertor.");
61 | }
62 | loadLayout.showCallback(convertor.map(t));
63 | }
64 |
65 | public LoadLayout getLoadLayout() {
66 | return loadLayout;
67 | }
68 |
69 | public Class<? extends Callback> getCurrentCallback() {
70 | return loadLayout.getCurrentCallback();
71 | }
72 |
73 | /**
74 | * obtain rootView if you want keep the toolbar in Fragment
75 | *
76 | * @since 1.2.2
77 | * @deprecated
78 | */
79 | public LinearLayout getTitleLoadLayout(Context context, ViewGroup rootView, View titleView) {
80 | LinearLayout newRootView = new LinearLayout(context);
81 | newRootView.setOrientation(LinearLayout.VERTICAL);
82 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
83 | ViewGroup.LayoutParams.MATCH_PARENT);
84 | newRootView.setLayoutParams(layoutParams);
85 | rootView.removeView(titleView);
86 | newRootView.addView(titleView);
87 | newRootView.addView(loadLayout, layoutParams);
88 | return newRootView;
89 | }
90 |
91 | /**
92 | * modify the callback dynamically
93 | *
94 | * @param callback which callback you want modify(layout, event)
95 | * @param transport a interface include modify logic
96 | * @since 1.2.2
97 | */
98 | public LoadService<T> setCallBack(Class<? extends Callback> callback, Transport transport) {
99 | loadLayout.setCallBack(callback, transport);
100 | return this;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/LoadSir.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 |
4 | import com.kingja.loadsir.LoadSirUtil;
5 | import com.kingja.loadsir.callback.Callback;
6 | import com.kingja.loadsir.target.ActivityTarget;
7 | import com.kingja.loadsir.target.ITarget;
8 | import com.kingja.loadsir.target.ViewTarget;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import androidx.annotation.NonNull;
14 |
15 | /**
16 | * Description:TODO
17 | * Create Time:2017/9/2 16:36
18 | * Author:KingJA
19 | * Email:kingjavip@gmail.com
20 | */
21 | public class LoadSir {
22 | private static volatile LoadSir loadSir;
23 | private Builder builder;
24 |
25 | public static LoadSir getDefault() {
26 | if (loadSir == null) {
27 | synchronized (LoadSir.class) {
28 | if (loadSir == null) {
29 | loadSir = new LoadSir();
30 | }
31 | }
32 | }
33 | return loadSir;
34 | }
35 |
36 | private LoadSir() {
37 | this.builder = new Builder();
38 | }
39 |
40 | private void setBuilder(@NonNull Builder builder) {
41 | this.builder = builder;
42 | }
43 |
44 | private LoadSir(Builder builder) {
45 | this.builder = builder;
46 | }
47 |
48 | public LoadService register(@NonNull Object target) {
49 | return register(target, null, null);
50 | }
51 |
52 | public LoadService register(Object target, Callback.OnReloadListener onReloadListener) {
53 | return register(target, onReloadListener, null);
54 | }
55 |
56 | public <T> LoadService register(Object target, Callback.OnReloadListener onReloadListener, Convertor<T>
57 | convertor) {
58 | ITarget targetContext = LoadSirUtil.getTargetContext(target, builder.getTargetContextList());
59 | LoadLayout loadLayout = targetContext.replaceView(target, onReloadListener);
60 | return new LoadService<>(convertor,loadLayout, builder);
61 | }
62 |
63 | public static Builder beginBuilder() {
64 | return new Builder();
65 | }
66 |
67 | public static class Builder {
68 | private List<Callback> callbacks = new ArrayList<>();
69 | private List<ITarget> targetContextList = new ArrayList<>();
70 | private Class<? extends Callback> defaultCallback;
71 |
72 | {
73 | targetContextList.add(new ActivityTarget());
74 | targetContextList.add(new ViewTarget());
75 | }
76 |
77 | public Builder addCallback(@NonNull Callback callback) {
78 | callbacks.add(callback);
79 | return this;
80 | }
81 |
82 | /**
83 | * @param targetContext
84 | * @return Builder
85 | * @since 1.3.8
86 | */
87 | public Builder addTargetContext(ITarget targetContext) {
88 | targetContextList.add(targetContext);
89 | return this;
90 | }
91 |
92 | public List<ITarget> getTargetContextList() {
93 | return targetContextList;
94 | }
95 |
96 | public Builder setDefaultCallback(@NonNull Class<? extends Callback> defaultCallback) {
97 | this.defaultCallback = defaultCallback;
98 | return this;
99 | }
100 |
101 | List<Callback> getCallbacks() {
102 | return callbacks;
103 | }
104 |
105 | Class<? extends Callback> getDefaultCallback() {
106 | return defaultCallback;
107 | }
108 |
109 | public void commit() {
110 | getDefault().setBuilder(this);
111 | }
112 |
113 | public LoadSir build() {
114 | return new LoadSir(this);
115 | }
116 |
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/Transport.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | /**
7 | * Description:TODO
8 | * Create Time:2017/9/28 6:45
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 | public interface Transport {
13 | void order(Context context, View view);
14 | }
15 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/target/ActivityTarget.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.target;
2 |
3 | import android.app.Activity;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 | import com.kingja.loadsir.callback.SuccessCallback;
9 | import com.kingja.loadsir.core.LoadLayout;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2019/8/29 0029 下午 2:44
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class ActivityTarget implements ITarget {
18 |
19 | @Override
20 | public boolean equals(Object target) {
21 | return target instanceof Activity;
22 | }
23 |
24 | @Override
25 | public LoadLayout replaceView(Object target, Callback.OnReloadListener onReloadListener) {
26 | Activity activity = (Activity) target;
27 | ViewGroup contentParent = activity.findViewById(android.R.id.content);
28 | int childIndex = 0;
29 | View oldContent = contentParent.getChildAt(childIndex);
30 | contentParent.removeView(oldContent);
31 |
32 | ViewGroup.LayoutParams oldLayoutParams = oldContent.getLayoutParams();
33 | LoadLayout loadLayout = new LoadLayout(activity, onReloadListener);
34 | loadLayout.setupSuccessLayout(new SuccessCallback(oldContent, activity,
35 | onReloadListener));
36 | contentParent.addView(loadLayout, childIndex, oldLayoutParams);
37 | return loadLayout;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/target/ITarget.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.target;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 | import com.kingja.loadsir.core.LoadLayout;
5 |
6 | /**
7 | * Description:TODO
8 | * Create Time:2019/8/29 0029 下午 2:43
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 | public interface ITarget {
13 | /**
14 | *
15 | * @param target
16 | * @return
17 | * v1.3.8
18 | */
19 | boolean equals(Object target);
20 | /**
21 | * 1.removeView 2.确定LP 3.addView
22 | * @param target
23 | * @param onReloadListener
24 | * @return
25 | * v1.3.8
26 | */
27 | LoadLayout replaceView(Object target, Callback.OnReloadListener onReloadListener);
28 | }
29 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/target/ViewTarget.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.callback.SuccessCallback;
8 | import com.kingja.loadsir.core.LoadLayout;
9 |
10 | import androidx.constraintlayout.widget.ConstraintLayout;
11 |
12 | /**
13 | * Description:TODO
14 | * Create Time:2019/8/29 0029 下午 2:44
15 | * Author:KingJA
16 | * Email:kingjavip@gmail.com
17 | */
18 | public class ViewTarget implements ITarget {
19 |
20 | @Override
21 | public boolean equals(Object target) {
22 | return target instanceof View;
23 | }
24 |
25 | @Override
26 | public LoadLayout replaceView(Object target, Callback.OnReloadListener onReloadListener) {
27 | View oldContent = (android.view.View) target;
28 | ViewGroup contentParent = (ViewGroup) (oldContent.getParent());
29 | int childIndex = 0;
30 | int childCount = contentParent == null ? 0 : contentParent.getChildCount();
31 | for (int i = 0; i < childCount; i++) {
32 | if (contentParent.getChildAt(i) == oldContent) {
33 | childIndex = i;
34 | break;
35 | }
36 | }
37 | if (contentParent != null) {
38 | contentParent.removeView(oldContent);
39 | }
40 | ViewGroup.LayoutParams oldLayoutParams = oldContent.getLayoutParams();
41 | LoadLayout loadLayout = new LoadLayout(oldContent.getContext(), onReloadListener);
42 | loadLayout.setupSuccessLayout(new SuccessCallback(oldContent, oldContent.getContext(),onReloadListener));
43 | if (contentParent != null) {
44 | contentParent.addView(loadLayout, childIndex, oldLayoutParams);
45 | }
46 | return loadLayout;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':loadsir'
2 |
--------------------------------------------------------------------------------