-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54082f6
commit 6678b54
Showing
25 changed files
with
432 additions
and
1 deletion.
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.