Skip to content

Commit

Permalink
feat: in app sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Aug 3, 2022
1 parent 94a64ea commit 1036c80
Show file tree
Hide file tree
Showing 47 changed files with 1,059 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
module: [sdk, messagingpush] # android modules
module: [sdk, messagingpush, messaginginapp] # android modules
name: Android Lint (${{ matrix.module }})
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
module: [sdk, messagingpush, base]
module: [sdk, messagingpush, messaginginapp, base]
name: Unit tests (${{ matrix.module }})
steps:
- uses: actions/checkout@v2
Expand Down

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ allprojects {
repositories {
google()
mavenCentral()
// added for gist SDK
maven {
url 'https://maven.gist.build'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object Dependencies {
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.DOKKA}"
const val firebaseMessaging =
"com.google.firebase:firebase-messaging:${Versions.FIREBASE_MESSAGING}"
const val gist = "build:gist:${Versions.GIST}"
const val googlePlayServicesBase =
"com.google.android.gms:play-services-base:${Versions.GOOGLE_PLAY_SERVICES_BASE}"
const val gradleNexusPublishPlugin =
Expand Down
5 changes: 3 additions & 2 deletions buildSrc/src/main/kotlin/io.customer/android/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.customer.android

object Versions {
internal const val ANDROID_GRADLE_PLUGIN = "7.0.3"
internal const val ANDROID_GRADLE_PLUGIN = "7.2.0"
internal const val ANDROIDX_TEST_JUNIT = "1.1.3"
internal const val ANDROIDX_TEST_RUNNER = "1.4.0"
internal const val ANDROIDX_TEST_RULES = "1.4.0"
Expand All @@ -15,13 +15,14 @@ object Versions {
internal const val FIREBASE_MESSAGING = "22.0.0"
internal const val GRADLE_NEXUS_PUBLISH_PLUGIN = "1.1.0"
internal const val GRADLE_VERSIONS_PLUGIN = "0.39.0"
internal const val GIST = "2.1.3"
internal const val GOOGLE_PLAY_SERVICES_BASE = "17.6.0"
internal const val KLUENT = "1.68"
internal const val KOTLIN = "1.5.31"
internal const val MATERIAL_COMPONENTS = "1.4.0"
internal const val MOCKITO_KOTLIN = "4.0.0"
internal const val MOCKITO = "3.11.2"
internal const val MOSHI = "1.12.0"
internal const val MOSHI = "1.13.0"
internal const val TIMBER = "5.0.0"
internal const val ROBOLECTRIC = "4.6.1"
internal const val OKHTTP = "4.9.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class BaseTest {

di = CustomerIOComponent(
sdkConfig = cioConfig,
context = this@BaseTest.context
context = application
)
di.fileStorage.deleteAllSdkFiles()
di.sharedPreferenceRepository.clearAll()
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 01 11:17:23 CDT 2021
#Wed May 11 20:51:08 PKT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
1 change: 1 addition & 0 deletions messaginginapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
52 changes: 52 additions & 0 deletions messaginginapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import io.customer.android.Configurations
import io.customer.android.Dependencies

plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

ext {
PUBLISH_GROUP_ID = Configurations.artifactGroup
PUBLISH_ARTIFACT_ID = "messaging-in-app"
}

apply from: "${rootDir}/scripts/publish-module.gradle"
apply from: "${rootDir}/scripts/android-config.gradle"
apply from: "${rootDir}/scripts/codecov-android.gradle"
apply from: "${rootDir}/scripts/android-module-testing.gradle"

android {
defaultConfig {
consumerProguardFiles "consumer-rules.pro"
}

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 {
api project(":base")
api project(":sdk")

implementation Dependencies.coroutinesCore
implementation Dependencies.coroutinesAndroid
implementation Dependencies.retrofit
api Dependencies.gist
implementation Dependencies.retrofitMoshiConverter
implementation Dependencies.okhttpLoggingInterceptor
testImplementation Dependencies.androidxTestJunit
androidTestImplementation Dependencies.junit4

}
Empty file.
21 changes: 21 additions & 0 deletions messaginginapp/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
5 changes: 5 additions & 0 deletions messaginginapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.customer.messaginginapp">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.customer.messaginginapp

import android.app.Application
import io.customer.messaginginapp.di.gistProvider
import io.customer.messaginginapp.hook.ModuleInAppHookProvider
import io.customer.sdk.CustomerIO
import io.customer.sdk.CustomerIOModule
import io.customer.sdk.data.request.MetricEvent
import io.customer.sdk.di.CustomerIOComponent
import io.customer.sdk.hooks.HookModule
import io.customer.sdk.hooks.HooksManager
import io.customer.sdk.repository.TrackRepository

class ModuleMessagingInApp internal constructor(
private val overrideDiGraph: CustomerIOComponent?,
private val organizationId: String
) : CustomerIOModule {

constructor(organizationId: String) : this(
overrideDiGraph = null,
organizationId = organizationId
)

override val moduleName: String
get() = "MessagingInApp"

private val diGraph: CustomerIOComponent
get() = overrideDiGraph ?: CustomerIO.instance().diGraph

private val trackRepository: TrackRepository
get() = diGraph.trackRepository

private val hooksManager: HooksManager by lazy { diGraph.hooksManager }

private val gistProvider by lazy { diGraph.gistProvider }

private val logger by lazy { diGraph.logger }

override fun initialize() {
initializeGist(organizationId)
setupHooks()
setupGistCallbacks()
}

private fun setupGistCallbacks() {
gistProvider.subscribeToEvents(
onMessageShown = { deliveryID ->
logger.debug("in-app message shown $deliveryID")
trackRepository.trackInAppMetric(
deliveryID = deliveryID,
event = MetricEvent.opened
)
},
onAction = { deliveryID: String, _: String, _: String ->
logger.debug("in-app message clicked $deliveryID")
trackRepository.trackInAppMetric(
deliveryID = deliveryID,
event = MetricEvent.clicked
)
},
onError = { errorMessage ->
logger.error("in-app message error occurred $errorMessage")
}
)
}

private fun setupHooks() {
hooksManager.add(
module = HookModule.MessagingInApp,
subscriber = ModuleInAppHookProvider()
)
}

private fun initializeGist(organizationId: String) {
gistProvider.initProvider(
application = diGraph.context as Application,
organizationId = organizationId
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.customer.messaginginapp.di

import io.customer.messaginginapp.provider.GistApi
import io.customer.messaginginapp.provider.GistApiProvider
import io.customer.messaginginapp.provider.GistInAppMessagesProvider
import io.customer.messaginginapp.provider.InAppMessagesProvider
import io.customer.sdk.di.CustomerIOComponent

internal val CustomerIOComponent.gistApiProvider: GistApi
get() = override() ?: GistApiProvider()

internal val CustomerIOComponent.gistProvider: InAppMessagesProvider
get() = override() ?: GistInAppMessagesProvider(gistApiProvider)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.customer.messaginginapp.hook

import io.customer.messaginginapp.di.gistProvider
import io.customer.messaginginapp.provider.InAppMessagesProvider
import io.customer.sdk.CustomerIO
import io.customer.sdk.di.CustomerIOComponent
import io.customer.sdk.hooks.ModuleHook
import io.customer.sdk.hooks.ModuleHookProvider

class ModuleInAppHookProvider : ModuleHookProvider() {

private val diGraph: CustomerIOComponent
get() = CustomerIO.instance().diGraph

private val gistProvider: InAppMessagesProvider
get() = diGraph.gistProvider

override fun profileIdentifiedHook(hook: ModuleHook.ProfileIdentifiedHook) {
gistProvider.setUserToken(hook.identifier)
}

override fun screenTrackedHook(hook: ModuleHook.ScreenTrackedHook) {
gistProvider.setCurrentRoute(hook.screen)
}

override fun beforeProfileStoppedBeingIdentified(hook: ModuleHook.BeforeProfileStoppedBeingIdentified) {
gistProvider.clearUserToken()
}
}
Loading

0 comments on commit 1036c80

Please sign in to comment.