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

Simplify code #522

Merged
merged 1 commit into from
Jul 11, 2024
Merged
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
6 changes: 2 additions & 4 deletions exampleapp/src/main/java/org/matomo/demo/DemoApp.kt
Original file line number Diff line number Diff line change
@@ -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
@@ -46,10 +44,10 @@ class DemoApp : MatomoApplication() {
// Alternative:
// i.e. "http://org.matomo.demo:1/com.android.vending"
// getTracker().download();
val mDimensionQueue = DimensionQueue(tracker)
val dimensionQueue = DimensionQueue(tracker)

// This will be send the next time something is tracked.
mDimensionQueue.add(0, "test")
dimensionQueue.add(0, "test")
tracker.addTrackingCallback { trackMe: TrackMe? ->
Timber.i("Tracker.Callback.onTrack(%s)", trackMe)
trackMe
17 changes: 6 additions & 11 deletions tracker/src/main/java/org/matomo/sdk/Matomo.kt
Original file line number Diff line number Diff line change
@@ -18,30 +18,25 @@ import org.matomo.sdk.tools.PropertySource
import timber.log.Timber

class Matomo private constructor(context: Context) {
private val mPreferenceMap: MutableMap<Tracker, SharedPreferences?> = HashMap()
val context: Context
private val preferenceMap: MutableMap<Tracker, SharedPreferences?> = HashMap()
val context: Context = context.applicationContext

/**
* Base preferences, tracker independent.
*/
val preferences: SharedPreferences
val preferences: SharedPreferences = context.getSharedPreferences(BASE_PREFERENCE_FILE, Context.MODE_PRIVATE)

/**
* If you want to use your own [org.matomo.sdk.dispatcher.Dispatcher]
*/
var dispatcherFactory: DispatcherFactory = DefaultDispatcherFactory()

init {
this.context = context.applicationContext
preferences = context.getSharedPreferences(BASE_PREFERENCE_FILE, Context.MODE_PRIVATE)
}

/**
* @return Tracker specific settings object
*/
fun getTrackerPreferences(tracker: Tracker): SharedPreferences? {
synchronized(mPreferenceMap) {
var newPrefs = mPreferenceMap[tracker]
synchronized(preferenceMap) {
var newPrefs = preferenceMap[tracker]
if (newPrefs == null) {
val prefName: String = try {
"org.matomo.sdk_" + Checksum.getMD5Checksum(tracker.name)
@@ -50,7 +45,7 @@ class Matomo private constructor(context: Context) {
"org.matomo.sdk_" + tracker.name
}
newPrefs = context.getSharedPreferences(prefName, Context.MODE_PRIVATE)
mPreferenceMap[tracker] = newPrefs
preferenceMap[tracker] = newPrefs
}
return newPrefs
}