Skip to content

Commit 1079a03

Browse files
committed
see 05/25 log
1 parent e3842d2 commit 1079a03

File tree

10 files changed

+91
-31
lines changed

10 files changed

+91
-31
lines changed

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
* `20/05/21` [add] Publish bus plugin v2.6. Publish api plugin v1.4. Publish. Publish 1.28.5.
1+
* `20/05/23` [fix] BusUtils#postSticky times not right. Publish v1.28.6.
2+
* `20/05/22` [add] IntentUtils#getInstallAppIntent support Uri param. Publish.
3+
* `20/05/21` [add] Publish bus plugin v2.6. Publish api plugin v1.4. Publish. Publish v1.28.5.
24
* `20/05/19` [fix] FileUtils#copyOrMoveDird NPE.
35
* `20/05/18` [add] IntentUtils#getLaunchAppDetailsSettingsIntent support isNewTask.
46
* `20/05/17` [add] ImageUtils#save2Album, NetworkUtils#getSSID, UtilsTransActivity4MainProcess.
5-
* `20/05/03` [add] Publish bus plugin v2.5. Publish api plugin v1.3. Publish. Publish 1.28.4.
7+
* `20/05/03` [add] Publish bus plugin v2.5. Publish api plugin v1.3. Publish. Publish v1.28.4.
68
* `20/04/30` [add] BaseItem support partialUpdate.
79
* `20/04/29` [add] Publish plugin lib com.blankj:base-transform:1.0.
810
* `20/04/28` [fix] LanguageUtils#applyLanguage.
911
* `20/04/27` [fix] BarUtils#isNavBarVisible.
10-
* `20/04/26` [fix] Utils#init fit tinker. Publish 1.28.3.
12+
* `20/04/26` [fix] Utils#init fit tinker. Publish v1.28.3.
1113
* `20/04/25` [fix] UriUtils#uri2File Unknown URI. Publish 1.28.2.
1214
* `20/04/24` [add] SnackbarUtils support show on the top; UriUtils#uri2InputStream.
1315
* `20/04/23` [fix] UriUtils#uri2File not support HW; TransActivity crash below 21.

buildSrc/src/main/groovy/Config.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Config {
1414
static compileSdkVersion = 29
1515
static minSdkVersion = 14
1616
static targetSdkVersion = 29
17-
static versionCode = 1_028_005
18-
static versionName = '1.28.5'// E.g. 1.9.72 => 1,009,072
17+
static versionCode = 1_028_006
18+
static versionName = '1.28.6'// E.g. 1.9.72 => 1,009,072
1919

2020
// lib version
2121
static gradlePluginVersion = '3.5.0'

feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.blankj.utilcode.pkg.feature.bus
22

33
import android.content.Context
44
import android.content.Intent
5-
import android.os.Bundle
65
import android.support.annotation.Keep
76
import com.blankj.common.activity.CommonActivity
87
import com.blankj.common.item.CommonItem

lib/utilcode/README-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.28.5'
5+
implementation 'com.blankj:utilcode:1.28.6'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.28.5'
8+
implementation 'com.blankj:utilcodex:1.28.6'
99
```
1010

1111

lib/utilcode/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.28.5'
5+
implementation 'com.blankj:utilcode:1.28.6'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.28.5'
8+
implementation 'com.blankj:utilcodex:1.28.6'
99
```
1010

1111

lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.content.pm.PackageManager;
1111
import android.content.pm.Signature;
1212
import android.graphics.drawable.Drawable;
13+
import android.net.Uri;
1314
import android.support.annotation.NonNull;
1415
import android.util.Log;
1516

@@ -68,8 +69,22 @@ public static void installApp(final String filePath) {
6869
* @param file The file.
6970
*/
7071
public static void installApp(final File file) {
71-
if (!UtilsBridge.isFileExists(file)) return;
72-
Utils.getApp().startActivity(UtilsBridge.getInstallAppIntent(file));
72+
Intent installAppIntent = UtilsBridge.getInstallAppIntent(file);
73+
if (installAppIntent == null) return;
74+
Utils.getApp().startActivity(installAppIntent);
75+
}
76+
77+
/**
78+
* Install the app.
79+
* <p>Target APIs greater than 25 must hold
80+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
81+
*
82+
* @param uri The uri.
83+
*/
84+
public static void installApp(final Uri uri) {
85+
Intent installAppIntent = UtilsBridge.getInstallAppIntent(uri);
86+
if (installAppIntent == null) return;
87+
Utils.getApp().startActivity(installAppIntent);
7388
}
7489

7590
/**

lib/utilcode/src/main/java/com/blankj/utilcode/util/BusUtils.java

+21-11
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private void processSticky(final Object bus) {
147147
if (tagArgMap == null) return;
148148
synchronized (mClassName_Tag_Arg4StickyMap) {
149149
for (Map.Entry<String, Object> tagArgEntry : tagArgMap.entrySet()) {
150-
postInner(tagArgEntry.getKey(), tagArgEntry.getValue());
150+
postStickyInner(tagArgEntry.getKey(), tagArgEntry.getValue(), true);
151151
}
152152
}
153153
}
@@ -176,15 +176,19 @@ private void postInner(final String tag, final Object arg, final boolean sticky)
176176
return;
177177
}
178178
for (BusInfo busInfo : busInfoList) {
179-
if (busInfo.method == null) {
180-
Method method = getMethodByBusInfo(busInfo);
181-
if (method == null) {
182-
return;
183-
}
184-
busInfo.method = method;
179+
invokeBus(tag, arg, busInfo, sticky);
180+
}
181+
}
182+
183+
private void invokeBus(String tag, Object arg, BusInfo busInfo, boolean sticky) {
184+
if (busInfo.method == null) {
185+
Method method = getMethodByBusInfo(busInfo);
186+
if (method == null) {
187+
return;
185188
}
186-
invokeMethod(tag, arg, busInfo, sticky);
189+
busInfo.method = method;
187190
}
191+
invokeMethod(tag, arg, busInfo, sticky);
188192
}
189193

190194
private Method getMethodByBusInfo(BusInfo busInfo) {
@@ -287,15 +291,21 @@ private void realInvokeMethod(final String tag, Object arg, BusInfo busInfo, boo
287291
}
288292

289293
private void postStickyInner(final String tag, final Object arg) {
294+
postStickyInner(tag, arg, false);
295+
}
296+
297+
private void postStickyInner(final String tag, final Object arg, boolean isInvokeOnlySticky) {
290298
List<BusInfo> busInfoList = mTag_BusInfoListMap.get(tag);
291299
if (busInfoList == null) {
292300
Log.e(TAG, "The bus of tag <" + tag + "> is not exists.");
293301
return;
294302
}
295303
for (BusInfo busInfo : busInfoList) {
296304
if (!busInfo.sticky) { // not sticky bus will post directly.
297-
postInner(tag, arg);
298-
return;
305+
if (!isInvokeOnlySticky) {
306+
invokeBus(tag, arg, busInfo, false);
307+
}
308+
continue;
299309
}
300310
synchronized (mClassName_Tag_Arg4StickyMap) {
301311
Map<String, Object> tagArgMap = mClassName_Tag_Arg4StickyMap.get(busInfo.className);
@@ -305,7 +315,7 @@ private void postStickyInner(final String tag, final Object arg) {
305315
}
306316
tagArgMap.put(tag, arg);
307317
}
308-
postInner(tag, arg, true);
318+
invokeBus(tag, arg, busInfo, true);
309319
}
310320
}
311321

lib/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java

+23-8
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,33 @@ public static Intent getInstallAppIntent(final String filePath) {
6666
* @return the intent of install app
6767
*/
6868
public static Intent getInstallAppIntent(final File file) {
69-
if (file == null) return null;
70-
Intent intent = new Intent(Intent.ACTION_VIEW);
71-
Uri data;
72-
String type = "application/vnd.android.package-archive";
69+
if (UtilsBridge.isFileExists(file)) return null;
70+
Uri uri;
7371
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
74-
data = Uri.fromFile(file);
72+
uri = Uri.fromFile(file);
7573
} else {
76-
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
7774
String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
78-
data = FileProvider.getUriForFile(Utils.getApp(), authority, file);
75+
uri = FileProvider.getUriForFile(Utils.getApp(), authority, file);
76+
}
77+
return getInstallAppIntent(uri);
78+
}
79+
80+
/**
81+
* Return the intent of install app.
82+
* <p>Target APIs greater than 25 must hold
83+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
84+
*
85+
* @param uri The uri.
86+
* @return the intent of install app
87+
*/
88+
public static Intent getInstallAppIntent(final Uri uri) {
89+
if (uri == null) return null;
90+
Intent intent = new Intent(Intent.ACTION_VIEW);
91+
String type = "application/vnd.android.package-archive";
92+
intent.setDataAndType(uri, type);
93+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
94+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
7995
}
80-
intent.setDataAndType(data, type);
8196
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8297
}
8398

lib/utilcode/src/main/java/com/blankj/utilcode/util/UtilsBridge.java

+4
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ static Intent getInstallAppIntent(final File file) {
371371
return IntentUtils.getInstallAppIntent(file);
372372
}
373373

374+
static Intent getInstallAppIntent(final Uri uri) {
375+
return IntentUtils.getInstallAppIntent(uri);
376+
}
377+
374378
static Intent getUninstallAppIntent(final String pkgName) {
375379
return IntentUtils.getUninstallAppIntent(pkgName);
376380
}

lib/utilcode/src/test/java/com/blankj/utilcode/util/BusUtilsTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public void noParamStickyFun() {
4545
System.out.println("noParamSticky");
4646
}
4747

48+
@BusUtils.Bus(tag = TAG_NO_PARAM_STICKY)
49+
public void foo() {
50+
System.out.println("foo");
51+
}
52+
4853
@BusUtils.Bus(tag = TAG_ONE_PARAM_STICKY, sticky = true)
4954
public void oneParamStickyFun(Callback callback) {
5055
if (callback != null) {
@@ -81,6 +86,7 @@ public void setUp() throws Exception {
8186
BusUtils.registerBus4Test(TAG_NO_PARAM, BusUtilsTest.class.getName(), "noParamFun", "", "", false, "POSTING", 0);
8287
BusUtils.registerBus4Test(TAG_ONE_PARAM, BusUtilsTest.class.getName(), "oneParamFun", String.class.getName(), "param", false, "POSTING", 0);
8388
BusUtils.registerBus4Test(TAG_NO_PARAM_STICKY, BusUtilsTest.class.getName(), "noParamStickyFun", "", "", true, "POSTING", 0);
89+
BusUtils.registerBus4Test(TAG_NO_PARAM_STICKY, BusUtilsTest.class.getName(), "foo", "", "", false, "POSTING", 0);
8490
BusUtils.registerBus4Test(TAG_ONE_PARAM_STICKY, BusUtilsTest.class.getName(), "oneParamStickyFun", Callback.class.getName(), "callback", true, "POSTING", 0);
8591

8692
BusUtils.registerBus4Test(TAG_IO, BusUtilsTest.class.getName(), "ioFun", CountDownLatch.class.getName(), "latch", false, "IO", 0);
@@ -89,6 +95,15 @@ public void setUp() throws Exception {
8995
BusUtils.registerBus4Test(TAG_SINGLE, BusUtilsTest.class.getName(), "singleFun", CountDownLatch.class.getName(), "latch", false, "SINGLE", 0);
9096
}
9197

98+
@Test
99+
public void testSticky() {
100+
BusUtils.postSticky(TAG_NO_PARAM_STICKY);
101+
BusUtilsTest test = new BusUtilsTest();
102+
BusUtils.register(test);
103+
104+
BusUtils.postSticky(TAG_NO_PARAM_STICKY);
105+
}
106+
92107
@Test
93108
public void testMultiThread() {
94109
final BusUtilsTest test = new BusUtilsTest();

0 commit comments

Comments
 (0)