Skip to content

Commit 61fe0a9

Browse files
committed
Merge branch 'develop' into BOOK-434-refactor/#222
2 parents ea31299 + 0b5e477 commit 61fe0a9

File tree

7 files changed

+18
-42
lines changed

7 files changed

+18
-42
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ninecraft.booket.core.common.utils
2+
3+
fun shouldSyncNotification(effectiveEnabled: Boolean, lastSynced: Boolean?): Boolean =
4+
lastSynced == null || lastSynced != effectiveEnabled

core/data/impl/src/main/kotlin/com/ninecraft/booket/core/data/impl/repository/DefaultUserRepository.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,11 @@ class DefaultUserRepository(
4444

4545
override suspend fun syncFcmToken() = runSuspendCatching {
4646
val newToken = getRemoteFcmToken()
47-
val localToken = getLocalFcmToken()
48-
49-
if (newToken == localToken) {
50-
Logger.d("Skip FCM token sync (already up-to-date)")
51-
return@runSuspendCatching
52-
}
53-
5447
registerDevice(newToken)
55-
setFcmToken(newToken)
5648
}
5749

5850
override suspend fun syncFcmToken(fcmToken: String): Result<Unit> = runSuspendCatching {
5951
registerDevice(fcmToken)
60-
setFcmToken(fcmToken)
6152
}
6253

6354
override val isUserNotificationEnabled = notificationDataSource.isUserNotificationEnabled
@@ -97,12 +88,6 @@ class DefaultUserRepository(
9788
}
9889
}
9990

100-
private suspend fun getLocalFcmToken(): String = notificationDataSource.fcmToken.first()
101-
102-
private suspend fun setFcmToken(fcmToken: String) {
103-
notificationDataSource.setFcmToken(fcmToken)
104-
}
105-
10691
private suspend fun getDeviceId(): String {
10792
return try {
10893
firebaseInstallations.id.await()

core/datastore/api/src/main/kotlin/com/ninecraft/booket/core/datastore/api/datasource/NotificationDataSource.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package com.ninecraft.booket.core.datastore.api.datasource
33
import kotlinx.coroutines.flow.Flow
44

55
interface NotificationDataSource {
6-
val fcmToken: Flow<String>
7-
suspend fun setFcmToken(fcmToken: String)
8-
96
val isUserNotificationEnabled: Flow<Boolean>
107
suspend fun setUserNotificationEnabled(isEnabled: Boolean)
118

core/datastore/impl/src/main/kotlin/com/ninecraft/booket/core/datastore/impl/datasource/DefaultNotificationDataSource.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.datastore.core.DataStore
44
import androidx.datastore.preferences.core.Preferences
55
import androidx.datastore.preferences.core.booleanPreferencesKey
66
import androidx.datastore.preferences.core.edit
7-
import androidx.datastore.preferences.core.stringPreferencesKey
87
import com.ninecraft.booket.core.datastore.api.datasource.NotificationDataSource
98
import com.ninecraft.booket.core.datastore.impl.di.NotificationDataStore
109
import com.ninecraft.booket.core.datastore.impl.util.handleIOException
@@ -19,18 +18,6 @@ import kotlinx.coroutines.flow.map
1918
class DefaultNotificationDataSource(
2019
@NotificationDataStore private val dataStore: DataStore<Preferences>,
2120
) : NotificationDataSource {
22-
override val fcmToken: Flow<String> = dataStore.data
23-
.handleIOException()
24-
.map { prefs ->
25-
prefs[FCM_TOKEN] ?: ""
26-
}
27-
28-
override suspend fun setFcmToken(fcmToken: String) {
29-
dataStore.edit { prefs ->
30-
prefs[FCM_TOKEN] = fcmToken
31-
}
32-
}
33-
3421
override val isUserNotificationEnabled: Flow<Boolean> = dataStore.data
3522
.handleIOException()
3623
.map { prefs ->
@@ -62,7 +49,6 @@ class DefaultNotificationDataSource(
6249
}
6350

6451
companion object Companion {
65-
private val FCM_TOKEN = stringPreferencesKey("FCM_TOKEN")
6652
private val USER_NOTIFICATION_ENABLED = booleanPreferencesKey("USER_NOTIFICATION_ENABLED")
6753
private val LAST_SYNCED_NOTIFICATION_ENABLED = booleanPreferencesKey("LAST_SYNCED_NOTIFICATION_ENABLED")
6854
}

feature/home/src/main/kotlin/com/ninecraft/booket/feature/home/HomePresenter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.runtime.rememberCoroutineScope
77
import androidx.compose.runtime.setValue
88
import com.ninecraft.booket.core.common.analytics.AnalyticsHelper
99
import com.ninecraft.booket.core.common.utils.handleException
10+
import com.ninecraft.booket.core.common.utils.shouldSyncNotification
1011
import com.ninecraft.booket.core.data.api.repository.AuthRepository
1112
import com.ninecraft.booket.core.data.api.repository.BookRepository
1213
import com.ninecraft.booket.core.data.api.repository.UserRepository
@@ -122,14 +123,15 @@ class HomePresenter(
122123
is HomeUiEvent.OnNotificationPermissionResult -> {
123124
scope.launch {
124125
val isPermissionGranted = event.granted
125-
val userEnabled = userRepository.getUserNotificationEnabled()
126+
val userSettingEnabled = userRepository.getUserNotificationEnabled()
126127
val lastSyncedServerEnabled = userRepository.getLastSyncedNotificationEnabled()
127128

128-
val shouldSync = (!isPermissionGranted && lastSyncedServerEnabled != false) ||
129-
(userEnabled && (lastSyncedServerEnabled == null || lastSyncedServerEnabled != isPermissionGranted))
129+
val effectiveNotificationEnabled = userSettingEnabled && isPermissionGranted
130+
131+
val shouldSync = shouldSyncNotification(effectiveNotificationEnabled, lastSyncedServerEnabled)
130132

131133
if (shouldSync) {
132-
syncNotificationSettings(isPermissionGranted)
134+
syncNotificationSettings(effectiveNotificationEnabled)
133135
}
134136
}
135137
}

feature/settings/src/main/kotlin/com/ninecraft/booket/feature/settings/notification/NotificationPresenter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.rememberCoroutineScope
77
import androidx.compose.runtime.setValue
88
import com.ninecraft.booket.core.common.utils.handleException
9+
import com.ninecraft.booket.core.common.utils.shouldSyncNotification
910
import com.ninecraft.booket.core.data.api.repository.UserRepository
1011
import com.ninecraft.booket.feature.screens.LoginScreen
1112
import com.ninecraft.booket.feature.screens.NotificationScreen
@@ -100,14 +101,15 @@ class NotificationPresenter(
100101
is NotificationUiEvent.OnNotificationPermissionResult -> {
101102
scope.launch {
102103
val isPermissionGranted = event.granted
103-
val userEnabled = userRepository.getUserNotificationEnabled()
104+
val userSettingEnabled = userRepository.getUserNotificationEnabled()
104105
val lastSyncedServerEnabled = userRepository.getLastSyncedNotificationEnabled()
105106

106-
val shouldSync = (!isPermissionGranted && lastSyncedServerEnabled != false) ||
107-
(userEnabled && (lastSyncedServerEnabled == null || lastSyncedServerEnabled != isPermissionGranted))
107+
val effectiveNotificationEnabled = userSettingEnabled && isPermissionGranted
108+
109+
val shouldSync = shouldSyncNotification(effectiveNotificationEnabled, lastSyncedServerEnabled)
108110

109111
if (shouldSync) {
110-
syncNotificationSettings(isPermissionGranted)
112+
syncNotificationSettings(effectiveNotificationEnabled)
111113
}
112114
}
113115
}

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
minSdk = "28"
44
targetSdk = "35"
55
compileSdk = "35"
6-
versionName = "1.2.0"
7-
versionCode = "8"
6+
versionName = "1.3.0"
7+
versionCode = "9"
88
packageName = "com.ninecraft.booket"
99

1010
## Android gradle plugin

0 commit comments

Comments
 (0)