-
Notifications
You must be signed in to change notification settings - Fork 33
Refactor to support JVM #13
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
Conversation
import android.content.SharedPreferences | ||
import com.segment.analytics.kotlin.core.utilities.KVS | ||
|
||
class AndroidKVS(val sharedPreferences: SharedPreferences): KVS { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.
import com.segment.analytics.kotlin.core.utilities.KVS | ||
|
||
class AndroidKVS(val sharedPreferences: SharedPreferences): KVS { | ||
override fun getInt(key: String, defaultVal: Int): Int = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider a default parameter value for defaultVal or add an additional method if they don't want to pass a defaultVal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the rest of them were defaulted to 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an internal api, only being used in 1 place currently. im not sure if having default values will give us any additional benefits
@@ -22,7 +22,8 @@ import java.util.* | |||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | |||
class EventsFileTest { | |||
private val epochTimestamp = Date(0).toInstant().toString() | |||
private val sharedPreferences = MemorySharedPreferences() | |||
private val _sharedPreferences = MemorySharedPreferences() | |||
private val kvStore = AndroidKVS(_sharedPreferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed you used _sharedPreferences for shadow var. We often do this to signify to "not touch" on the obj-c side. Do we want to apply underscore to kvStore as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this was a refactoring issue. normally ur suggestion would apply, but this is a test file so im not sure if the concept of shadow var / "do not touch" applies here
import sovran.kotlin.Store | ||
import java.io.File | ||
|
||
fun mockAnalytics(): Analytics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? It may be beneficial to add here for when we have new eng coming and knowing if / who they should use this for testing.
@@ -19,14 +20,14 @@ import java.util.concurrent.atomic.AtomicInteger | |||
class SegmentDestination( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be good to add here since it's such an integral part of our library (not related to PR)
@@ -108,6 +109,7 @@ class SegmentDestination( | |||
} | |||
|
|||
override fun flush() { | |||
println("flush") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove println or alternate for analytics?.log()?
import kotlinx.serialization.json.JsonObject | ||
import sovran.kotlin.Store | ||
|
||
interface Storage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.
} | ||
} | ||
|
||
interface StorageProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.
|
||
// Platform abstraction for managing plugins' execution (of a specific type) | ||
// All operations are thread safe via the `synchronized` function | ||
internal class Mediator(internal val plugins: MutableList<Plugin>) { | ||
class Mediator(internal val plugins: MutableList<Plugin>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the mediator pattern ++!
Should we give it a more specific name? and since it's public now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im actually going to move it back to being internal and expose the applyClosure
function via Analytics
import kotlinx.serialization.json.buildJsonObject | ||
import kotlinx.serialization.json.put | ||
|
||
class ContextPlugin: Plugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
import java.io.FileOutputStream | ||
import java.util.* | ||
|
||
class PropertiesFile(private val directory: File, writeKey: String): KVS { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
import sovran.kotlin.Subscriber | ||
import java.io.File | ||
|
||
class StorageImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
val dispatcher = coroutineContext[ContinuationInterceptor] as CoroutineDispatcher | ||
val analytics = Analytics("gNHARErhCjBxvBErXOMrTTuwoIlxKkCg") { | ||
application = "MainApp" | ||
// flushInterval = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment?
} | ||
) | ||
analytics.flush() | ||
delay(30 * 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be good to know why we're delaying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nit picky review
import com.segment.analytics.kotlin.core.* | ||
import com.segment.analytics.kotlin.core.platform.* | ||
|
||
class TestRunPlugin(override val name: String = "TestRunPlugin", var closure: (BaseEvent?) -> Unit): EventPlugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, added some docs to outline use-cases
@@ -62,7 +67,7 @@ public fun Analytics( | |||
} | |||
|
|||
// Logger instance that uses the android `Log` class | |||
object AndroidLogger: Logger("AndroidLogger") { | |||
object AndroidLogger : Logger("AndroidLogger") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we adding spaces or was this an accident? I noticed others don't have that space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i ran a auto-lint on the project after the rebase, so all of the files should conform to the same convention
Kind of a big refactor, so will try to capture as much context as possible.
We have refactored our
analytics-kotlin
module into 2 seperate modules in order to support JVM as a first-class source. The 2 componentscore
: main analytics moduleandroid
: android analytics module which defines android-specific functionality, built on top ofcore
This refactor will allow users to import the analytics-kotlin based on the app type.
If using a JVM kotlin app you would do
dependencies { implementation 'com.github.segmentio.kotlin-analytics:core' }
and for android kotlin app you would do
dependencies { implementation 'com.github.segmentio.kotlin-analytics:android' }
Closes #11