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.
feat: Push notification (customerio#31)
- Loading branch information
Showing
27 changed files
with
725 additions
and
42 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
base/src/main/java/io/customer/base/extenstions/DateExtensions.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,8 @@ | ||
package io.customer.base.extenstions | ||
|
||
import java.util.* | ||
import java.util.concurrent.TimeUnit | ||
|
||
fun Date.getUnixTimestamp(): Long { | ||
return TimeUnit.MILLISECONDS.toSeconds(this.time / 100) | ||
} |
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,49 @@ | ||
package io.customer.base.utils | ||
|
||
import io.customer.base.comunication.Action | ||
import io.customer.base.data.ErrorResult | ||
import io.customer.base.data.Result | ||
import io.customer.base.data.Success | ||
import io.customer.base.error.ErrorDetail | ||
import io.customer.base.error.StatusCode | ||
|
||
abstract class ActionUtils { | ||
companion object { | ||
private fun <T> unIdentifiedUserErrorResult(): ErrorResult<T> { | ||
return ErrorResult( | ||
error = ErrorDetail( | ||
statusCode = StatusCode.UnIdentifiedUser | ||
) | ||
) | ||
} | ||
|
||
private fun <T : Any> getErrorAction(errorResult: ErrorResult<T>): Action<T> { | ||
return object : Action<T> { | ||
override fun execute(): Result<T> = errorResult | ||
|
||
override fun enqueue(callback: Action.Callback<T>) { | ||
callback.onResult(errorResult) | ||
} | ||
|
||
override fun cancel() {} | ||
} | ||
} | ||
|
||
fun <T : Any> getUnidentifiedUserAction(): Action<T> { | ||
return getErrorAction(unIdentifiedUserErrorResult()) | ||
} | ||
|
||
fun getEmptyAction(): Action<Unit> { | ||
return object : Action<Unit> { | ||
override fun execute(): Result<Unit> = Success(data = Unit) | ||
|
||
override fun enqueue(callback: Action.Callback<Unit>) { | ||
callback.onResult(Success(data = Unit)) | ||
} | ||
|
||
override fun cancel() {} | ||
} | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -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,60 @@ | ||
import io.customer.android.Configurations | ||
import io.customer.android.Dependencies | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
} | ||
|
||
ext { | ||
PUBLISH_GROUP_ID = Configurations.artifactGroup | ||
PUBLISH_ARTIFACT_ID = "messaging-push-fcm" | ||
} | ||
|
||
apply from: "${rootDir}/scripts/publish-module.gradle" | ||
apply from: "${rootDir}/scripts/android-config.gradle" | ||
|
||
android { | ||
defaultConfig { | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
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' | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
// From: http://robolectric.org/getting-started/ | ||
includeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
api project(":sdk") | ||
|
||
implementation Dependencies.coroutinesCore | ||
implementation Dependencies.coroutinesAndroid | ||
implementation Dependencies.retrofit | ||
implementation Dependencies.retrofitMoshiConverter | ||
implementation Dependencies.okhttpLoggingInterceptor | ||
testImplementation Dependencies.androidxTestJunit | ||
androidTestImplementation Dependencies.junit4 | ||
|
||
api Dependencies.firebaseMessaging | ||
implementation Dependencies.googlePlayServicesBase | ||
|
||
} |
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 |
24 changes: 24 additions & 0 deletions
24
messagingpush/src/androidTest/java/io/customer/messagingpush/ExampleInstrumentedTest.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,24 @@ | ||
package io.customer.messagingpush | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("io.customer.messagingpush.test", appContext.packageName) | ||
} | ||
} |
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.customer.messagingpush"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application> | ||
<service | ||
android:name=".CustomerIOFirebaseMessagingService" | ||
android:exported="false"> | ||
<intent-filter android:priority="-1"> | ||
<action android:name="com.google.firebase.MESSAGING_EVENT" /> | ||
</intent-filter> | ||
</service> | ||
|
||
<!-- Action receiver for push interactions --> | ||
<receiver | ||
android:name=".CustomerIOPushActionReceiver" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="io.customer.messagingpush.PUSH_ACTION" /> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
|
||
</manifest> |
Oops, something went wrong.