Skip to content

Commit

Permalink
[FIX/#117] Service handleIntent로 메서드 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Aug 23, 2024
1 parent 9c6c7dc commit 5c99405
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ class GentiMessagingService : FirebaseMessagingService() {
}
}

override fun handleIntent(intent: Intent?) {
intent?.let {
if (intent.getStringExtra(MSG_TITLE).isNullOrEmpty()) return
sendNotification(
mapOf(
MSG_TITLE to it.getStringExtra(MSG_TITLE).toString(),
MSG_BODY to it.getStringExtra(MSG_BODY).toString(),
),
)
}
}

private fun sendNotification(messageBody: Map<String, String>) {
val notifyId = Random().nextInt()
val intent = Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val intent =
MainActivity.getIntent(this, TYPE_DEFAULT).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent =
PendingIntent.getActivity(
this,
Expand Down Expand Up @@ -71,7 +84,9 @@ class GentiMessagingService : FirebaseMessagingService() {
}

companion object {
private const val MSG_TITLE = "MSG_TITLE"
private const val MSG_BODY = "MSG_BODY"
private const val MSG_TITLE = "title"
private const val MSG_BODY = "body"

const val TYPE_DEFAULT = "TYPE_DEFAULT"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.genti.presentation.main

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
Expand Down Expand Up @@ -41,6 +42,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
initBnvItemSelectedListener()
initCreateBtnListener()
setStatusBarColor()
getNotificationIntent()
observeStatusResult()
observeNotificationState()
observeResetResult()
Expand Down Expand Up @@ -90,6 +92,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
setStatusBarColorFromResource(R.color.background_white)
}

private fun getNotificationIntent() {
if (!intent.getStringExtra(EXTRA_TYPE).isNullOrEmpty()) {
viewModel.getGenerateStatusFromServer(true)
}
}

private fun navigateByGenerateStatus() {
when (viewModel.currentStatus) {
GenerateStatus.NEW_REQUEST_AVAILABLE -> {
Expand Down Expand Up @@ -174,5 +182,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
companion object {
private const val DIALOG_FINISHED = "DIALOG_FINISHED"
private const val DIALOG_ERROR = "DIALOG_ERROR"

private const val EXTRA_TYPE = "EXTRA_DEFAULT"

@JvmStatic
fun getIntent(
context: Context,
type: String? = null,
) = Intent(context, MainActivity::class.java).apply {
putExtra(EXTRA_TYPE, type)
}
}
}

0 comments on commit 5c99405

Please sign in to comment.