Skip to content

Commit

Permalink
🐞 PlayStore 사전 μΆœμ‹œ λ³΄κ³ μ„œ | 비정상 μ’…λ£Œ 및 ANR (#20)
Browse files Browse the repository at this point in the history
* 🐞 FirebaseCloudMessage | getToken Task μˆ˜μ •

* 🫑 Push Notification | Add App Logo
  • Loading branch information
moondev03 authored Sep 9, 2024
1 parent aa5b3de commit 17caf9c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.neverland.core.utils.LoggerUtil
Expand Down Expand Up @@ -61,7 +60,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
}

private fun sendRegistrationToServer(token: String?) {
LoggerUtil.d("sendRegistrationTokenToServer($token)")
LoggerUtil.d("Send Registration New Token To Server:\n$token")
}

private fun sendNotification(title: String, body: String, url: String?) {
Expand All @@ -80,7 +79,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
val channelId = "fcm_default_channel"
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setSmallIcon(R.drawable.ic_thinkerbell)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
Expand Down Expand Up @@ -108,17 +107,4 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
return Result.success()
}
}

fun getRegistrationToken(callback: (String?) -> Unit) {
FirebaseMessaging.getInstance().token
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val token = task.result
callback(token)
} else {
LoggerUtil.w("Fetching FCM Registration Token failed\n${task.exception}")
callback(null)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.neverland.thinkerbell.view.splash

import android.content.Intent
import androidx.activity.viewModels
import com.google.firebase.messaging.FirebaseMessaging
import com.neverland.core.utils.LoggerUtil
import com.neverland.thinkerbell.R
import com.neverland.thinkerbell.base.BaseActivity
import com.neverland.thinkerbell.base.ThinkerBellApplication
import com.neverland.thinkerbell.databinding.ActivityStartBinding
import com.neverland.thinkerbell.utils.UiState
import com.neverland.thinkerbell.view.HomeActivity
Expand All @@ -14,7 +17,10 @@ class StartActivity : BaseActivity<ActivityStartBinding>() {
private val viewModel: StartViewModel by viewModels()

override fun initView() {
viewModel.saveDeviceInfo()
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
viewModel.saveDeviceInfo(task.result)
}

setStatusBarColor(R.color.primary2, false)
}

Expand All @@ -24,9 +30,8 @@ class StartActivity : BaseActivity<ActivityStartBinding>() {
viewModel.fcmState.observe(this) {
when (it) {
is UiState.Loading -> {}
is UiState.Error -> {}
is UiState.Empty -> {}
is UiState.Success -> {
else -> {
moveHome()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.viewModelScope
import com.neverland.core.utils.LoggerUtil
import com.neverland.domain.usecase.user.PostUserInfoUseCase
import com.neverland.thinkerbell.base.ThinkerBellApplication.Companion.application
import com.neverland.thinkerbell.fcm.MyFirebaseMessagingService
import com.neverland.thinkerbell.utils.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -23,29 +22,18 @@ class StartViewModel @Inject constructor(
val fcmState: LiveData<UiState<Unit>> get() = _fcmState

@SuppressLint("HardwareIds")
fun saveDeviceInfo() {
fun saveDeviceInfo(token: String) {
_fcmState.value = UiState.Loading

try {
MyFirebaseMessagingService().getRegistrationToken { token ->
if (token != null) {
viewModelScope.launch {
postUserInfoUseCase(application.getAndroidId(), token)
.onSuccess {
_fcmState.value = UiState.Success(Unit)
}
.onFailure { e ->
_fcmState.value = UiState.Error(e)
LoggerUtil.e("Register fcm failed: ${e.message}")
}
}
} else {
throw Exception("Null Fcm Token Exception")
viewModelScope.launch {
postUserInfoUseCase(application.getAndroidId(), token)
.onSuccess {
_fcmState.value = UiState.Success(Unit)
}
.onFailure { e ->
_fcmState.value = UiState.Error(e)
LoggerUtil.e("Register fcm failed: ${e.message}")
}
}
} catch (e: Exception) {
_fcmState.value = UiState.Error(e)
LoggerUtil.e("Register fcm exception: ${e.message}")
}
}

Expand Down
18 changes: 18 additions & 0 deletions ThinkerBell/presentation/src/main/res/drawable/ic_thinkerbell.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M77.71,0L434.29,0A77.71,77.71 0,0 1,512 77.71L512,434.29A77.71,77.71 0,0 1,434.29 512L77.71,512A77.71,77.71 0,0 1,0 434.29L0,77.71A77.71,77.71 0,0 1,77.71 0z"
android:fillColor="#00368A"/>
<path
android:pathData="M182.21,144.97L229.01,226.23C232.29,231.92 240.51,231.92 243.79,226.23L290.59,144.97C292.11,142.33 294.93,140.7 297.98,140.7H341.18C345.89,140.7 349.7,144.52 349.7,149.23V368.22C349.7,372.93 345.89,376.75 341.18,376.75H311.02C306.31,376.75 302.49,372.93 302.49,368.22V219.38L243.97,332.59C240.8,338.74 232.01,338.74 228.83,332.59L170.31,219.38V219.38L125,143.86C126.56,141.93 128.95,140.7 131.62,140.7H174.82C177.87,140.7 180.69,142.33 182.21,144.97ZM123.1,170.21L170.31,248.89V278.39L123.1,199.71V170.21ZM123.1,229.22L170.31,307.9V337.4L123.1,258.72V229.22ZM170.31,366.91L123.1,288.23V368.22C123.1,372.93 126.92,376.75 131.62,376.75H161.78C166.49,376.75 170.31,372.93 170.31,368.22V366.91Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
<path
android:pathData="M432.72,170.21C432.72,183.88 422.13,194.6 409.51,194.6C396.88,194.6 386.29,183.88 386.29,170.21C386.29,156.54 396.88,145.82 409.51,145.82C422.13,145.82 432.72,156.54 432.72,170.21Z"
android:strokeWidth="10.2286"
android:fillColor="#00000000"
android:strokeColor="#ffffff"/>
</vector>

0 comments on commit 17caf9c

Please sign in to comment.