Skip to content

Commit

Permalink
Merge pull request #522 from matomo-org/SimplifyCode
Browse files Browse the repository at this point in the history
Simplify code
  • Loading branch information
hannesa2 authored Jul 11, 2024
2 parents fd12a56 + a5ad6e4 commit aed4990
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
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
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 Expand Up @@ -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
Expand Down
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
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit aed4990

Please sign in to comment.