Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin Tracker #521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions exampleapp/src/main/java/org/matomo/demo/DemoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.matomo.demo

import info.hannes.timber.DebugFormatTree
import org.matomo.sdk.TrackMe
import org.matomo.sdk.Tracker
import org.matomo.sdk.TrackerBuilder
import org.matomo.sdk.extra.DimensionQueue
import org.matomo.sdk.extra.DownloadTracker.Extra
Expand Down Expand Up @@ -48,9 +49,11 @@ class DemoApp : MatomoApplication() {

// This will be send the next time something is tracked.
dimensionQueue.add(0, "test")
tracker.addTrackingCallback { trackMe: TrackMe? ->
Timber.i("Tracker.Callback.onTrack(%s)", trackMe)
trackMe
}
tracker.addTrackingCallback(object: Tracker.Callback {
override fun onTrack(trackMe: TrackMe?): TrackMe? {
Timber.i("Tracker.Callback.onTrack(%s)", trackMe)
return trackMe
}
})
}
}
31 changes: 13 additions & 18 deletions tracker/src/main/java/org/matomo/sdk/LegacySettingsPorter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,46 @@ import android.content.SharedPreferences
import java.util.UUID

class LegacySettingsPorter(matomo: Matomo) {
private val mLegacyPrefs: SharedPreferences

init {
mLegacyPrefs = matomo.preferences
}
private val mLegacyPrefs: SharedPreferences = matomo.preferences

fun port(tracker: Tracker) {
val newSettings = tracker.preferences
if (mLegacyPrefs.getBoolean(LEGACY_PREF_OPT_OUT, false)) {
newSettings.edit()
.putBoolean(Tracker.PREF_KEY_TRACKER_OPTOUT, true)
.apply()
newSettings?.edit()?.putBoolean(Tracker.PREF_KEY_TRACKER_OPTOUT, true)
?.apply()
mLegacyPrefs.edit().remove(LEGACY_PREF_OPT_OUT).apply()
}
if (mLegacyPrefs.contains(LEGACY_PREF_USER_ID)) {
newSettings.edit()
.putString(Tracker.PREF_KEY_TRACKER_USERID, mLegacyPrefs.getString(LEGACY_PREF_USER_ID, UUID.randomUUID().toString()))
.apply()
newSettings?.edit()
?.putString(Tracker.PREF_KEY_TRACKER_USERID, mLegacyPrefs.getString(LEGACY_PREF_USER_ID, UUID.randomUUID().toString()))
?.apply()
mLegacyPrefs.edit().remove(LEGACY_PREF_USER_ID).apply()
}
if (mLegacyPrefs.contains(LEGACY_PREF_FIRST_VISIT)) {
newSettings.edit().putLong(
newSettings?.edit()?.putLong(
Tracker.PREF_KEY_TRACKER_FIRSTVISIT,
mLegacyPrefs.getLong(LEGACY_PREF_FIRST_VISIT, -1L)
).apply()
)?.apply()
mLegacyPrefs.edit().remove(LEGACY_PREF_FIRST_VISIT).apply()
}
if (mLegacyPrefs.contains(LEGACY_PREF_VISITCOUNT)) {
newSettings.edit().putLong(
newSettings?.edit()?.putLong(
Tracker.PREF_KEY_TRACKER_VISITCOUNT,
mLegacyPrefs.getInt(LEGACY_PREF_VISITCOUNT, 0)
.toLong()
).apply()
)?.apply()
mLegacyPrefs.edit().remove(LEGACY_PREF_VISITCOUNT).apply()
}
if (mLegacyPrefs.contains(LEGACY_PREF_PREV_VISIT)) {
newSettings.edit().putLong(
newSettings?.edit()?.putLong(
Tracker.PREF_KEY_TRACKER_PREVIOUSVISIT,
mLegacyPrefs.getLong(LEGACY_PREF_PREV_VISIT, -1)
).apply()
)?.apply()
mLegacyPrefs.edit().remove(LEGACY_PREF_PREV_VISIT).apply()
}
for ((key) in mLegacyPrefs.all) {
if (key.startsWith("downloaded:")) {
newSettings.edit().putBoolean(key, true).apply()
newSettings?.edit()?.putBoolean(key, true)?.apply()
mLegacyPrefs.edit().remove(key).apply()
}
}
Expand Down
Loading
Loading