Skip to content

Commit

Permalink
feat: migrate test branch logic to main
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Jan 4, 2024
1 parent 7b05172 commit d45cea3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 59 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* "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)"
* "setDisableLocation()"
* 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.
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions sdk-java/src/main/java/ly/count/sdk/java/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions sdk-java/src/main/java/ly/count/sdk/java/Usage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions sdk-java/src/main/java/ly/count/sdk/java/View.java
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 16 additions & 5 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ Future<Boolean> end(Long now, final Tasks.Callback<Boolean> 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);

Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand Down
53 changes: 11 additions & 42 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -57,37 +44,19 @@ 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
public String toString() {
return "ViewImpl{" +
"name='" + name + '\'' +
", session=" + session +
", start=" + start +
", started=" + started +
", ended=" + ended +
'}';
}
}

0 comments on commit d45cea3

Please sign in to comment.