Skip to content

Commit 784d68a

Browse files
committed
Improve comment
1 parent 0af1875 commit 784d68a

File tree

7 files changed

+74
-57
lines changed

7 files changed

+74
-57
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ compile 'me.jessyan:rxerrorhandler:1.0.1' //rxjava1
3232
}
3333
Log.w(TAG, "Error handle");
3434
}
35-
}).build(); //
35+
}).build();
3636
```
3737

3838
## Usage
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2017 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package me.jessyan.rxerrorhandler.demo;
17+
18+
import android.app.Application;
19+
import android.content.Context;
20+
import android.net.ParseException;
21+
import android.util.Log;
22+
23+
import org.json.JSONException;
24+
25+
import java.net.SocketTimeoutException;
26+
import java.net.UnknownHostException;
27+
28+
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
29+
import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener;
30+
31+
import static android.content.ContentValues.TAG;
32+
33+
/**
34+
* ================================================
35+
* Created by JessYan on 22/09/2017 15:01
36+
* Contact with <mailto:jess.yan.effort@gmail.com>
37+
* Follow me on <https://github.com/JessYanCoding>
38+
* ================================================
39+
*/
40+
public class App extends Application {
41+
42+
private RxErrorHandler mRxErrorHandler;
43+
44+
@Override
45+
public void onCreate() {
46+
super.onCreate();
47+
//Initialization
48+
mRxErrorHandler = RxErrorHandler
49+
.builder()
50+
.with(this)
51+
.responseErrorListener(new ResponseErrorListener() {
52+
@Override
53+
public void handleResponseError(Context context, Throwable t) {
54+
if (t instanceof UnknownHostException) {
55+
//do something ...
56+
} else if (t instanceof SocketTimeoutException) {
57+
//do something ...
58+
} else if (t instanceof ParseException || t instanceof JSONException) {
59+
//do something ...
60+
} else {
61+
//handle other Exception ...
62+
}
63+
Log.w(TAG, "Error handle");
64+
}
65+
}).build();
66+
}
67+
68+
public RxErrorHandler getRxErrorHandler() {
69+
return mRxErrorHandler;
70+
}
71+
}

β€Žapp/src/main/java/me/jessyan/rxerrorhandler/demo/MainActivity.javaβ€Ž

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@
1515
*/
1616
package me.jessyan.rxerrorhandler.demo;
1717

18-
import android.content.Context;
19-
import android.net.ParseException;
2018
import android.os.Bundle;
2119
import android.support.v7.app.AppCompatActivity;
22-
import android.util.Log;
23-
24-
import org.json.JSONException;
25-
26-
import java.net.SocketTimeoutException;
27-
import java.net.UnknownHostException;
2820

2921
import io.reactivex.Observable;
3022
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
3123
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
3224
import me.jessyan.rxerrorhandler.handler.RetryWithDelay;
33-
import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener;
3425

3526
/**
3627
* ================================================
@@ -47,25 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
4738
super.onCreate(savedInstanceState);
4839
setContentView(R.layout.activity_main);
4940

50-
RxErrorHandler rxErrorHandler = RxErrorHandler
51-
.builder()
52-
.with(this)
53-
.responseErrorListener(new ResponseErrorListener() {
54-
@Override
55-
public void handleResponseError(Context context, Throwable t) {
56-
if (t instanceof UnknownHostException) {
57-
//do something ...
58-
} else if (t instanceof SocketTimeoutException) {
59-
//do something ...
60-
} else if (t instanceof ParseException || t instanceof JSONException) {
61-
//do something ...
62-
} else {
63-
//handle other Exception ...
64-
}
65-
Log.w(TAG, "Error handle");
66-
}
67-
}).build();
68-
41+
RxErrorHandler rxErrorHandler = ((App) getApplicationContext()).getRxErrorHandler();
6942
Observable
7043
.error(new Exception("Error"))
7144
.retryWhen(new RetryWithDelay(3, 2))//retry(http connect timeout)

β€Žbuild.gradleβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ buildscript {
1414
allprojects {
1515
repositories {
1616
jcenter()
17+
maven { url "https://maven.google.com" }
1718
}
1819
}
1920

-52.4 KB
Binary file not shown.

β€Žrxerrorhandler/src/androidTest/java/me/jessyan/rxerrorhandler/ApplicationTest.javaβ€Ž

Lines changed: 0 additions & 13 deletions
This file was deleted.

β€Žrxerrorhandler/src/test/java/me/jessyan/rxerrorhandler/ExampleUnitTest.javaβ€Ž

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
Β (0)