-
Notifications
You must be signed in to change notification settings - Fork 3
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
[AN] feat: FCM 구현 #312
Merged
Merged
[AN] feat: FCM 구현 #312
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5a04254
feat: 알람 설정 여부 로컬 저장 기능 구현
gaeun5744 b62eed7
feat: FCM receiver 구현
gaeun5744 a0b2e79
feat: FCM 토큰 저장 로직 구현
gaeun5744 43b6b48
style: ktlint 적용
gaeun5744 b6372d8
feat: alarm 설정 여부 삭제 useCase 구현
gaeun5744 c34845e
rename: Setting -> AlarmSetting으로 네이밍 수정
gaeun5744 8cdf24d
fix: git 충돌 해결
gaeun5744 aa8d3ac
style:ktlint 적용
gaeun5744 3b4ee1a
feat: local -> remote에 fcm 토큰 저장하도록 수정
gaeun5744 5da4d6d
fix: 불필요한 import 제거
gaeun5744 fe371d0
fix: git 충돌 해결
gaeun5744 12cb10b
fix: allowBack false 설정
gaeun5744 f8455c7
feat: 로그인시, 토큰 저장
gaeun5744 315cafd
feat: 직렬화 추가
gaeun5744 9917b9f
remove: 불필요한 로직 제거
gaeun5744 ea02fd4
style: ktlint 적용
gaeun5744 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
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/data/mapper/AlarmTokenMapper.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,9 @@ | ||
package com.happy.friendogly.data.mapper | ||
|
||
import com.happy.friendogly.data.model.AlarmTokenDto | ||
import com.happy.friendogly.remote.model.request.DeviceTokenRequest | ||
|
||
fun AlarmTokenDto.toRemote(): DeviceTokenRequest = | ||
DeviceTokenRequest( | ||
deviceToken = token, | ||
) |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/happy/friendogly/data/model/AlarmTokenDto.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,5 @@ | ||
package com.happy.friendogly.data.model | ||
|
||
data class AlarmTokenDto( | ||
val token: String, | ||
) |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/com/happy/friendogly/data/repository/AlarmSettingRepositoryImpl.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,12 @@ | ||
package com.happy.friendogly.data.repository | ||
|
||
import com.happy.friendogly.data.source.AlarmSettingDataSource | ||
import com.happy.friendogly.domain.repository.AlarmSettingRepository | ||
|
||
class AlarmSettingRepositoryImpl(private val source: AlarmSettingDataSource) : AlarmSettingRepository { | ||
override suspend fun saveAlarm(isSet: Boolean): Result<Unit> = source.saveAlarm(isSet) | ||
|
||
override suspend fun getAlarm(): Result<Boolean> = source.getAlarm() | ||
|
||
override suspend fun deleteAlarm(): Result<Unit> = source.deleteAlarm() | ||
} |
8 changes: 8 additions & 0 deletions
8
android/app/src/main/java/com/happy/friendogly/data/repository/AlarmTokenRepositoryImpl.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 com.happy.friendogly.data.repository | ||
|
||
import com.happy.friendogly.data.source.AlarmTokenDataSource | ||
import com.happy.friendogly.domain.repository.AlarmTokenRepository | ||
|
||
class AlarmTokenRepositoryImpl(private val source: AlarmTokenDataSource) : AlarmTokenRepository { | ||
override suspend fun saveToken(token: String): Result<Unit> = source.saveToken(token) | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/data/source/AlarmSettingDataSource.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,9 @@ | ||
package com.happy.friendogly.data.source | ||
|
||
interface AlarmSettingDataSource { | ||
suspend fun saveAlarm(isSet: Boolean): Result<Unit> | ||
|
||
suspend fun getAlarm(): Result<Boolean> | ||
|
||
suspend fun deleteAlarm(): Result<Unit> | ||
} |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/happy/friendogly/data/source/AlarmTokenDataSource.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,5 @@ | ||
package com.happy.friendogly.data.source | ||
|
||
interface AlarmTokenDataSource { | ||
suspend fun saveToken(token: String): Result<Unit> | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/repository/AlarmSettingRepository.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,9 @@ | ||
package com.happy.friendogly.domain.repository | ||
|
||
interface AlarmSettingRepository { | ||
suspend fun saveAlarm(isSet: Boolean): Result<Unit> | ||
|
||
suspend fun getAlarm(): Result<Boolean> | ||
|
||
suspend fun deleteAlarm(): Result<Unit> | ||
} |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/happy/friendogly/domain/repository/AlarmTokenRepository.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,5 @@ | ||
package com.happy.friendogly.domain.repository | ||
|
||
interface AlarmTokenRepository { | ||
suspend fun saveToken(token: String): Result<Unit> | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/usecase/DeleteAlarmSettingUseCase.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,9 @@ | ||
package com.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.AlarmSettingRepository | ||
|
||
class DeleteAlarmSettingUseCase( | ||
private val repository: AlarmSettingRepository, | ||
) { | ||
suspend operator fun invoke(): Result<Unit> = repository.deleteAlarm() | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/usecase/GetAlarmSettingUseCase.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,9 @@ | ||
package com.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.AlarmSettingRepository | ||
|
||
class GetAlarmSettingUseCase( | ||
private val repository: AlarmSettingRepository, | ||
) { | ||
suspend operator fun invoke(): Result<Boolean> = repository.getAlarm() | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/usecase/SaveAlamTokenUseCase.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,9 @@ | ||
package com.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.AlarmTokenRepository | ||
|
||
class SaveAlamTokenUseCase( | ||
private val repository: AlarmTokenRepository, | ||
) { | ||
suspend operator fun invoke(token: String): Result<Unit> = repository.saveToken(token) | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/usecase/SaveAlarmSettingUseCase.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,9 @@ | ||
package com.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.AlarmSettingRepository | ||
|
||
class SaveAlarmSettingUseCase( | ||
private val repository: AlarmSettingRepository, | ||
) { | ||
suspend operator fun invoke(isSet: Boolean): Result<Unit> = repository.saveAlarm(isSet) | ||
} |
47 changes: 47 additions & 0 deletions
47
android/app/src/main/java/com/happy/friendogly/local/di/AlarmModule.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,47 @@ | ||
package com.happy.friendogly.local.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.map | ||
import java.io.IOException | ||
|
||
class AlarmModule(val context: Context) { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = DATA_STORE_NAME) | ||
|
||
private val key = booleanPreferencesKey(ALARM_SETTING) | ||
|
||
var isSet: Flow<Boolean> = | ||
context.dataStore.data.catch { exception -> | ||
if (exception is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.map { preferences -> | ||
preferences[key] ?: true | ||
} | ||
|
||
suspend fun saveSetting(value: Boolean) { | ||
context.dataStore.edit { preferences -> | ||
preferences[key] = value | ||
} | ||
} | ||
|
||
suspend fun deleteSetting() { | ||
context.dataStore.edit { prefs -> | ||
prefs.remove(key) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val ALARM_SETTING = "ALARM_SETTING" | ||
private const val DATA_STORE_NAME = "alarmDataStore" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
android/app/src/main/java/com/happy/friendogly/local/di/AlarmTokenModule.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,47 @@ | ||
package com.happy.friendogly.local.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.map | ||
import java.io.IOException | ||
|
||
class AlarmTokenModule(val context: Context) { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = DATA_STORE_NAME) | ||
|
||
private val key = stringPreferencesKey(FCM_TOKEN) | ||
|
||
var token: Flow<String> = | ||
context.dataStore.data.catch { exception -> | ||
if (exception is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.map { preferences -> | ||
preferences[key] ?: "" | ||
} | ||
|
||
suspend fun saveToken(value: String) { | ||
context.dataStore.edit { preferences -> | ||
preferences[key] = value | ||
} | ||
} | ||
|
||
suspend fun deleteToken() { | ||
context.dataStore.edit { prefs -> | ||
prefs.remove(key) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val FCM_TOKEN = "FCM_TOKEN" | ||
private const val DATA_STORE_NAME = "fcmDataStore" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
android/app/src/main/java/com/happy/friendogly/local/source/AlarmSettingDataSourceImpl.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 com.happy.friendogly.local.source | ||
|
||
import com.happy.friendogly.data.source.AlarmSettingDataSource | ||
import com.happy.friendogly.local.di.AlarmModule | ||
import kotlinx.coroutines.flow.first | ||
|
||
class AlarmSettingDataSourceImpl( | ||
private val alarmModule: AlarmModule, | ||
) : AlarmSettingDataSource { | ||
override suspend fun saveAlarm(isSet: Boolean): Result<Unit> = | ||
runCatching { | ||
alarmModule.saveSetting(isSet) | ||
} | ||
|
||
override suspend fun getAlarm(): Result<Boolean> = | ||
runCatching { | ||
alarmModule.isSet.first() | ||
} | ||
|
||
override suspend fun deleteAlarm(): Result<Unit> = | ||
runCatching { | ||
alarmModule.deleteSetting() | ||
} | ||
} |
Oops, something went wrong.
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.
아래 코멘트와 유사합니다!