From 45964c6ed563c9aeba305fa6063d906b30623989 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Wed, 20 Dec 2023 13:40:59 +0300 Subject: [PATCH] fix: some of orders --- .../count/sdk/java/internal/ModuleViews.java | 36 +++-- .../ly/count/sdk/java/internal/SDKCore.java | 144 +++++++++--------- 2 files changed, 101 insertions(+), 79 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleViews.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleViews.java index 35a5f0f1..914b1ea4 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleViews.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleViews.java @@ -15,7 +15,13 @@ public class ModuleViews extends ModuleBase { String currentViewID = null; String previousViewID = null; private boolean firstView = true; - final static String VIEW_EVENT_KEY = "[CLY]_view"; + static final String KEY_VIEW_EVENT = "[CLY]_view"; + static final String KEY_NAME = "name"; + static final String KEY_VISIT = "visit"; + static final String KEY_VISIT_VALUE = "1"; + static final String KEY_SEGMENT = "segment"; + static final String KEY_START = "start"; + static final String KEY_START_VALUE = "1"; Map viewDataMap = new LinkedHashMap<>(); // map viewIDs to its viewData String[] reservedSegmentationKeysViews = new String[] { "name", "visit", "start", "segment" }; //interface for SDK users @@ -40,8 +46,9 @@ public void init(InternalConfig config) { } @Override - public void onSessionBegan(Session session, InternalConfig config) { - super.onSessionBegan(session, config); + public void onSessionEnded(Session session, InternalConfig config) { + super.onSessionEnded(session, config); + stopAllViewsInternal(null); resetFirstView(); } @@ -74,14 +81,14 @@ public void resetFirstView() { Map createViewEventSegmentation(@Nonnull ViewData vd, boolean firstView, boolean visit, Map customViewSegmentation) { Map viewSegmentation = new ConcurrentHashMap<>(); - viewSegmentation.put("name", vd.viewName); + viewSegmentation.put(KEY_NAME, vd.viewName); if (visit) { - viewSegmentation.put("visit", "1"); + viewSegmentation.put(KEY_VISIT, KEY_VISIT_VALUE); } if (firstView) { - viewSegmentation.put("start", "1"); + viewSegmentation.put(KEY_START, KEY_START_VALUE); } - viewSegmentation.put("segment", internalConfig.getSdkPlatform()); + viewSegmentation.put(KEY_SEGMENT, internalConfig.getSdkPlatform()); if (customViewSegmentation != null) { viewSegmentation.putAll(customViewSegmentation); } @@ -155,8 +162,7 @@ void autoCloseRequiredViews(boolean closeAllViews, Map customVie firstView = false; } - Countly.instance().events().recordEvent(VIEW_EVENT_KEY, viewSegmentation, 1, 0.0, 0.0); - + recordView(0.0, viewSegmentation); return currentViewData.viewID; } @@ -182,6 +188,16 @@ void stopViewWithIDInternal(@Nullable String viewID, @Nullable Map segmentation) { + ModuleEvents.Events events = Countly.instance().events(); + if (events == null) { + L.e("[ModuleViews] recordView, events module is not initialized"); + return; + } + + events.recordEvent(KEY_VIEW_EVENT, segmentation, 1, 0.0, duration); + } + void recordViewEndEvent(ViewData vd, @Nullable Map filteredCustomViewSegmentation, String viewRecordingSource) { long lastElapsedDurationSeconds = 0; //we do sanity check the time component and print error in case of problem @@ -201,7 +217,7 @@ void recordViewEndEvent(ViewData vd, @Nullable Map filteredCusto long viewDurationSeconds = lastElapsedDurationSeconds; Map segments = createViewEventSegmentation(vd, false, false, filteredCustomViewSegmentation); - Countly.instance().events().recordEvent(VIEW_EVENT_KEY, segments, 1, 0.0, new Long(viewDurationSeconds).doubleValue()); + recordView(new Long(viewDurationSeconds).doubleValue(), segments); } void pauseViewWithIDInternal(String viewID) { 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 a0a7a80a..bd8041f3 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,63 +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 ModuleViews.Views views() { - if (!hasConsentForFeature(CoreFeature.Views)) { - L.v("[SDKCore] views, Views feature has no consent, returning null"); - return null; - } - - return module(ModuleViews.class).viewsInterface; - } - - 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}. * @@ -590,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; } @@ -766,4 +697,79 @@ 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; + } + return module(ModuleEvents.class).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 ModuleViews.Views views() { + if (!hasConsentForFeature(CoreFeature.Views)) { + L.v("[SDKCore] views, Views feature has no consent, returning null"); + return null; + } + + return module(ModuleViews.class).viewsInterface; + } + + 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; + } }