Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

강원대_Android_이아림_6주차과제_STEP2 #74

Open
wants to merge 39 commits into
base: arieum
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
56c0f65
Resolved conflicts & Add google-services.json(.gitignore)
arieum Jul 29, 2024
f656ea1
Feat: Write README.md
arieum Jul 29, 2024
60687d8
Create: Add initial entry screen_WelcomeActivity
arieum Jul 29, 2024
21a284a
feat: Add Remote_Config function
arieum Jul 30, 2024
264327d
refactor: databinding 제거
arieum Jul 30, 2024
6d838e2
refactor: Resolve Issue!
arieum Jul 31, 2024
1c4dec6
refactor: Resolve issue(Add coroutine)
arieum Jul 31, 2024
a770a31
refactor: Add WelcomeViewModel_init_function
arieum Jul 31, 2024
74ea599
feat: Add Foreground_Custom_Notification
arieum Aug 1, 2024
813f910
feat: Add Function_firebase_MSG_Recieved
arieum Aug 2, 2024
6a4db28
refactor: remove unnecessary import & typo correction
arieum Aug 2, 2024
e14ebea
Delete MyPlaceContract.kt
arieum Aug 2, 2024
b611435
Delete PlaceDbHelper.kt
arieum Aug 2, 2024
9c8289d
Delete RetrofitClient.kt
arieum Aug 2, 2024
945bb92
refactor: Resolved conflict in .gitignore
arieum Aug 2, 2024
27a1288
refactor: Resolved conflicts in gradlew
arieum Aug 2, 2024
0fc30e8
refactor: Resolved conflicts in gradlew.bat
arieum Aug 2, 2024
7aa3d7d
refactor: Inject sharedPreference in MapRepository.kt
arieum Aug 2, 2024
64075b7
refactor: changed mapRepository parameter in RepositoryModule.kt
arieum Aug 2, 2024
53d0ec3
refactor: add const variable KakaoAK in PlaceRepository.kt
arieum Aug 2, 2024
1468dd3
refactor: Apply STEP1 Feedback
arieum Aug 2, 2024
3ff02b5
refactor: remove img entity in place
arieum Aug 2, 2024
a4ad50c
Merge branch 'arieum' into arieum_step2
arieum Aug 3, 2024
abc69b8
Merge remote-tracking branch 'arieum_remote/arieum_step1' into arieum…
arieum Aug 3, 2024
70419e2
feat: Add Foreground_Custom_Notification
arieum Aug 1, 2024
15cda87
feat: Add Function_firebase_MSG_Recieved
arieum Aug 2, 2024
a521fd2
refactor: remove unnecessary import & typo correction
arieum Aug 2, 2024
3abdb54
refactor: Apply STEP1 Feedback
arieum Aug 2, 2024
7748b14
refactor: remove img entity in place
arieum Aug 2, 2024
2cfcdee
refactor: Replace runBlocking with coroutineScope to prevent ANR
arieum Aug 3, 2024
63cb7ae
rebase
arieum Aug 3, 2024
e2a532c
Resolved conflicts
arieum Aug 3, 2024
381cfa9
refacotr: typo correction
arieum Aug 3, 2024
c673313
refactor: Use Dispatcher.IO for database operations in LogRepository
arieum Aug 3, 2024
5a5e991
refacotr: Restructure package
arieum Aug 3, 2024
1001f19
refactor: refactor db&repository implementation
arieum Aug 3, 2024
4a17bd6
refactor: Improve delayed UI update using coroutines in WelcomeAcitivity
arieum Aug 3, 2024
e96fff7
refactor: refactor FCMservice for proper initialization and foregroun…
arieum Aug 4, 2024
7904df8
refactor: Move hardcoded strings to string resources
arieum Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: refactor FCMservice for proper initialization and foregroun…
…d notification handling
arieum committed Aug 4, 2024
commit e96fff75496abbb0b544c117b0d8df4804818b0f
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import campus.tech.kakao.map.data.repository.map.MapRepository
import campus.tech.kakao.map.data.repository.map.MapRepositoryInterface
import campus.tech.kakao.map.data.repository.place.PlaceRepository
import campus.tech.kakao.map.data.repository.place.PlaceRepositoryInterface
import campus.tech.kakao.map.data.repository.WelcomeRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -46,10 +45,4 @@ object RepositoryModule {
fun provideMapRepository(sharedPreferences: SharedPreferences): MapRepositoryInterface {
return MapRepository(sharedPreferences)
}

@Provides
@Singleton
fun provideWelcomeRepository(): WelcomeRepository {
return WelcomeRepository()
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,82 @@
package campus.tech.kakao.map.data.remote.service

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.core.app.NotificationCompat
import campus.tech.kakao.map.R
import campus.tech.kakao.map.presentation.view.WelcomeActivity
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class FCMservice : FirebaseMessagingService() {
override fun onCreate() {
super.onCreate()
createNotificationChannel()
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Log.d("TEST_FcmService", "Received Message")

remoteMessage.notification?.let { notification ->
// 일반 알림 처리
showNotification(notification.title, notification.body)
}

remoteMessage.data.let { data ->
// 커스텀 알림 처리
val title = data["title"]
val body = data["body"]
if (title != null && body != null) {
showNotification(title, body)
}
}
}

private fun showNotification(title: String?, body: String?) {
val intent = Intent(this, WelcomeActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent: PendingIntent = PendingIntent.getActivity(applicationContext,
REQUEST_CODE, intent, PendingIntent.FLAG_IMMUTABLE)

val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build()

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(NOTIFICATION_ID, notification)
}

private fun createNotificationChannel() {
val channelId = CHANNEL_ID
val channelName = CHANNEL_NAME
val channelDescription = CHANNEL_DESCRIPTION
val importance = NotificationManager.IMPORTANCE_DEFAULT

val channel = NotificationChannel(channelId, channelName, importance).apply {
description = channelDescription
}

val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}

companion object {
private const val NOTIFICATION_ID = 222222
private const val REQUEST_CODE = 0
private const val CHANNEL_ID = "Mychannel"
private const val CHANNEL_NAME = "Mychannel"
private const val CHANNEL_DESCRIPTION = "This is Mychannel"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ class WelcomeActivity : AppCompatActivity() {
setupBinding()
observeServiceStateChanges()
askNotificationPermission()
setForegroundNotification()
}

private fun setupBinding() {
@@ -65,10 +64,6 @@ class WelcomeActivity : AppCompatActivity() {
val intent = Intent(this@WelcomeActivity, MapViewActivity::class.java)
startActivity(intent)
}
private fun setForegroundNotification(){
welcomeViewModel.createNotificationChannel(this)
welcomeViewModel.sendForegroundNotification(this)
}
private fun askNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
when {
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package campus.tech.kakao.map.presentation.viewmodel

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import campus.tech.kakao.map.data.remote.config.RemoteConfigManager
import campus.tech.kakao.map.data.repository.WelcomeRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class WelcomeViewModel @Inject constructor(
private val remoteConfigManager: RemoteConfigManager,
private val repository: WelcomeRepository
): ViewModel() {
private val _serviceState = MutableLiveData<String>()
val serviceState: LiveData<String> get() = _serviceState
@@ -44,12 +41,4 @@ class WelcomeViewModel @Inject constructor(
}
}
}

fun createNotificationChannel(context: Context) {
repository.createNotificationChannel(context)
}

fun sendForegroundNotification(context: Context) {
repository.sendForegroundNotification(context)
}
}