Skip to content

Commit

Permalink
fixbug
Browse files Browse the repository at this point in the history
  • Loading branch information
caikaidev committed Mar 25, 2017
1 parent d9e7b60 commit d764f1c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android app update library

```groovy
dependencies {
compile 'com.github.fccaikai:AppUpdate:2.0.3'
compile 'com.github.fccaikai:AppUpdate:2.0.4'
}
```

Expand Down
10 changes: 5 additions & 5 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Android 检查更新库

### 屏幕截图

![](https://ww3.sinaimg.cn/large/006tNbRwgy1fdhug16dnhj30km0b4glu.jpg)
![](https://ww3.sinaimg.cn/large/006tNbRwgy1fdhug16dnhj30km0b4glu.jpg)



Expand Down Expand Up @@ -33,7 +33,7 @@ Android 检查更新库

```groovy
dependencies {
compile 'com.github.fccaikai:AppUpdate:2.0.3'
compile 'com.github.fccaikai:AppUpdate:2.0.4'
}
```

Expand Down Expand Up @@ -86,7 +86,7 @@ updateWrapper.start();
Activity需要设置为Dialog主题,在```Androidmanifest.xml```中注册Activity中设置主题

```xml
<activity
<activity
android:name=".CustomsUpdateActivity"
android:theme="@style/UpdateDialog">
</activity>
Expand Down Expand Up @@ -150,9 +150,9 @@ updateWrapper.start();
具体使用请查看[demo](https://github.com/fccaikai/AppUpdate/blob/master/app/src/main/java/com/kcode/appupdate/MainActivity.java)
### 依赖的库

- v7-support
- v7-support

```compile 'com.android.support:appcompat-v7:25.2.0'```
```compile 'com.android.support:appcompat-v7:25.2.0'```

- okhttp

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/kcode/appupdate/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void onGrant() {
public void callBack(VersionModel model) {
Log.d(TAG,"new version :" + model.getVersionName());
}

@Override
public void isLatestVersion() {

}
});

if (cls != null) {
Expand Down
23 changes: 6 additions & 17 deletions lib/src/main/java/com/kcode/lib/UpdateWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.widget.Toast;

import com.kcode.lib.bean.VersionModel;
import com.kcode.lib.common.Constant;
import com.kcode.lib.dialog.UpdateActivity;
import com.kcode.lib.log.L;
import com.kcode.lib.net.CheckUpdateTask;
import com.kcode.lib.utils.PackageUtils;
import com.kcode.lib.utils.PublicFunctionUtils;

/**
Expand Down Expand Up @@ -45,26 +43,17 @@ public void start() {
new CheckUpdateTask(url, new CheckUpdateTask.Callback() {
@Override
public void callBack(VersionModel model) {
if (model == null) {
Toast.makeText(mContext, "最新版本", Toast.LENGTH_SHORT).show();
return;
}
//记录本次更新时间
PublicFunctionUtils.setLastCheckTime(mContext, System.currentTimeMillis());
callBackIfHasNewVersion(model);
mCallback.callBack(model);
start2Activity(mContext, model);
}
}).start();
}

private void callBackIfHasNewVersion(VersionModel model) {
if (model == null) {
return;
}
if (PackageUtils.getVersionCode(mContext) < model.getVersionCode()
&& mCallback != null) {
mCallback.callBack(model);
}
@Override
public void isLatestVersion() {
mCallback.isLatestVersion();
}
}).start();
}

private boolean checkUpdateTime(long time) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/main/java/com/kcode/lib/net/CheckUpdateTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void run() {
mOkHttpClient.newCall(request).enqueue(new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException e) {
mCallBack.callBack(null);
mCallBack.isLatestVersion();
}

@Override
Expand All @@ -56,5 +56,7 @@ public void onResponse(Call call, Response response) throws IOException {

public interface Callback {
void callBack(VersionModel model);

void isLatestVersion();
}
}

0 comments on commit d764f1c

Please sign in to comment.