Skip to content

Commit

Permalink
fix: some of orders
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Dec 20, 2023
1 parent 41427ab commit 45964c6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 79 deletions.
36 changes: 26 additions & 10 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ViewData> viewDataMap = new LinkedHashMap<>(); // map viewIDs to its viewData
String[] reservedSegmentationKeysViews = new String[] { "name", "visit", "start", "segment" };
//interface for SDK users
Expand All @@ -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();
}

Expand Down Expand Up @@ -74,14 +81,14 @@ public void resetFirstView() {
Map<String, Object> createViewEventSegmentation(@Nonnull ViewData vd, boolean firstView, boolean visit, Map<String, Object> customViewSegmentation) {
Map<String, Object> 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);
}
Expand Down Expand Up @@ -155,8 +162,7 @@ void autoCloseRequiredViews(boolean closeAllViews, Map<String, Object> customVie
firstView = false;
}

Countly.instance().events().recordEvent(VIEW_EVENT_KEY, viewSegmentation, 1, 0.0, 0.0);

recordView(0.0, viewSegmentation);
return currentViewData.viewID;
}

Expand All @@ -182,6 +188,16 @@ void stopViewWithIDInternal(@Nullable String viewID, @Nullable Map<String, Objec
viewDataMap.remove(vd.viewID);
}

void recordView(Double duration, Map<String, Object> 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<String, Object> filteredCustomViewSegmentation, String viewRecordingSource) {
long lastElapsedDurationSeconds = 0;
//we do sanity check the time component and print error in case of problem
Expand All @@ -201,7 +217,7 @@ void recordViewEndEvent(ViewData vd, @Nullable Map<String, Object> filteredCusto

long viewDurationSeconds = lastElapsedDurationSeconds;
Map<String, Object> 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) {
Expand Down
144 changes: 75 additions & 69 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down Expand Up @@ -590,18 +533,6 @@ public UserImpl user() {
return user;
}

/**
* @return timedEvents interface
* @deprecated use {@link ModuleEvents.Events#startEvent(String)} instead via <code>instance().events()</code> 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;
}
Expand Down Expand Up @@ -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 <code>instance().events()</code> 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;
}
}

0 comments on commit 45964c6

Please sign in to comment.