forked from droidknights/DroidKnightsApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request droidknights#245 from l2hyunwoo/feature/droidknigh…
…ts#202 [feature/droidknights#202] 앱이 종료된 이후에도 북마크 세션들을 유지한다
- Loading branch information
Showing
11 changed files
with
92 additions
and
20 deletions.
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
2 changes: 1 addition & 1 deletion
2
.../src/main/java/com/droidknights/app2023/core/data/repository/DefaultSettingsRepository.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
15 changes: 15 additions & 0 deletions
15
...ava/com/droidknights/app2023/core/data/datastore/fake/FakeSessionPreferencesDataSource.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,15 @@ | ||
package com.droidknights.app2023.core.data.datastore.fake | ||
|
||
import com.droidknights.app2023.core.datastore.datasource.SessionPreferencesDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.filterNotNull | ||
|
||
class FakeSessionPreferencesDataSource : SessionPreferencesDataSource { | ||
private val _bookmarkedSession = MutableStateFlow(emptySet<String>()) | ||
override val bookmarkedSession: Flow<Set<String>> = _bookmarkedSession.filterNotNull() | ||
|
||
override suspend fun updateBookmarkedSession(bookmarkedSession: Set<String>) { | ||
_bookmarkedSession.value = bookmarkedSession.toSet() | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...com/droidknights/app2023/core/datastore/datasource/DefaultSessionPreferencesDataSource.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,27 @@ | ||
package com.droidknights.app2023.core.datastore.datasource | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringSetPreferencesKey | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
class DefaultSessionPreferencesDataSource @Inject constructor( | ||
@Named("session") private val dataStore: DataStore<Preferences> | ||
) : SessionPreferencesDataSource { | ||
object PreferencesKey { | ||
val BOOKMARKED_SESSION = stringSetPreferencesKey("BOOKMARKED_SESSION") | ||
} | ||
|
||
override val bookmarkedSession = dataStore.data.map { preferences -> | ||
preferences[PreferencesKey.BOOKMARKED_SESSION] ?: emptySet() | ||
} | ||
|
||
override suspend fun updateBookmarkedSession(bookmarkedSession: Set<String>) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKey.BOOKMARKED_SESSION] = bookmarkedSession | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...n/java/com/droidknights/app2023/core/datastore/datasource/SessionPreferencesDataSource.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.droidknights.app2023.core.datastore.datasource | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface SessionPreferencesDataSource { | ||
val bookmarkedSession: Flow<Set<String>> | ||
suspend fun updateBookmarkedSession(bookmarkedSession: Set<String>) | ||
} |
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
1 change: 1 addition & 0 deletions
1
...rc/test/java/com/droidknights/app2023/core/datastore/SettingsPreferencesDataSourceTest.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
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