Skip to content

Commit

Permalink
Merge pull request #292 from JaesungLeee/develop
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
JaesungLeee authored Aug 6, 2023
2 parents 247e2b2 + c1d5c5f commit ea3c488
Show file tree
Hide file tree
Showing 128 changed files with 3,144 additions and 652 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ render.experimental.xml
# Keystore files
*.jks
*.keystore
output-metadata.json

# Google Services (e.g. APIs or Firebase)
google-services.json
#google-services.json

# Android Profiling
*.hprof
Expand Down
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
id 'com.google.gms.google-services'
}

def keystorePropertiesFile = rootProject.file("keystore.properties")
Expand All @@ -28,8 +29,8 @@ android {
applicationId "com.mashup.ssamd"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -95,4 +96,8 @@ dependencies {

// kakao login
implementation Dep.Kakao.sdk

// firebase
implementation platform(Dep.Firebase.firebaseBom)
implementation Dep.Firebase.cloudMessaging
}
76 changes: 76 additions & 0 deletions app/src/debug/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"project_info": {
"project_number": "832727038255",
"project_id": "keylink-731df",
"storage_bucket": "keylink-731df.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:832727038255:android:2a36823f5b6835c29d09da",
"android_client_info": {
"package_name": "com.mashup.ssamd"
}
},
"oauth_client": [
{
"client_id": "832727038255-789jestndq3tqhosf2rj0lodgv06ii23.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.mashup.ssamd",
"certificate_hash": "1519448b6407650d0d0e6d3fe0c2cb361ddeef68"
}
},
{
"client_id": "832727038255-dmmombtpj0n3rjihgu8nsk3didie2h97.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCYzKRoLm4ZdbAGgIJ9kgGtQQCLed_Q37M"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "832727038255-dmmombtpj0n3rjihgu8nsk3didie2h97.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:832727038255:android:bc5a57ee6437bce19d09da",
"android_client_info": {
"package_name": "com.mashup.ssamd.debug"
}
},
"oauth_client": [
{
"client_id": "832727038255-dmmombtpj0n3rjihgu8nsk3didie2h97.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCYzKRoLm4ZdbAGgIJ9kgGtQQCLed_Q37M"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "832727038255-dmmombtpj0n3rjihgu8nsk3didie2h97.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
13 changes: 11 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@

<application
android:name=".SsamDApplication"
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="${appName}"
android:supportsRtl="true"
android:theme="@style/Theme.Ssam_D_Android"
tools:targetApi="31" />
android:usesCleartextTraffic="true"
tools:targetApi="31">

<service
android:name=".KeyLinkService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>

</manifest>
30 changes: 30 additions & 0 deletions app/src/main/java/com/mashup/ssamd/KeyLinkService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mashup.ssamd

import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.mashup.ssamd.notification.ShowPushNotificationUseCase
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/07/29
*/
@AndroidEntryPoint
class KeyLinkService : FirebaseMessagingService() {

@Inject
lateinit var showPushNotificationUseCase: ShowPushNotificationUseCase

override fun onNewToken(token: String) {
super.onNewToken(token)
Log.e("SSSS","Device Token : $token")
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
showPushNotificationUseCase.invoke(remoteMessage)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.mashup.ssamd.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import com.google.firebase.messaging.FirebaseMessagingService

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/08/01
*/
object NotificationConfigs {

private const val SIGNAL_CHANNEL_ID = "KeyLinkSignal"
private const val SIGNAL_CHANNEL_NAME = "구독 키워드 시그널 도착 알림"
private const val CHAT_CHANNEL_ID = "KeyLinkChat"
private const val CHAT_CHANNEL_NAME = "채팅 도착 알림"

fun notifyReceivedSignal(
context: Context,
setNotificationAttrs: NotificationCompat.Builder.() -> NotificationCompat.Builder
) {
initializeNotificationChannel(context)
context.getNotificationManager().run {
notify(
(System.currentTimeMillis()/1000).toInt(),
NotificationCompat.Builder(
context,
SIGNAL_CHANNEL_ID
).setNotificationAttrs().build()
)
}
}

fun notifyNewChat(
context: Context,
setNotificationAttrs: NotificationCompat.Builder.() -> NotificationCompat.Builder
) {
initializeNotificationChannel(context)
context.getNotificationManager().run {
notify(
(System.currentTimeMillis()/1000).toInt(),
NotificationCompat.Builder(
context,
CHAT_CHANNEL_ID
).setNotificationAttrs().build()
)
}
}

private fun initializeNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.getNotificationManager().run {
val signalChannel = NotificationChannel(
SIGNAL_CHANNEL_ID,
SIGNAL_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH
)

val chatChannel = NotificationChannel(
CHAT_CHANNEL_ID,
CHAT_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH
)
createNotificationChannels(listOf(signalChannel, chatChannel))
}
}
}

private fun Context.getNotificationManager(): NotificationManager {
return getSystemService(FirebaseMessagingService.NOTIFICATION_SERVICE) as NotificationManager
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mashup.ssamd.notification

import com.google.firebase.messaging.RemoteMessage
import com.mashup.ssamd.notification.builder.NotificationBuilder
import javax.inject.Inject

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/08/01
*/
class ShowPushNotificationUseCase @Inject constructor(
private val notificationBuilder: NotificationBuilder
) {
operator fun invoke(remoteMessage: RemoteMessage) {
val title = remoteMessage.data["title"].orEmpty()
val body = remoteMessage.data["body"].orEmpty()
val notificationType = remoteMessage.data["notiType"].orEmpty()
val roomId = remoteMessage.data["roomId"].orEmpty()

if (title != null && body != null && notificationType != null && roomId != null) {
when (notificationType) {
SIGNAL_TYPE -> notificationBuilder.showReceivedSignalNotification(title, body)
CHAT_TYPE -> notificationBuilder.showNewChatNotification(title, body, roomId)
}
}
}

companion object {
private const val SIGNAL_TYPE = "SIGNAL"
private const val CHAT_TYPE = "CHAT"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mashup.ssamd.notification.builder

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/08/01
*/
interface NotificationBuilder {

fun showReceivedSignalNotification(title: String, body: String)

fun showNewChatNotification(title: String, body: String, roomId: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.mashup.ssamd.notification.builder

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.core.app.NotificationCompat
import com.mashup.presentation.navigation.MainActivity
import com.mashup.ssamd.R
import com.mashup.ssamd.notification.NotificationConfigs
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/08/01
*/
class NotificationBuilderImpl @Inject constructor(
@ApplicationContext private val context: Context
) : NotificationBuilder {

override fun showReceivedSignalNotification(title: String, body: String) {
NotificationConfigs.notifyReceivedSignal(context) {
setStyle(NotificationCompat.BigTextStyle().bigText(body))
setSmallIcon(R.mipmap.ic_launcher)
setContentTitle(title)
setContentText(body)
priority = NotificationCompat.PRIORITY_HIGH
setAutoCancel(true)
setCategory(NotificationCompat.CATEGORY_MESSAGE)
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
setContentIntent(makeSignalLauncherPendingIntent())
}
}

override fun showNewChatNotification(title: String, body: String, roomId: String) {
NotificationConfigs.notifyNewChat(context) {
setStyle(NotificationCompat.BigTextStyle().bigText(body))
setSmallIcon(R.mipmap.ic_launcher)
setContentTitle(title)
setContentText(body)
priority = NotificationCompat.PRIORITY_HIGH
setAutoCancel(true)
setCategory(NotificationCompat.CATEGORY_MESSAGE)
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
setContentIntent(makeChatLauncherPendingIntent())
}
}

private fun createMainIntent(): Intent {
return Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
}

private fun makeChatLauncherPendingIntent(): PendingIntent {
val intent = createMainIntent()
val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ONE_SHOT
} else {
PendingIntent.FLAG_ONE_SHOT
}

return PendingIntent.getActivity(
context,
(System.currentTimeMillis()).toInt(),
intent,
pendingIntentFlags
)
}

private fun makeSignalLauncherPendingIntent(): PendingIntent {
val intent = createMainIntent()
val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ONE_SHOT
} else {
PendingIntent.FLAG_ONE_SHOT
}

return PendingIntent.getActivity(
context,
(System.currentTimeMillis()).toInt(),
intent,
pendingIntentFlags
)
}
}
Loading

0 comments on commit ea3c488

Please sign in to comment.