Skip to content

Commit d6cb96e

Browse files
committed
combine utils and initial context by ContentProvider
1 parent 24ef852 commit d6cb96e

File tree

13 files changed

+77
-81
lines changed

13 files changed

+77
-81
lines changed

app/app.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.jakewharton/butterknife/8.5.1/jars" />
9999
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.4-beta2/jars" />
100100
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.tbruyelle.rxpermissions/rxpermissions/0.9.2/jars" />
101-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/org.lzh.nonview.updateplugin/UpdatePlugin/2.0/jars" />
102101
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
103102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
104103
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
@@ -135,7 +134,7 @@
135134
<orderEntry type="library" exported="" name="leakcanary-watcher-1.4-beta2" level="project" />
136135
<orderEntry type="library" exported="" name="appcompat-v7-25.1.0" level="project" />
137136
<orderEntry type="library" exported="" name="support-core-utils-25.1.0" level="project" />
138-
<orderEntry type="library" exported="" name="UpdatePlugin-2.0" level="project" />
139137
<orderEntry type="library" exported="" name="leakcanary-android-1.4-beta2" level="project" />
138+
<orderEntry type="module" module-name="updatepluginlib" exported="" />
140139
</component>
141140
</module>

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ android {
2424
dependencies {
2525
compile fileTree(dir: 'libs', include: ['*.jar'])
2626
testCompile 'junit:junit:4.12'
27-
// compile project(':updatepluginlib')
27+
compile project(':updatepluginlib')
2828
compile 'com.android.support:appcompat-v7:25.1.0'
29-
compile 'org.lzh.nonview.updateplugin:UpdatePlugin:2.0'
29+
// compile 'org.lzh.nonview.updateplugin:UpdatePlugin:2.0'
3030
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
3131
compile 'com.jakewharton:butterknife:8.5.1'
3232
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

app/src/main/java/org/lzh/framework/updateplugin/MyApplication.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.lzh.framework.updateplugin;
22

33
import android.app.Application;
4-
import android.widget.Toast;
54

65
import org.json.JSONException;
76
import org.json.JSONObject;
@@ -11,7 +10,7 @@
1110
import org.lzh.framework.updatepluginlib.callback.UpdateDownloadCB;
1211
import org.lzh.framework.updatepluginlib.model.Update;
1312
import org.lzh.framework.updatepluginlib.model.UpdateParser;
14-
import org.lzh.framework.updatepluginlib.util.HandlerUtil;
13+
import org.lzh.framework.updatepluginlib.util.Utils;
1514

1615
import java.io.File;
1716

@@ -27,8 +26,6 @@ public void onCreate() {
2726
// 对于没传的参数,会默认使用UpdateConfig中的全局配置
2827
ToastTool.init(this);
2928
UpdateConfig.getConfig()
30-
// 必填:初始化一个Application框架内使用
31-
.init(this)
3229
// 必填:数据更新接口,url与checkEntity两种方式任选一种填写
3330
.url("https://raw.githubusercontent.com/yjfnypeu/UpdatePlugin/master/update.json")
3431
// .checkEntity(new CheckEntity().setMethod(HttpMethod.GET).setUrl("http://www.baidu.com"))
@@ -86,7 +83,7 @@ public void onCheckIgnore(Update update) {
8683
public void onCheckStart() {
8784
// 此方法的回调所处线程异于其他回调。其他回调所处线程为UI线程。
8885
// 此方法所处线程为你启动更新任务是所在线程
89-
HandlerUtil.getMainHandler().post(new Runnable() {
86+
Utils.getMainHandler().post(new Runnable() {
9087
@Override
9188
public void run() {
9289
ToastTool.show("启动更新任务");

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/business/DownloadWorker.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.lzh.framework.updatepluginlib.business;
22

3-
import org.lzh.framework.updatepluginlib.UpdateBuilder;
43
import org.lzh.framework.updatepluginlib.callback.UpdateDownloadCB;
54
import org.lzh.framework.updatepluginlib.model.Update;
6-
import org.lzh.framework.updatepluginlib.util.HandlerUtil;
75
import org.lzh.framework.updatepluginlib.util.Recyclable;
6+
import org.lzh.framework.updatepluginlib.util.Utils;
87

98
import java.io.File;
109

@@ -64,7 +63,7 @@ public void run() {
6463
private void sendUpdateStart() {
6564
if (downloadCB == null) return;
6665

67-
HandlerUtil.getMainHandler().post(new Runnable() {
66+
Utils.getMainHandler().post(new Runnable() {
6867
@Override
6968
public void run() {
7069
downloadCB.onUpdateStart();
@@ -75,7 +74,7 @@ public void run() {
7574
protected void sendUpdateProgress(final long current, final long total) {
7675
if (downloadCB == null) return;
7776

78-
HandlerUtil.getMainHandler().post(new Runnable() {
77+
Utils.getMainHandler().post(new Runnable() {
7978
@Override
8079
public void run() {
8180
downloadCB.onUpdateProgress(current, total);
@@ -86,7 +85,7 @@ public void run() {
8685
private void sendUpdateComplete(final File file) {
8786
if (downloadCB == null) return;
8887

89-
HandlerUtil.getMainHandler().post(new Runnable() {
88+
Utils.getMainHandler().post(new Runnable() {
9089
@Override
9190
public void run() {
9291
downloadCB.onUpdateComplete(file);
@@ -98,7 +97,7 @@ public void run() {
9897
private void sendUpdateError (final int code, final String errorMsg) {
9998
if (downloadCB == null) return;
10099

101-
HandlerUtil.getMainHandler().post(new Runnable() {
100+
Utils.getMainHandler().post(new Runnable() {
102101
@Override
103102
public void run() {
104103
downloadCB.onUpdateError(code,errorMsg);

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/business/UpdateWorker.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import org.lzh.framework.updatepluginlib.model.Update;
77
import org.lzh.framework.updatepluginlib.model.UpdateChecker;
88
import org.lzh.framework.updatepluginlib.model.UpdateParser;
9-
import org.lzh.framework.updatepluginlib.util.HandlerUtil;
109
import org.lzh.framework.updatepluginlib.util.Recyclable;
10+
import org.lzh.framework.updatepluginlib.util.Utils;
1111

1212
/**
1313
* The network task to check out whether or not a new version of apk is exist
@@ -79,7 +79,7 @@ public void run() {
7979

8080
private void sendHasUpdate(final Update update) {
8181
if (checkCB == null) return;
82-
HandlerUtil.getMainHandler().post(new Runnable() {
82+
Utils.getMainHandler().post(new Runnable() {
8383
@Override
8484
public void run() {
8585
checkCB.hasUpdate(update);
@@ -90,7 +90,7 @@ public void run() {
9090

9191
private void sendNoUpdate() {
9292
if (checkCB == null) return;
93-
HandlerUtil.getMainHandler().post(new Runnable() {
93+
Utils.getMainHandler().post(new Runnable() {
9494
@Override
9595
public void run() {
9696
checkCB.noUpdate();
@@ -101,7 +101,7 @@ public void run() {
101101

102102
private void sendOnErrorMsg(final int code, final String errorMsg) {
103103
if (checkCB == null) return;
104-
HandlerUtil.getMainHandler().post(new Runnable() {
104+
Utils.getMainHandler().post(new Runnable() {
105105
@Override
106106
public void run() {
107107
checkCB.onCheckError(code,errorMsg);

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/creator/InstallCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import org.lzh.framework.updatepluginlib.UpdateConfig;
77
import org.lzh.framework.updatepluginlib.callback.UpdateCheckCB;
88
import org.lzh.framework.updatepluginlib.model.Update;
9-
import org.lzh.framework.updatepluginlib.util.InstallUtil;
109
import org.lzh.framework.updatepluginlib.util.Recyclable;
1110
import org.lzh.framework.updatepluginlib.util.UpdatePreference;
11+
import org.lzh.framework.updatepluginlib.util.Utils;
1212

1313
public abstract class InstallCreator implements Recyclable {
1414

@@ -36,7 +36,7 @@ public void setUpdate(Update update) {
3636
*/
3737
public void sendToInstall(String filename) {
3838
if (installChecker == null || installChecker.check(update,filename)) {
39-
InstallUtil.installApk(UpdateConfig.getConfig().getContext(),filename);
39+
Utils.installApk(UpdateConfig.getConfig().getContext(),filename);
4040
} else {
4141
checkCB.onCheckError(-1,String.format("apk %s checked failed",filename));
4242
}

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/model/DefaultChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.lzh.framework.updatepluginlib.model;
22

33
import org.lzh.framework.updatepluginlib.UpdateConfig;
4-
import org.lzh.framework.updatepluginlib.util.InstallUtil;
54
import org.lzh.framework.updatepluginlib.util.UpdatePreference;
5+
import org.lzh.framework.updatepluginlib.util.Utils;
66

77
public class DefaultChecker implements UpdateChecker {
88
@Override
99
public boolean check(Update update) {
1010
try {
11-
int curVersion = InstallUtil.getApkVersion(UpdateConfig.getConfig().getContext());
11+
int curVersion = Utils.getApkVersion(UpdateConfig.getConfig().getContext());
1212
if (update.getVersionCode() > curVersion &&
1313
(update.isForced()||
1414
!UpdatePreference.getIgnoreVersions().contains(String.valueOf(update.getVersionCode())))) {

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/strategy/WifiFirstStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.lzh.framework.updatepluginlib.strategy;
22

33
import org.lzh.framework.updatepluginlib.model.Update;
4-
import org.lzh.framework.updatepluginlib.util.NetworkUtil;
4+
import org.lzh.framework.updatepluginlib.util.Utils;
55

66
public class WifiFirstStrategy implements UpdateStrategy {
77

88
private boolean isWifi;
99

1010
@Override
1111
public boolean isShowUpdateDialog(Update update) {
12-
isWifi = NetworkUtil.isConnectedByWifi();
12+
isWifi = Utils.isConnectedByWifi();
1313
return !isWifi;
1414
}
1515

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/HandlerUtil.java

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

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/NetworkUtil.java

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

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/UpdateInstallProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import android.content.ContentProvider;
44
import android.content.ContentValues;
5+
import android.content.Context;
6+
import android.content.pm.ProviderInfo;
57
import android.database.Cursor;
68
import android.net.Uri;
79
import android.os.ParcelFileDescriptor;
810

11+
import org.lzh.framework.updatepluginlib.UpdateConfig;
12+
913
import java.io.File;
1014
import java.io.FileNotFoundException;
1115
import java.io.IOException;
@@ -24,6 +28,12 @@ public boolean onCreate() {
2428
return false;
2529
}
2630

31+
@Override
32+
public void attachInfo(Context context, ProviderInfo info) {
33+
super.attachInfo(context, info);
34+
UpdateConfig.getConfig().init(context);
35+
}
36+
2737
@Override
2838
public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) {
2939
return null;

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/InstallUtil.java renamed to updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/Utils.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
import android.content.Intent;
66
import android.content.pm.PackageInfo;
77
import android.content.pm.PackageManager;
8+
import android.net.ConnectivityManager;
9+
import android.net.NetworkInfo;
810
import android.net.Uri;
911
import android.os.Build;
12+
import android.os.Handler;
13+
import android.os.Looper;
1014
import android.text.TextUtils;
1115

16+
import org.lzh.framework.updatepluginlib.UpdateConfig;
17+
1218
import java.io.File;
1319

14-
/**
15-
* @author Administrator
16-
*/
17-
public class InstallUtil {
20+
public class Utils {
1821

1922
private static final int REQUEST_INSTALL = 0x010101;
2023
private static String DEFAULT_AUTHOR = null;
@@ -56,4 +59,30 @@ public static int getApkVersion (Context context) throws PackageManager.NameNotF
5659
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
5760
return packageInfo.versionCode;
5861
}
62+
63+
/**
64+
* Determine whether to use wifi
65+
* @return true if is connected by wifi
66+
*/
67+
public static boolean isConnectedByWifi() {
68+
NetworkInfo info = getNetworkInfos();
69+
return info != null
70+
&& info.isConnected()
71+
&& info.getType() == ConnectivityManager.TYPE_WIFI;
72+
}
73+
74+
private static NetworkInfo getNetworkInfos() {
75+
Context context = UpdateConfig.getConfig().getContext();
76+
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
77+
return connManager.getActiveNetworkInfo();
78+
}
79+
80+
private static Handler handler;
81+
public static Handler getMainHandler() {
82+
if (handler == null) {
83+
handler = new Handler(Looper.getMainLooper());
84+
}
85+
return handler;
86+
}
87+
5988
}

updatepluginlib/updatepluginlib.iml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6868
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6969
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
76-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
77-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
7971
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
8072
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
@@ -83,16 +75,30 @@
8375
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
8476
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
8577
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
84+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
85+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8787
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
8890
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
91+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
92+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8993
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
9094
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
9195
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
9296
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
9397
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
9498
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
99+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
95100
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
101+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
96102
</content>
97103
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
98104
<orderEntry type="sourceFolder" forTests="false" />

0 commit comments

Comments
 (0)