From d45cea3b45cad27650156f4e9e1f9da5133f3bd3 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 4 Jan 2024 09:47:45 +0300 Subject: [PATCH] feat: migrate test branch logic to main --- CHANGELOG.md | 8 ++- .../main/java/ly/count/sdk/java/Countly.java | 10 ++++ .../main/java/ly/count/sdk/java/Usage.java | 11 ++-- .../src/main/java/ly/count/sdk/java/View.java | 14 +++++ .../count/sdk/java/internal/ModuleEvents.java | 9 +--- .../count/sdk/java/internal/SessionImpl.java | 21 ++++++-- .../ly/count/sdk/java/internal/ViewImpl.java | 53 ++++--------------- 7 files changed, 67 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9baeb66b8..e5323e213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ * "setLocale(String)" * Added the user profiles feature interface, and it is accessible through "Countly::instance()::userProfile()" call. - * Added the location feature interface, and it is accessible through "Countly::instance()::location()" call. * Added init time configuration for the location parameters: * "setLocation(String countryCode, String city, String location, String ipAddress)" @@ -12,6 +11,7 @@ * Crash Reporting interface added and accessible through "Countly::instance()::crash()" call. * Added "disableUnhandledCrashReporting" function to the "Config" class to disable automatic uncaught crash reporting. * Added "setMaxBreadcrumbCount(int)" function to the "Config" class to change allowed max breadcrumb count. +* Added the views feature interface, and it is accessible through "Countly::instance()::views()" call. * Fixed a bug where setting custom user properties would not work. * Fixed a bug where setting organization of the user would not work. @@ -46,6 +46,12 @@ * "setCustom(String, Object)" instead use "Countly::userProfile::setProperty" via "instance()" call * "set(String, Object)" instead use "Countly::userProfile::setProperty" via "instance()" call * "picture(byte[])" instead use "Countly::userProfile::setProperty" via "instance()" call +* Deprecated "View::start(bool)" call, use "Countly::views::startView" instead via "instance()" call. +* Deprecated "View::stop(bool)" call, use "Countly::views::stopViewWithName" or "Countly::views::stopViewWithID" instead via "instance()" call. +* Deprecated "Usage::view(String)" call, use "Countly::views::startView" instead via "instance()" call. +* Deprecated "Usage::view(String, bool)" call, use "Countly::views::startView" instead via "instance()" call. +* Deprecated "Countly::view(String)" call, use "Countly::views::startView" instead via "instance()" call. +* Deprecated "Countly::view(String, bool)" call, use "Countly::views::startView" instead via "instance()" call. ## 23.10.1 diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java index 22cae574d..70cf205b9 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java @@ -563,12 +563,22 @@ public Usage addLocation(double latitude, double longitude) { return ((Session) sdk.session(null)).addLocation(latitude, longitude); } + /** + * {@inheritDoc} + * + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} instance() call + */ @Override public View view(String name, boolean start) { L.d("[Countly] view: name = " + name + " start = " + start); return ((Session) sdk.session(null)).view(name, start); } + /** + * {@inheritDoc} + * + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} instance() call + */ @Override public View view(String name) { L.d("[Countly] view: name = " + name); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Usage.java b/sdk-java/src/main/java/ly/count/sdk/java/Usage.java index e2e237f15..d33f555c0 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Usage.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Usage.java @@ -3,6 +3,7 @@ import java.util.Map; import ly.count.sdk.java.internal.ModuleDeviceIdCore; import ly.count.sdk.java.internal.ModuleEvents; +import ly.count.sdk.java.internal.ModuleViews; /** * This interface represents session concept, that is one indivisible usage occasion of your application. @@ -17,7 +18,7 @@ public interface Usage { /** * Create event object, don't record it yet. Creates begin request if this session - * hasn't yet been began. + * hasn't yet been begun. * * @param key key for this event, cannot be null or empty * @return Event instance. @@ -28,7 +29,7 @@ public interface Usage { /** * Get existing or create new timed event object, don't record it. Creates begin request if this session - * hasn't yet been began. + * hasn't yet been begun. * * @param key key for this event, cannot be null or empty * @return timed Event instance. @@ -97,21 +98,23 @@ public interface Usage { * Start new view. * In case previous view in this session is not ended yet, it will be ended automatically. * In case session ends and last view haven't been ended yet, it will be ended automatically. - * Creates begin request if this session hasn't yet been began. + * Creates begin request if this session hasn't yet been begun. * * @param name String representing name of this View * @param start whether this view is first in current application launch * @return new but already started {@link View}, you're responsible for its ending by calling {@link View#stop(boolean)} + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} */ View view(String name, boolean start); /** * Identical to {@link #view(String, boolean)}, but without {@code start} parameter which * is determined automatically based on whether this view is first in this session. - * Creates begin request if this session hasn't yet been began. + * Creates begin request if this session hasn't yet been begun. * * @param name String representing name of this View * @return new but already started {@link View}, you're responsible for its ending by calling {@link View#stop(boolean)} + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} */ View view(String name); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/View.java b/sdk-java/src/main/java/ly/count/sdk/java/View.java index 8e57b1502..2c970a7b0 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/View.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/View.java @@ -1,11 +1,25 @@ package ly.count.sdk.java; +import ly.count.sdk.java.internal.ModuleViews; /** * Contract interface for Views functionality */ public interface View { + + /** + * Start view + * + * @param firstView true if this is the first view in the session + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} + */ void start(boolean firstView); + /** + * Stop view + * + * @param lastView true if this is the last view in the session + * @deprecated use {@link ModuleViews.Views#stopViewWithName(String)} or {@link ModuleViews.Views#stopViewWithID(String)} instead via {@link Countly#views()} + */ void stop(boolean lastView); } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java index 6ca2564a4..c4b5df889 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java @@ -6,7 +6,6 @@ import java.util.stream.Collectors; import ly.count.sdk.java.Countly; import ly.count.sdk.java.Session; -import ly.count.sdk.java.View; public class ModuleEvents extends ModuleBase { protected EventQueue eventQueue = null; @@ -45,12 +44,8 @@ public void deviceIdChanged(String oldDeviceId, boolean withMerge) { // this part is to end and record the current view if exists Session session = Countly.session(); if ((session != null && session.isActive())) { - View currentView = ((SessionImpl) session).currentView; - if (currentView != null) { - currentView.stop(true); - } else { - Storage.pushAsync(internalConfig, ((SessionImpl) Countly.session())); - } + Countly.instance().views().stopAllViews(null); + Storage.pushAsync(internalConfig, ((SessionImpl) Countly.session())); } addEventsToRequestQ(oldDeviceId); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java index 715f9c434..bcfc502f7 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java @@ -193,11 +193,7 @@ Future end(Long now, final Tasks.Callback callback, String did this.consents = SDKCore.instance.consents; - if (currentView != null) { - currentView.stop(true); - } else { - Storage.pushAsync(config, this); - } + Storage.pushAsync(config, this); Long duration = updateDuration(now); @@ -368,6 +364,14 @@ public Session addLocation(double latitude, double longitude) { return this; } + /** + * Start view + * + * @param name String representing name of this View + * @param start whether this view is first in current application launch + * @return View instance + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} + */ public View view(String name, boolean start) { L.d("[SessionImpl] view: name = " + name + " start = " + start); if (!SDKCore.enabled(CoreFeature.Views)) { @@ -385,6 +389,13 @@ public View view(String name, boolean start) { return currentView; } + /** + * Start view + * + * @param name String representing name of this View + * @return View instance + * @deprecated use {@link ModuleViews.Views#startView(String)} instead via {@link Countly#views()} + */ public View view(String name) { return view(name, startView); } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java index 7b70fbebd..6c2c2c118 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java @@ -1,5 +1,6 @@ package ly.count.sdk.java.internal; +import ly.count.sdk.java.Countly; import ly.count.sdk.java.Session; import ly.count.sdk.java.View; @@ -9,18 +10,10 @@ class ViewImpl implements View { private Log L = null; - static final String EVENT = "[CLY]_view"; - static final String NAME = "name"; - static final String VISIT = "visit"; - static final String VISIT_VALUE = "1"; - static final String SEGMENT = "segment"; - static final String START = "start"; - static final String START_VALUE = "1"; - final String name; final Session session; - EventImpl start; - boolean started, ended; + boolean start = false; + boolean stop = false; ViewImpl(Session session, String name, Log logger) { this.L = logger; @@ -35,19 +28,13 @@ public void start(boolean firstView) { return; } - L.d("[ViewImpl] start: firstView = " + firstView); - if (started) { + if (start) { + L.w("[ViewImpl] start: View already started!"); return; } - this.started = true; - - start = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, VISIT, VISIT_VALUE, SEGMENT, SDKCore.instance.config.getSdkPlatform()); - - if (firstView) { - start.addSegment(START, START_VALUE); - } - start.record(); + start = true; + Countly.instance().views().startView(name); } @Override @@ -57,27 +44,12 @@ public void stop(boolean lastView) { return; } - if (start == null) { - L.e("[ViewImpl] stop: We are trying to end a view that has not been started."); - return; - } - - L.d("[ViewImpl] stop: lastView = " + lastView); - - if (ended) { + if (stop) { + L.w("[ViewImpl] stop: View already stopped!"); return; } - ended = true; - EventImpl event = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, SEGMENT, SDKCore.instance.config.getSdkPlatform()); - - long startTs = start.getTimestamp(); - long endTs = TimeUtils.timestampMs(); - - long viewDurationSeconds = (endTs - startTs) / 1000; - - event.setDuration(viewDurationSeconds); - - event.record(); + stop = true; + Countly.instance().views().stopViewWithName(name); } @Override @@ -85,9 +57,6 @@ public String toString() { return "ViewImpl{" + "name='" + name + '\'' + ", session=" + session + - ", start=" + start + - ", started=" + started + - ", ended=" + ended + '}'; } }