Skip to content

Commit

Permalink
3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKaN committed May 2, 2024
2 parents 190b8c2 + 565d4f3 commit bffb050
Show file tree
Hide file tree
Showing 41 changed files with 1,224 additions and 384 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
run: chmod +x gradlew
- name: Check code style
run: ./gradlew ktlintCheck --continue
- name: Check API binary compatibility
run: ./gradlew apiCheck
- name: Run tests
run: ./gradlew testDebug
- name: Build project
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ jobs:
run: chmod +x gradlew
- name: Generate Javadoc
run: ./gradlew javaDocReleaseGeneration --no-parallel
- name: Upload artifacts
run: ./gradlew publish --no-configuration-cache
- name: Close repository
run: ./gradlew closeAndReleaseRepository --no-configuration-cache
- name: Release artifacts
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Piano Analytics SDK for Android

## v3.4.0
* Updated to Kotlin 1.9
* Added support for `PianoConsents`
* Added `PrivacyMode.CUSTOM`, that will be used if set `ConsentMode.CUSTOM`
* Deprecated `PrivacyModesStorage`, use `PianoConsents` instead
* Added switching to main thread when required
* Removed requirement for `READ_PHONE_STATE` permission for Android 6-9
* Updated dependencies:
- Kotlin [1.8.22 -> 1.9.23]
- com.squareup.moshi:moshi [1.15.0 -> 1.15.1]
https://github.com/square/moshi/
- androidx.lifecycle:lifecycle-process [2.6.2 -> 2.7.0]
https://developer.android.com/jetpack/androidx/releases/lifecycle#2.7.0

## v3.3.5
* Decreased default offline storage lifetime for events
* Fixed bug with cyclic read/save current privacy mode after its expiration
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Pianoanlayticsandroid.NoActionBar">
android:theme="@style/Theme.Pianoanlayticsandroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/example/pianoanalytics/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Application
import io.piano.android.analytics.Configuration
import io.piano.android.analytics.PianoAnalytics
import io.piano.android.analytics.model.VisitorIDType
import io.piano.android.consents.PianoConsents
import io.piano.android.consents.models.ConsentConfiguration
import timber.log.Timber

class App: Application() {
Expand All @@ -15,7 +17,11 @@ class App: Application() {
site = 552987,
visitorIDType = VisitorIDType.ADVERTISING_ID
).ignoreLimitedAdTracking(true).build()
PianoAnalytics.init(applicationContext, configuration).apply {
val pianoConsents = PianoConsents.init(
applicationContext,
ConsentConfiguration(requireConsent = true)
)
PianoAnalytics.init(applicationContext, configuration, pianoConsents).apply {
// just an example of callback
eventProcessorCallback = PianoAnalytics.EventProcessorCallback { events ->
events.forEach { event ->
Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/com/example/pianoanalytics/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.example.pianoanalytics

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import by.kirich1409.viewbindingdelegate.viewBinding
Expand All @@ -10,9 +12,13 @@ import io.piano.android.analytics.PianoAnalytics
import io.piano.android.analytics.model.Event
import io.piano.android.analytics.model.Property
import io.piano.android.analytics.model.PropertyName
import io.piano.android.consents.PianoConsents
import io.piano.android.consents.models.ConsentMode
import io.piano.android.consents.models.Purpose

class MainActivity : AppCompatActivity(R.layout.activity_main) {
private val binding: ActivityMainBinding by viewBinding(R.id.recyclerview)
private val pianoConsents by lazy { PianoConsents.getInstance() }

private val animals = listOf(
"___media___",
Expand Down Expand Up @@ -43,6 +49,40 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.main_menu, menu)
return true
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
val currentPaConsent = requireNotNull(pianoConsents.consents[Purpose.AUDIENCE_MEASUREMENT]).mode
val chosenItem = when (currentPaConsent) {
ConsentMode.OPT_IN -> R.id.consent_opt_in
ConsentMode.ESSENTIAL -> R.id.consent_essential
ConsentMode.OPT_OUT -> R.id.consent_opt_out
ConsentMode.CUSTOM -> R.id.consent_custom
ConsentMode.NOT_ACQUIRED -> null
}
if (chosenItem != null) {
menu.findItem(chosenItem).isChecked = true
}
return super.onPrepareOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val newMode = when (item.itemId) {
R.id.consent_opt_in -> ConsentMode.OPT_IN
R.id.consent_essential -> ConsentMode.ESSENTIAL
R.id.consent_opt_out -> ConsentMode.OPT_OUT
R.id.consent_custom -> ConsentMode.CUSTOM
else -> null
}
return if (newMode != null) {
pianoConsents.set(Purpose.AUDIENCE_MEASUREMENT, newMode)
true
} else super.onOptionsItemSelected(item)
}

private fun onItemClick(item: String) {
PianoAnalytics.getInstance().sendEvents(
Event.Builder(Event.CLICK_NAVIGATION)
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single" >
<item
android:id="@+id/consent_opt_in"
android:title="opt in" />
<item
android:id="@+id/consent_essential"
android:title="essential" />
<item
android:id="@+id/consent_opt_out"
android:title="opt out" />
<item
android:id="@+id/consent_custom"
android:title="custom" />
</group>
</menu>
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.app) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.binaryCompatibility) apply false
alias(libs.plugins.mavenRelease) apply false
alias(libs.plugins.moshiIR) apply false
alias(libs.plugins.versionUpdater)
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ android.useAndroidX=true
android.enableJetifier=false
android.nonTransitiveRClass=true
android.nonFinalResIds=false
android.defaults.buildfeatures.buildconfig=true

org.gradle.configuration-cache=true
kotlin.incremental.useClasspathSnapshot=true
31 changes: 17 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
[versions]
# Plugins
kotlin = "1.8.22"
android = "8.1.3"
versionUpdater = "0.49.0"
ktlint = "11.6.1"
dokka = "1.8.20"
mavenRelease = "0.25.3"
moshiIR = "0.22.1"
kotlin = "1.9.23"
android = "8.3.2"
binaryCompatibility = "0.14.0"
versionUpdater = "0.51.0"
ktlint = "12.1.0"
mavenRelease = "0.28.0"
moshiIR = "0.25.1"
ksp = "1.9.23-1.0.20"

# AndroidX libraries
compatLibrary = "1.6.1"
lifecycle = "2.6.2"
materialLibrary = "1.10.0"
lifecycle = "2.7.0"
materialLibrary = "1.11.0"

# Third party Libraries
googleAdsId = "18.0.1"
huaweiAdsId = "3.4.26.303"
retrofit = "2.6.4"
moshi = "1.15.1"
okhttp = "4.12.0"
moshi = "1.15.0"
pianoConsents = "1.0.0"
timber = "5.0.1"
viewBindingProperty = "1.5.9"

# Test Libraries
junit = "4.13.2"
androidxTestCore = "1.5.0"
mockitoKotlin = "2.2.0"
mockitoCore = "5.7.0"
mockitoCore = "5.11.0"

[plugins]
android-library = { id = "com.android.library", version.ref = "android" }
android-app = { id = "com.android.application", version.ref = "android" }
binaryCompatibility = {id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompatibility" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
mavenRelease = { id = "com.vanniktech.maven.publish", version.ref = "mavenRelease" }
moshiIR = { id = "dev.zacsweers.moshix", version.ref = "moshiIR"}
versionUpdater = { id = "com.github.ben-manes.versions", version.ref = "versionUpdater" }
Expand All @@ -44,10 +46,11 @@ lifecycleProcess = { module = "androidx.lifecycle:lifecycle-process", version.re
material = { module = "com.google.android.material:material", version.ref = "materialLibrary" }
googleAdsId = { module = "com.google.android.gms:play-services-ads-identifier", version.ref = "googleAdsId" }
huaweiAdsId = { module = "com.huawei.hms:hms-ads-identifier", version.ref = "huaweiAdsId" }
moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttpLogging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
pianoConsents = { module = "io.piano.android:consents", version.ref = "pianoConsents" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
viewBindingProperty = { module = "com.github.kirich1409:viewbindingpropertydelegate", version.ref = "viewBindingProperty" }

kotlinJunit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
Loading

0 comments on commit bffb050

Please sign in to comment.