-
Notifications
You must be signed in to change notification settings - Fork 30
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 #54
Open
kimseongyu
wants to merge
17
commits into
kakao-tech-campus-2nd-step2:kimseongyu
Choose a base branch
from
kimseongyu:step2
base: kimseongyu
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6c2fcb8
충남대 Android_김선규 5주차 Step0 (#33)
kimseongyu 5631fd6
충남대 Android_김선규 4주차 Step0 (#10)
kimseongyu c98c5dc
충남대 Android_김선규 4주차 Step 1 제출 (#47)
kimseongyu e81a7c0
충남대 Android_김선규 4주차 Step2 수정 (#73)
kimseongyu 8b15140
feat: change SQLite to Room about DB
kimseongyu 1523266
feat: add Hilt for MVVM
kimseongyu 67ca3f8
feat: modify about Hilt
kimseongyu 09b905a
docs: add week6 step1 requirements
kimseongyu a2266c9
chore: add Firebase dependency
kimseongyu 78e9f5a
feat: add splash screen layout
kimseongyu 6b6750c
feat: add splash screen implementation
kimseongyu 24f6f05
feat: rename Service to ServiceState
kimseongyu bd0d3f1
feat: modify delay using coroutine
kimseongyu 1863e3b
docs: add week6 step2 requirements
kimseongyu c31eb17
feat: add FCM and notification implementation
kimseongyu e9d4146
feat: separate logic into utilities
kimseongyu 5f79e05
feat: modify code for testing
kimseongyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/campus/tech/kakao/map/model/splashscreen/ServiceState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package campus.tech.kakao.map.model.splashscreen | ||
|
||
data class ServiceState( | ||
var state: String, | ||
var msg: String | ||
) | ||
|
||
object ServiceRemoteConfig { | ||
const val SERVICE_STATE = "serviceState" | ||
const val SERVICE_MESSAGE = "serviceMessage" | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/campus/tech/kakao/map/repository/splashscreen/FirebaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package campus.tech.kakao.map.repository.splashscreen | ||
|
||
import android.content.Context | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.remoteConfig | ||
import com.google.firebase.remoteconfig.remoteConfigSettings | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object FirebaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRemoteConfig(@ApplicationContext context: Context): FirebaseRemoteConfig { | ||
val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig | ||
val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = 0 | ||
} | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
return remoteConfig | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/campus/tech/kakao/map/repository/splashscreen/FirebaseRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package campus.tech.kakao.map.repository.splashscreen | ||
|
||
import campus.tech.kakao.map.model.splashscreen.ServiceState | ||
import campus.tech.kakao.map.model.splashscreen.ServiceRemoteConfig.SERVICE_MESSAGE | ||
import campus.tech.kakao.map.model.splashscreen.ServiceRemoteConfig.SERVICE_STATE | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import kotlinx.coroutines.tasks.await | ||
import javax.inject.Inject | ||
|
||
private const val ON_SERIVCE = "ON_SERVICE" | ||
|
||
class FirebaseRepository @Inject constructor( | ||
private val remoteConfig: FirebaseRemoteConfig | ||
) { | ||
|
||
suspend fun getService(): ServiceState { | ||
val serviceState = ServiceState("", "") | ||
remoteConfig.fetchAndActivate().await() | ||
serviceState.state = remoteConfig.getString(SERVICE_STATE) | ||
if (serviceState.state != ON_SERIVCE) | ||
serviceState.msg = remoteConfig.getString(SERVICE_MESSAGE) | ||
return serviceState | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/campus/tech/kakao/map/service/FCMService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package campus.tech.kakao.map.service | ||
|
||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import android.os.Build | ||
import androidx.core.app.NotificationCompat | ||
import campus.tech.kakao.map.R | ||
import campus.tech.kakao.map.view.splashscreen.SplashScreenActivity | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
|
||
private const val CUSTOM_HEADER = "[Foreground] " | ||
class FCMService : FirebaseMessagingService() { | ||
companion object { | ||
private const val NOTIFICATION_ID = 0 | ||
private const val CHANNEL_ID = "main_default_channel" | ||
private const val CHANNEL_NAME = "main channelName" | ||
} | ||
|
||
private lateinit var notificationManager: NotificationManager | ||
|
||
override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
remoteMessage.notification?.let { | ||
val customTitle = CUSTOM_HEADER + it.title | ||
showNotification(customTitle, it.body) | ||
} | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val channel = NotificationChannel( | ||
CHANNEL_ID, | ||
CHANNEL_NAME, | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
notificationManager.createNotificationChannel(channel) | ||
} | ||
} | ||
|
||
private fun showNotification(title: String?, message: String?) { | ||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager | ||
createNotificationChannel() | ||
|
||
val intent = Intent(this, SplashScreenActivity::class.java) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) | ||
|
||
val pendingIntent = PendingIntent.getActivity( | ||
this, 0, intent, PendingIntent.FLAG_IMMUTABLE | ||
) | ||
|
||
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID) | ||
.setSmallIcon(R.drawable.map) | ||
.setContentTitle(title) | ||
.setContentText(message) | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT) | ||
.setContentIntent(pendingIntent) | ||
.setAutoCancel(true) | ||
|
||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/campus/tech/kakao/map/utils/UtilityManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package campus.tech.kakao.map.utils | ||
|
||
import android.util.Log | ||
import com.google.android.gms.tasks.OnCompleteListener | ||
import com.google.firebase.messaging.Constants | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
|
||
class UtilityManager { | ||
private fun getToken(){ | ||
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task -> | ||
if (!task.isSuccessful) { | ||
Log.w(Constants.TAG, "Fetching FCM registration token failed", task.exception) | ||
return@OnCompleteListener | ||
} | ||
Log.w(Constants.TAG, "FCM Token: ${task.result}") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UtilityManager를 추상화하고, FirebaseMessaging의 instance를 인자로 받도록 만드는 것이 테스트 작성 관점에서 더 좋습니다. :)