1
- package com .surcumference .fingerprint .network .updateCheck .github ;
1
+ package com .surcumference .fingerprint .network .update .github ;
2
2
3
3
import android .text .TextUtils ;
4
4
5
5
import com .google .gson .Gson ;
6
6
import com .surcumference .fingerprint .BuildConfig ;
7
- import com .surcumference .fingerprint .Constant ;
8
7
import com .surcumference .fingerprint .Lang ;
9
8
import com .surcumference .fingerprint .R ;
10
9
import com .surcumference .fingerprint .bean .UpdateInfo ;
11
10
import com .surcumference .fingerprint .network .inf .UpdateResultListener ;
12
- import com .surcumference .fingerprint .network .updateCheck .BaseUpdateChecker ;
13
- import com .surcumference .fingerprint .network .updateCheck .github .bean .GithubAssetsInfo ;
14
- import com .surcumference .fingerprint .network .updateCheck .github .bean .GithubLatestInfo ;
11
+ import com .surcumference .fingerprint .network .update .BaseUpdateChecker ;
12
+ import com .surcumference .fingerprint .network .update .github .bean .GithubAssetsInfo ;
13
+ import com .surcumference .fingerprint .network .update .github .bean .GithubLatestInfo ;
15
14
import com .surcumference .fingerprint .util .DateUtils ;
16
15
import com .surcumference .fingerprint .util .StringUtils ;
17
16
import com .surcumference .fingerprint .util .log .L ;
32
31
public class GithubUpdateChecker extends BaseUpdateChecker {
33
32
34
33
public static OkHttpClient sHttpClient = new OkHttpClient ();
34
+ private final String mLocalVersion ;
35
+ private final String mUpdateUrl ;
35
36
36
- public GithubUpdateChecker (UpdateResultListener listener ) {
37
+ public GithubUpdateChecker (String localVersion , String updateUrl , UpdateResultListener listener ) {
37
38
super (listener );
39
+ this .mLocalVersion = localVersion ;
40
+ this .mUpdateUrl = updateUrl ;
38
41
}
39
42
40
43
@ Override
@@ -43,7 +46,7 @@ public void doUpdateCheck() {
43
46
callback = new Callback () {
44
47
@ Override
45
48
public void onFailure (Call call , IOException e ) {
46
- onNetErr ();
49
+ onNetErr (e );
47
50
}
48
51
49
52
@ Override
@@ -53,32 +56,32 @@ public void onResponse(Call call, Response response) throws IOException {
53
56
response .close ();
54
57
try {
55
58
GithubLatestInfo info = new Gson ().fromJson (replay , GithubLatestInfo .class );
56
- if (info != null ) {
57
- if (info .isDataComplete ()) {
58
- if (BuildConfig .DEBUG || StringUtils .isAppNewVersion (BuildConfig .VERSION_NAME , info .version )) {
59
- L .d ("info" , info );
60
- String content = appendUpdateExtInfo (info .content , info .date , info .contentUrl );
61
- L .d ("content" , content );
62
- GithubAssetsInfo assetsInfo = info .getDownloadAssetsInfo ();
63
- UpdateInfo updateInfo = new UpdateInfo (info .version , content ,
64
- info .contentUrl , assetsInfo .url , assetsInfo .name , assetsInfo .size );
65
- onHasUpdate (updateInfo );
66
- } else {
67
- onNoUpdate ();
68
- }
69
- return ;
70
- }
59
+ if (!info .isDataComplete ()) {
60
+ onNetErr (new IllegalArgumentException ("data not complete!" ));
61
+ return ;
71
62
}
63
+ if (BuildConfig .DEBUG || StringUtils .isAppNewVersion (mLocalVersion , info .version )) {
64
+ L .d ("info" , info );
65
+ String content = appendUpdateExtInfo (info .content , info .date , info .contentUrl );
66
+ L .d ("content" , content );
67
+ GithubAssetsInfo assetsInfo = info .getDownloadAssetsInfo ();
68
+ UpdateInfo updateInfo = new UpdateInfo (info .version , content ,
69
+ info .contentUrl , assetsInfo .url , assetsInfo .name , assetsInfo .size );
70
+ onHasUpdate (updateInfo );
71
+ } else {
72
+ onNoUpdate ();
73
+ }
74
+ return ;
72
75
} catch (Exception e ) {
73
76
L .d (e );
74
77
}
75
78
}
76
- onNetErr ();
79
+ onNetErr (new IOException ( "response not successful. code: " + response . code ()) );
77
80
}
78
81
};
79
82
80
83
Request request = new Request .Builder ()
81
- .url (Constant . UPDATE_URL_GITHUB )
84
+ .url (this . mUpdateUrl )
82
85
.build ();
83
86
sHttpClient .newCall (request ).enqueue (callback );
84
87
}
0 commit comments