Renamed toggle function signature with boolean parameters

Change-Id: I0d6c0ed4d4c0ee4bd387e5645fc558970f5f202b
pull/618/head
Roy Matero 2 years ago committed by Miłosz Moczkowski
parent d2d12b958b
commit 4e6cda1965

@ -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