Skip to content

Commit

Permalink
Kotlin Tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jul 10, 2024
1 parent fd12a56 commit 0a45b08
Show file tree
Hide file tree
Showing 4 changed files with 552 additions and 606 deletions.
2 changes: 0 additions & 2 deletions exampleapp/src/main/java/org/matomo/demo/DemoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.matomo.demo

import android.os.StrictMode
import android.os.StrictMode.ThreadPolicy
import info.hannes.timber.DebugFormatTree
import org.matomo.sdk.TrackMe
import org.matomo.sdk.TrackerBuilder
Expand Down
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

0 comments on commit 0a45b08

Please sign in to comment.