├── loadsir
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── kingja
│ │ └── loadsir
│ │ ├── core
│ │ ├── Convertor.java
│ │ ├── Transport.java
│ │ ├── TargetContext.java
│ │ ├── LoadSir.java
│ │ ├── LoadService.java
│ │ └── LoadLayout.java
│ │ ├── callback
│ │ ├── SuccessCallback.java
│ │ ├── ProgressCallback.java
│ │ ├── HintCallback.java
│ │ └── Callback.java
│ │ └── LoadSirUtil.java
├── build.gradle
└── proguard-rules.pro
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── img.jpg
│ │ │ │ ├── custom.png
│ │ │ │ ├── empty.png
│ │ │ │ ├── error.png
│ │ │ │ ├── music.png
│ │ │ │ ├── awkward.png
│ │ │ │ └── timeout.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── back.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── layout
│ │ │ │ ├── activity_fragment.xml
│ │ │ │ ├── layout_loading.xml
│ │ │ │ ├── layout_animate.xml
│ │ │ │ ├── layout_custom_error.xml
│ │ │ │ ├── layout_lottie_empty.xml
│ │ │ │ ├── layout_lottie_loading.xml
│ │ │ │ ├── activity_fragment_viewpager.xml
│ │ │ │ ├── fragment_b_content.xml
│ │ │ │ ├── activity_activity_convertor.xml
│ │ │ │ ├── fragment_a_content.xml
│ │ │ │ ├── activity_content.xml
│ │ │ │ ├── layout_timeout.xml
│ │ │ │ ├── include_title.xml
│ │ │ │ ├── layout_error.xml
│ │ │ │ ├── layout_empty.xml
│ │ │ │ ├── layout_custom.xml
│ │ │ │ ├── activity_view.xml
│ │ │ │ ├── title_title_bar.xml
│ │ │ │ ├── activity_fragment_mutil.xml
│ │ │ │ ├── activity_best_practices.xml
│ │ │ │ ├── activity_title.xml
│ │ │ │ ├── activity_placeholder.xml
│ │ │ │ ├── layout_placeholder.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── sample
│ │ │ │ └── kingja
│ │ │ │ └── loadsir
│ │ │ │ ├── callback
│ │ │ │ ├── ErrorCallback.java
│ │ │ │ ├── EmptyCallback.java
│ │ │ │ ├── LottieEmptyCallback.java
│ │ │ │ ├── PlaceholderCallback.java
│ │ │ │ ├── LottieLoadingCallback.java
│ │ │ │ ├── LoadingCallback.java
│ │ │ │ ├── TimeoutCallback.java
│ │ │ │ ├── CustomCallback.java
│ │ │ │ └── AnimateCallback.java
│ │ │ │ ├── target
│ │ │ │ ├── FragmentSingleActivity.java
│ │ │ │ ├── BestPracticesActivity.java
│ │ │ │ ├── KeepTitleFragmentActivity.java
│ │ │ │ ├── FragmentB.java
│ │ │ │ ├── FragmentA.java
│ │ │ │ ├── MultiFragmentActivity.java
│ │ │ │ ├── PlaceholderActivity.java
│ │ │ │ ├── KeepTitleActivity.java
│ │ │ │ ├── LottieActivity.java
│ │ │ │ ├── NormalFragment.java
│ │ │ │ ├── ViewTargetActivity.java
│ │ │ │ ├── MultiFragmentWithViewPagerActivity.java
│ │ │ │ ├── DefaultCallbackActivity.java
│ │ │ │ ├── AnimateActivity.java
│ │ │ │ ├── NormalActivity.java
│ │ │ │ ├── KeepTitleFragment.java
│ │ │ │ └── ConvertorActivity.java
│ │ │ │ ├── PostUtil.java
│ │ │ │ ├── App.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseFragment.java
│ │ │ │ └── BaseTitleActivity.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── sample
│ │ │ └── kingja
│ │ │ └── loadsir
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── sample
│ │ └── kingja
│ │ └── loadsir
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── imgs
├── LoadSir.jpg
├── LoadSir_flow.jpg
├── qcode_1.3.2.png
├── muitl_fragment.gif
├── normal_activity.gif
├── single_fragment.gif
├── view_activity.gif
├── viewpage_fragment.gif
└── placeholder_activity.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── docs
├── BestPractice-cn.md
├── NextVersion.md
├── BestPractice.md
├── changelog.md
├── FAQ-cn.md
└── FAQ.md
├── .gitignore
├── config.gradle
├── gradle.properties
├── gradlew.bat
├── gradlew
├── README-cn.md
└── README.md
/loadsir/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .idea
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':loadsir'
2 |
--------------------------------------------------------------------------------
/loadsir/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/imgs/LoadSir.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/LoadSir.jpg
--------------------------------------------------------------------------------
/imgs/LoadSir_flow.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/LoadSir_flow.jpg
--------------------------------------------------------------------------------
/imgs/qcode_1.3.2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/qcode_1.3.2.png
--------------------------------------------------------------------------------
/imgs/muitl_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/muitl_fragment.gif
--------------------------------------------------------------------------------
/imgs/normal_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/normal_activity.gif
--------------------------------------------------------------------------------
/imgs/single_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/single_fragment.gif
--------------------------------------------------------------------------------
/imgs/view_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/view_activity.gif
--------------------------------------------------------------------------------
/imgs/viewpage_fragment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/viewpage_fragment.gif
--------------------------------------------------------------------------------
/imgs/placeholder_activity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/imgs/placeholder_activity.gif
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/img.jpg
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/custom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/custom.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/empty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/error.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/music.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/music.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/awkward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/awkward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/timeout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/drawable/timeout.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xxhdpi/back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darryrzhong/LoadSir/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/docs/BestPractice-cn.md:
--------------------------------------------------------------------------------
1 | 最佳实践
2 | ---
3 |
4 | 如果有你关于LoadSir好的使用场景或者封装方式,欢迎发起`pull request`.
5 |
6 | ### #1 xxx
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
11 |
--------------------------------------------------------------------------------
/docs/NextVersion.md:
--------------------------------------------------------------------------------
1 | The Next Version
2 | ---
3 |
4 | The next version will include:
5 |
6 | **1.3.x**
7 | - [ ] Samples how to use LoadSir with other common open-source libs.
8 | - [ ] you tell me
9 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | compileSdkVersion = 26
3 | buildToolsVersion = "26.0.2"
4 | minSdkVersion = 14
5 | targetSdkVersion = 26
6 |
7 | versionCode = 20180320
8 | versionName = "1.3.6"
9 | supportVersion = '26.0.0-alpha1'
10 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 20 16:48:24 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.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/BestPractice.md:
--------------------------------------------------------------------------------
1 | Best Practice
2 | ---
3 |
4 | In this documentation I collect good examples how to use LoadSir - and how to use LoadSir with other common open-source libs.
5 |
6 | If you have any wishes or ideas, please make a PR or an issue.
7 | Thank you for your help.
8 |
9 | ### #1 xxx
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/Convertor.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | /**
6 | * Description:TODO
7 | * Create Time:2017/9/4 8:58
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public interface Convertor {
12 | Class map(T t);
13 | }
14 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/Transport.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | /**
7 | * Description:TODO
8 | * Create Time:2017/9/28 6:45
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 | public interface Transport {
13 | void order(Context context, View view);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 | #787878
5 | #FF4081
6 |
7 | #000000
8 | #ffffff
9 | #bb2c28
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/ErrorCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 |
4 | import com.kingja.loadsir.callback.Callback;
5 |
6 | import sample.kingja.loadsir.R;
7 |
8 | /**
9 | * Description:TODO
10 | * Create Time:2017/9/4 10:20
11 | * Author:KingJA
12 | * Email:kingjavip@gmail.com
13 | */
14 |
15 | public class ErrorCallback extends Callback {
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_error;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/EmptyCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | import sample.kingja.loadsir.R;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 10:22
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 |
14 | public class EmptyCallback extends Callback {
15 |
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_empty;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LottieEmptyCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import com.kingja.loadsir.callback.Callback;
4 |
5 | import sample.kingja.loadsir.R;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 10:22
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 |
14 | public class LottieEmptyCallback extends Callback {
15 |
16 | @Override
17 | protected int onCreateView() {
18 | return R.layout.layout_lottie_empty;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_animate.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/loadsir/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode rootProject.ext.versionCode
11 | versionName rootProject.ext.versionName
12 | }
13 | buildTypes {
14 | release {
15 | }
16 | }
17 | }
18 |
19 | dependencies {
20 | compile fileTree(include: ['*.jar'], dir: 'libs')
21 | compile "com.android.support:support-annotations:$rootProject.ext.supportVersion"
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/PlaceholderCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class PlaceholderCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_placeholder;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(Context context, View view) {
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/test/java/sample/kingja/loadsir/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.util.Log;
4 |
5 | import org.junit.Test;
6 |
7 | import static org.junit.Assert.*;
8 |
9 | /**
10 | * Example local unit test, which will execute on the development machine (host).
11 | *
12 | * @see Testing documentation
13 | */
14 | public class ExampleUnitTest {
15 |
16 | @Test
17 | public void addition_isCorrect() throws Exception {
18 | assertEquals(4, 2 + 2);
19 | Object o = new Object();
20 | System.out.println( "o1: "+o.hashCode());
21 | o = new Object();
22 | System.out.println( "o2: "+o.hashCode());
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LottieLoadingCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class LottieLoadingCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_lottie_loading;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(Context context, View view) {
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_lottie_empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_lottie_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentSingleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import sample.kingja.loadsir.R;
7 |
8 | /**
9 | * Description:TODO
10 | * Create Time:2017/9/4 10:56
11 | * Author:KingJA
12 | * Email:kingjavip@gmail.com
13 | */
14 |
15 | public class FragmentSingleActivity extends AppCompatActivity {
16 | private static final String TAG ="FragmentSingleActivity" ;
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_fragment);
21 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new NormalFragment()).commit();
22 |
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/LoadingCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import sample.kingja.loadsir.R;
9 |
10 | /**
11 | * Description:TODO
12 | * Create Time:2017/9/4 10:22
13 | * Author:KingJA
14 | * Email:kingjavip@gmail.com
15 | */
16 |
17 | public class LoadingCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_loading;
22 | }
23 |
24 | @Override
25 | public boolean getSuccessVisible() {
26 | return super.getSuccessVisible();
27 | }
28 |
29 | @Override
30 | protected boolean onReloadEvent(Context context, View view) {
31 | return true;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_b_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/TimeoutCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 |
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/2 16:17
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 |
18 | public class TimeoutCallback extends Callback {
19 |
20 | @Override
21 | protected int onCreateView() {
22 | return R.layout.layout_timeout;
23 | }
24 |
25 | @Override
26 | protected boolean onReloadEvent(Context context, View view) {
27 | Toast.makeText(context.getApplicationContext(),"Connecting to the network again!",Toast.LENGTH_SHORT).show();
28 | return false;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_activity_convertor.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/sample/kingja/loadsir/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
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 | * Instrumentation 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() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("sample.kingja.loadsir", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_a_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/BestPracticesActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/29 13:54
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class BestPracticesActivity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_best_practices);
22 | }
23 |
24 | public void mvpActivity(View view) {
25 | }
26 |
27 | public void onLottie(View view) {
28 | startActivity(new Intent(this, LottieActivity.class));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.Window;
6 |
7 | import sample.kingja.loadsir.R;
8 |
9 | /**
10 | * Description:
11 | * Create Time:2017/9/4 10:56
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 |
16 | public class KeepTitleFragmentActivity extends AppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | requestWindowFeature(Window.FEATURE_NO_TITLE);
22 | setContentView(R.layout.activity_fragment);
23 | if (getSupportActionBar() != null) {
24 | getSupportActionBar().hide();
25 | }
26 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, new KeepTitleFragment()).commit();
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_timeout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
17 |
18 |
21 |
22 |
27 |
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | -dontwarn com.kingja.loadsir.**
28 | -keep class com.kingja.loadsir.** {*;}
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/TargetContext.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | /**
8 | * Description:TODO
9 | * Create Time:2017/9/4 16:28
10 | * Author:KingJA
11 | * Email:kingjavip@gmail.com
12 | */
13 | public class TargetContext {
14 | private Context context;
15 | private ViewGroup parentView;
16 | private View oldContent;
17 | private int childIndex;
18 |
19 | public TargetContext(Context context, ViewGroup parentView, View oldContent, int childIndex) {
20 | this.context = context;
21 | this.parentView = parentView;
22 | this.oldContent = oldContent;
23 | this.childIndex = childIndex;
24 | }
25 |
26 | public Context getContext() {
27 | return context;
28 | }
29 |
30 | View getOldContent() {
31 | return oldContent;
32 | }
33 |
34 | int getChildIndex() {
35 | return childIndex;
36 | }
37 |
38 | ViewGroup getParentView() {
39 | return parentView;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/loadsir/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | #-dontwarn com.kingja.loadsir.**
28 | #-keep class com.kingja.loadsir.** {*;}
29 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/callback/SuccessCallback.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | /**
7 | * Description:TODO
8 | * Create Time:2017/9/4 10:22
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 |
13 | public class SuccessCallback extends Callback {
14 | public SuccessCallback(View view, Context context, OnReloadListener onReloadListener) {
15 | super(view, context, onReloadListener);
16 | }
17 |
18 | @Override
19 | protected int onCreateView() {
20 | return 0;
21 | }
22 |
23 | /**
24 | * @deprecated Use {@link #showWithCallback(boolean successVisible)} instead.
25 | */
26 | public void hide() {
27 | obtainRootView().setVisibility(View.INVISIBLE);
28 | }
29 |
30 | public void show() {
31 | obtainRootView().setVisibility(View.VISIBLE);
32 | }
33 |
34 | public void showWithCallback(boolean successVisible) {
35 | obtainRootView().setVisibility(successVisible ? View.VISIBLE : View.INVISIBLE);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/title_title_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
16 |
17 |
23 |
24 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/CustomCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import com.kingja.loadsir.callback.Callback;
8 |
9 | import sample.kingja.loadsir.R;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/3 10:22
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class CustomCallback extends Callback {
18 |
19 | @Override
20 | protected int onCreateView() {
21 | return R.layout.layout_custom;
22 | }
23 |
24 | @Override
25 | protected boolean onReloadEvent(final Context context, View view) {
26 | Toast.makeText(context.getApplicationContext(), "Hello buddy, how r u! :p", Toast.LENGTH_SHORT).show();
27 | (view.findViewById(R.id.iv_gift)).setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | Toast.makeText(context.getApplicationContext(), "It's your gift! :p", Toast.LENGTH_SHORT).show();
31 | }
32 | });
33 | return true;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LoadSir
3 | Activity(empty)
4 | Activity(placeholder)
5 | Activity with Convertor
6 | single Fragment(custom)
7 | multiple Fragment
8 | multiple Fragment+ViewPager
9 | View(timeout)
10 | Animat Callback
11 | keep title bar in Fragment
12 | LoadSir
13 | Success
14 | keep title bar
15 | fine, no data.
16 | click me to retry!
17 | best practices
18 | default LoadSir Callback
19 | keep title bar in Activity
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_mutil.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
11 |
18 |
19 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_best_practices.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
16 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/docs/changelog.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | ---
3 |
4 | **1.3.6**
5 | - [x] modify code in`showWithCallback(boolean successVisible)`, use INVISIBLE instead of GONE thanks @X
6 |
7 | **1.3.5**
8 | - [x] add API `public Class extends Callback> getCurrentCallback()`
9 | - [x] deprecated API `public LinearLayout getTitleLoadLayout(Context context, ViewGroup rootView, View titleView)`
10 |
11 | **1.3.2**
12 | - [x] add API `public boolean getSuccessVisible()` used for displaying callback above successView.
13 | - [x] fix layout fault when register in View.
14 |
15 | **1.3.0**
16 | - [x] in default, addView(SuccessfulView). Hide SuccessfulView instead of removeView(SuccessfulView).
17 | - [x] add default Callback `ProgressCallback`, `HintCallback`.
18 |
19 | **v1.2.2**
20 | - [x] change minSdkVersion 16 to 14 [issues #8](https://github.com/KingJA/LoadSir/issues/8)
21 | - [x] modify callback dynamically [issues #11](https://github.com/KingJA/LoadSir/issues/11) [issues #7](https://github.com/KingJA/LoadSir/issues/7)
22 | - [x] add TitleBar sample [issues #12](https://github.com/KingJA/LoadSir/issues/12)
23 | - [x] add API in Callback [issues #10](https://github.com/KingJA/LoadSir/issues/10)
24 | * protected abstract int onCreateView()
25 | * public void onDetach()
26 | * public void onAttach(Context context, View view)
27 | - [x] make LoadLayout public
28 |
29 | **v1.2.0**
30 | - [x] Improve API naming notations.
31 |
32 | **v1.1.1**
33 | - [x] Initial release .
34 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentB.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 | import android.widget.Toast;
6 |
7 | import butterknife.BindView;
8 | import sample.kingja.loadsir.callback.EmptyCallback;
9 | import sample.kingja.loadsir.callback.LoadingCallback;
10 |
11 | import sample.kingja.loadsir.PostUtil;
12 | import sample.kingja.loadsir.R;
13 | import sample.kingja.loadsir.base.BaseFragment;
14 |
15 | /**
16 | * Description:TODO
17 | * Create Time:2017/9/5 13:27
18 | * Author:KingJA
19 | * Email:kingjavip@gmail.com
20 | */
21 | public class FragmentB extends BaseFragment {
22 | @BindView(R.id.tv_result_b)
23 | TextView mTvResultB;
24 | @Override
25 | protected int onCreateFragmentView() {
26 | return R.layout.fragment_b_content;
27 | }
28 |
29 | @Override
30 | protected void loadNet() {
31 | // do net here...
32 | // call back
33 | PostUtil.postCallbackDelayed(mBaseLoadService, EmptyCallback.class);
34 | }
35 | @Override
36 | protected void onNetReload(View v) {
37 | mTvResultB.setText("Oh, Yes too.");
38 | Toast.makeText(getContext(),"reload in Fragment B",Toast.LENGTH_SHORT).show();
39 | mBaseLoadService.showCallback(LoadingCallback.class);
40 | //do retry logic...
41 |
42 | //callback
43 | PostUtil.postSuccessDelayed(mBaseLoadService);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
36 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/FragmentA.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.ImageView;
5 | import android.widget.TextView;
6 | import android.widget.Toast;
7 |
8 | import butterknife.BindView;
9 | import sample.kingja.loadsir.callback.ErrorCallback;
10 | import sample.kingja.loadsir.callback.LoadingCallback;
11 |
12 | import sample.kingja.loadsir.PostUtil;
13 | import sample.kingja.loadsir.R;
14 | import sample.kingja.loadsir.base.BaseFragment;
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/9/5 13:28
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 | public class FragmentA extends BaseFragment {
23 | @BindView(R.id.tv_result_a)
24 | TextView mTvResultA;
25 | @Override
26 | protected int onCreateFragmentView() {
27 | return R.layout.fragment_a_content;
28 | }
29 |
30 | @Override
31 | protected void loadNet() {
32 | // do net here...
33 | // call back
34 | PostUtil.postCallbackDelayed(mBaseLoadService, ErrorCallback.class);
35 | }
36 |
37 | @Override
38 | protected void onNetReload(View v) {
39 | mTvResultA.setText("Oh, Yes.");
40 | Toast.makeText(getContext(),"reload in Fragment A",Toast.LENGTH_SHORT).show();
41 | mBaseLoadService.showCallback(LoadingCallback.class);
42 | //do retry logic...
43 |
44 | //callback
45 | PostUtil.postSuccessDelayed(mBaseLoadService);
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 |
7 | import sample.kingja.loadsir.R;
8 |
9 | /**
10 | * Description:TODO
11 | * Create Time:2017/9/4 10:56
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 |
16 | public class MultiFragmentActivity extends AppCompatActivity {
17 | private static final String TAG = "FragmentSingleActivity";
18 | private FragmentA fragmentA;
19 | private FragmentB fragmentB;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_fragment_mutil);
25 | fragmentA = new FragmentA();
26 | fragmentB = new FragmentB();
27 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, fragmentA).commit();
28 | getSupportFragmentManager().beginTransaction().add(R.id.fl_content, fragmentB).commit();
29 | getSupportFragmentManager().beginTransaction().show(fragmentA).hide(fragmentB).commit();
30 | }
31 |
32 |
33 | public void showFragmentA(View view) {
34 | getSupportFragmentManager().beginTransaction().show(fragmentA).hide(fragmentB).commit();
35 | }
36 |
37 | public void showFragmentB(View view) {
38 | getSupportFragmentManager().beginTransaction().show(fragmentB).hide(fragmentA).commit();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/PlaceholderActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.core.LoadService;
10 | import com.kingja.loadsir.core.LoadSir;
11 |
12 | import sample.kingja.loadsir.PostUtil;
13 | import sample.kingja.loadsir.R;
14 | import sample.kingja.loadsir.callback.PlaceholderCallback;
15 |
16 |
17 | /**
18 | * Description:TODO
19 | * Create Time:2017/9/3 11:22
20 | * Author:KingJA
21 | * Email:kingjavip@gmail.com
22 | */
23 |
24 | public class PlaceholderActivity extends AppCompatActivity {
25 |
26 | private LoadService loadService;
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_placeholder);
32 | LoadSir loadSir = new LoadSir.Builder()
33 | .addCallback(new PlaceholderCallback())
34 | .setDefaultCallback(PlaceholderCallback.class)
35 | .build();
36 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
37 | @Override
38 | public void onReload(View v) {
39 | //do retry logic...
40 | }
41 | });
42 | PostUtil.postSuccessDelayed(loadService, 1000);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/PostUtil.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import com.kingja.loadsir.callback.Callback;
7 | import com.kingja.loadsir.core.LoadService;
8 |
9 | /**
10 | * Description:TODO
11 | * Create Time:2017/9/4 15:21
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 | public class PostUtil {
16 | private static final int DELAY_TIME = 1000;
17 |
18 | public static void postCallbackDelayed(final LoadService loadService, final Class extends Callback> clazz) {
19 | postCallbackDelayed(loadService, clazz, DELAY_TIME);
20 | }
21 |
22 | public static void postCallbackDelayed(final LoadService loadService, final Class extends Callback> clazz, long
23 | delay) {
24 | new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
25 | @Override
26 | public void run() {
27 | loadService.showCallback(clazz);
28 | }
29 | }, delay);
30 | }
31 |
32 | public static void postSuccessDelayed(final LoadService loadService) {
33 | postSuccessDelayed(loadService, DELAY_TIME);
34 | }
35 |
36 | public static void postSuccessDelayed(final LoadService loadService, long delay) {
37 | new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
38 | @Override
39 | public void run() {
40 | loadService.showSuccess();
41 | }
42 | }, delay);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import butterknife.BindView;
7 | import sample.kingja.loadsir.PostUtil;
8 | import sample.kingja.loadsir.R;
9 | import sample.kingja.loadsir.base.BaseTitleActivity;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 |
13 | /**
14 | * Description:
15 | * Create Time:2017/9/4 10:56
16 | * Author:KingJA
17 | * Email:kingjavip@gmail.com
18 | */
19 |
20 | public class KeepTitleActivity extends BaseTitleActivity {
21 | @BindView(R.id.tv_title)
22 | TextView mTvTitle;
23 |
24 |
25 | @Override
26 | protected String getContentTitle() {
27 | return "Title";
28 | }
29 |
30 | @Override
31 | protected int getContentView() {
32 | return R.layout.activity_content;
33 | }
34 |
35 | @Override
36 | protected void initView() {
37 | TextView mTvMsg = (TextView) findViewById(R.id.tv_subTitle);
38 | mTvMsg.setText("Keep Title In Activity");
39 | mTvTitle.setText("Yes, Success");
40 | }
41 |
42 | @Override
43 | protected void initNet() {
44 | PostUtil.postCallbackDelayed(mBaseLoadService, ErrorCallback.class);
45 | }
46 |
47 | @Override
48 | protected void onNetReload(View v) {
49 | mBaseLoadService.showCallback(LoadingCallback.class);
50 | PostUtil.postSuccessDelayed(mBaseLoadService);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/App.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.app.Application;
4 |
5 | import com.kingja.loadsir.core.LoadSir;
6 | import com.squareup.leakcanary.LeakCanary;
7 |
8 | import sample.kingja.loadsir.callback.CustomCallback;
9 | import sample.kingja.loadsir.callback.EmptyCallback;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 | import sample.kingja.loadsir.callback.TimeoutCallback;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/3 14:02
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 |
21 | public class App extends Application {
22 | @Override
23 | public void onCreate() {
24 | super.onCreate();
25 | if (setupLeakCanary()) {
26 | return;
27 | }
28 |
29 | LoadSir.beginBuilder()
30 | .addCallback(new ErrorCallback())
31 | .addCallback(new EmptyCallback())
32 | .addCallback(new LoadingCallback())
33 | .addCallback(new TimeoutCallback())
34 | .addCallback(new CustomCallback())
35 | .setDefaultCallback(LoadingCallback.class)
36 | .commit();
37 | }
38 |
39 | private boolean setupLeakCanary() {
40 | if (LeakCanary.isInAnalyzerProcess(this)) {
41 | // This process is dedicated to LeakCanary for heap analysis.
42 | // You should not init your app in this process.
43 | return true;
44 | }
45 | LeakCanary.install(this);
46 | return false;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 | import com.kingja.loadsir.core.LoadService;
12 | import com.kingja.loadsir.core.LoadSir;
13 |
14 | import butterknife.ButterKnife;
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/9/6 14:34
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 | public abstract class BaseFragment extends Fragment {
23 |
24 | protected LoadService mBaseLoadService;
25 |
26 | @Nullable
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
29 | savedInstanceState) {
30 | View rootView = View.inflate(getActivity(), onCreateFragmentView(), null);
31 | ButterKnife.bind(this, rootView);
32 | mBaseLoadService = LoadSir.getDefault().register(rootView, new Callback.OnReloadListener() {
33 | @Override
34 | public void onReload(View v) {
35 | onNetReload(v);
36 | }
37 | });
38 | return mBaseLoadService.getLoadLayout();
39 | }
40 |
41 | protected abstract int onCreateFragmentView();
42 |
43 | @Override
44 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
45 | super.onViewCreated(view, savedInstanceState);
46 | loadNet();
47 | }
48 |
49 | protected abstract void loadNet();
50 |
51 | protected abstract void onNetReload(View v);
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/LottieActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.core.LoadService;
10 | import com.kingja.loadsir.core.LoadSir;
11 |
12 | import sample.kingja.loadsir.PostUtil;
13 | import sample.kingja.loadsir.R;
14 | import sample.kingja.loadsir.callback.LottieEmptyCallback;
15 | import sample.kingja.loadsir.callback.LottieLoadingCallback;
16 |
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/4 10:12
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class LottieActivity extends AppCompatActivity {
26 |
27 | private LoadService loadService;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_content);
33 | LoadSir loadSir = new LoadSir.Builder()
34 | .addCallback(new LottieLoadingCallback())
35 | .addCallback(new LottieEmptyCallback())
36 | .setDefaultCallback(LottieLoadingCallback.class)
37 | .build();
38 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
39 | @Override
40 | public void onReload(View v) {
41 | loadService.showCallback(LottieLoadingCallback.class);
42 | PostUtil.postSuccessDelayed(loadService, 1500);
43 | }
44 | });
45 | PostUtil.postCallbackDelayed(loadService, LottieEmptyCallback.class);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/NormalFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 |
12 | import sample.kingja.loadsir.callback.CustomCallback;
13 | import sample.kingja.loadsir.callback.LoadingCallback;
14 |
15 | import com.kingja.loadsir.core.LoadService;
16 | import com.kingja.loadsir.core.LoadSir;
17 |
18 | import sample.kingja.loadsir.PostUtil;
19 | import sample.kingja.loadsir.R;
20 |
21 | /**
22 | * Description:TODO
23 | * Create Time:2017/9/5 13:28
24 | * Author:KingJA
25 | * Email:kingjavip@gmail.com
26 | */
27 | public class NormalFragment extends Fragment {
28 |
29 | private LoadService loadService;
30 | private View rootView;
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
35 | savedInstanceState) {
36 | rootView = View.inflate(getActivity(), R.layout.fragment_a_content, null);
37 | LoadSir loadSir = new LoadSir.Builder()
38 | .addCallback(new CustomCallback())
39 | .addCallback(new LoadingCallback())
40 | .setDefaultCallback(LoadingCallback.class)
41 | .build();
42 | loadService = loadSir.register(rootView);
43 | return loadService.getLoadLayout();
44 | }
45 |
46 | @Override
47 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
48 | super.onViewCreated(view, savedInstanceState);
49 | PostUtil.postCallbackDelayed(loadService, CustomCallback.class);
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 | defaultConfig {
7 | applicationId "sample.kingja.loadsir"
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode rootProject.ext.versionCode
11 | versionName rootProject.ext.versionName
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled true
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | debug {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | compile "com.android.support:design:$rootProject.ext.supportVersion"
29 | compile "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
30 | compile fileTree(include: ['*.jar'], dir: 'libs')
31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
32 | exclude group: 'com.android.support', module: 'support-annotations'
33 | })
34 | testCompile 'junit:junit:4.12'
35 | compile project(':loadsir')
36 | // compile 'com.kingja.loadsir:loadsir:1.3.6'
37 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
38 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
39 | /*ButterKnife*/
40 | compile 'com.jakewharton:butterknife:8.8.1'
41 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
42 | /*lottie*/
43 | compile('com.airbnb.android:lottie:2.2.5') { exclude group: 'com.android.support' }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/ViewTargetActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 |
9 | import sample.kingja.loadsir.callback.LoadingCallback;
10 |
11 | import com.kingja.loadsir.callback.Callback;
12 | import com.kingja.loadsir.core.LoadService;
13 | import com.kingja.loadsir.core.LoadSir;
14 |
15 | import sample.kingja.loadsir.R;
16 | import sample.kingja.loadsir.callback.TimeoutCallback;
17 | import sample.kingja.loadsir.PostUtil;
18 |
19 |
20 | /**
21 | * Description:TODO
22 | * Create Time:2017/9/3 11:22
23 | * Author:KingJA
24 | * Email:kingjavip@gmail.com
25 | */
26 |
27 | public class ViewTargetActivity extends AppCompatActivity {
28 |
29 | private LoadService loadService;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_view);
35 | ImageView imageView = (ImageView) findViewById(R.id.iv_img);
36 | LoadSir loadSir = new LoadSir.Builder()
37 | .addCallback(new TimeoutCallback())
38 | .addCallback(new LoadingCallback())
39 | .setDefaultCallback(LoadingCallback.class)
40 | .build();
41 | loadService = loadSir.register(imageView, new Callback.OnReloadListener() {
42 | @Override
43 | public void onReload(View v) {
44 | loadService.showCallback(LoadingCallback.class);
45 | //do retry logic...
46 |
47 | //callback
48 | PostUtil.postSuccessDelayed(loadService);
49 | }
50 | });
51 | PostUtil.postCallbackDelayed(loadService, TimeoutCallback.class);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/callback/AnimateCallback.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.callback;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.animation.Animation;
6 | import android.view.animation.LinearInterpolator;
7 | import android.view.animation.RotateAnimation;
8 | import android.widget.Toast;
9 |
10 | import com.kingja.loadsir.callback.Callback;
11 |
12 | import sample.kingja.loadsir.R;
13 |
14 | /**
15 | * Description:TODO
16 | * Create Time:2017/9/3 10:22
17 | * Author:KingJA
18 | * Email:kingjavip@gmail.com
19 | */
20 | public class AnimateCallback extends Callback {
21 |
22 | private Context context;
23 | private View animateView;
24 |
25 | @Override
26 | protected int onCreateView() {
27 | return R.layout.layout_animate;
28 | }
29 |
30 | @Override
31 | protected void onViewCreate(Context context, View view) {
32 | super.onViewCreate(context, view);
33 | }
34 |
35 | @Override
36 | public void onAttach(Context context, View view) {
37 | this.context = context;
38 | animateView = view.findViewById(R.id.view_animate);
39 | Animation animation = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF,
40 | 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
41 | animation.setDuration(1000);
42 | animation.setRepeatCount(Integer.MAX_VALUE);
43 | animation.setFillAfter(true);
44 | animation.setInterpolator(new LinearInterpolator());
45 | animateView.startAnimation(animation);
46 | Toast.makeText(context.getApplicationContext(), "start animation", Toast.LENGTH_SHORT).show();
47 | }
48 |
49 | @Override
50 | public void onDetach() {
51 | super.onDetach();
52 | if (animateView != null) {
53 | animateView.clearAnimation();
54 | }
55 | Toast.makeText(context.getApplicationContext(), "stop animation", Toast.LENGTH_SHORT).show();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/MultiFragmentWithViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.TabLayout;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentManager;
7 | import android.support.v4.app.FragmentPagerAdapter;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v7.app.AppCompatActivity;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import sample.kingja.loadsir.R;
15 |
16 | /**
17 | * Description:TODO
18 | * Create Time:2017/9/4 10:56
19 | * Author:KingJA
20 | * Email:kingjavip@gmail.com
21 | */
22 |
23 | public class MultiFragmentWithViewPagerActivity extends AppCompatActivity {
24 | private Listfragments=new ArrayList<>();
25 | private String[]tabTitles={"Fragment A","Fragment B"};
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_fragment_viewpager);
30 | ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager);
31 | TabLayout tablayout = (TabLayout) findViewById(R.id.tablayout);
32 |
33 | fragments.add(new FragmentA());
34 | fragments.add(new FragmentB());
35 | viewpager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
36 |
37 | tablayout.setupWithViewPager(viewpager);
38 | tablayout.setTabMode(TabLayout.MODE_FIXED);
39 |
40 | }
41 |
42 | private class PagerAdapter extends FragmentPagerAdapter {
43 |
44 | PagerAdapter(FragmentManager fm) {
45 | super(fm);
46 | }
47 |
48 | @Override
49 | public Fragment getItem(int position) {
50 | return fragments.get(position);
51 | }
52 |
53 | @Override
54 | public int getCount() {
55 | return fragments.size();
56 | }
57 |
58 | @Override
59 | public CharSequence getPageTitle(int position) {
60 | return tabTitles[position];
61 | }
62 | }
63 |
64 |
65 |
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/DefaultCallbackActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.callback.HintCallback;
10 | import com.kingja.loadsir.callback.ProgressCallback;
11 | import com.kingja.loadsir.core.LoadService;
12 | import com.kingja.loadsir.core.LoadSir;
13 |
14 | import sample.kingja.loadsir.PostUtil;
15 | import sample.kingja.loadsir.R;
16 |
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/9/4 10:12
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 |
25 | public class DefaultCallbackActivity extends AppCompatActivity {
26 |
27 | private LoadService loadService;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_content);
33 |
34 | ProgressCallback loadingCallback = new ProgressCallback.Builder()
35 | .setTitle("Loading", R.style.Hint_Title)
36 | // .setAboveSuccess(true)// attach loadingView above successView
37 | .build();
38 |
39 | HintCallback hintCallback = new HintCallback.Builder()
40 | .setTitle("Error", R.style.Hint_Title)
41 | .setSubTitle("Sorry, buddy, I will try it again.")
42 | .setHintImg(R.drawable.error)
43 | .build();
44 |
45 | LoadSir loadSir = new LoadSir.Builder()
46 | .addCallback(loadingCallback)
47 | .addCallback(hintCallback)
48 | .setDefaultCallback(ProgressCallback.class)
49 | .build();
50 |
51 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
52 | @Override
53 | public void onReload(View v) {
54 | loadService.showCallback(ProgressCallback.class);
55 | PostUtil.postSuccessDelayed(loadService);
56 |
57 | }
58 | });
59 | PostUtil.postCallbackDelayed(loadService, HintCallback.class);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/AnimateActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.os.SystemClock;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 | import com.kingja.loadsir.callback.Callback;
10 | import com.kingja.loadsir.core.LoadService;
11 | import com.kingja.loadsir.core.LoadSir;
12 |
13 | import sample.kingja.loadsir.PostUtil;
14 | import sample.kingja.loadsir.R;
15 | import sample.kingja.loadsir.callback.AnimateCallback;
16 | import sample.kingja.loadsir.callback.EmptyCallback;
17 | import sample.kingja.loadsir.callback.LoadingCallback;
18 |
19 |
20 | /**
21 | * Description:TODO
22 | * Create Time:2017/9/4 10:12
23 | * Author:KingJA
24 | * Email:kingjavip@gmail.com
25 | */
26 |
27 | public class AnimateActivity extends AppCompatActivity {
28 |
29 |
30 | private LoadService loadService;
31 |
32 | @Override
33 | protected void onCreate(@Nullable Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_content);
36 | // Your can change the callback on sub thread directly.
37 | LoadSir loadSir = new LoadSir.Builder()
38 | .addCallback(new EmptyCallback())
39 | .addCallback(new AnimateCallback())
40 | .setDefaultCallback(AnimateCallback.class)
41 | .build();
42 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
43 | @Override
44 | public void onReload(View v) {
45 | // Your can change the status out of Main thread.
46 | new Thread(new Runnable() {
47 | @Override
48 | public void run() {
49 | loadService.showCallback(AnimateCallback.class);
50 | //do retry logic...
51 | SystemClock.sleep(500);
52 | //callback on sub thread
53 | loadService.showSuccess();
54 | }
55 | }).start();
56 | }
57 | });
58 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1000);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
20 |
21 |
26 |
27 |
33 |
34 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
54 |
55 |
66 |
67 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/LoadSirUtil.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Looper;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.kingja.loadsir.core.TargetContext;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/4 16:24
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class LoadSirUtil {
18 | public static TargetContext getTargetContext(Object target) {
19 | ViewGroup contentParent;
20 | Context context;
21 | if (target instanceof Activity) {
22 | Activity activity = (Activity) target;
23 | context = activity;
24 | contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
25 | } else if (target instanceof View) {
26 | View view = (View) target;
27 | contentParent = (ViewGroup) (view.getParent());
28 | context = view.getContext();
29 | } else {
30 | throw new IllegalArgumentException("The target must be within Activity, Fragment, View.");
31 | }
32 | int childIndex = 0;
33 | int childCount = contentParent == null ? 0 : contentParent.getChildCount();
34 | View oldContent;
35 | if (target instanceof View) {
36 | oldContent = (View) target;
37 | for (int i = 0; i < childCount; i++) {
38 | if (contentParent.getChildAt(i) == oldContent) {
39 | childIndex = i;
40 | break;
41 | }
42 | }
43 | } else {
44 | oldContent = contentParent != null ? contentParent.getChildAt(0) : null;
45 | }
46 | if (oldContent == null) {
47 | throw new IllegalArgumentException(String.format("enexpected error when register LoadSir in %s", target
48 | .getClass().getSimpleName()));
49 | }
50 | if (contentParent != null) {
51 | contentParent.removeView(oldContent);
52 | }
53 | return new TargetContext(context, contentParent, oldContent, childIndex);
54 | }
55 |
56 | public static boolean isMainThread() {
57 | return Looper.myLooper() == Looper.getMainLooper();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/NormalActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.SystemClock;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import sample.kingja.loadsir.callback.EmptyCallback;
12 | import sample.kingja.loadsir.callback.LoadingCallback;
13 |
14 | import com.kingja.loadsir.callback.Callback;
15 | import com.kingja.loadsir.core.LoadService;
16 | import com.kingja.loadsir.core.LoadSir;
17 | import com.kingja.loadsir.core.Transport;
18 |
19 | import sample.kingja.loadsir.R;
20 | import sample.kingja.loadsir.PostUtil;
21 |
22 |
23 | /**
24 | * Description:TODO
25 | * Create Time:2017/9/4 10:12
26 | * Author:KingJA
27 | * Email:kingjavip@gmail.com
28 | */
29 |
30 | public class NormalActivity extends AppCompatActivity {
31 |
32 | private LoadService loadService;
33 |
34 | @Override
35 | protected void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_content);
38 | // Your can change the callback on sub thread directly.
39 | loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
40 | @Override
41 | public void onReload(View v) {
42 | // Your can change the status out of Main thread.
43 | new Thread(new Runnable() {
44 | @Override
45 | public void run() {
46 | loadService.showCallback(LoadingCallback.class);
47 | //do retry logic...
48 | SystemClock.sleep(500);
49 | //callback
50 | loadService.showSuccess();
51 | }
52 | }).start();
53 | }
54 | }).setCallBack(EmptyCallback.class, new Transport() {
55 | @Override
56 | public void order(Context context, View view) {
57 | TextView mTvEmpty = (TextView) view.findViewById(R.id.tv_empty);
58 | mTvEmpty.setText("fine, no data. You must fill it!");
59 | }
60 | });
61 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
55 |
56 |
61 |
62 |
67 |
68 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/KeepTitleFragment.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 |
12 | import com.kingja.loadsir.callback.Callback;
13 | import com.kingja.loadsir.core.LoadService;
14 | import com.kingja.loadsir.core.LoadSir;
15 |
16 | import butterknife.BindView;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 | import butterknife.Unbinder;
20 | import sample.kingja.loadsir.PostUtil;
21 | import sample.kingja.loadsir.R;
22 | import sample.kingja.loadsir.callback.EmptyCallback;
23 | import sample.kingja.loadsir.callback.LoadingCallback;
24 |
25 | /**
26 | * Description:
27 | * Create Time:2017/9/26 14:33
28 | * Author:KingJA
29 | * Email:kingjavip@gmail.com
30 | */
31 | public class KeepTitleFragment extends Fragment {
32 |
33 | private LoadService loadService;
34 | @BindView(R.id.iv_back)
35 | ImageView mIvBack;
36 | private Unbinder unBinder;
37 | private ViewGroup rootView;
38 |
39 | @OnClick(R.id.iv_back)
40 | public void onBack() {
41 | getActivity().finish();
42 | }
43 |
44 | @Override
45 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
46 | super.onViewCreated(view, savedInstanceState);
47 | LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
48 | LoadSir loadSir = new LoadSir.Builder()
49 | .addCallback(new EmptyCallback())
50 | .addCallback(new LoadingCallback())
51 | .setDefaultCallback(LoadingCallback.class)
52 | .build();
53 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
54 | @Override
55 | public void onReload(View v) {
56 | loadService.showSuccess();
57 | }
58 | });
59 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
60 | }
61 |
62 | @Nullable
63 | @Override
64 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
65 | savedInstanceState) {
66 | rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
67 | unBinder = ButterKnife.bind(this, rootView);
68 | return rootView;
69 | }
70 |
71 | @Override
72 | public void onDetach() {
73 | super.onDetach();
74 | unBinder.unbind();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/docs/FAQ-cn.md:
--------------------------------------------------------------------------------
1 | 常见问题
2 | ---
3 |
4 | 如果下列问题中,你有更好的解决方法,欢迎对docs/FAQ-cn.md 发起pull request。
5 |
6 | ### #1 如何和ButterKnife配合使用?
7 |
8 | in Activity
9 |
10 | ```java
11 |
12 | public class BufferKnifeActivity extends AppCompatActivity {
13 | @BindView(R.id.tv_msg)
14 | TextView mTv_msg;
15 | private LoadService loadService;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ButterKnife.bind(this);
22 |
23 | LoadSir loadSir = new LoadSir.Builder()
24 | .addCallback(new EmptyCallback())
25 | .build();
26 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
27 | @Override
28 | public void onReload(View v) {
29 | //TODO
30 | }
31 |
32 | });
33 | loadService.showCallback(EmptyCallback.class);
34 | }
35 | }
36 |
37 | ```
38 |
39 | in Fragment
40 |
41 | ```java
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
45 | savedInstanceState) {
46 | View rootView = View.inflate(getActivity(), R.layout.fragment_bk, null);
47 | ButterKnife.bind(this, rootView);
48 |
49 | LoadSir loadSir = new LoadSir.Builder()
50 | .addCallback(new EmptyCallback())
51 | .build();
52 | loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | //TODO
56 | }
57 |
58 | });
59 | return loadService.getLoadLayout();
60 | }
61 | ```
62 |
63 | ### #2 如果保留原布局的标题栏(toolbar,或者titileView)?
64 | 在Activity,在Fragment中,只要注册toolbar,或者titileView以下的布局View即可,这样LoadSir就会保留标题栏。
65 | 在Fragment,请看参考代码:
66 | ```java
67 | @Override
68 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
69 | super.onViewCreated(view, savedInstanceState);
70 | LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
71 | LoadSir loadSir = new LoadSir.Builder()
72 | .addCallback(new EmptyCallback())
73 | .addCallback(new LoadingCallback())
74 | .setDefaultCallback(LoadingCallback.class)
75 | .build();
76 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
77 | @Override
78 | public void onReload(View v) {
79 | loadService.showSuccess();
80 | }
81 | });
82 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
83 | }
84 | ```
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/LoadSir.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.kingja.loadsir.LoadSirUtil;
6 | import com.kingja.loadsir.callback.Callback;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Description:TODO
13 | * Create Time:2017/9/2 16:36
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class LoadSir {
18 | private static volatile LoadSir loadSir;
19 | private Builder builder;
20 |
21 | public static LoadSir getDefault() {
22 | if (loadSir == null) {
23 | synchronized (LoadSir.class) {
24 | if (loadSir == null) {
25 | loadSir = new LoadSir();
26 | }
27 | }
28 | }
29 | return loadSir;
30 | }
31 |
32 | private LoadSir() {
33 | this.builder = new Builder();
34 | }
35 |
36 | private void setBuilder(@NonNull Builder builder) {
37 | this.builder = builder;
38 | }
39 |
40 | private LoadSir(Builder builder) {
41 | this.builder = builder;
42 | }
43 |
44 | public LoadService register(@NonNull Object target) {
45 | return register(target, null, null);
46 | }
47 |
48 | public LoadService register(Object target, Callback.OnReloadListener onReloadListener) {
49 | return register(target, onReloadListener, null);
50 | }
51 |
52 | public LoadService register(Object target, Callback.OnReloadListener onReloadListener, Convertor
53 | convertor) {
54 | TargetContext targetContext = LoadSirUtil.getTargetContext(target);
55 | return new LoadService<>(convertor, targetContext, onReloadListener, builder);
56 | }
57 |
58 | public static Builder beginBuilder() {
59 | return new Builder();
60 | }
61 |
62 | public static class Builder {
63 | private List callbacks = new ArrayList<>();
64 | private Class extends Callback> defaultCallback;
65 |
66 | public Builder addCallback(@NonNull Callback callback) {
67 | callbacks.add(callback);
68 | return this;
69 | }
70 |
71 | public Builder setDefaultCallback(@NonNull Class extends Callback> defaultCallback) {
72 | this.defaultCallback = defaultCallback;
73 | return this;
74 | }
75 |
76 | List getCallbacks() {
77 | return callbacks;
78 | }
79 |
80 | Class extends Callback> getDefaultCallback() {
81 | return defaultCallback;
82 | }
83 |
84 | public void commit() {
85 | getDefault().setBuilder(this);
86 | }
87 |
88 | public LoadSir build() {
89 | return new LoadSir(this);
90 | }
91 |
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/base/BaseTitleActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 | import android.widget.LinearLayout;
9 | import android.widget.TextView;
10 |
11 | import com.kingja.loadsir.callback.Callback;
12 | import com.kingja.loadsir.core.LoadService;
13 | import com.kingja.loadsir.core.LoadSir;
14 |
15 | import butterknife.ButterKnife;
16 | import sample.kingja.loadsir.R;
17 |
18 | /**
19 | * Description:TODO
20 | * Create Time:2017/3/20 14:17
21 | * Author:KingJA
22 | * Email:kingjavip@gmail.com
23 | */
24 | public abstract class BaseTitleActivity extends AppCompatActivity {
25 | protected View rootView;
26 | protected LoadService mBaseLoadService;
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | rootView = View.inflate(this, R.layout.activity_title, null);
32 | addContent();
33 | setContentView(rootView);
34 | initView();
35 | initNet();
36 | }
37 |
38 |
39 | private void addContent() {
40 | FrameLayout flContent = (FrameLayout) rootView.findViewById(R.id.fl_content);
41 | TextView tvTitleTitle = (TextView) rootView.findViewById(R.id.tv_title_title);
42 | LinearLayout llTitleBack = (LinearLayout) rootView.findViewById(R.id.ll_title_back);
43 | tvTitleTitle.setText(getContentTitle() == null ? "" : getContentTitle());
44 | llTitleBack.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | backClick();
48 | }
49 | });
50 | View content = View.inflate(this, getContentView(), null);
51 | if (content != null) {
52 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
53 | FrameLayout.LayoutParams.MATCH_PARENT);
54 | flContent.addView(content, params);
55 | ButterKnife.bind(this, rootView);
56 | mBaseLoadService = LoadSir.getDefault().register(content, new Callback.OnReloadListener() {
57 | @Override
58 | public void onReload(View v) {
59 | onNetReload(v);
60 | }
61 | });
62 | }
63 | }
64 |
65 | private void backClick() {
66 | finish();
67 | }
68 |
69 | protected abstract String getContentTitle();
70 |
71 | protected abstract int getContentView();
72 |
73 | protected abstract void initView();
74 |
75 | protected abstract void initNet();
76 |
77 | protected abstract void onNetReload(View v);
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/MainActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import sample.kingja.loadsir.target.AnimateActivity;
9 | import sample.kingja.loadsir.target.BestPracticesActivity;
10 | import sample.kingja.loadsir.target.DefaultCallbackActivity;
11 | import sample.kingja.loadsir.target.KeepTitleActivity;
12 | import sample.kingja.loadsir.target.KeepTitleFragmentActivity;
13 | import sample.kingja.loadsir.target.MultiFragmentActivity;
14 | import sample.kingja.loadsir.target.FragmentSingleActivity;
15 | import sample.kingja.loadsir.target.NormalActivity;
16 | import sample.kingja.loadsir.target.ConvertorActivity;
17 | import sample.kingja.loadsir.target.MultiFragmentWithViewPagerActivity;
18 | import sample.kingja.loadsir.target.PlaceholderActivity;
19 | import sample.kingja.loadsir.target.ViewTargetActivity;
20 |
21 | /**
22 | * Description:TODO
23 | * Create Time:2017/9/2 16:02
24 | * Author:KingJA
25 | * Email:kingjavip@gmail.com
26 | */
27 |
28 | public class MainActivity extends AppCompatActivity {
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | }
35 |
36 | public void inActivity(View view) {
37 | startActivity(new Intent(this, NormalActivity.class));
38 | }
39 |
40 | public void showPlaceholder(View view) {
41 | startActivity(new Intent(this, PlaceholderActivity.class));
42 | }
43 |
44 | public void inActivityWithConvertor(View view) {
45 | startActivity(new Intent(this, ConvertorActivity.class));
46 | }
47 |
48 | public void inFragment(View view) {
49 | startActivity(new Intent(this, FragmentSingleActivity.class));
50 | }
51 |
52 | public void inFragmentMutil(View view) {
53 | startActivity(new Intent(this, MultiFragmentActivity.class));
54 | }
55 |
56 | public void inFragmentViewSirPager(View view) {
57 | startActivity(new Intent(this, MultiFragmentWithViewPagerActivity.class));
58 | }
59 |
60 | public void inView(View view) {
61 | startActivity(new Intent(this, ViewTargetActivity.class));
62 | }
63 |
64 | public void defaultCallback(View view) {
65 | startActivity(new Intent(this, DefaultCallbackActivity.class));
66 | }
67 |
68 | public void animatCallback(View view) {
69 | startActivity(new Intent(this, AnimateActivity.class));
70 | }
71 |
72 | public void keepTitleInFragment(View view) {
73 | startActivity(new Intent(this, KeepTitleFragmentActivity.class));
74 | }
75 |
76 | public void bestPractices(View view) {
77 | startActivity(new Intent(this, BestPracticesActivity.class));
78 | }
79 |
80 | public void keepTitleInActivity(View view) {
81 | startActivity(new Intent(this, KeepTitleActivity.class));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/docs/FAQ.md:
--------------------------------------------------------------------------------
1 | FAQ
2 | ---
3 |
4 | If you have better solutions about the questions below, welcome to push pull requests to me.
5 |
6 | ### #1 How to use with ButterKnife?
7 |
8 | * ###### in Activity
9 |
10 | ```java
11 |
12 | public class BufferKnifeActivity extends AppCompatActivity {
13 | @BindView(R.id.tv_msg)
14 | TextView mTv_msg;
15 | private LoadService loadService;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ButterKnife.bind(this);
22 |
23 | LoadSir loadSir = new LoadSir.Builder()
24 | .addCallback(new EmptyCallback())
25 | .build();
26 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
27 | @Override
28 | public void onReload(View v) {
29 | //TODO
30 | }
31 |
32 | });
33 | loadService.showCallback(EmptyCallback.class);
34 | }
35 | }
36 |
37 | ```
38 |
39 | * ###### in Fragment
40 |
41 | ```java
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
45 | savedInstanceState) {
46 | View rootView = View.inflate(getActivity(), R.layout.fragment_bk, null);
47 | ButterKnife.bind(this, rootView);
48 |
49 | LoadSir loadSir = new LoadSir.Builder()
50 | .addCallback(new EmptyCallback())
51 | .build();
52 | loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | //TODO
56 | }
57 |
58 | });
59 | return loadService.getLoadLayout();
60 | }
61 | ```
62 |
63 | ### #2 How to keep the toolbar in Fragment?
64 | ```java
65 | @Override
66 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
67 | super.onViewCreated(view, savedInstanceState);
68 | //fetch contentView View,the View except toolbar or titleView.
69 | LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
70 | LoadSir loadSir = new LoadSir.Builder()
71 | .addCallback(new EmptyCallback())
72 | .addCallback(new LoadingCallback())
73 | .setDefaultCallback(LoadingCallback.class)
74 | .build();
75 | loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
76 | @Override
77 | public void onReload(View v) {
78 | loadService.showSuccess();
79 | }
80 | });
81 | PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
82 | }
83 | ```
84 |
85 | If you have a better idea, please let me know. I'm very interested to improve LoadSir in any way. Thanks for your help.
86 |
87 |
88 | ### #3 `setDefaultCallback(...)` vs `addCallback(...)`
89 | What's the purpose of a `DefaultCallback`?
90 |
91 | With `setDefaultCallback(...)` you set the **first** visible "view" for LoadSir.
92 | With `addCallback(...)` you could set other "views" for different purposes.
93 | Normally you have the use case to show a loading view/ProgressBar, therefore you should use `setDefaultCallback("your LoadingCallback")`.
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/loadsir/src/main/java/com/kingja/loadsir/core/LoadService.java:
--------------------------------------------------------------------------------
1 | package com.kingja.loadsir.core;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.LinearLayout;
7 |
8 | import com.kingja.loadsir.callback.Callback;
9 | import com.kingja.loadsir.callback.SuccessCallback;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Description:TODO
15 | * Create Time:2017/9/6 10:05
16 | * Author:KingJA
17 | * Email:kingjavip@gmail.com
18 | */
19 | public class LoadService {
20 | private LoadLayout loadLayout;
21 | private Convertor convertor;
22 |
23 | LoadService(Convertor convertor, TargetContext targetContext, Callback.OnReloadListener onReloadListener,
24 | LoadSir.Builder builder) {
25 | this.convertor = convertor;
26 | Context context = targetContext.getContext();
27 | View oldContent = targetContext.getOldContent();
28 | ViewGroup.LayoutParams oldLayoutParams = oldContent.getLayoutParams();
29 | loadLayout = new LoadLayout(context, onReloadListener);
30 | loadLayout.setupSuccessLayout(new SuccessCallback(oldContent, context,
31 | onReloadListener));
32 | if (targetContext.getParentView() != null) {
33 | targetContext.getParentView().addView(loadLayout, targetContext.getChildIndex(), oldLayoutParams);
34 | }
35 | initCallback(builder);
36 | }
37 |
38 | private void initCallback(LoadSir.Builder builder) {
39 | List callbacks = builder.getCallbacks();
40 | Class extends Callback> defalutCallback = builder.getDefaultCallback();
41 | if (callbacks != null && callbacks.size() > 0) {
42 | for (Callback callback : callbacks) {
43 | loadLayout.setupCallback(callback);
44 | }
45 | }
46 | if (defalutCallback != null) {
47 | loadLayout.showCallback(defalutCallback);
48 | }
49 | }
50 |
51 | public void showSuccess() {
52 | loadLayout.showCallback(SuccessCallback.class);
53 | }
54 |
55 | public void showCallback(Class extends Callback> callback) {
56 | loadLayout.showCallback(callback);
57 | }
58 |
59 | public void showWithConvertor(T t) {
60 | if (convertor == null) {
61 | throw new IllegalArgumentException("You haven't set the Convertor.");
62 | }
63 | loadLayout.showCallback(convertor.map(t));
64 | }
65 |
66 | public LoadLayout getLoadLayout() {
67 | return loadLayout;
68 | }
69 |
70 | public Class extends Callback> getCurrentCallback() {
71 | return loadLayout.getCurrentCallback();
72 | }
73 |
74 | /**
75 | * obtain rootView if you want keep the toolbar in Fragment
76 | * @since 1.2.2
77 | * @deprecated
78 | */
79 | public LinearLayout getTitleLoadLayout(Context context, ViewGroup rootView, View titleView) {
80 | LinearLayout newRootView = new LinearLayout(context);
81 | newRootView.setOrientation(LinearLayout.VERTICAL);
82 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
83 | ViewGroup.LayoutParams.MATCH_PARENT);
84 | newRootView.setLayoutParams(layoutParams);
85 | rootView.removeView(titleView);
86 | newRootView.addView(titleView);
87 | newRootView.addView(loadLayout, layoutParams);
88 | return newRootView;
89 | }
90 |
91 | /**
92 | * modify the callback dynamically
93 | *
94 | * @param callback which callback you want modify(layout, event)
95 | * @param transport a interface include modify logic
96 | * @since 1.2.2
97 | */
98 | public LoadService setCallBack(Class extends Callback> callback, Transport transport) {
99 | loadLayout.setCallBack(callback, transport);
100 | return this;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/kingja/loadsir/target/ConvertorActivity.java:
--------------------------------------------------------------------------------
1 | package sample.kingja.loadsir.target;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 | import sample.kingja.loadsir.callback.EmptyCallback;
10 | import sample.kingja.loadsir.callback.ErrorCallback;
11 | import sample.kingja.loadsir.callback.LoadingCallback;
12 |
13 | import com.kingja.loadsir.callback.Callback;
14 | import com.kingja.loadsir.callback.SuccessCallback;
15 | import com.kingja.loadsir.core.LoadService;
16 | import com.kingja.loadsir.core.LoadSir;
17 |
18 | import com.kingja.loadsir.core.Convertor;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.Random;
23 |
24 | import sample.kingja.loadsir.R;
25 | import sample.kingja.loadsir.PostUtil;
26 |
27 |
28 | /**
29 | * Description:TODO
30 | * Create Time:2017/9/4 10:35
31 | * Author:KingJA
32 | * Email:kingjavip@gmail.com
33 | */
34 |
35 | public class ConvertorActivity extends AppCompatActivity {
36 |
37 | private LoadService loadService;
38 | private HttpResult mHttpResult = new HttpResult(new Random().nextInt(2), new ArrayList<>());
39 | private static final int SUCCESS_CODE = 0x00;
40 | private static final int ERROR_CODE = 0x01;
41 |
42 | @Override
43 | protected void onCreate(@Nullable Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_activity_convertor);
46 | LoadSir loadSir = new LoadSir.Builder()
47 | .addCallback(new LoadingCallback())
48 | .addCallback(new EmptyCallback())
49 | .addCallback(new ErrorCallback())
50 | .setDefaultCallback(LoadingCallback.class)
51 | .build();
52 | loadService = loadSir.register(this, new Callback.OnReloadListener() {
53 | @Override
54 | public void onReload(View v) {
55 | loadService.showCallback(LoadingCallback.class);
56 | PostUtil.postCallbackDelayed(loadService, SuccessCallback.class);
57 | }
58 | }, new Convertor() {
59 | @Override
60 | public Class extends Callback> map(HttpResult httpResult) {
61 | Class extends Callback> resultCode = SuccessCallback.class;
62 | switch (httpResult.getResultCode()) {
63 | //成功回调
64 | case SUCCESS_CODE:
65 | if (httpResult.getData().size() == 0) {
66 | resultCode = EmptyCallback.class;
67 | } else {
68 | resultCode = SuccessCallback.class;
69 | }
70 | break;
71 | case ERROR_CODE:
72 | resultCode = ErrorCallback.class;
73 | break;
74 | default:
75 | resultCode = ErrorCallback.class;
76 | }
77 | return resultCode;
78 | }
79 | });
80 | new Handler().postDelayed(new Runnable() {
81 | @Override
82 | public void run() {
83 | // do net here...
84 |
85 | //callback
86 | loadService.showWithConvertor(mHttpResult);
87 | }
88 | }, 500);
89 | }
90 |
91 | private class HttpResult {
92 | private int resultCode;
93 | private List