Skip to content

Commit 0d196bb

Browse files
Enuvielmilos1290
authored andcommitted
feat(channels): adding support for notification channels
1 parent 1bfeeef commit 0d196bb

File tree

8 files changed

+930
-22
lines changed

8 files changed

+930
-22
lines changed

AndroidSDK/src/com/leanplum/Leanplum.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
import com.leanplum.callbacks.StartCallback;
3939
import com.leanplum.callbacks.VariablesChangedCallback;
4040
import com.leanplum.internal.Constants;
41-
import com.leanplum.internal.LeanplumEventDataManager;
4241
import com.leanplum.internal.FileManager;
4342
import com.leanplum.internal.JsonConverter;
43+
import com.leanplum.internal.LeanplumEventDataManager;
4444
import com.leanplum.internal.LeanplumInternal;
4545
import com.leanplum.internal.LeanplumMessageMatchFilter;
4646
import com.leanplum.internal.LeanplumUIEditorWrapper;
@@ -88,18 +88,15 @@ public class Leanplum {
8888
new ArrayList<>();
8989
private static final ArrayList<VariablesChangedCallback> onceNoDownloadsHandlers =
9090
new ArrayList<>();
91+
private static final Object heartbeatLock = new Object();
9192
private static RegisterDeviceCallback registerDeviceHandler;
9293
private static RegisterDeviceFinishedCallback registerDeviceFinishedHandler;
93-
9494
private static LeanplumDeviceIdMode deviceIdMode = LeanplumDeviceIdMode.MD5_MAC_ADDRESS;
9595
private static String customDeviceId;
9696
private static boolean userSpecifiedDeviceId;
9797
private static boolean initializedMessageTemplates = false;
9898
private static boolean locationCollectionEnabled = true;
99-
10099
private static ScheduledExecutorService heartbeatExecutor;
101-
private static final Object heartbeatLock = new Object();
102-
103100
private static Context context;
104101

105102
private static Runnable pushStartCallback;
@@ -765,6 +762,22 @@ protected Void doInBackground(Void... params) {
765762
Log.d("No variants received from the server.");
766763
}
767764

765+
// Get notification channels and groups.
766+
JSONArray notificationChannels = response.optJSONArray(
767+
Constants.Keys.NOTIFICATION_CHANNELS);
768+
JSONArray notificationGroups = response.optJSONArray(
769+
Constants.Keys.NOTIFICATION_GROUPS);
770+
String defaultNotificationChannel = response.optString(
771+
Constants.Keys.DEFAULT_NOTIFICATION_CHANNEL);
772+
773+
// Configure notification channels and groups
774+
LeanplumNotificationChannel.configureNotificationGroups(
775+
context, notificationGroups);
776+
LeanplumNotificationChannel.configureNotificationChannels(
777+
context, notificationChannels);
778+
LeanplumNotificationChannel.configureDefaultNotificationChannel(
779+
context, defaultNotificationChannel);
780+
768781
String token = response.optString(Constants.Keys.TOKEN, null);
769782
Request.setToken(token);
770783
Request.saveToken();
@@ -883,7 +896,6 @@ public void run() {
883896
LeanplumInternal.onHasStartedAndRegisteredAsDeveloper();
884897
}
885898
}
886-
887899
LeanplumInternal.moveToForeground();
888900
startHeartbeat();
889901
} catch (Throwable t) {
@@ -1928,13 +1940,13 @@ public void response(JSONObject response) {
19281940
}
19291941
});
19301942
req.onError(new Request.ErrorCallback() {
1931-
@Override
1932-
public void error(Exception e) {
1933-
if (callback != null) {
1934-
OsHandler.getInstance().post(callback);
1935-
}
1936-
}
1937-
});
1943+
@Override
1944+
public void error(Exception e) {
1945+
if (callback != null) {
1946+
OsHandler.getInstance().post(callback);
1947+
}
1948+
}
1949+
});
19381950
req.sendIfConnected();
19391951
} catch (Throwable t) {
19401952
Util.handleException(t);

0 commit comments

Comments
 (0)