From 90a9d6ea47ea0fef0f570396544fb4cd916fcadd Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Tue, 9 Jan 2024 17:06:14 +0300 Subject: [PATCH] refactor: reorder sdk core module calls --- .../ly/count/sdk/java/internal/SDKCore.java | 132 ++++++++++-------- 1 file changed, 72 insertions(+), 60 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java index ba5a361c..259cfb4a 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java @@ -379,54 +379,6 @@ public SessionImpl getSession() { return null; } - public ModuleFeedback.Feedback feedback() { - - if (!hasConsentForFeature(CoreFeature.Feedback)) { - L.v("[SDKCore] feedback, Feedback feature has no consent, returning null"); - return null; - } - - return module(ModuleFeedback.class).feedbackInterface; - } - - public ModuleCrashes.Crashes crashes() { - if (!hasConsentForFeature(CoreFeature.CrashReporting)) { - L.v("[SDKCore] crash, Crash Reporting feature has no consent, returning null"); - return null; - } - - return module(ModuleCrashes.class).crashInterface; - } - - public ModuleDeviceIdCore.DeviceId deviceId() { - return module(ModuleDeviceIdCore.class).deviceIdInterface; - } - - public ModuleRemoteConfig.RemoteConfig remoteConfig() { - if (!hasConsentForFeature(CoreFeature.RemoteConfig)) { - L.v("[SDKCore] remoteConfig, RemoteConfig feature has no consent, returning null"); - return null; - } - - return module(ModuleRemoteConfig.class).remoteConfigInterface; - } - - public ModuleUserProfile.UserProfile userProfile() { - return module(ModuleUserProfile.class).userProfileInterface; - } - - public ModuleLocation.Location location() { - if (!hasConsentForFeature(CoreFeature.Location)) { - L.v("[SDKCore] location, Location feature has no consent, returning null"); - return null; - } - ModuleLocation module = module(ModuleLocation.class); - if (module == null) { - return null; - } - return module.locationInterface; - } - /** * Get current {@link SessionImpl} or create new one if current is {@code null}. * @@ -581,18 +533,6 @@ public UserImpl user() { return user; } - /** - * @return timedEvents interface - * @deprecated use {@link ModuleEvents.Events#startEvent(String)} instead via instance().events() call - */ - TimedEvents timedEvents() { - return ((ModuleSessions) module(CoreFeature.Sessions.getIndex())).timedEvents(); - } - - public ModuleEvents.Events events() { - return ((ModuleEvents) module(CoreFeature.Events.getIndex())).eventsInterface; - } - public InternalConfig config() { return config; } @@ -757,4 +697,76 @@ private boolean processCrash(InternalConfig config, Long id) { public void onRequest(InternalConfig config, Request request) { onSignal(config, SDKCore.Signal.Ping.getIndex(), null); } + + //Module functions + + /** + * @return timedEvents interface + * @deprecated use {@link ModuleEvents.Events#startEvent(String)} instead via instance().events() call + */ + TimedEvents timedEvents() { + return ((ModuleSessions) module(CoreFeature.Sessions.getIndex())).timedEvents(); + } + + public ModuleEvents.Events events() { + if (!hasConsentForFeature(CoreFeature.Events)) { + L.v("[SDKCore] events, Events feature has no consent, returning null"); + return null; + } + + ModuleEvents module = module(ModuleEvents.class); + if (module == null) { + return null; + } + + return module.eventsInterface; + } + + public ModuleFeedback.Feedback feedback() { + + if (!hasConsentForFeature(CoreFeature.Feedback)) { + L.v("[SDKCore] feedback, Feedback feature has no consent, returning null"); + return null; + } + + return module(ModuleFeedback.class).feedbackInterface; + } + + public ModuleCrashes.Crashes crashes() { + if (!hasConsentForFeature(CoreFeature.CrashReporting)) { + L.v("[SDKCore] crash, Crash Reporting feature has no consent, returning null"); + return null; + } + + return module(ModuleCrashes.class).crashInterface; + } + + public ModuleDeviceIdCore.DeviceId deviceId() { + return module(ModuleDeviceIdCore.class).deviceIdInterface; + } + + public ModuleRemoteConfig.RemoteConfig remoteConfig() { + if (!hasConsentForFeature(CoreFeature.RemoteConfig)) { + L.v("[SDKCore] remoteConfig, RemoteConfig feature has no consent, returning null"); + return null; + } + + return module(ModuleRemoteConfig.class).remoteConfigInterface; + } + + public ModuleUserProfile.UserProfile userProfile() { + return module(ModuleUserProfile.class).userProfileInterface; + } + + public ModuleLocation.Location location() { + if (!hasConsentForFeature(CoreFeature.Location)) { + L.v("[SDKCore] location, Location feature has no consent, returning null"); + return null; + } + ModuleLocation module = module(ModuleLocation.class); + if (module == null) { + return null; + } + return module.locationInterface; + } }