Skip to content

Commit

Permalink
Migrate published API to Kotlin (close #561)
Browse files Browse the repository at this point in the history
* Migrate the public API to Kotlin (#1)

* Rebase for Android tracker v4.2 changes

* Translate Controllers

* Translate entity folder

* Translate Emitter, Gdpr, and GlobalContext Configs

* Tidy up remaining Config classes

* Add stuff to build.gradle files

* Compile both kotlin and java

* Add 'public' modifier to various things

* Make Gdpr properties nullable

* Convert util to kotlin

* Convert payload classes

* Be strict about Payload Map types

* Translate Tracker stuff

* Remove accidental character

* Make Map types in Payload less strict

* Translate Emitter classes

* Use entrySet() properly

* Remove SDJ Precondition

* Update all changes from Android v4.1

* Convert Event classes to Kotlin

* Fix tests

* Don't test for builders null handling

* Translate network classes

* Translate global context stuff

* Translate Snowplow class

* Add new Kotlin demo (doesn't run)

* Configure Kotlin demo app

* Move public configuration classes to Snowplow package

* Distinguish between the demo apps

* Prepare for 0.1.0 release

* Restore MessageNotificationTrigger enum

* Fix Kotlin demo

* Restore original snowplow-android-tracker repo links

* Restore old version numbers

* Restore CHANGELOG

* Remove 'Kotlin' from README

Bump dokka dependency
  • Loading branch information
mscwilson committed Nov 30, 2022
1 parent 97ec6a7 commit aaec930
Show file tree
Hide file tree
Showing 272 changed files with 6,871 additions and 6,550 deletions.
2 changes: 1 addition & 1 deletion .doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "Snowplow Android Tracker"
PROJECT_NAME = "Snowplow Kotlin Android Tracker"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ With this tracker you can collect event data from your applications, games or fr

### Demo apps using the Snowplow Android Tracker

A [demo app](https://github.com/snowplow/snowplow-android-tracker/tree/master/snowplow-demo-app) is part of this repository.
Two demo apps are included in this repository: one in [Java](https://github.com/snowplow/snowplow-android-tracker/tree/next/snowplow-demo-java), one in [Kotlin](https://github.com/snowplow/snowplow-android-tracker/tree/next/snowplow-demo-kotlin).

An example of app instrumented with the Android Tracker can be found in the [snowplow-android-tracker-examples](https://github.com/snowplow-incubator/snowplow-android-tracker-examples) repository.

### Instrument the Android Tracker

Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
Expand All @@ -9,6 +9,9 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.7.20"
classpath "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.10.1"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.13.0'
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include ':snowplow-tracker'
include ':snowplow-demo-app'
include ':snowplow-demo-java'
include ':snowplow-demo-kotlin'

project(":snowplow-tracker").name = "snowplow-android-tracker"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import androidx.core.content.ContextCompat;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.util.Consumer;
import androidx.core.util.Pair;

import com.snowplowanalytics.snowplow.Snowplow;
import com.snowplowanalytics.snowplow.configuration.EmitterConfiguration;
Expand All @@ -55,14 +54,13 @@
import com.snowplowanalytics.snowplow.controller.TrackerController;
import com.snowplowanalytics.snowplow.emitter.BufferOption;
import com.snowplowanalytics.snowplow.globalcontexts.GlobalContext;
import com.snowplowanalytics.snowplow.internal.remoteconfiguration.ConfigurationState;
import com.snowplowanalytics.snowplow.tracker.DevicePlatform;
import com.snowplowanalytics.snowplow.tracker.LoggerDelegate;
import com.snowplowanalytics.snowplow.network.HttpMethod;
import com.snowplowanalytics.snowplow.network.RequestCallback;
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
import com.snowplowanalytics.snowplow.tracker.LogLevel;
import com.snowplowanalytics.snowplow.internal.utils.Util;
import com.snowplowanalytics.core.utils.Util;
import com.snowplowanalytics.snowplow.util.Basis;
import com.snowplowanalytics.snowplow.util.TimeMeasure;
import com.snowplowanalytics.snowplowtrackerdemo.utils.DemoUtils;
Expand All @@ -74,7 +72,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.snowplowanalytics.snowplow.internal.utils.Util.addToMap;
import static com.snowplowanalytics.core.utils.Util.addToMap;

/**
* Classic Demo Activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import androidx.annotation.Nullable;

import com.snowplowanalytics.snowplow.tracker.LogLevel;
import com.snowplowanalytics.snowplow.internal.tracker.Logger;
import com.snowplowanalytics.core.tracker.Logger;

/**
* Main Activity
Expand All @@ -36,9 +36,8 @@ public class MainActivity extends Activity {
private Button _liteBtn;

private final String repo_url = "https://github.com/snowplow/snowplow-android-tracker";
private final String integration_url = "https://github.com/snowplow/snowplow/wiki/Android-Integration";
private final String tech_docs_url = "https://github.com/snowplow/snowplow/wiki/Android-Tracker";
private final String setup_guide_url = "https://github.com/snowplow/snowplow/wiki/Android-Tracker-Setup";
private final String tech_docs_url = "https://snowplow.github.io/snowplow-android-tracker";
private final String snowplow_docs_url = "https://docs.snowplow.io/docs/collecting-data/collecting-from-own-applications/mobile-trackers";

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -59,22 +58,17 @@ public void onClick(View v) {
// Setup Hyperlinks

TextView link1 = (TextView) findViewById(R.id.link_tech_docs);
String linkText1 = "- <a href='" + tech_docs_url + "'>Technical Documentation</a>";
String linkText1 = "- <a href='" + tech_docs_url + "'>API Documentation</a>";
link1.setText(Html.fromHtml(linkText1));
link1.setMovementMethod(LinkMovementMethod.getInstance());

TextView link2 = (TextView) findViewById(R.id.link_integration);
String linkText2 = "- <a href='" + integration_url + "'>Integration Examples</a>";
link2.setText(Html.fromHtml(linkText2));
link2.setMovementMethod(LinkMovementMethod.getInstance());

TextView link3 = (TextView) findViewById(R.id.link_repo);
String linkText3 = "- <a href='" + repo_url + "'>Github Repository</a>";
link3.setText(Html.fromHtml(linkText3));
link3.setMovementMethod(LinkMovementMethod.getInstance());

TextView link4 = (TextView) findViewById(R.id.link_setup_guide);
String linkText4 = "- <a href='" + setup_guide_url + "'>Setup Guide</a>";
TextView link4 = (TextView) findViewById(R.id.link_docs);
String linkText4 = "- <a href='" + snowplow_docs_url + "'>Documentation</a>";
link4.setText(Html.fromHtml(linkText4));
link4.setMovementMethod(LinkMovementMethod.getInstance());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import androidx.annotation.NonNull;

import com.snowplowanalytics.snowplow.controller.TrackerController;
import com.snowplowanalytics.snowplow.event.AbstractPrimitive;
import com.snowplowanalytics.snowplow.event.DeepLinkReceived;
import com.snowplowanalytics.snowplow.event.MessageNotification;
import com.snowplowanalytics.snowplow.event.MessageNotificationTrigger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/link_integration"
android:text="@string/link_docs"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textSize="16sp"
android:textColor="@android:color/black"
android:id="@+id/link_integration"
android:layout_below="@+id/link_setup_guide"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/link_setup_guide"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textSize="16sp"
android:textColor="@android:color/black"
android:id="@+id/link_setup_guide"
android:id="@+id/link_docs"
android:layout_below="@+id/link_tech_docs"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<resources>
<string name="app_name">Tracker Demo</string>
<string name="app_name">Tracker Demo (Java)</string>

<string name="main_demo_header">Android Tracker Demo</string>
<string name="main_demo_header">Java Android Tracker Demo</string>
<string name="main_demo_info">
To launch the demonstration simply click the button below.
The demo will send every combination of event construction available to the tracker to an
endpoint you will enter on the demo page.
</string>
<string name="link_header">Useful Links:</string>
<string name="link_tech_docs">- Technical Documentation</string>
<string name="link_integration">- Integration Examples</string>
<string name="link_setup_guide">- Setup Guide</string>
<string name="link_tech_docs">- API Documentation</string>
<string name="link_docs">- Documentation</string>
<string name="link_repo">- Github Repository</string>

<string name="main_demo_button">Tracker Demo</string>

<string name="title_activity_demo">Tracker Demo</string>
<string name="demo_header">Tracker Demo</string>
<string name="demo_header">Tracker Demo (Java)</string>
<string name="demo_info">Enter settings below and then hit start.</string>

<string name="uri_text">URI:</string>
Expand Down
1 change: 1 addition & 0 deletions snowplow-demo-kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions snowplow-demo-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.snowplowanalytics.snowplowdemokotlin'
compileSdkVersion 32

defaultConfig {
applicationId 'com.snowplowanalytics.snowplowdemokotlin'
minSdkVersion 24
targetSdkVersion 32
versionCode 1
versionName '1.0'

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':snowplow-android-tracker')
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.browser:browser:1.3.0'
}
21 changes: 21 additions & 0 deletions snowplow-demo-kotlin/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
37 changes: 37 additions & 0 deletions snowplow-demo-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.snowplowanalytics.snowplowdemokotlin" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!--Enable the permissions below for getting users geographical location.-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_snowplow"
android:label="@string/app_name"
android:fullBackupContent="false"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Demo"
android:label="@string/title_activity_demo"
android:screenOrientation="portrait">
</activity>
</application>

</manifest>
Loading

0 comments on commit aaec930

Please sign in to comment.