forked from customerio/customerio-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,059 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
app/src/androidTest/java/io/customer/example/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
base/src/main/java/io/customer/base/extenstions/CoroutineExtensions.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
80 changes: 80 additions & 0 deletions
80
messaginginapp/src/main/java/io/customer/messaginginapp/ModuleMessagingInApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
messaginginapp/src/main/java/io/customer/messaginginapp/di/DIGraphMessaginIApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
29 changes: 29 additions & 0 deletions
29
messaginginapp/src/main/java/io/customer/messaginginapp/hook/ModuleInAppHookProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
Oops, something went wrong.