Merge pull request #618 from materoy/main

Renamed functions with signature toggle(isOn: Boolean)
pull/935/head
James Rose 1 year ago committed by GitHub
commit 7945a2beba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,13 +37,13 @@ class OfflineFirstUserDataRepository @Inject constructor(
override suspend fun setFollowedTopicIds(followedTopicIds: Set<String>) = override suspend fun setFollowedTopicIds(followedTopicIds: Set<String>) =
niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds) niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds)
override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) { override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) {
niaPreferencesDataSource.toggleFollowedTopicId(followedTopicId, followed) niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed)
analyticsHelper.logTopicFollowToggled(followedTopicId, followed) analyticsHelper.logTopicFollowToggled(followedTopicId, followed)
} }
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.toggleNewsResourceBookmark(newsResourceId, bookmarked) niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
analyticsHelper.logNewsResourceBookmarkToggled( analyticsHelper.logNewsResourceBookmarkToggled(
newsResourceId = newsResourceId, newsResourceId = newsResourceId,
isBookmarked = bookmarked, isBookmarked = bookmarked,

@ -34,9 +34,9 @@ interface UserDataRepository {
suspend fun setFollowedTopicIds(followedTopicIds: Set<String>) suspend fun setFollowedTopicIds(followedTopicIds: Set<String>)
/** /**
* Toggles the user's newly followed/unfollowed topic * Sets the user's newly followed/unfollowed topic
*/ */
suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean)
/** /**
* Updates the bookmarked status for a news resource * Updates the bookmarked status for a news resource

@ -40,11 +40,11 @@ class FakeUserDataRepository @Inject constructor(
override suspend fun setFollowedTopicIds(followedTopicIds: Set<String>) = override suspend fun setFollowedTopicIds(followedTopicIds: Set<String>) =
niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds) niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds)
override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) = override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) =
niaPreferencesDataSource.toggleFollowedTopicId(followedTopicId, followed) niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed)
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.toggleNewsResourceBookmark(newsResourceId, bookmarked) niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
} }
override suspend fun setNewsResourceViewed(newsResourceId: String, viewed: Boolean) = override suspend fun setNewsResourceViewed(newsResourceId: String, viewed: Boolean) =

@ -80,7 +80,7 @@ class OfflineFirstUserDataRepositoryTest {
@Test @Test
fun offlineFirstUserDataRepository_toggle_followed_topics_logic_delegates_to_nia_preferences() = fun offlineFirstUserDataRepository_toggle_followed_topics_logic_delegates_to_nia_preferences() =
testScope.runTest { testScope.runTest {
subject.toggleFollowedTopicId(followedTopicId = "0", followed = true) subject.setTopicIdFollowed(followedTopicId = "0", followed = true)
assertEquals( assertEquals(
setOf("0"), setOf("0"),
@ -89,7 +89,7 @@ class OfflineFirstUserDataRepositoryTest {
.first(), .first(),
) )
subject.toggleFollowedTopicId(followedTopicId = "1", followed = true) subject.setTopicIdFollowed(followedTopicId = "1", followed = true)
assertEquals( assertEquals(
setOf("0", "1"), setOf("0", "1"),

@ -73,7 +73,7 @@ class NiaPreferencesDataSource @Inject constructor(
} }
} }
suspend fun toggleFollowedTopicId(topicId: String, followed: Boolean) { suspend fun setTopicIdFollowed(topicId: String, followed: Boolean) {
try { try {
userPreferences.updateData { userPreferences.updateData {
it.copy { it.copy {
@ -122,7 +122,7 @@ class NiaPreferencesDataSource @Inject constructor(
} }
} }
suspend fun toggleNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { suspend fun setNewsResourceBookmarked(newsResourceId: String, bookmarked: Boolean) {
try { try {
userPreferences.updateData { userPreferences.updateData {
it.copy { it.copy {

@ -59,11 +59,11 @@ class NiaPreferencesDataSourceTest {
fun userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse() = fun userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse() =
testScope.runTest { testScope.runTest {
// Given: user completes onboarding by selecting a single topic. // Given: user completes onboarding by selecting a single topic.
subject.toggleFollowedTopicId("1", true) subject.setTopicIdFollowed("1", true)
subject.setShouldHideOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow that topic. // When: they unfollow that topic.
subject.toggleFollowedTopicId("1", false) subject.setTopicIdFollowed("1", false)
// Then: onboarding should be shown again // Then: onboarding should be shown again
assertFalse(subject.userData.first().shouldHideOnboarding) assertFalse(subject.userData.first().shouldHideOnboarding)

@ -49,7 +49,7 @@ class TestUserDataRepository : UserDataRepository {
_userData.tryEmit(currentUserData.copy(followedTopics = followedTopicIds)) _userData.tryEmit(currentUserData.copy(followedTopics = followedTopicIds))
} }
override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) { override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) {
currentUserData.let { current -> currentUserData.let { current ->
val followedTopics = if (followed) { val followedTopics = if (followed) {
current.followedTopics + followedTopicId current.followedTopics + followedTopicId

@ -111,7 +111,7 @@ class ForYouViewModel @Inject constructor(
fun updateTopicSelection(topicId: String, isChecked: Boolean) { fun updateTopicSelection(topicId: String, isChecked: Boolean) {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.toggleFollowedTopicId(topicId, isChecked) userDataRepository.setTopicIdFollowed(topicId, isChecked)
} }
} }

@ -47,7 +47,7 @@ class InterestsViewModel @Inject constructor(
fun followTopic(followedTopicId: String, followed: Boolean) { fun followTopic(followedTopicId: String, followed: Boolean) {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.toggleFollowedTopicId(followedTopicId, followed) userDataRepository.setTopicIdFollowed(followedTopicId, followed)
} }
} }
} }

@ -75,7 +75,7 @@ class TopicViewModel @Inject constructor(
fun followTopicToggle(followed: Boolean) { fun followTopicToggle(followed: Boolean) {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.toggleFollowedTopicId(topicArgs.topicId, followed) userDataRepository.setTopicIdFollowed(topicArgs.topicId, followed)
} }
} }

Loading…
Cancel
Save