├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── dictionaries
│ └── static.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── README.md.bak
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── aiceking
│ │ └── view_load_retry
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── aiceking
│ │ │ └── view_load_retry
│ │ │ ├── MainActivity.java
│ │ │ ├── activity
│ │ │ ├── LoadFragmentActivity.java
│ │ │ └── NormalActivity.java
│ │ │ ├── application
│ │ │ └── MyApplication.java
│ │ │ ├── fragment
│ │ │ ├── TestFragment.java
│ │ │ └── adapter
│ │ │ │ └── TestAdapter.java
│ │ │ ├── loadretryadapter
│ │ │ ├── foractivity
│ │ │ │ ├── LoadAdapterForActivity.java
│ │ │ │ └── NetErrorAdapterForActivity.java
│ │ │ ├── forfragment
│ │ │ │ ├── LoadAdapterForFragment.java
│ │ │ │ └── NetErrorAdapterForFragment.java
│ │ │ ├── forimageview
│ │ │ │ ├── LoadAdapterForImageView.java
│ │ │ │ └── NetErrorAdapterForImageView.java
│ │ │ └── fortablayout
│ │ │ │ ├── LoadAdapterForTabLayout.java
│ │ │ │ └── NetErrorAdapterForTabLayout.java
│ │ │ └── util
│ │ │ └── ToolBarUtil.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_load_fragment.xml
│ │ ├── activity_main.xml
│ │ ├── activity_normal.xml
│ │ ├── fragment_test.xml
│ │ ├── load_activity.xml
│ │ ├── load_fragment.xml
│ │ ├── load_imageview.xml
│ │ ├── load_tablayout.xml
│ │ ├── recycle_test.xml
│ │ ├── retry_activity.xml
│ │ ├── retry_fragment.xml
│ │ ├── retry_imageview.xml
│ │ └── retry_tablayout.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── back.png
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ ├── logo.jpg
│ │ └── timeout.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── aiceking
│ └── view_load_retry
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── img
├── fixed.gif
└── normal.gif
├── settings.gradle
└── viewloadretrylibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── aiceking
│ └── viewloadretrylibrary
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── aiceking
│ │ └── viewloadretrylibrary
│ │ ├── adapter
│ │ ├── BaseLoadRetryAdapter.java
│ │ └── loadRtryAdapterInterface.java
│ │ ├── coverview
│ │ └── CoverLayout.java
│ │ ├── listener
│ │ └── LoadRetryListener.java
│ │ ├── manager
│ │ └── LoadRetryManager.java
│ │ └── viewmodel
│ │ └── ContentViewModel.java
└── res
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── aiceking
└── viewloadretrylibrary
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/dictionaries/static.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # View-Load-ReTry
2 |
3 | [](https://jitpack.io/#NoEndToLF/View-Load-ReTry)
4 |
5 | **View-Load-ReTry**:这个加载框架有点不一样,针对View进行加载,加载页面还保持了原View的属性,侧重点在灵活,哪里需要加载哪里
6 |
7 | - **原理** :找到需要加载的View,放入FrameLayout(包含自定义的各种情况的加载反馈View),再把FrameLayout放回需要加载View的Parent中 ,然后根据需求调用显示加载或者异常View。
8 | - **功能** :只要当前需要加载View有Parent就可以实现加载反馈(仅不支持复用型的View场景),同一页面支持N个View的加载,彼此互不影响。
9 | - **封装** :全局配置封装,与业务解耦,一个入口控制全部的加载反馈页面。
10 |
11 | -------------------
12 | # 示例,Demo只添加了一种Error反馈页面做演示,使用时可按需自定义多种Error反馈页面(Gif中的View残留现象是录制时丢帧问题,嘿嘿)
13 | | 常规使用 |Activity+Fragment多View加载 |
14 | | :--------:| :--------:|
15 | || |
16 |
17 |
18 | # 使用
19 | * [初步配置](#初步配置)
20 | * [引入](#引入)
21 | * [自定义](#自定义加载状态页面-Adapter继承-BaseLoadRetryAdapter下面各方法都是按需被调用取决于你主动设置的显示哪个Adapter)
22 | * [初始化](#示例代码Demo中normal用法建议在-Application的-onCreate中进行初始化有多少个Adapter就添加多少个这里统一了入口是方便管理)
23 | * [使用](#最常规用法针对一个View针对多个View和针对一个View用法一致流程都是针对某个View的)
24 | * [1、注册](#1注册一般在-oncreate中调用)
25 | * [2、开始加载](#2开始加载)
26 | * [3、加载结果回调](#3加载结果回调在你的请求成功和失败的回调中加入加载结果回调)
27 | * [4、解除绑定](#4解除绑定)
28 | * [为何要造这个看起来重复的轮子](#为何要造这个看起来重复的轮子)
29 | * [反馈与建议](#反馈与建议)
30 |
31 | # 初步配置
32 | ## 引入
33 | Step 1. Add it in your root build.gradle at the end of repositories:
34 |
35 | allprojects {
36 | repositories {
37 | ...
38 | maven { url 'https://jitpack.io' }
39 | }
40 | }
41 | Step 2. Add the dependency
42 |
43 | dependencies {
44 | implementation 'com.github.NoEndToLF:View-Load-ReTry:2.0.2'
45 | }
46 | ## 自定义加载状态页面 Adapter,继承 BaseLoadRetryAdapter,下面各方法都是按需被调用,取决于你主动设置的显示哪个Adapter。
47 | | 方法 |参数 | 作用 |
48 | | :-------- | :--------| :--: |
49 | | onLoadStart| View | 显示这个加载状态页面前开始前调用,用于你自定义页面中控件的初始化,此View为当前显示的加载页面View,以下方法中的View都是。 |
50 | | getCoverViewLayoutId | return R.layout | 加载页面的布局Layout |
51 | | onFalied| View,Ogject | 加载失败的回调(会在你主动调用错误页面对应的那个Adapter里调用),Object可以是任意的对象,方便你显示加载错误的原因|
52 | | onSuccess| View | 加载成功的回调(会在你设置的Load状态那个Adapter里调用),这里可以做一些加载动画的停止操作,另需要手动让View.Gone,暴露在这里是方便各位添加加载页面消失的动画|
53 |
54 | 自定义Adapter示例(Demo中normal用法)
55 | ``` java
56 | public class LoadAdapterForActivity extends BaseLoadRetryAdapter{
57 | @Override
58 | public void onLoadStart(View view) {
59 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
60 | }
61 | @Override
62 | public void onFalied(View view, Object object) {
63 | }
64 | /**这里在加载完成的时候做了一个淡出动画*/
65 | @Override
66 | public void onSuccess(View view) {
67 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
68 | alphaAnimation.setDuration(500);
69 | view.startAnimation(alphaAnimation);
70 | view.setVisibility(View.GONE);
71 | }
72 |
73 | @Override
74 | public int getCoverViewLayoutId() {
75 | return R.layout.load_activity;
76 | }
77 | }
78 | ```
79 | ``` java
80 | /**默认给加载失败页面添加了点击事件,回调到retry方法,开始重试,重试时显示加载中Adapter对应的页面*/
81 | public class NetErrorAdapterForActivity extends BaseLoadRetryAdapter{
82 | @Override
83 | public void onLoadStart(View view) {
84 | ((TextView)view.findViewById(R.id.tv_retry)).setText("点击重新加载");
85 | }
86 |
87 | @Override
88 | public void onFalied(View view, Object object) {
89 | ((ImageView) view.findViewById(R.id.iv_head)).setImageResource(R.mipmap.timeout);
90 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object);
91 | ((TextView)view.findViewById(R.id.tv_retry)).setVisibility(View.VISIBLE);
92 | }
93 |
94 | @Override
95 | public void onSuccess(View view) {
96 |
97 | }
98 |
99 | @Override
100 | public int getCoverViewLayoutId() {
101 | return R.layout.retry_activity;
102 | }
103 | }
104 | ```
105 | ## 示例代码(Demo中normal用法):建议在 Application的 onCreate中进行初始化,有多少个Adapter就添加多少个,这里统一了入口是方便管理。
106 | ``` java
107 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForActivity());
108 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForActivity());.......
109 | ```
110 | # 最常规用法,针对一个View(针对多个View和针对一个View用法一致,流程都是针对某个View的)
111 |
112 | | 方法 |参数 | 作用 |
113 | | :-------- | :--------| :--|
114 | | register| View,LoadRetryRefreshListener | 注册 |
115 | | startLoad| View,Class extends BaseLoadRetryAdapter> | 开始加载,加载中类Adapter.Calss |
116 | | unRegister| View | 解除绑定|
117 | | unRegister| List | 解除多个View的绑定|
118 | | onSuccess | View | 加载成功,会调用View对应加载中Adapter的onSuccess方法|
119 | | onFailed |View,Class extends BaseLoadRetryAdapter>,Object| 加载失败时显示加载失败类Adapter.Class对应的页面,并调用该Adapter的onFalied()方法,Object为加载失败原因|
120 |
121 |
122 | ### 1、注册,一般在 onCreate中调用
123 | ``` java
124 | LoadRetryManager.getInstance().register(view, new LoadRetryListener() {
125 | @Override
126 | public void load() {
127 | //执行你的网络请求
128 | //dosomething();
129 | }
130 |
131 | @Override
132 | public void reTry() {
133 | //执行你的重试请求
134 | //dosomethingRetry();
135 | }
136 | });
137 | ```
138 | ### 2、开始加载
139 | ``` java
140 | LoadRetryManager.getInstance().load(view, LoadAdapterForActivity.class);
141 | ```
142 | ### 3、加载结果回调,在你的请求成功和失败的回调中加入加载结果回调
143 | ``` java
144 | @Override
145 | public void onSuccess(Integer value) {
146 | //加载成功你要做的事.....
147 |
148 | //加载结果回调
149 | LoadRetryManager.getInstance().onSuccess(view);
150 | }
151 |
152 | @Override
153 | public void onFailed(Throwable e) {
154 | //加载失败你要做的事.....
155 |
156 | //加载结果回调
157 | LoadRetryManager.getInstance().onFailed(view, NetErrorAdapterForActivity.class, "请检查网络连接");
158 |
159 | }
160 | ```
161 | ### 4、解除绑定
162 | ``` java
163 | //在Activity中
164 | Override
165 | protected void onDestroy() {
166 | super.onDestroy();
167 | LoadRetryManager.getInstance().unRegister(view);
168 |
169 | //加载多个View时建议在BaseActivity中封装方法,维护一个List,每注册一个加载View就Add一次,解绑时方便操作
170 | LoadRetryManager.getInstance().unRegister(list);
171 | }
172 | ```
173 | ``` java
174 | //在Fragment中
175 | @Override
176 | public void onDestroyView() {
177 | super.onDestroyView();
178 | LoadRetryManager.getInstance().unRegister(view);
179 |
180 | //加载多个View时建议在BaseFragment中封装方法,维护一个List,每注册一个加载View就Add一次,解绑时方便操作
181 | LoadRetryManager.getInstance().unRegister(list);
182 | }
183 | ```
184 | # 为何要造这个看起来重复的轮子
185 | 目前好多开源的加载反馈框架大多是针对Activity和Fragment的,原理都是从根上替换加载布局,但是有个缺点,反馈布局的作用域太大了,不够灵活,现在闲的蛋疼造这个轮子也是为了灵活性,比如说Sample中的同一个页面要加载3块内容的时候,这个轮子的优势就显示出来了,而且原View具有的基本特性加载反馈页面依然包含。
186 |
187 | # 反馈与建议
188 | - 邮箱:
189 |
190 | # License
191 | ```
192 | Copyright (c) [2018] [static]
193 |
194 | Permission is hereby granted, free of charge, to any person obtaining a copy
195 | of this software and associated documentation files (the "Software"), to deal
196 | in the Software without restriction, including without limitation the rights
197 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
198 | copies of the Software, and to permit persons to whom the Software is
199 | furnished to do so, subject to the following conditions:
200 |
201 | The above copyright notice and this permission notice shall be included in all
202 | copies or substantial portions of the Software.
203 |
204 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
205 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
206 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
207 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
208 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
209 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
210 | SOFTWARE.
211 | ```
212 | ---------
213 |
--------------------------------------------------------------------------------
/README.md.bak:
--------------------------------------------------------------------------------
1 | # View-Load-ReTry
2 |
3 | [](https://jitpack.io/#NoEndToLF/View-Load-ReTry)
4 |
5 | **View-Load-ReTry**:这个加载框架有点不一样,针对View进行加载,加载页面还保持了原View的属性,侧重点在灵活,哪里需要加载哪里
6 |
7 | - **原理** :找到需要加载的View,放入FrameLayout(包含自定义的各种情况的加载反馈View),再把FrameLayout放回需要加载View的Parent中 ,然后根据需求调用显示加载或者异常View。
8 | - **功能** :只要当前需要加载View有Parent就可以实现加载反馈(仅不支持复用型的View场景),同一页面支持N个View的加载,彼此互不影响。
9 | - **封装** :全局配置封装,与业务解耦,一个入口控制全部的加载反馈页面。
10 |
11 | -------------------
12 | # 示例,Demo只添加了一种Error反馈页面做演示,使用时可按需自定义多种Error反馈页面(Gif中的View残留现象是录制时丢帧问题,嘿嘿)
13 | | 常规使用 |Activity+Fragment多View加载 |
14 | | :--------:| :--------:|
15 | || |
16 |
17 |
18 | # 使用
19 | * [初步配置](#初步配置)
20 | * [引入](#引入)
21 | * [自定义](#自定义加载状态页面-Adapter继承-BaseLoadRetryAdapter下面各方法都是按需被调用取决于你主动设置的显示哪个Adapter)
22 | * [初始化](#示例代码Demo中normal用法建议在-Application的-onCreate中进行初始化有多少个Adapter就添加多少个这里统一了入口是方便管理)
23 | * [使用](#最常规用法针对一个View针对多个View和针对一个View用法一致流程都是针对某个View的)
24 | * [1、注册](#1注册一般在-oncreate中调用)
25 | * [2、开始加载](#2开始加载)
26 | * [3、加载结果回调](#3加载结果回调在你的请求成功和失败的回调中加入加载结果回调)
27 | * [4、解除绑定](#4解除绑定)
28 | * [为何要造这个看起来重复的轮子](#为何要造这个看起来重复的轮子)
29 | * [反馈与建议](#反馈与建议)
30 |
31 | # 初步配置
32 | ## 引入
33 | Step 1. Add it in your root build.gradle at the end of repositories:
34 |
35 | allprojects {
36 | repositories {
37 | ...
38 | maven { url 'https://jitpack.io' }
39 | }
40 | }
41 | Step 2. Add the dependency
42 |
43 | dependencies {
44 | implementation 'com.github.NoEndToLF:View-Load-ReTry:2.0.1'
45 | }
46 | ## 自定义加载状态页面 Adapter,继承 BaseLoadRetryAdapter,下面各方法都是按需被调用,取决于你主动设置的显示哪个Adapter。
47 | | 方法 |参数 | 作用 |
48 | | :-------- | :--------| :--: |
49 | | onLoadStart| View | 显示这个加载状态页面前开始前调用,用于你自定义页面中控件的初始化,此View为当前显示的加载页面View,以下方法中的View都是。 |
50 | | getCoverViewLayoutId | return R.layout | 加载页面的布局Layout |
51 | | onFalied| View,Ogject | 加载失败的回调(会在你主动调用错误页面对应的那个Adapter里调用),Object可以是任意的对象,方便你显示加载错误的原因|
52 | | onSuccess| View | 加载成功的回调(会在你设置的Load状态那个Adapter里调用),这里可以做一些加载动画的停止操作,另需要手动让View.Gone,暴露在这里是方便各位添加加载页面消失的动画|
53 |
54 | 自定义Adapter示例(Demo中normal用法)
55 | ``` java
56 | public class LoadAdapterForActivity extends BaseLoadRetryAdapter{
57 | @Override
58 | public void onLoadStart(View view) {
59 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
60 | }
61 | @Override
62 | public void onFalied(View view, Object object) {
63 | }
64 | /**这里在加载完成的时候做了一个淡出动画*/
65 | @Override
66 | public void onSuccess(View view) {
67 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
68 | alphaAnimation.setDuration(500);
69 | view.startAnimation(alphaAnimation);
70 | view.setVisibility(View.GONE);
71 | }
72 |
73 | @Override
74 | public int getCoverViewLayoutId() {
75 | return R.layout.load_activity;
76 | }
77 | }
78 | ```
79 | ``` java
80 | /**默认给加载失败页面添加了点击事件,回调到retry方法,开始重试,重试时显示加载中Adapter对应的页面*/
81 | public class NetErrorAdapterForActivity extends BaseLoadRetryAdapter{
82 | @Override
83 | public void onLoadStart(View view) {
84 | ((TextView)view.findViewById(R.id.tv_retry)).setText("点击重新加载");
85 | }
86 |
87 | @Override
88 | public void onFalied(View view, Object object) {
89 | ((ImageView) view.findViewById(R.id.iv_head)).setImageResource(R.mipmap.timeout);
90 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object);
91 | ((TextView)view.findViewById(R.id.tv_retry)).setVisibility(View.VISIBLE);
92 | }
93 |
94 | @Override
95 | public void onSuccess(View view) {
96 |
97 | }
98 |
99 | @Override
100 | public int getCoverViewLayoutId() {
101 | return R.layout.retry_activity;
102 | }
103 | }
104 | ```
105 | ## 示例代码(Demo中normal用法):建议在 Application的 onCreate中进行初始化,有多少个Adapter就添加多少个,这里统一了入口是方便管理。
106 | ``` java
107 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForActivity());
108 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForActivity());.......
109 | ```
110 | # 最常规用法,针对一个View(针对多个View和针对一个View用法一致,流程都是针对某个View的)
111 |
112 | | 方法 |参数 | 作用 |
113 | | :-------- | :--------| :--|
114 | | register| View,LoadRetryRefreshListener | 注册 |
115 | | startLoad| View,Class extends BaseLoadRetryAdapter> | 开始加载,加载中类Adapter.Calss |
116 | | unRegister| View | 解除绑定|
117 | | unRegister| List | 解除多个View的绑定|
118 | | onSuccess | View | 加载成功,会调用View对应加载中Adapter的onSuccess方法|
119 | | onFailed |View,Class extends BaseLoadRetryAdapter>,Object| 加载失败时显示加载失败类Adapter.Class对应的页面,并调用该Adapter的onFalied()方法,Object为加载失败原因|
120 |
121 |
122 | ### 1、注册,一般在 onCreate中调用
123 | ``` java
124 | LoadRetryManager.getInstance().register(view, new LoadRetryListener() {
125 | @Override
126 | public void load() {
127 | //执行你的网络请求
128 | //dosomething();
129 | }
130 |
131 | @Override
132 | public void reTry() {
133 | //执行你的重试请求
134 | //dosomethingRetry();
135 | }
136 | });
137 | ```
138 | ### 2、开始加载
139 | ``` java
140 | LoadRetryManager.getInstance().load(view, LoadAdapterForActivity.class);
141 | ```
142 | ### 3、加载结果回调,在你的请求成功和失败的回调中加入加载结果回调
143 | ``` java
144 | @Override
145 | public void onSuccess(Integer value) {
146 | //加载成功你要做的事.....
147 |
148 | //加载结果回调
149 | LoadRetryManager.getInstance().onSuccess(view);
150 | }
151 |
152 | @Override
153 | public void onFailed(Throwable e) {
154 | //加载失败你要做的事.....
155 |
156 | //加载结果回调
157 | LoadRetryManager.getInstance().onFailed(view, NetErrorAdapterForActivity.class, "请检查网络连接");
158 |
159 | }
160 | ```
161 | ### 4、解除绑定
162 | ``` java
163 | //在Activity中
164 | Override
165 | protected void onDestroy() {
166 | super.onDestroy();
167 | LoadRetryManager.getInstance().unRegister(view);
168 |
169 | //加载多个View时建议在BaseActivity中封装方法,维护一个List,每注册一个加载View就Add一次,解绑时方便操作
170 | LoadRetryManager.getInstance().unRegister(list);
171 | }
172 | ```
173 | ``` java
174 | //在Fragment中
175 | @Override
176 | public void onDestroyView() {
177 | super.onDestroyView();
178 | LoadRetryManager.getInstance().unRegister(view);
179 |
180 | //加载多个View时建议在BaseFragment中封装方法,维护一个List,每注册一个加载View就Add一次,解绑时方便操作
181 | LoadRetryManager.getInstance().unRegister(list);
182 | }
183 | ```
184 | # 为何要造这个看起来重复的轮子
185 | 目前好多开源的加载反馈框架大多是针对Activity和Fragment的,原理都是从根上替换加载布局,但是有个缺点,反馈布局的作用域太大了,不够灵活,现在闲的蛋疼造这个轮子也是为了灵活性,比如说Sample中的同一个页面要加载3块内容的时候,这个轮子的优势就显示出来了,而且原View具有的基本特性加载反馈页面依然包含。
186 |
187 | # 反馈与建议
188 | - 邮箱:
189 |
190 | # License
191 | ```
192 | Copyright (c) [2018] [static]
193 |
194 | Permission is hereby granted, free of charge, to any person obtaining a copy
195 | of this software and associated documentation files (the "Software"), to deal
196 | in the Software without restriction, including without limitation the rights
197 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
198 | copies of the Software, and to permit persons to whom the Software is
199 | furnished to do so, subject to the following conditions:
200 |
201 | The above copyright notice and this permission notice shall be included in all
202 | copies or substantial portions of the Software.
203 |
204 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
205 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
206 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
207 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
208 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
209 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
210 | SOFTWARE.
211 | ```
212 | ---------
213 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.aiceking.view_load_retry"
7 | minSdkVersion 16
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | // implementation project(':viewloadretrylibrary')
29 | implementation 'com.github.NoEndToLF:View-Load-ReTry:2.0.1'
30 | implementation 'com.jaywei:mdprogress:1.0.2' /*加载动画View*/
31 | implementation 'com.github.NoEndToLF:LazyBaseFragment:1.0.4'//lazyFragment
32 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'//万能adapter
33 | implementation 'com.jakewharton:butterknife:8.8.1'
34 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
35 | implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
36 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
37 | implementation "com.android.support:design:28.+"
38 | implementation 'com.gyf.barlibrary:barlibrary:2.3.0'//沉浸式状态栏,透明状态栏
39 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2'
40 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2'
41 | // Optional, if you use support library fragments:
42 | debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.2'
43 | }
44 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/aiceking/view_load_retry/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.aiceking.view_load_retry", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.aiceking.view_load_retry.activity.LoadFragmentActivity;
11 | import com.aiceking.view_load_retry.activity.NormalActivity;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import butterknife.OnClick;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 | @BindView(R.id.btn_normal)
19 | Button btnNormal;
20 | @BindView(R.id.btn_fix)
21 | Button btnFix;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | ButterKnife.bind(this);
28 |
29 | }
30 |
31 |
32 | @OnClick({R.id.btn_normal, R.id.btn_fix})
33 | public void onViewClicked(View view) {
34 | switch (view.getId()) {
35 | case R.id.btn_normal:
36 | startActivity(new Intent(this, NormalActivity.class));
37 | break;
38 | case R.id.btn_fix:
39 | startActivity(new Intent(this, LoadFragmentActivity.class));
40 | break;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/activity/LoadFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.AppBarLayout;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 |
17 | import com.aiceking.view_load_retry.R;
18 | import com.aiceking.view_load_retry.fragment.TestFragment;
19 | import com.aiceking.view_load_retry.loadretryadapter.forimageview.LoadAdapterForImageView;
20 | import com.aiceking.view_load_retry.loadretryadapter.fortablayout.LoadAdapterForTabLayout;
21 | import com.aiceking.view_load_retry.loadretryadapter.forimageview.NetErrorAdapterForImageView;
22 | import com.aiceking.view_load_retry.loadretryadapter.fortablayout.NetErrorAdapterForTabLayout;
23 | import com.aiceking.view_load_retry.util.ToolBarUtil;
24 | import com.aiceking.viewloadretrylibrary.listener.LoadRetryListener;
25 | import com.aiceking.viewloadretrylibrary.manager.LoadRetryManager;
26 | import com.gyf.barlibrary.ImmersionBar;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | import butterknife.BindView;
32 | import butterknife.ButterKnife;
33 | import butterknife.OnClick;
34 | import io.reactivex.Observable;
35 | import io.reactivex.ObservableEmitter;
36 | import io.reactivex.ObservableOnSubscribe;
37 | import io.reactivex.Observer;
38 | import io.reactivex.android.schedulers.AndroidSchedulers;
39 | import io.reactivex.disposables.Disposable;
40 | import io.reactivex.schedulers.Schedulers;
41 | /**测试提交*/
42 | public class LoadFragmentActivity extends AppCompatActivity {
43 |
44 | @BindView(R.id.iv_head)
45 | ImageView ivHead;
46 | @BindView(R.id.tv_name)
47 | TextView tvName;
48 | @BindView(R.id.toolbar)
49 | Toolbar toolbar;
50 | @BindView(R.id.tablayout)
51 | TabLayout tablayout;
52 | @BindView(R.id.appbar)
53 | AppBarLayout appbar;
54 | @BindView(R.id.vp)
55 | ViewPager vp;
56 | @BindView(R.id.linear_back)
57 | LinearLayout linearBack;
58 | private List list_fragments;
59 | private List list_titles;
60 | private List contentViewList;
61 | @Override
62 | protected void onCreate(Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | setContentView(R.layout.activity_load_fragment);
65 | ButterKnife.bind(this);
66 | contentViewList=new ArrayList<>();
67 | contentViewList.add(ivHead);
68 | contentViewList.add(tablayout);
69 | initToolBar();
70 | initData();
71 | initViewPagerAndTabLayout();
72 | loadRetryImageView();
73 | loadRetryTablayout();
74 | }
75 |
76 | private void loadRetryImageView() {
77 | LoadRetryManager.getInstance().register(ivHead, new LoadRetryListener() {
78 | @Override
79 | public void load() {
80 | doSomethingOne(false);
81 | }
82 |
83 | @Override
84 | public void reTry() {
85 | doSomethingOne(true);
86 | }
87 | });
88 | LoadRetryManager.getInstance().load(ivHead, LoadAdapterForImageView.class);
89 | }
90 |
91 | private void loadRetryTablayout() {
92 | LoadRetryManager.getInstance().register(tablayout, new LoadRetryListener() {
93 | @Override
94 | public void load() {
95 | doSomethingTwo(false);
96 | }
97 |
98 | @Override
99 | public void reTry() {
100 | doSomethingTwo(true);
101 | }
102 | });
103 | LoadRetryManager.getInstance().load(tablayout, LoadAdapterForTabLayout.class);
104 | }
105 |
106 | public void doSomethingOne(final boolean isSuccess) {
107 | Observable.create(new ObservableOnSubscribe() {
108 | @Override
109 | public void subscribe(ObservableEmitter emitter) throws Exception {
110 | Thread.sleep(3000);
111 | if (isSuccess) {
112 | emitter.onNext(0);
113 | } else {
114 | emitter.onNext(2);
115 | }
116 | }
117 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
118 | @Override
119 | public void onSubscribe(Disposable d) {
120 |
121 | }
122 |
123 | @Override
124 | public void onNext(Integer value) {
125 | if (value == 0) {
126 | LoadRetryManager.getInstance().onSuccess(ivHead);
127 | } else {
128 | LoadRetryManager.getInstance().onFailed(ivHead, NetErrorAdapterForImageView.class, "请检查网络连接");
129 | }
130 | }
131 |
132 | @Override
133 | public void onError(Throwable e) {
134 | }
135 |
136 | @Override
137 | public void onComplete() {
138 | }
139 | });
140 | }
141 |
142 | public void doSomethingTwo(final boolean isSuccess) {
143 | Observable.create(new ObservableOnSubscribe() {
144 | @Override
145 | public void subscribe(ObservableEmitter emitter) throws Exception {
146 | Thread.sleep(3000);
147 | if (isSuccess) {
148 | emitter.onNext(0);
149 | } else {
150 | emitter.onNext(2);
151 | }
152 | }
153 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
154 | @Override
155 | public void onSubscribe(Disposable d) {
156 |
157 | }
158 |
159 | @Override
160 | public void onNext(Integer value) {
161 | if (value == 0) {
162 | LoadRetryManager.getInstance().onSuccess(tablayout);
163 | } else {
164 | LoadRetryManager.getInstance().onFailed(tablayout, NetErrorAdapterForTabLayout.class, "请检查网络连接");
165 | }
166 | }
167 |
168 | @Override
169 | public void onError(Throwable e) {
170 | }
171 |
172 | @Override
173 | public void onComplete() {
174 | }
175 | });
176 | }
177 |
178 | private void initData() {
179 | list_titles = new ArrayList<>();
180 | list_fragments = new ArrayList<>();
181 | list_titles.add("测试一");
182 | list_titles.add("测试二");
183 | list_fragments.add(new TestFragment());
184 | list_fragments.add(new TestFragment());
185 | for (String title : list_titles) {
186 | tablayout.addTab(tablayout.newTab().setText(title));
187 | }
188 | }
189 |
190 | private void initViewPagerAndTabLayout() {
191 | vp.setAdapter(new MyAdapter(getSupportFragmentManager()));
192 | tablayout.setupWithViewPager(vp);
193 | }
194 |
195 | private void initToolBar() {
196 | setSupportActionBar(toolbar);
197 | ToolBarUtil.setToolbarPaddingTop(toolbar, this);
198 | ImmersionBar.with(this).transparentStatusBar().init();
199 | appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
200 | @Override
201 | public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
202 | toolbar.setBackgroundColor(ToolBarUtil.changeAlpha(getResources().getColor(R.color.blue), Math.abs(verticalOffset * 1.0f) / appBarLayout.getTotalScrollRange()));
203 | tvName.setTextColor(ToolBarUtil.changeAlpha(getResources().getColor(R.color.white), Math.abs(verticalOffset * 1.0f) / appBarLayout.getTotalScrollRange()));
204 | }
205 | });
206 | }
207 |
208 | @OnClick(R.id.linear_back)
209 | public void onViewClicked() {
210 | finish();
211 | }
212 |
213 | public class MyAdapter extends FragmentStatePagerAdapter {
214 |
215 | public MyAdapter(FragmentManager fm) {
216 | super(fm);
217 | }
218 |
219 | @Override
220 | public CharSequence getPageTitle(int position) {
221 | return list_titles.get(position);
222 | }
223 |
224 | @Override
225 | public Fragment getItem(int position) {
226 | return list_fragments.get(position);
227 | }
228 |
229 | @Override
230 | public int getCount() {
231 | return list_fragments.size();
232 | }
233 | }
234 |
235 | @Override
236 | protected void onDestroy() {
237 | super.onDestroy();
238 | ImmersionBar.with(this).destroy();
239 | LoadRetryManager.getInstance().unRegister(contentViewList);
240 | // LoadRetryManager.getInstance().unRegister(ivHead);
241 | // LoadRetryManager.getInstance().unRegister(tablayout);
242 | }
243 | }
244 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/activity/NormalActivity.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.widget.SwipeRefreshLayout;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.Toolbar;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import com.aiceking.view_load_retry.R;
13 | import com.aiceking.view_load_retry.fragment.adapter.TestAdapter;
14 | import com.aiceking.view_load_retry.loadretryadapter.foractivity.LoadAdapterForActivity;
15 | import com.aiceking.view_load_retry.loadretryadapter.foractivity.NetErrorAdapterForActivity;
16 | import com.aiceking.viewloadretrylibrary.listener.LoadRetryListener;
17 | import com.aiceking.viewloadretrylibrary.manager.LoadRetryManager;
18 | import com.gyf.barlibrary.ImmersionBar;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import butterknife.BindView;
24 | import butterknife.ButterKnife;
25 | import butterknife.OnClick;
26 | import io.reactivex.Observable;
27 | import io.reactivex.ObservableEmitter;
28 | import io.reactivex.ObservableOnSubscribe;
29 | import io.reactivex.Observer;
30 | import io.reactivex.android.schedulers.AndroidSchedulers;
31 | import io.reactivex.disposables.Disposable;
32 | import io.reactivex.schedulers.Schedulers;
33 |
34 | public class NormalActivity extends AppCompatActivity {
35 |
36 | @BindView(R.id.linear_back)
37 | LinearLayout linearBack;
38 | @BindView(R.id.tv_name)
39 | TextView tvName;
40 | @BindView(R.id.toolbar)
41 | Toolbar toolbar;
42 | @BindView(R.id.recycler)
43 | RecyclerView recycler;
44 | @BindView(R.id.sw)
45 | SwipeRefreshLayout sw;
46 | private List stringList;
47 | private TestAdapter testAdapter;
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_normal);
53 | ButterKnife.bind(this);
54 | ImmersionBar.with(this).statusBarColor(R.color.blue).fitsSystemWindows(true).init();
55 |
56 | tvName.setText("常规使用");
57 | stringList = new ArrayList<>();
58 | testAdapter = new TestAdapter(R.layout.recycle_test, stringList);
59 | LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
60 | recycler.setLayoutManager(layoutManager);
61 | recycler.setAdapter(testAdapter);
62 | sw.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
63 | @Override
64 | public void onRefresh() {
65 | doSomethingOne(false);
66 | }
67 | });
68 | loadRetryRecycleview();
69 | }
70 |
71 | private void loadRetryRecycleview() {
72 | LoadRetryManager.getInstance().register(sw, new LoadRetryListener() {
73 | @Override
74 | public void load() {
75 | doSomethingOne(false);
76 | }
77 |
78 | @Override
79 | public void reTry() {
80 | doSomethingOne(true);
81 | }
82 | });
83 | LoadRetryManager.getInstance().load(sw, LoadAdapterForActivity.class);
84 |
85 | }
86 |
87 | public void doSomethingOne(final boolean isSuccess) {
88 | Observable.create(new ObservableOnSubscribe() {
89 | @Override
90 | public void subscribe(ObservableEmitter emitter) throws Exception {
91 | Thread.sleep(3000);
92 | if (isSuccess) {
93 | emitter.onNext(0);
94 | } else {
95 | emitter.onNext(2);
96 | }
97 | }
98 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
99 | @Override
100 | public void onSubscribe(Disposable d) {
101 |
102 | }
103 |
104 | @Override
105 | public void onNext(Integer value) {
106 | sw.setRefreshing(false);
107 | if (value == 0) {
108 | LoadRetryManager.getInstance().onSuccess(sw);
109 | for (int i = 0; i < 20; i++) {
110 | stringList.add("测试数据:" + (i + 1));
111 | }
112 | testAdapter.notifyDataSetChanged();
113 | } else {
114 | LoadRetryManager.getInstance().onFailed(sw, NetErrorAdapterForActivity.class, "请检查网络连接");
115 | }
116 | }
117 |
118 | @Override
119 | public void onError(Throwable e) {
120 | }
121 |
122 | @Override
123 | public void onComplete() {
124 | }
125 | });
126 | }
127 |
128 | @OnClick(R.id.linear_back)
129 | public void onViewClicked() {
130 | finish();
131 | }
132 |
133 | @Override
134 | protected void onDestroy() {
135 | super.onDestroy();
136 | ImmersionBar.with(this).destroy();
137 | LoadRetryManager.getInstance().unRegister(sw);
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/application/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.application;
2 |
3 | import android.app.Application;
4 |
5 | import com.aiceking.view_load_retry.loadretryadapter.foractivity.LoadAdapterForActivity;
6 | import com.aiceking.view_load_retry.loadretryadapter.forfragment.LoadAdapterForFragment;
7 | import com.aiceking.view_load_retry.loadretryadapter.fortablayout.LoadAdapterForTabLayout;
8 | import com.aiceking.view_load_retry.loadretryadapter.foractivity.NetErrorAdapterForActivity;
9 | import com.aiceking.view_load_retry.loadretryadapter.forfragment.NetErrorAdapterForFragment;
10 | import com.aiceking.view_load_retry.loadretryadapter.forimageview.NetErrorAdapterForImageView;
11 | import com.aiceking.view_load_retry.loadretryadapter.forimageview.LoadAdapterForImageView;
12 | import com.aiceking.view_load_retry.loadretryadapter.fortablayout.NetErrorAdapterForTabLayout;
13 | import com.aiceking.viewloadretrylibrary.manager.LoadRetryManager;
14 | import com.squareup.leakcanary.LeakCanary;
15 | /**测试提交*/
16 | public class MyApplication extends Application{
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 | if (LeakCanary.isInAnalyzerProcess(this)) {
21 | // This process is dedicated to LeakCanary for heap analysis.
22 | // You should not init your app in this process.
23 | return;
24 | }
25 | LeakCanary.install(this);
26 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForImageView());
27 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForImageView());
28 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForTabLayout());
29 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForTabLayout());
30 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForFragment());
31 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForFragment());
32 | LoadRetryManager.getInstance().addAdapter(new LoadAdapterForActivity());
33 | LoadRetryManager.getInstance().addAdapter(new NetErrorAdapterForActivity());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/fragment/TestFragment.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.fragment;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.aiceking.view_load_retry.R;
13 | import com.aiceking.view_load_retry.fragment.adapter.TestAdapter;
14 | import com.aiceking.view_load_retry.loadretryadapter.forfragment.LoadAdapterForFragment;
15 | import com.aiceking.view_load_retry.loadretryadapter.forfragment.NetErrorAdapterForFragment;
16 | import com.aiceking.viewloadretrylibrary.listener.LoadRetryListener;
17 | import com.aiceking.viewloadretrylibrary.manager.LoadRetryManager;
18 | import com.android.lazyfragmentlibrary.LazyBaseFragment;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import butterknife.BindView;
24 | import butterknife.ButterKnife;
25 | import io.reactivex.Observable;
26 | import io.reactivex.ObservableEmitter;
27 | import io.reactivex.ObservableOnSubscribe;
28 | import io.reactivex.Observer;
29 | import io.reactivex.android.schedulers.AndroidSchedulers;
30 | import io.reactivex.disposables.Disposable;
31 | import io.reactivex.schedulers.Schedulers;
32 |
33 | public class TestFragment extends LazyBaseFragment {
34 | @BindView(R.id.recycler)
35 | RecyclerView recycler;
36 | private AppCompatActivity activity;
37 | private View contentView;
38 | private List stringList;
39 | private TestAdapter testAdapter;
40 | @Override
41 | public void onAttach(Context context) {
42 | super.onAttach(context);
43 | activity = (AppCompatActivity) context;
44 | }
45 |
46 | @Override
47 | protected View setFragmentView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup) {
48 | contentView = layoutInflater.inflate(R.layout.fragment_test, viewGroup, false);
49 | ButterKnife.bind(this, contentView);
50 | stringList=new ArrayList<>();
51 | loadRetryRecycleview();
52 | testAdapter=new TestAdapter(R.layout.recycle_test,stringList);
53 | LinearLayoutManager layoutManager=new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false);
54 | recycler.setLayoutManager(layoutManager);
55 | recycler.setAdapter(testAdapter);
56 | return contentView;
57 | }
58 | private void loadRetryRecycleview() {
59 | LoadRetryManager.getInstance().register(recycler, new LoadRetryListener() {
60 | @Override
61 | public void load() {
62 | doSomethingOne(false);
63 | }
64 |
65 | @Override
66 | public void reTry() {
67 | doSomethingOne(true);
68 | }
69 | });
70 | }
71 | @Override
72 | protected void loadData() {
73 | LoadRetryManager.getInstance().load(recycler, LoadAdapterForFragment.class);
74 |
75 | }
76 | public void doSomethingOne(final boolean isSuccess) {
77 | Observable.create(new ObservableOnSubscribe() {
78 | @Override
79 | public void subscribe(ObservableEmitter emitter) throws Exception {
80 | Thread.sleep(3000);
81 | if (isSuccess) {
82 | emitter.onNext(0);
83 | } else {
84 | emitter.onNext(2);
85 | }
86 | }
87 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
88 | @Override
89 | public void onSubscribe(Disposable d) {
90 |
91 | }
92 |
93 | @Override
94 | public void onNext(Integer value) {
95 | if (value == 0) {
96 | LoadRetryManager.getInstance().onSuccess(recycler);
97 | for (int i=0;i<20;i++){
98 | stringList.add("测试数据:"+(i+1));
99 | }
100 | testAdapter.notifyDataSetChanged();
101 | } else {
102 | LoadRetryManager.getInstance().onFailed(recycler, NetErrorAdapterForFragment.class, "请检查网络连接");
103 | }
104 | }
105 |
106 | @Override
107 | public void onError(Throwable e) {
108 | }
109 |
110 | @Override
111 | public void onComplete() {
112 | }
113 | });
114 | }
115 |
116 | @Override
117 | protected void stopLoadData() {
118 |
119 |
120 | }
121 |
122 | @Override
123 | public void onDestroyView() {
124 | super.onDestroyView();
125 | LoadRetryManager.getInstance().unRegister(recycler);
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/fragment/adapter/TestAdapter.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.fragment.adapter;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import com.aiceking.view_load_retry.R;
8 | import com.chad.library.adapter.base.BaseQuickAdapter;
9 | import com.chad.library.adapter.base.BaseViewHolder;
10 |
11 | import java.util.List;
12 |
13 | public class TestAdapter extends BaseQuickAdapter{
14 | public TestAdapter(int layoutResId, @Nullable List data) {
15 | super(layoutResId, data);
16 | }
17 |
18 | @Override
19 | protected void convert(BaseViewHolder helper, String item) {
20 | ((TextView)helper.getView(R.id.tv_text)).setText(item);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/foractivity/LoadAdapterForActivity.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.foractivity;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.TextView;
6 |
7 | import com.aiceking.view_load_retry.R;
8 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
9 | import com.jaywei.mdprogress.CircularProgressBar;
10 |
11 | public class LoadAdapterForActivity extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | }
19 | /**这里在加载完成的时候做了一个淡出动画*/
20 | @Override
21 | public void onSuccess(View view) {
22 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
23 | alphaAnimation.setDuration(500);
24 | view.startAnimation(alphaAnimation);
25 | view.setVisibility(View.GONE);
26 | }
27 |
28 | @Override
29 | public int getCoverViewLayoutId() {
30 | return R.layout.load_activity;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/foractivity/NetErrorAdapterForActivity.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.foractivity;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.aiceking.view_load_retry.R;
9 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
10 |
11 | public class NetErrorAdapterForActivity extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_retry)).setText("点击重新加载");
15 | }
16 |
17 | @Override
18 | public void onFalied(View view, Object object) {
19 | ((ImageView) view.findViewById(R.id.iv_head)).setImageResource(R.mipmap.timeout);
20 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object);
21 | ((TextView)view.findViewById(R.id.tv_retry)).setVisibility(View.VISIBLE);
22 | }
23 |
24 | @Override
25 | public void onSuccess(View view) {
26 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
27 | alphaAnimation.setDuration(500);
28 | view.startAnimation(alphaAnimation);
29 | view.setVisibility(View.GONE);
30 | }
31 |
32 | @Override
33 | public int getCoverViewLayoutId() {
34 | return R.layout.retry_activity;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/forfragment/LoadAdapterForFragment.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.forfragment;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.TextView;
6 |
7 | import com.aiceking.view_load_retry.R;
8 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
9 | import com.jaywei.mdprogress.CircularProgressBar;
10 |
11 | public class LoadAdapterForFragment extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | }
19 |
20 | @Override
21 | public void onSuccess(View view) {
22 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
23 | alphaAnimation.setDuration(500);
24 | view.startAnimation(alphaAnimation);
25 | view.setVisibility(View.GONE);
26 | }
27 |
28 | @Override
29 | public int getCoverViewLayoutId() {
30 | return R.layout.load_fragment;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/forfragment/NetErrorAdapterForFragment.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.forfragment;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.aiceking.view_load_retry.R;
9 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
10 |
11 | public class NetErrorAdapterForFragment extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_retry)).setText("点击重新加载");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | ((ImageView) view.findViewById(R.id.iv_head)).setImageResource(R.mipmap.timeout);
19 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object);
20 | ((TextView)view.findViewById(R.id.tv_retry)).setVisibility(View.VISIBLE);
21 | }
22 | @Override
23 | public void onSuccess(View view) {
24 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
25 | alphaAnimation.setDuration(500);
26 | view.startAnimation(alphaAnimation);
27 | view.setVisibility(View.GONE);
28 | }
29 |
30 | @Override
31 | public int getCoverViewLayoutId() {
32 | return R.layout.retry_fragment;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/forimageview/LoadAdapterForImageView.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.forimageview;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.TextView;
6 |
7 | import com.aiceking.view_load_retry.R;
8 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
9 | import com.jaywei.mdprogress.CircularProgressBar;
10 |
11 | public class LoadAdapterForImageView extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | }
19 |
20 | @Override
21 | public void onSuccess(View view) {
22 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
23 | alphaAnimation.setDuration(500);
24 | view.startAnimation(alphaAnimation);
25 | view.setVisibility(View.GONE);
26 | }
27 |
28 | @Override
29 | public int getCoverViewLayoutId() {
30 | return R.layout.load_imageview;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/forimageview/NetErrorAdapterForImageView.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.forimageview;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.aiceking.view_load_retry.R;
9 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
10 |
11 | public class NetErrorAdapterForImageView extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_retry)).setText("点击重新加载");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | ((ImageView) view.findViewById(R.id.iv_head)).setImageResource(R.mipmap.timeout);
19 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object);
20 | ((TextView)view.findViewById(R.id.tv_retry)).setVisibility(View.VISIBLE);
21 | }
22 | @Override
23 | public void onSuccess(View view) {
24 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
25 | alphaAnimation.setDuration(500);
26 | view.startAnimation(alphaAnimation);
27 | view.setVisibility(View.GONE);
28 | }
29 |
30 | @Override
31 | public int getCoverViewLayoutId() {
32 | return R.layout.retry_imageview;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/fortablayout/LoadAdapterForTabLayout.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.fortablayout;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.TextView;
6 |
7 | import com.aiceking.view_load_retry.R;
8 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
9 | import com.jaywei.mdprogress.CircularProgressBar;
10 |
11 | public class LoadAdapterForTabLayout extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | ((TextView)view.findViewById(R.id.tv_text)).setText("加载中 ...");
15 | }
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | }
19 |
20 | @Override
21 | public void onSuccess(View view) {
22 | AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
23 | alphaAnimation.setDuration(500);
24 | view.startAnimation(alphaAnimation);
25 | view.setVisibility(View.GONE);
26 | }
27 |
28 | @Override
29 | public int getCoverViewLayoutId() {
30 | return R.layout.load_tablayout;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/loadretryadapter/fortablayout/NetErrorAdapterForTabLayout.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.loadretryadapter.fortablayout;
2 |
3 | import android.view.View;
4 | import android.view.animation.AlphaAnimation;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.aiceking.view_load_retry.R;
9 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
10 |
11 | public class NetErrorAdapterForTabLayout extends BaseLoadRetryAdapter{
12 | @Override
13 | public void onLoadStart(View view) {
14 | }
15 |
16 | @Override
17 | public void onFalied(View view, Object object) {
18 | ((TextView)view.findViewById(R.id.tv_text)).setText((String)object+",点击重新加载");
19 | }
20 |
21 | @Override
22 | public void onSuccess(View view) {
23 |
24 | }
25 |
26 | @Override
27 | public int getCoverViewLayoutId() {
28 | return R.layout.retry_tablayout;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aiceking/view_load_retry/util/ToolBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry.util;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 | import android.support.v7.widget.Toolbar;
7 |
8 | public class ToolBarUtil {
9 | public static void setToolbarPaddingTop(Toolbar toolbar,Context context) {
10 | toolbar.setPadding(0, getStatusBarHeight(context), 0, 0);
11 | }
12 |
13 | public static int getStatusBarHeight(Context context) {
14 | Resources resources = context.getResources();
15 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
16 | int height = resources.getDimensionPixelSize(resourceId);
17 | return height;
18 | }
19 |
20 | public static int changeAlpha(int color, float fraction) {
21 | int red = Color.red(color);
22 | int green = Color.green(color);
23 | int blue = Color.blue(color);
24 | int alpha = (int) (Color.alpha(color) * fraction);
25 | return Color.argb(alpha, red, green, blue);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_load_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
18 |
26 |
32 |
36 |
41 |
46 |
47 |
55 |
56 |
57 |
58 |
66 |
67 |
68 |
69 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
16 |
21 |
26 |
31 |
32 |
41 |
42 |
43 |
47 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/load_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
26 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/load_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
25 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/load_imageview.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
26 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/load_tablayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
25 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recycle_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/retry_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
18 |
27 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/retry_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
19 |
28 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/retry_imageview.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
18 |
27 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/retry_tablayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xhdpi/back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xhdpi/logo.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/timeout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xhdpi/timeout.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #03a9f4
7 | #ffffff
8 | #a6baff
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | View-Load-ReTry
3 |
4 | "Material is the metaphor.\n\n"
5 |
6 | "A material metaphor is the unifying theory of a rationalized space and a system of motion."
7 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet "
8 | "technologically advanced and open to imagination and magic.\n"
9 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The "
10 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the "
11 | "flexibility of the material creates new affordances that supercede those in the physical "
12 | "world, without breaking the rules of physics.\n"
13 | "The fundamentals of light, surface, and movement are key to conveying how objects move, "
14 | "interact, and exist in space and in relation to each other. Realistic lighting shows "
15 | "seams, divides space, and indicates moving parts.\n\n"
16 |
17 | "Bold, graphic, intentional.\n\n"
18 |
19 | "The foundational elements of print based design typography, grids, space, scale, color, "
20 | "and use of imagery guide visual treatments. These elements do far more than please the "
21 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge "
22 | "imagery, large scale typography, and intentional white space create a bold and graphic "
23 | "interface that immerse the user in the experience.\n"
24 | "An emphasis on user actions makes core functionality immediately apparent and provides "
25 | "waypoints for the user.\n\n"
26 |
27 | "Motion provides meaning.\n\n"
28 |
29 | "Motion respects and reinforces the user as the prime mover. Primary user actions are "
30 | "inflection points that initiate motion, transforming the whole design.\n"
31 | "All action takes place in a single environment. Objects are presented to the user without "
32 | "breaking the continuity of experience even as they transform and reorganize.\n"
33 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. "
34 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n"
35 |
36 | "3D world.\n\n"
37 |
38 | "The material environment is a 3D space, which means all objects have x, y, and z "
39 | "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the "
40 | "positive z-axis extending towards the viewer. Every sheet of material occupies a single "
41 | "position along the z-axis and has a standard 1dp thickness.\n"
42 | "On the web, the z-axis is used for layering and not for perspective. The 3D world is "
43 | "emulated by manipulating the y-axis.\n\n"
44 |
45 | "Light and shadow.\n\n"
46 |
47 | "Within the material environment, virtual lights illuminate the scene. Key lights create "
48 | "directional shadows, while ambient light creates soft shadows from all angles.\n"
49 | "Shadows in the material environment are cast by these two light sources. In Android "
50 | "development, shadows occur when light sources are blocked by sheets of material at "
51 | "various positions along the z-axis. On the web, shadows are depicted by manipulating the "
52 | "y-axis only. The following example shows the card with a height of 6dp.\n\n"
53 |
54 | "Resting elevation.\n\n"
55 |
56 | "All material objects, regardless of size, have a resting elevation, or default elevation "
57 | "that does not change. If an object changes elevation, it should return to its resting "
58 | "elevation as soon as possible.\n\n"
59 |
60 | "Component elevations.\n\n"
61 |
62 | "The resting elevation for a component type is consistent across apps (e.g., FAB elevation "
63 | "does not vary from 6dp in one app to 16dp in another app).\n"
64 | "Components may have different resting elevations across platforms, depending on the depth "
65 | "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n"
66 |
67 | "Responsive elevation and dynamic elevation offsets.\n\n"
68 |
69 | "Some component types have responsive elevation, meaning they change elevation in response "
70 | "to user input (e.g., normal, focused, and pressed) or system events. These elevation "
71 | "changes are consistently implemented using dynamic elevation offsets.\n"
72 | "Dynamic elevation offsets are the goal elevation that a component moves towards, relative "
73 | "to the component’s resting state. They ensure that elevation changes are consistent "
74 | "across actions and component types. For example, all components that lift on press have "
75 | "the same elevation change relative to their resting elevation.\n"
76 | "Once the input event is completed or cancelled, the component will return to its resting "
77 | "elevation.\n\n"
78 |
79 | "Avoiding elevation interference.\n\n"
80 |
81 | "Components with responsive elevations may encounter other components as they move between "
82 | "their resting elevations and dynamic elevation offsets. Because material cannot pass "
83 | "through other material, components avoid interfering with one another any number of ways, "
84 | "whether on a per component basis or using the entire app layout.\n"
85 | "On a component level, components can move or be removed before they cause interference. "
86 | "For example, a floating action button (FAB) can disappear or move off screen before a "
87 | "user picks up a card, or it can move if a snackbar appears.\n"
88 | "On the layout level, design your app layout to minimize opportunities for interference. "
89 | "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere "
90 | "when a user tries to pick up one of cards."
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/aiceking/view_load_retry/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.view_load_retry;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.3'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | maven { url 'https://jitpack.io' }
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 27 16:48:40 CST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/img/fixed.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/img/fixed.gif
--------------------------------------------------------------------------------
/img/normal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aiceking/View-Load-ReTry/4a6ea70a4e2e0095ddf71c9dc15aecb94d6b6137/img/normal.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':viewloadretrylibrary'
2 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin:'com.github.dcendents.android-maven'
3 | group='com.github.NoEndToLF'
4 | android {
5 | compileSdkVersion 28
6 |
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:28.0.0'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | implementation "com.android.support:design:28.+"
36 | }
37 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/androidTest/java/com/aiceking/viewloadretrylibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.aiceking.viewloadretrylibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/adapter/BaseLoadRetryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.adapter;
2 |
3 | import android.view.View;
4 |
5 | import com.aiceking.viewloadretrylibrary.coverview.CoverLayout;
6 |
7 | public abstract class BaseLoadRetryAdapter implements loadRtryAdapterInterface{
8 |
9 | public abstract void onLoadStart(View view);
10 | public abstract void onFalied(View view,Object object);
11 | public abstract void onSuccess(View view);
12 | }
13 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/adapter/loadRtryAdapterInterface.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.adapter;
2 |
3 | public interface loadRtryAdapterInterface {
4 | int getCoverViewLayoutId();
5 | }
6 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/coverview/CoverLayout.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.coverview;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.FrameLayout;
11 |
12 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
13 | import com.aiceking.viewloadretrylibrary.listener.LoadRetryListener;
14 |
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 |
19 | public class CoverLayout extends FrameLayout{
20 | private LayoutInflater mInflater;
21 | private List viewList;
22 | private HashMap viewHashMap;
23 | private LoadRetryListener loadRetryListener;
24 | private int layout;
25 | private View contentView;
26 |
27 | public void setLoadAdapter(Class extends BaseLoadRetryAdapter> loadAdapter) {
28 | this.loadAdapter = loadAdapter;
29 | }
30 |
31 | public Class extends BaseLoadRetryAdapter> getLoadAdapter() {
32 | return loadAdapter;
33 | }
34 |
35 | private Class extends BaseLoadRetryAdapter> loadAdapter;
36 | private HashMap,BaseLoadRetryAdapter> baseLoadRetryAdapterHashMap;
37 | public CoverLayout(@NonNull Context context) {
38 | this(context,null);
39 | }
40 |
41 | public CoverLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
42 | this(context, attrs,-1);
43 | }
44 | public CoverLayout(Context context, AttributeSet attrs, int defStyleAttr)
45 | {
46 | super(context, attrs, defStyleAttr);
47 | mInflater = LayoutInflater.from(context);
48 | viewList=new ArrayList<>();
49 | viewHashMap=new HashMap<>();
50 | }
51 | public void setLoadRetryListener(LoadRetryListener loadRetryListener) {
52 | this.loadRetryListener = loadRetryListener;
53 | }
54 | public void setAdapters(HashMap,BaseLoadRetryAdapter> baseLoadRetryAdapterHashMap){
55 | this.baseLoadRetryAdapterHashMap=baseLoadRetryAdapterHashMap;
56 | }
57 | public void addContentView(View view){
58 | this.contentView=view;
59 | viewList.add(view);
60 | addView(contentView);
61 | }
62 | public void showView(int layout){
63 | if (!viewHashMap.containsKey(layout)){
64 | View view=mInflater.inflate(layout,this,false);
65 | viewHashMap.put(layout,view);
66 | viewList.add(view);
67 | addView(view);
68 | }
69 | for (View view:viewList){
70 | view.setVisibility(View.GONE);
71 | }
72 | this.layout=layout;
73 | viewHashMap.get(layout).setVisibility(View.VISIBLE);
74 | }
75 | public void onSuccess(Class extends BaseLoadRetryAdapter> cla){
76 | if (baseLoadRetryAdapterHashMap==null)return;
77 | baseLoadRetryAdapterHashMap.get(cla).onSuccess(getNowShowView());
78 | contentView.setVisibility(View.VISIBLE);
79 | }
80 | public void onFailed(final Class extends BaseLoadRetryAdapter> cla,Object object){
81 | if (baseLoadRetryAdapterHashMap==null)return;
82 | showView(baseLoadRetryAdapterHashMap.get(cla).getCoverViewLayoutId());
83 | baseLoadRetryAdapterHashMap.get(cla).onLoadStart(getNowShowView());
84 | baseLoadRetryAdapterHashMap.get(cla).onFalied(getNowShowView(),object);
85 | getNowShowView().setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | reTry();
89 | }
90 | });
91 | }
92 | public View getNowShowView(){
93 | return viewHashMap.get(layout);
94 | }
95 | public void reTry(){
96 | if (loadRetryListener!=null){
97 | showView(baseLoadRetryAdapterHashMap.get(loadAdapter).getCoverViewLayoutId());
98 | loadRetryListener.reTry();
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/listener/LoadRetryListener.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.listener;
2 |
3 | public interface LoadRetryListener {
4 | void load();
5 | void reTry();
6 | }
7 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/manager/LoadRetryManager.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.manager;
2 |
3 | import android.support.design.widget.AppBarLayout;
4 | import android.support.design.widget.CollapsingToolbarLayout;
5 | import android.support.design.widget.CoordinatorLayout;
6 | import android.support.v4.widget.NestedScrollView;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.FrameLayout;
11 | import android.widget.LinearLayout;
12 | import android.widget.RelativeLayout;
13 |
14 | import com.aiceking.viewloadretrylibrary.adapter.BaseLoadRetryAdapter;
15 | import com.aiceking.viewloadretrylibrary.coverview.CoverLayout;
16 | import com.aiceking.viewloadretrylibrary.listener.LoadRetryListener;
17 | import com.aiceking.viewloadretrylibrary.viewmodel.ContentViewModel;
18 |
19 | import java.util.HashMap;
20 | import java.util.List;
21 | import java.util.zip.Inflater;
22 |
23 | public class LoadRetryManager {
24 | private static LoadRetryManager loadRetryManager;
25 | private String Tag="LoadRetryManager";
26 | private HashMap,BaseLoadRetryAdapter> baseLoadRetryAdapterHashMap;
27 | private HashMap coverLayoutHashMap;
28 | private HashMap loadRetryListenerHashMap;
29 | private HashMap viewLoadSuccess;
30 | public void addAdapter(BaseLoadRetryAdapter baseLoadRetryAdapter){
31 | baseLoadRetryAdapterHashMap.put(baseLoadRetryAdapter.getClass(),baseLoadRetryAdapter);
32 | }
33 |
34 | private LoadRetryManager(){
35 | baseLoadRetryAdapterHashMap=new HashMap<>();
36 | coverLayoutHashMap=new HashMap<>();
37 | loadRetryListenerHashMap=new HashMap<>();
38 | viewLoadSuccess=new HashMap<>();
39 | }
40 | public static LoadRetryManager getInstance(){
41 | if (loadRetryManager ==null){
42 | synchronized (LoadRetryManager.class){
43 | if (loadRetryManager ==null){
44 | loadRetryManager =new LoadRetryManager();
45 | }
46 | }
47 | }
48 | return loadRetryManager;
49 | }
50 | public void register(final View view, final LoadRetryListener loadRetryListener) {
51 | if (!coverLayoutHashMap.containsKey(System.identityHashCode(view))){
52 | final CoverLayout coverLayout=new CoverLayout(view.getContext());
53 | coverLayout.setLoadRetryListener(loadRetryListener);
54 | viewLoadSuccess.put(System.identityHashCode(view),false);
55 | coverLayoutHashMap.put(System.identityHashCode(view),coverLayout);
56 | loadRetryListenerHashMap.put(System.identityHashCode(view),loadRetryListener);
57 | }
58 | }
59 | public void unRegister(final View view) {
60 | if (coverLayoutHashMap.containsKey(System.identityHashCode(view))){
61 | coverLayoutHashMap.remove(System.identityHashCode(view));
62 | viewLoadSuccess.remove(System.identityHashCode(view));
63 | loadRetryListenerHashMap.remove(System.identityHashCode(view));
64 |
65 | }
66 | }
67 | public void unRegister(final List viewList) {
68 | if (viewList==null){
69 | Log.i(Tag,"View集合为空");
70 | return;
71 | }
72 | for (View view:viewList){
73 | if (coverLayoutHashMap.containsKey(System.identityHashCode(view))){
74 | coverLayoutHashMap.remove(System.identityHashCode(view));
75 | viewLoadSuccess.remove(System.identityHashCode(view));
76 | loadRetryListenerHashMap.remove(System.identityHashCode(view));
77 |
78 | }
79 | }
80 | }
81 | public void load(View view,Class extends BaseLoadRetryAdapter> cla){
82 | if (isRegister(view)){
83 | if (isHasAdapter(cla)) {
84 | if (!viewLoadSuccess.get(System.identityHashCode(view))){
85 | Cover(view, baseLoadRetryAdapterHashMap.get(cla).getCoverViewLayoutId());
86 | coverLayoutHashMap.get(System.identityHashCode(view)).setLoadAdapter(cla);
87 | baseLoadRetryAdapterHashMap.get(cla).onLoadStart(coverLayoutHashMap.get(System.identityHashCode(view)).getNowShowView());
88 | loadRetryListenerHashMap.get(System.identityHashCode(view)).load();
89 | }
90 | }
91 | }
92 | }
93 | private boolean isHasAdapter(Class extends BaseLoadRetryAdapter> cla){
94 | boolean isHasAdapter=false;
95 | if (baseLoadRetryAdapterHashMap.containsKey(cla)){
96 | isHasAdapter=true;
97 | }else {
98 | Log.i(Tag,"未找到该adapter");
99 | }
100 | return isHasAdapter;
101 | }
102 | private boolean isRegister(View view){
103 | boolean isRegister=false;
104 | if (coverLayoutHashMap.containsKey(System.identityHashCode(view))){
105 | isRegister=true;
106 | }else {
107 | Log.i(Tag,"未进行register");
108 | }
109 | return isRegister;
110 | }
111 | public void onSuccess(View view){
112 | if (isRegister(view)){
113 | if (isHasAdapter(coverLayoutHashMap.get(System.identityHashCode(view)).getLoadAdapter())) {
114 | if (!viewLoadSuccess.get(System.identityHashCode(view))){
115 | viewLoadSuccess.put(System.identityHashCode(view),true);
116 | coverLayoutHashMap.get(System.identityHashCode(view)).onSuccess(coverLayoutHashMap.get(System.identityHashCode(view)).getLoadAdapter());
117 | }
118 | }
119 | }
120 | }
121 | public void onFailed(View view,Class extends BaseLoadRetryAdapter> cla,Object object){
122 | if (isRegister(view)){
123 | if (isHasAdapter(cla)) {
124 | if (!viewLoadSuccess.get(System.identityHashCode(view))){
125 | coverLayoutHashMap.get(System.identityHashCode(view)).onFailed(cla,object);
126 | }
127 | }
128 | }
129 | }
130 | public void Cover(final View contentView, final int layout){
131 | ViewGroup mRoot = (ViewGroup) contentView.getParent();
132 | ViewGroup.LayoutParams lp;
133 | if (mRoot instanceof CoordinatorLayout){
134 | lp = (CoordinatorLayout.LayoutParams) contentView.getLayoutParams();
135 | }else if (mRoot instanceof CollapsingToolbarLayout){
136 | lp = (CollapsingToolbarLayout.LayoutParams) contentView.getLayoutParams();
137 | }else if (mRoot instanceof AppBarLayout){
138 | lp = (AppBarLayout.LayoutParams) contentView.getLayoutParams();
139 | }else if (mRoot instanceof NestedScrollView){
140 | lp = (NestedScrollView.LayoutParams) contentView.getLayoutParams();
141 | }else if (mRoot instanceof LinearLayout){
142 | lp = (LinearLayout.LayoutParams) contentView.getLayoutParams();
143 | }else if (mRoot instanceof RelativeLayout){
144 | lp = (RelativeLayout.LayoutParams) contentView.getLayoutParams();
145 | }else if (mRoot instanceof FrameLayout){
146 | lp = (FrameLayout.LayoutParams) contentView.getLayoutParams();
147 | }else {
148 | lp = (ViewGroup.LayoutParams) contentView.getLayoutParams();
149 | }
150 | int index=-1;
151 | for (int i = 0; i < mRoot.getChildCount(); i++) {
152 | if (contentView.getId() == mRoot.getChildAt(i).getId()) {
153 | index=i;
154 | break;
155 | }
156 | }
157 | if (index>=0){
158 | mRoot.removeView(contentView);
159 | mRoot.addView(coverLayoutHashMap.get(System.identityHashCode(contentView)),index,lp );
160 | coverLayoutHashMap.get(System.identityHashCode(contentView)).setAdapters(baseLoadRetryAdapterHashMap);
161 | coverLayoutHashMap.get(System.identityHashCode(contentView)).addContentView(contentView);
162 | coverLayoutHashMap.get(System.identityHashCode(contentView)).showView(layout);
163 | }
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/java/com/aiceking/viewloadretrylibrary/viewmodel/ContentViewModel.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary.viewmodel;
2 |
3 | import android.view.ViewGroup;
4 |
5 | public class ContentViewModel {
6 | private int index;
7 |
8 | public ContentViewModel(int index, ViewGroup viewGroup) {
9 | this.index = index;
10 | this.viewGroup = viewGroup;
11 | }
12 |
13 | private ViewGroup viewGroup;
14 |
15 | public int getIndex() {
16 | return index;
17 | }
18 |
19 | public void setIndex(int index) {
20 | this.index = index;
21 | }
22 |
23 | public ViewGroup getViewGroup() {
24 | return viewGroup;
25 | }
26 |
27 | public void setViewGroup(ViewGroup viewGroup) {
28 | this.viewGroup = viewGroup;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ViewLoadRetryLibrary
3 |
4 |
--------------------------------------------------------------------------------
/viewloadretrylibrary/src/test/java/com/aiceking/viewloadretrylibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.aiceking.viewloadretrylibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------