-
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주차 2단계 #59
Open
JieunYume
wants to merge
15
commits into
kakao-tech-campus-2nd-step2:jieunyume
Choose a base branch
from
JieunYume:step2
base: jieunyume
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e40af58
docs: update README.md
JieunYume 0951159
feat: Firebase의 Remote Config 설정하기 위해 라이브러리 추가
JieunYume a03a1f8
feat: ServiceInfo model 추가
JieunYume 1c65fd1
feat: RemoteConfig Repository 구현 및 의존성 추가
JieunYume a8eb6e6
feat: RemoteConfig ViewModel과 Model 구현
JieunYume 010a87b
feat: RemoteConfig DataSource 구현
JieunYume 94aafb9
feat: Splash Screen 구현
JieunYume 16526b7
feat: Splash Screen API를 사용하지 않고 Splash Activity 구현
JieunYume 2fdd5b3
refactor: SplashActivity 함수 분리
JieunYume ee0f20a
docs: update README.md
JieunYume 62e28f0
docs: step2
JieunYume bec5a69
feat: MyFirebaseMessagingService에서 onMessageReceived() 구현
JieunYume e2477b3
feat: NotificationManager.sendNotification 확장함수 구현
JieunYume 47658e8
feat: MapActivity에서 채널 생성 함수 구현
JieunYume 36122b6
feat: requestPermissionLauncher에 토스트 메세지 출력
JieunYume 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# android-map-notification | ||
# android-map-notification | ||
## step1 기능목록 | ||
- Firebase의 Remote Config 설정하기 | ||
- 서비스 상태를 나타내는 매개변수를 각각 등록한다. | ||
- 매개변수 이름:serviceState, serviceMessage | ||
- 초기 진입 화면 추가하기 | ||
- 서버 상태, UI 로딩 등에 대한 상태 관리를 한다. | ||
- 매개변수 serviceState 값이 ON_SERVICE일 때만 초기 진입 화면이 지도 화면으로 넘어간다. | ||
- 매개변수 serviceState 값이 ON_SERVICE이 아닌 경우에는 serviceMessage 값을 초기 진입 화면 하단에 표시하고 지도 화면으로 진입하지 않는다. | ||
## step2 기능목록 | ||
- Firebase Cloud Message(FCM) 설정하기 | ||
- 테스트 메시지를 보낸다. | ||
- 앱이 백그라운드 상태일 경우 FCM 기본 값을 사용하여 Notification을 발생한다. | ||
- 앱이 포그라운드 상태일 경우 커스텀 Notification을 발생한다. | ||
- Notification 창을 터치하면 초기 진입 화면이 호출된다. |
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.
43 changes: 43 additions & 0 deletions
43
app/src/main/java/campus/tech/kakao/map/NotificationUtil.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,43 @@ | ||
package campus.tech.kakao.map | ||
|
||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.app.NotificationCompat | ||
import android.graphics.BitmapFactory | ||
import campus.tech.kakao.map.view.map.SplashActivity | ||
import campus.tech.kakao.map.view.search.MainActivity | ||
|
||
private val NOTIFICATION_ID = 0 | ||
private val REQUEST_CODE = 0 | ||
private val FLAGS = 0 | ||
|
||
fun NotificationManager.sendNotification(messageTitle: String, messageBody: String, applicationContext: Context) { | ||
val contentIntent = Intent(applicationContext, SplashActivity::class.java) | ||
|
||
val contentPendingIntent = PendingIntent.getActivity( | ||
applicationContext, | ||
NOTIFICATION_ID, | ||
contentIntent, | ||
PendingIntent.FLAG_IMMUTABLE | ||
) | ||
|
||
val mapImage = BitmapFactory.decodeResource( | ||
applicationContext.resources, | ||
R.drawable.map_icon2 | ||
) | ||
|
||
val builder = NotificationCompat.Builder( | ||
applicationContext, | ||
BuildConfig.CHANNEL_ID | ||
).setSmallIcon(R.drawable.map_icon2) | ||
.setContentTitle(messageTitle) | ||
.setContentText(messageBody) | ||
.setContentIntent(contentPendingIntent) | ||
.setLargeIcon(mapImage) | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT) | ||
.setAutoCancel(true) | ||
|
||
notify(NOTIFICATION_ID, builder.build()) | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/campus/tech/kakao/map/LocationModule.kt → ...ampus/tech/kakao/map/di/LocationModule.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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/campus/tech/kakao/map/di/RemoteConfigModule.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,52 @@ | ||
package campus.tech.kakao.map.di | ||
|
||
import android.util.Log | ||
import campus.tech.kakao.map.model.datasource.RemoteConfigDataSource | ||
import campus.tech.kakao.map.model.repository.RemoteConfigRepository | ||
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.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object RemoteConfigModule { | ||
@Singleton | ||
@Provides | ||
fun provideFirebaseRemoteConfig(): FirebaseRemoteConfig { | ||
val remoteConfig = Firebase.remoteConfig | ||
return initRemoteConfig(remoteConfig) | ||
} | ||
|
||
fun initRemoteConfig(remoteConfig: FirebaseRemoteConfig): FirebaseRemoteConfig { | ||
val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = 0 // 바로바로 가져옴 | ||
} | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
remoteConfig.fetchAndActivate() | ||
.addOnCompleteListener { | ||
if (it.isSuccessful) { | ||
Log.d("jieun", "Successful ${it.result}") | ||
} else { | ||
Log.d("jieun", "Failed ${it.result}") | ||
} | ||
}.addOnFailureListener { | ||
Log.d("jieun", "Exception ${it.message}") | ||
} | ||
return remoteConfig | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun providesRemoteConfigDataSource(firebaseRemoteConfig: FirebaseRemoteConfig): RemoteConfigDataSource { | ||
return RemoteConfigDataSource(firebaseRemoteConfig) | ||
} | ||
|
||
|
||
|
||
} |
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
4 changes: 3 additions & 1 deletion
4
.../tech/kakao/map/RetrofitInstanceModule.kt → ...ch/kakao/map/di/RetrofitInstanceModule.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
2 changes: 1 addition & 1 deletion
2
...pus/tech/kakao/map/SavedLocationModule.kt → .../tech/kakao/map/di/SavedLocationModule.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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/campus/tech/kakao/map/model/RemoteConfig.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,6 @@ | ||
package campus.tech.kakao.map.model | ||
|
||
data class RemoteConfig( | ||
val serviceState: String, | ||
val serviceMessage: String | ||
) |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/campus/tech/kakao/map/model/datasource/RemoteConfigDataSource.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,17 @@ | ||
package campus.tech.kakao.map.model.datasource | ||
|
||
import campus.tech.kakao.map.BuildConfig | ||
import campus.tech.kakao.map.model.RemoteConfig | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import javax.inject.Inject | ||
|
||
class RemoteConfigDataSource @Inject constructor( | ||
private val firebaseRemoteConfig: FirebaseRemoteConfig | ||
){ | ||
fun getRemoteConfig(): RemoteConfig { | ||
return RemoteConfig( | ||
serviceState = firebaseRemoteConfig.getString(BuildConfig.SERVICE_STATE), | ||
serviceMessage = firebaseRemoteConfig.getString(BuildConfig.SERVICE_MESSAGE) | ||
) | ||
} | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 첫 실행시 firebase remote config 가 default 값으로 처리되거나 빈값으로 내려올 것 같아요. remote config fetch 를 해오는 메소드를 추가해보면 어떨까요? |
||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/campus/tech/kakao/map/model/repository/DefaultRemoteConfigRepository.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,13 @@ | ||
package campus.tech.kakao.map.model.repository | ||
|
||
import campus.tech.kakao.map.model.RemoteConfig | ||
import campus.tech.kakao.map.model.datasource.RemoteConfigDataSource | ||
import javax.inject.Inject | ||
|
||
class DefaultRemoteConfigRepository @Inject constructor( | ||
private val remoteConfigDataSource: RemoteConfigDataSource | ||
): RemoteConfigRepository { | ||
override fun getRemoteConfig(): RemoteConfig { | ||
return remoteConfigDataSource.getRemoteConfig() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/campus/tech/kakao/map/model/repository/RemoteConfigRepository.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,8 @@ | ||
package campus.tech.kakao.map.model.repository | ||
|
||
import campus.tech.kakao.map.model.RemoteConfig | ||
|
||
|
||
interface RemoteConfigRepository { | ||
fun getRemoteConfig(): RemoteConfig | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/campus/tech/kakao/map/service/MyFirebaseMessagingService.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.service | ||
|
||
import android.app.NotificationManager | ||
import android.util.Log | ||
import androidx.core.content.ContextCompat | ||
import campus.tech.kakao.map.sendNotification | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
|
||
class MyFirebaseMessagingService : FirebaseMessagingService() { | ||
override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
Log.d("jieun", "From: ${remoteMessage.from}") | ||
|
||
remoteMessage.notification?.let { | ||
Log.d("jieun", "Message Notification: ${it.title} ${it.body}") | ||
sendNotification(it.title!!, it.body!!) | ||
} | ||
} | ||
|
||
private fun sendNotification(messageTitle: String, messageBody: String) { | ||
val notificationManager = ContextCompat.getSystemService(applicationContext, NotificationManager::class.java) as NotificationManager | ||
notificationManager.sendNotification(messageTitle, messageBody, applicationContext) | ||
} | ||
} |
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.
apply 나 also 를 적절하게 사용하면 좋습니다!