Skip to content

Commit

Permalink
feat: Push notification (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed Nov 2, 2021
1 parent cbdc3f8 commit c639802
Show file tree
Hide file tree
Showing 27 changed files with 725 additions and 42 deletions.
@@ -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)
}
49 changes: 49 additions & 0 deletions base/src/main/java/io/customer/base/utils/ActionUtils.kt
@@ -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() {}
}
}
}

}
12 changes: 10 additions & 2 deletions buildSrc/src/main/kotlin/io.customer/android/Dependencies.kt
Expand Up @@ -9,7 +9,8 @@ object Dependencies {
const val coroutinesAndroid =
"org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.COROUTINES}"
const val androidxCoreKtx = "androidx.core:core-ktx:${Versions.ANDROIDX_KTX}"
const val androidxAnnotations = "androidx.annotation:annotation:${Versions.ANDROIDX_ANNOTATIONS}"
const val androidxAnnotations =
"androidx.annotation:annotation:${Versions.ANDROIDX_ANNOTATIONS}"
const val coroutinesCore =
"org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.COROUTINES}"
const val materialComponents =
Expand All @@ -19,17 +20,24 @@ object Dependencies {
"org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.COROUTINES}"
const val espressoCore = "androidx.test.espresso:espresso-core:${Versions.ESPRESSO}"
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.DOKKA}"
const val firebaseMessaging =
"com.google.firebase:firebase-messaging:${Versions.FIREBASE_MESSAGING}"
const val googlePlayServicesBase =
"com.google.android.gms:play-services-base:${Versions.GOOGLE_PLAY_SERVICES_BASE}"
const val gradleNexusPublishPlugin =
"io.github.gradle-nexus:publish-plugin:${Versions.GRADLE_NEXUS_PUBLISH_PLUGIN}"
const val gradleVersionsPlugin =
"com.github.ben-manes:gradle-versions-plugin:${Versions.GRADLE_VERSIONS_PLUGIN}"
const val junit4 = "junit:junit:${Versions.JUNIT4}"
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}"
const val timber = "com.jakewharton.timber:timber:${Versions.TIMBER}"
const val moshi = "com.squareup.moshi:moshi:${Versions.MOSHI}"
const val moshiCodeGen = "com.squareup.moshi:moshi-kotlin-codegen:${Versions.MOSHI}"
const val robolectric = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}"
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}"
const val retrofitMoshiConverter = "com.squareup.retrofit2:converter-moshi:${Versions.RETROFIT}"
const val okhttp = "com.squareup.okhttp3:okhttp:${Versions.OKHTTP}"
const val okhttpLoggingInterceptor = "com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}"
const val okhttpLoggingInterceptor =
"com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}"

}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/io.customer/android/Versions.kt
Expand Up @@ -11,10 +11,13 @@ object Versions {
internal const val DOKKA = "1.5.0"
internal const val JUNIT4 = "4.13.2"
internal const val ESPRESSO = "3.4.0"
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"
const val KOTLIN = "1.5.21"
internal const val GOOGLE_PLAY_SERVICES_BASE = "17.6.0"
internal const val KOTLIN = "1.5.31"
internal const val MATERIAL_COMPONENTS = "1.4.0"
internal const val MOSHI = "1.12.0"
internal const val TIMBER = "5.0.0"
internal const val ROBOLECTRIC = "4.6.1"
internal const val OKHTTP = "4.9.1"
Expand Down
1 change: 1 addition & 0 deletions messagingpush/.gitignore
@@ -0,0 +1 @@
/build
60 changes: 60 additions & 0 deletions messagingpush/build.gradle
@@ -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.
21 changes: 21 additions & 0 deletions messagingpush/proguard-rules.pro
@@ -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
@@ -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)
}
}
27 changes: 27 additions & 0 deletions messagingpush/src/main/AndroidManifest.xml
@@ -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>

0 comments on commit c639802

Please sign in to comment.