1- package com .surcumference .fingerprint .network .updateCheck .github ;
1+ package com .surcumference .fingerprint .network .update .github ;
22
33import android .text .TextUtils ;
44
55import com .google .gson .Gson ;
66import com .surcumference .fingerprint .BuildConfig ;
7- import com .surcumference .fingerprint .Constant ;
87import com .surcumference .fingerprint .Lang ;
98import com .surcumference .fingerprint .R ;
109import com .surcumference .fingerprint .bean .UpdateInfo ;
1110import 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 ;
1514import com .surcumference .fingerprint .util .DateUtils ;
1615import com .surcumference .fingerprint .util .StringUtils ;
1716import com .surcumference .fingerprint .util .log .L ;
3231public class GithubUpdateChecker extends BaseUpdateChecker {
3332
3433 public static OkHttpClient sHttpClient = new OkHttpClient ();
34+ private final String mLocalVersion ;
35+ private final String mUpdateUrl ;
3536
36- public GithubUpdateChecker (UpdateResultListener listener ) {
37+ public GithubUpdateChecker (String localVersion , String updateUrl , UpdateResultListener listener ) {
3738 super (listener );
39+ this .mLocalVersion = localVersion ;
40+ this .mUpdateUrl = updateUrl ;
3841 }
3942
4043 @ Override
@@ -43,7 +46,7 @@ public void doUpdateCheck() {
4346 callback = new Callback () {
4447 @ Override
4548 public void onFailure (Call call , IOException e ) {
46- onNetErr ();
49+ onNetErr (e );
4750 }
4851
4952 @ Override
@@ -53,32 +56,32 @@ public void onResponse(Call call, Response response) throws IOException {
5356 response .close ();
5457 try {
5558 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 ;
7162 }
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 ;
7275 } catch (Exception e ) {
7376 L .d (e );
7477 }
7578 }
76- onNetErr ();
79+ onNetErr (new IOException ( "response not successful. code: " + response . code ()) );
7780 }
7881 };
7982
8083 Request request = new Request .Builder ()
81- .url (Constant . UPDATE_URL_GITHUB )
84+ .url (this . mUpdateUrl )
8285 .build ();
8386 sHttpClient .newCall (request ).enqueue (callback );
8487 }
0 commit comments