Rename hasDismissedOnboarding to shouldHideOnboarding

Change-Id: I8a6b35f7216f9944652d8da346e7458614311e08
pull/406/head
Don Turner 2 years ago
parent 6654403498
commit 5b8c284c74

@ -51,6 +51,6 @@ class OfflineFirstUserDataRepository @Inject constructor(
override suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) =
niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig)
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) =
niaPreferencesDataSource.setHasDismissedOnboarding(hasDismissedOnboarding)
override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) =
niaPreferencesDataSource.setShouldHideOnboarding(shouldHideOnboarding)
}

@ -66,5 +66,5 @@ interface UserDataRepository {
/**
* Sets whether the user has completed the onboarding process.
*/
suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean)
suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean)
}

@ -64,7 +64,7 @@ class FakeUserDataRepository @Inject constructor(
niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig)
}
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) {
niaPreferencesDataSource.setHasDismissedOnboarding(hasDismissedOnboarding)
override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
niaPreferencesDataSource.setShouldHideOnboarding(shouldHideOnboarding)
}
}

@ -59,7 +59,7 @@ class OfflineFirstUserDataRepositoryTest {
followedAuthors = emptySet(),
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
hasDismissedOnboarding = false
shouldHideOnboarding = false
),
subject.userDataStream.first()
)
@ -190,13 +190,13 @@ class OfflineFirstUserDataRepositoryTest {
}
@Test
fun whenUserCompletesOnboarding_thenRemovesAllInterests_hasDismissedOnboardingIsFalse() =
fun whenUserCompletesOnboarding_thenRemovesAllInterests_shouldHideOnboardingIsFalse() =
runTest {
subject.setFollowedTopicIds(setOf("1"))
subject.setHasDismissedOnboarding(true)
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding)
subject.setShouldHideOnboarding(true)
assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
subject.setFollowedTopicIds(emptySet())
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
}

@ -53,7 +53,7 @@ class NiaPreferencesDataSource @Inject constructor(
DarkThemeConfig.LIGHT
DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK
},
hasDismissedOnboarding = it.hasDismissedOnboarding
shouldHideOnboarding = it.shouldHideOnboarding
)
}
@ -63,7 +63,7 @@ class NiaPreferencesDataSource @Inject constructor(
it.copy {
followedTopicIds.clear()
followedTopicIds.putAll(topicIds.associateWith { true })
updateHasDismissedOnboardingIfNecessary()
updateShouldHideOnboardingIfNecessary()
}
}
} catch (ioException: IOException) {
@ -80,7 +80,7 @@ class NiaPreferencesDataSource @Inject constructor(
} else {
followedTopicIds.remove(topicId)
}
updateHasDismissedOnboardingIfNecessary()
updateShouldHideOnboardingIfNecessary()
}
}
} catch (ioException: IOException) {
@ -94,7 +94,7 @@ class NiaPreferencesDataSource @Inject constructor(
it.copy {
followedAuthorIds.clear()
followedAuthorIds.putAll(authorIds.associateWith { true })
updateHasDismissedOnboardingIfNecessary()
updateShouldHideOnboardingIfNecessary()
}
}
} catch (ioException: IOException) {
@ -111,7 +111,7 @@ class NiaPreferencesDataSource @Inject constructor(
} else {
followedAuthorIds.remove(authorId)
}
updateHasDismissedOnboardingIfNecessary()
updateShouldHideOnboardingIfNecessary()
}
}
} catch (ioException: IOException) {
@ -194,18 +194,18 @@ class NiaPreferencesDataSource @Inject constructor(
}
}
suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) {
suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
userPreferences.updateData {
it.copy {
this.hasDismissedOnboarding = hasDismissedOnboarding
this.shouldHideOnboarding = shouldHideOnboarding
}
}
}
}
fun UserPreferencesKt.Dsl.updateHasDismissedOnboardingIfNecessary() {
fun UserPreferencesKt.Dsl.updateShouldHideOnboardingIfNecessary() {
if (followedTopicIds.isEmpty() && followedAuthorIds.isEmpty()) {
hasDismissedOnboarding = false
shouldHideOnboarding = false
}
}

@ -44,8 +44,5 @@ message UserPreferences {
ThemeBrandProto theme_brand = 16;
DarkThemeConfigProto dark_theme_config = 17;
// Note that proto3 only allows a default value of `false` for boolean types. This means that
// whilst the name `should_show_onboarding` would be preferable here we are forced to choose a
// name which works with this default value constraint.
bool has_dismissed_onboarding = 18;
bool should_hide_onboarding = 18;
}

@ -39,99 +39,99 @@ class NiaPreferencesDataSourceTest {
}
@Test
fun hasDismissedOnboardingIsFalseByDefault() = runTest {
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
fun shouldHideOnboardingIsFalseByDefault() = runTest {
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboardingIsTrueWhenSet() = runTest {
subject.setHasDismissedOnboarding(true)
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding)
fun userShouldHideOnboardingIsTrueWhenSet() = runTest {
subject.setShouldHideOnboarding(true)
assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsLastAuthor_hasDismissedOnboardingIsFalse() = runTest {
fun userShouldHideOnboarding_unfollowsLastAuthor_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting a single author.
subject.toggleFollowedAuthorId("1", true)
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow that author.
subject.toggleFollowedAuthorId("1", false)
// Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsLastTopic_hasDismissedOnboardingIsFalse() = runTest {
fun userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting a single topic.
subject.toggleFollowedTopicId("1", true)
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow that topic.
subject.toggleFollowedTopicId("1", false)
// Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsAllAuthors_hasDismissedOnboardingIsFalse() = runTest {
fun userShouldHideOnboarding_unfollowsAllAuthors_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting several authors.
subject.setFollowedAuthorIds(setOf("1", "2"))
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow those authors.
subject.setFollowedAuthorIds(emptySet())
// Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsAllTopics_hasDismissedOnboardingIsFalse() = runTest {
fun userShouldHideOnboarding_unfollowsAllTopics_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting several topics.
subject.setFollowedTopicIds(setOf("1", "2"))
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow those topics.
subject.setFollowedTopicIds(emptySet())
// Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsAllTopicsButNotAuthors_hasDismissedOnboardingIsTrue() =
fun userShouldHideOnboarding_unfollowsAllTopicsButNotAuthors_shouldHideOnboardingIsTrue() =
runTest {
// Given: user completes onboarding by selecting several topics and authors.
subject.setFollowedTopicIds(setOf("1", "2"))
subject.setFollowedAuthorIds(setOf("3", "4"))
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow just the topics.
subject.setFollowedTopicIds(emptySet())
// Then: onboarding should still be dismissed
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
}
@Test
fun userHasDismissedOnboarding_unfollowsAllAuthorsButNotTopics_hasDismissedOnboardingIsTrue() =
fun userShouldHideOnboarding_unfollowsAllAuthorsButNotTopics_shouldHideOnboardingIsTrue() =
runTest {
// Given: user completes onboarding by selecting several topics and authors.
subject.setFollowedTopicIds(setOf("1", "2"))
subject.setFollowedAuthorIds(setOf("3", "4"))
subject.setHasDismissedOnboarding(true)
subject.setShouldHideOnboarding(true)
// When: they unfollow just the authors.
subject.setFollowedAuthorIds(emptySet())
// Then: onboarding should still be dismissed
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding)
assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
}
}

@ -25,5 +25,5 @@ data class UserData(
val followedAuthors: Set<String>,
val themeBrand: ThemeBrand,
val darkThemeConfig: DarkThemeConfig,
val hasDismissedOnboarding: Boolean
val shouldHideOnboarding: Boolean
)

@ -31,7 +31,7 @@ private val emptyUserData = UserData(
followedAuthors = emptySet(),
themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
hasDismissedOnboarding = false
shouldHideOnboarding = false
)
class TestUserDataRepository : UserDataRepository {
@ -91,9 +91,9 @@ class TestUserDataRepository : UserDataRepository {
}
}
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) {
override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
currentUserData.let { current ->
_userData.tryEmit(current.copy(hasDismissedOnboarding = hasDismissedOnboarding))
_userData.tryEmit(current.copy(shouldHideOnboarding = shouldHideOnboarding))
}
}

@ -48,7 +48,7 @@ class ForYouViewModel @Inject constructor(
) : ViewModel() {
private val shouldShowOnboarding: Flow<Boolean> =
userDataRepository.userDataStream.map { !it.hasDismissedOnboarding }
userDataRepository.userDataStream.map { !it.shouldHideOnboarding }
val isSyncing = syncStatusMonitor.isSyncing
.stateIn(
@ -63,7 +63,7 @@ class ForYouViewModel @Inject constructor(
// If the user hasn't completed the onboarding and hasn't selected any interests
// show an empty news list to clearly demonstrate that their selections affect the
// news articles they will see.
if (!userData.hasDismissedOnboarding &&
if (!userData.shouldHideOnboarding &&
userData.followedAuthors.isEmpty() &&
userData.followedTopics.isEmpty()
) {
@ -126,7 +126,7 @@ class ForYouViewModel @Inject constructor(
fun dismissOnboarding() {
viewModelScope.launch {
userDataRepository.setHasDismissedOnboarding(true)
userDataRepository.setShouldHideOnboarding(true)
}
}
}

@ -1011,7 +1011,7 @@ class ForYouViewModelTest {
userDataRepository.setFollowedTopicIds(setOf("1"))
authorsRepository.sendAuthors(sampleAuthors)
userDataRepository.setFollowedAuthorIds(setOf("1"))
userDataRepository.setHasDismissedOnboarding(true)
userDataRepository.setShouldHideOnboarding(true)
newsRepository.sendNewsResources(sampleNewsResources)
viewModel.updateNewsResourceSaved("2", true)

Loading…
Cancel
Save