Skip to content

Commit 08b7e7d

Browse files
committed
Merge branch 'dev_androidx'
2 parents 2d4a5af + dd302fd commit 08b7e7d

32 files changed

+1213
-1411
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4+
ext.kotlin_version = "1.4.0"
5+
46
repositories {
57
jcenter()
68
maven {
@@ -10,6 +12,8 @@ buildscript {
1012
}
1113
dependencies {
1214
classpath 'com.android.tools.build:gradle:3.5.0'
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16+
1317
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
1418
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1519
// classpath 'me.tatarka:gradle-retrolambda:3.2.5'

library/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24
android {
35
compileSdkVersion 29
4-
buildToolsVersion "29.0.3"
6+
// buildToolsVersion "29.0.3"
57
resourcePrefix "versionchecklib"
68
defaultConfig {
79
minSdkVersion 14
@@ -24,7 +26,7 @@ android {
2426

2527
dependencies {
2628
implementation fileTree(include: ['*.jar'], dir: 'libs')
27-
implementation 'androidx.appcompat:appcompat:1.1.0'
29+
compileOnly 'androidx.appcompat:appcompat:1.1.0'
2830
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
2931
implementation 'org.greenrobot:eventbus:3.1.1'
3032

library/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
android:name=".core.MyService"
4040
android:enabled="true"
4141

42-
android:exported="true" />
42+
android:exported="false" />
4343
<service
4444
android:name=".v2.ui.VersionService"
4545
android:exported="false"

library/src/main/java/com/allenliu/versionchecklib/callback/DownloadListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Created by allenliu on 2017/8/16.
77
*/
88

9-
public interface DownloadListener {
9+
public interface DownloadListener {
1010
void onCheckerDownloading(int progress);
1111
void onCheckerDownloadSuccess(File file);
1212
void onCheckerDownloadFail();

library/src/main/java/com/allenliu/versionchecklib/core/VersionDialogActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,5 @@ public void showCustomDialog() {
371371

372372
}
373373

374+
374375
}

library/src/main/java/com/allenliu/versionchecklib/utils/FileHelper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.allenliu.versionchecklib.utils;
22

33
import android.content.Context;
4+
import android.os.Build;
45
import android.os.Environment;
56

6-
import java.io.File;
7-
87
import androidx.annotation.NonNull;
98

9+
import java.io.File;
10+
1011
public class FileHelper {
1112
@Deprecated
1213
public static String getDownloadApkCachePath() {
@@ -30,7 +31,11 @@ public static String getDownloadApkCachePath() {
3031
public static String getDownloadApkCachePath(Context context) {
3132
String appCachePath;
3233
if (checkSDCard()) {
33-
appCachePath = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/AllenVersionPath/";
34+
if (Build.VERSION.SDK_INT >= 29) {
35+
appCachePath = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/AllenVersionPath/";
36+
} else {
37+
appCachePath = context.getExternalCacheDir() + "/AllenVersionPath/";
38+
}
3439

3540
} else {
3641
appCachePath = context.getFilesDir().getAbsolutePath() + "/AllenVersionPath/";

library/src/main/java/com/allenliu/versionchecklib/v2/builder/BuilderManager.java

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.allenliu.versionchecklib.v2.builder
2+
3+
import android.content.Context
4+
import com.allenliu.versionchecklib.R
5+
import com.allenliu.versionchecklib.core.DownloadManager
6+
import com.allenliu.versionchecklib.utils.ALog
7+
import com.allenliu.versionchecklib.v2.AllenVersionChecker
8+
import java.io.File
9+
10+
/**
11+
* @author : shengliu7
12+
* @e-mail : shengliu7@iflytek.com
13+
* @date : 2020/12/19 12:34 PM
14+
* @desc :
15+
*
16+
*/
17+
object BuilderManager {
18+
private var downloadBuilder: DownloadBuilder? = null
19+
lateinit var context: Context
20+
fun getDownloadBuilder(): DownloadBuilder? {
21+
return downloadBuilder
22+
}
23+
24+
fun init(context: Context, downloadBuilder: DownloadBuilder): BuilderManager {
25+
this.context = context
26+
this.downloadBuilder = downloadBuilder
27+
return this
28+
}
29+
30+
fun destroy() {
31+
downloadBuilder = null
32+
}
33+
34+
/**
35+
* 验证安装包是否存在,并且在安装成功情况下删除安装包
36+
*/
37+
fun checkAndDeleteAPK() {
38+
doWhenNotNull {
39+
//判断versioncode与当前版本不一样的apk是否存在,存在删除安装包
40+
try {
41+
val downloadPath: String = downloadAPKPath + context.getString(R.string.versionchecklib_download_apkname, context.packageName)
42+
if (!DownloadManager.checkAPKIsExists(context, downloadPath)) {
43+
ALog.e("删除本地apk")
44+
File(downloadPath).delete()
45+
}
46+
} catch (e: Exception) {
47+
e.printStackTrace()
48+
}
49+
}
50+
51+
}
52+
53+
fun checkForceUpdate() {
54+
doWhenNotNull {
55+
forceUpdateListener?.onShouldForceUpdate()
56+
}
57+
}
58+
59+
fun <T> doWhenNotNull(nullBlock: (() -> T)? = null, block: DownloadBuilder.() -> T): T? {
60+
val builder = downloadBuilder
61+
if (builder != null) {
62+
return builder.block()
63+
64+
} else {
65+
nullBlock?.invoke()
66+
AllenVersionChecker.getInstance().cancelAllMission()
67+
}
68+
return null
69+
}
70+
71+
}

library/src/main/java/com/allenliu/versionchecklib/v2/builder/DownloadBuilder.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.content.pm.ApplicationInfo;
55
import android.content.pm.PackageManager;
6-
import android.os.Environment;
76

87
import androidx.annotation.NonNull;
98

@@ -307,11 +306,7 @@ public DownloadBuilder setDirectDownload(boolean directDownload) {
307306
return this;
308307
}
309308

310-
public void executeMission(Context context) {
311-
if (apkName == null) {
312-
apkName = context.getApplicationContext().getPackageName();
313-
}
314-
309+
private void setupDefaultNotificationIcon(Context context) {
315310
if (notificationBuilder.getIcon() == 0) {
316311
final PackageManager pm = context.getPackageManager();
317312
final ApplicationInfo applicationInfo;
@@ -323,6 +318,14 @@ public void executeMission(Context context) {
323318
e.printStackTrace();
324319
}
325320
}
321+
}
322+
323+
public void executeMission(Context context) {
324+
if (apkName == null) {
325+
//https://github.com/AlexLiuSheng/CheckVersionLib/issues/338
326+
apkName = context.getApplicationContext().getPackageName().replaceAll("\\.", "");
327+
}
328+
setupDefaultNotificationIcon(context);
326329
//fix path permission
327330
setupDownloadPath(context);
328331
// downloadAPKPath=context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath() + "/";
@@ -342,7 +345,7 @@ private void setupDownloadPath(Context context) {
342345
}
343346

344347
public void download(Context context) {
345-
VersionService.enqueueWork(context.getApplicationContext(), this);
348+
VersionService.Companion.enqueueWork(context.getApplicationContext(), this);
346349
}
347350

348351
private boolean checkWhetherNeedRequestVersion() {
@@ -352,21 +355,4 @@ private boolean checkWhetherNeedRequestVersion() {
352355
return false;
353356
}
354357

355-
public void destory() {
356-
setCustomDownloadFailedListener(null);
357-
setCustomDownloadingDialogListener(null);
358-
setCustomVersionDialogListener(null);
359-
setForceUpdateListener(null);
360-
setApkDownloadListener(null);
361-
setOnCancelListener(null);
362-
setReadyDownloadCommitClickListener(null);
363-
setDownloadFailedCommitClickListener(null);
364-
setReadyDownloadCancelListener(null);
365-
setDownloadingCancelListener(null);
366-
setDownloadFailedCancelListener(null);
367-
368-
if (getRequestVersionBuilder() != null)
369-
getRequestVersionBuilder().destory();
370-
requestVersionBuilder = null;
371-
}
372358
}

library/src/main/java/com/allenliu/versionchecklib/v2/builder/RequestVersionBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ public DownloadBuilder request(RequestVersionListener requestVersionListener) {
7070
return new DownloadBuilder(this, null);
7171
}
7272

73-
public void destory() {
74-
requestVersionListener = null;
75-
}
73+
7674

7775
}

library/src/main/java/com/allenliu/versionchecklib/v2/builder/VersionCheckBinder.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.allenliu.versionchecklib.v2.callback
2+
3+
import com.allenliu.versionchecklib.callback.DownloadListener
4+
5+
/**
6+
* @author : shengliu7
7+
* @e-mail : shengliu7@iflytek.com
8+
* @date : 2020/12/19 2:51 PM
9+
* @desc :
10+
*
11+
*/
12+
interface DownloadListenerKt : DownloadListener, LifecycleListener {
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.allenliu.versionchecklib.v2.callback
2+
3+
import com.allenliu.versionchecklib.v2.builder.BuilderManager
4+
5+
/**
6+
* @author : shengliu7
7+
* @e-mail : shengliu7@iflytek.com
8+
* @date : 2020/12/19 2:18 PM
9+
* @desc :
10+
*
11+
*/
12+
interface LifecycleListener {
13+
fun isDisposed() =
14+
BuilderManager.getDownloadBuilder() == null
15+
16+
}

library/src/main/java/com/allenliu/versionchecklib/v2/callback/RequestVersionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Created by allenliu on 2018/1/12.
1010
*/
1111

12-
public interface RequestVersionListener {
12+
public interface RequestVersionListener {
1313
/**
1414
* @param result the result string of request
1515
* @return developer should return version bundle ,to use when showing UI page,could be null

0 commit comments

Comments
 (0)