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>) =
niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds)
override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) {
niaPreferencesDataSource.toggleFollowedTopicId(followedTopicId, followed)
override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) {
niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed)
analyticsHelper.logTopicFollowToggled(followedTopicId, followed)
}
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.toggleNewsResourceBookmark(newsResourceId, bookmarked)
niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
analyticsHelper.logNewsResourceBookmarkToggled(
newsResourceId = newsResourceId,
isBookmarked = bookmarked,

@ -34,9 +34,9 @@ interface UserDataRepository {
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

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

@ -80,7 +80,7 @@ class OfflineFirstUserDataRepositoryTest {
@Test
fun offlineFirstUserDataRepository_toggle_followed_topics_logic_delegates_to_nia_preferences() =
testScope.runTest {
subject.toggleFollowedTopicId(followedTopicId = "0", followed = true)
subject.setTopicIdFollowed(followedTopicId = "0", followed = true)
assertEquals(
setOf("0"),
@ -89,7 +89,7 @@ class OfflineFirstUserDataRepositoryTest {
.first(),
)
subject.toggleFollowedTopicId(followedTopicId = "1", followed = true)
subject.setTopicIdFollowed(followedTopicId = "1", followed = true)
assertEquals(
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 {
userPreferences.updateData {
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 {
userPreferences.updateData {
it.copy {

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

@ -49,7 +49,7 @@ class TestUserDataRepository : UserDataRepository {
_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 ->
val followedTopics = if (followed) {
current.followedTopics + followedTopicId

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

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

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

Loading…
Cancel
Save