Skip to content

Commit dcbb524

Browse files
authored
forceContentUpdate with boolean flag (#477)
* Add callback with success flag to FCU * Fix PowerMock and lambdas issue
1 parent d7b3648 commit dcbb524

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import android.location.Location;
2626
import android.text.TextUtils;
2727

28+
import androidx.annotation.NonNull;
2829
import androidx.annotation.Nullable;
2930
import com.leanplum.ActionContext.ContextualValues;
3031
import com.leanplum.callbacks.ActionCallback;
32+
import com.leanplum.callbacks.ForceContentUpdateCallback;
3133
import com.leanplum.callbacks.MessageDisplayedCallback;
3234
import com.leanplum.callbacks.RegisterDeviceCallback;
3335
import com.leanplum.callbacks.RegisterDeviceFinishedCallback;
@@ -2018,7 +2020,7 @@ private static void resumeStateInternal() {
20182020
* inconsistent state or user experience.
20192021
*/
20202022
public static void forceContentUpdate() {
2021-
forceContentUpdate(null);
2023+
forceContentUpdate(success -> {});
20222024
}
20232025

20242026
/**
@@ -2029,10 +2031,26 @@ public static void forceContentUpdate() {
20292031
* @param callback The callback to invoke when the call completes from the server. The callback
20302032
* will fire regardless of whether the variables have changed.
20312033
*/
2032-
@SuppressWarnings("SameParameterValue")
2033-
public static void forceContentUpdate(final VariablesChangedCallback callback) {
2034+
public static void forceContentUpdate(VariablesChangedCallback callback) {
2035+
forceContentUpdate(success -> {
2036+
if (callback != null) {
2037+
callback.variablesChanged();
2038+
}
2039+
});
2040+
}
2041+
2042+
/**
2043+
* Forces content to update from the server. If variables have changed, the appropriate callbacks
2044+
* will fire. Use sparingly as if the app is updated, you'll have to deal with potentially
2045+
* inconsistent state or user experience.
2046+
*
2047+
* @param callback The callback to invoke when the call completes from the server. The callback
2048+
* will fire regardless of whether the variables have changed. Null value is not
2049+
* permitted.
2050+
*/
2051+
public static void forceContentUpdate(@NonNull ForceContentUpdateCallback callback) {
20342052
if (Constants.isNoop()) {
2035-
OperationQueue.sharedInstance().addUiOperation(callback);
2053+
OperationQueue.sharedInstance().addUiOperation(() -> callback.onContentUpdated(false));
20362054
return;
20372055
}
20382056
try {
@@ -2064,7 +2082,7 @@ public void response(JSONObject response) {
20642082
Map<String, String> filenameToURLs = parseFilenameToURLs(response);
20652083
FileManager.setFilenameToURLs(filenameToURLs);
20662084
}
2067-
OperationQueue.sharedInstance().addUiOperation(callback);
2085+
OperationQueue.sharedInstance().addUiOperation(() -> callback.onContentUpdated(true));
20682086
} catch (Throwable t) {
20692087
Log.exception(t);
20702088
}
@@ -2073,7 +2091,7 @@ public void response(JSONObject response) {
20732091
req.onError(new Request.ErrorCallback() {
20742092
@Override
20752093
public void error(Exception e) {
2076-
OperationQueue.sharedInstance().addUiOperation(callback);
2094+
OperationQueue.sharedInstance().addUiOperation(() -> callback.onContentUpdated(false));
20772095
LeanplumInbox.getInstance().triggerInboxSyncedWithStatus(false);
20782096
}
20792097
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2021, Leanplum, Inc. All rights reserved.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package com.leanplum.callbacks;
23+
24+
/**
25+
* Callback with success flag when updating content from server.
26+
*/
27+
public interface ForceContentUpdateCallback {
28+
29+
/**
30+
* Called after content has been updated.
31+
*
32+
* @param success True if content is successfully updated, false otherwise.
33+
*/
34+
void onContentUpdated(boolean success);
35+
}

AndroidSDKTests/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ dependencies {
7979
}
8080
testImplementation 'org.robolectric:shadows-play-services:3.3.2'
8181
testImplementation 'org.mockito:mockito-core:1.10.19'
82-
testImplementation 'org.powermock:powermock-module-junit4:1.6.6'
83-
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.6'
84-
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
85-
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.6'
82+
testImplementation 'org.powermock:powermock-module-junit4:1.6.5'
83+
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.5'
84+
testImplementation 'org.powermock:powermock-api-mockito:1.6.5'
85+
testImplementation 'org.powermock:powermock-classloading-xstream:1.6.5'
8686
testImplementation 'org.bouncycastle:bcmail-jdk15on:1.65'
8787

8888
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

0 commit comments

Comments
 (0)