diff --git a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt index c4dc95dbb..0f2a592de 100644 --- a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt +++ b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt @@ -44,7 +44,7 @@ interface Synchronizer { */ interface Syncable { /** - * Synchronizes the local database in backing the repository with the network. + * Synchronizes the local database backing the repository with the network. * Returns if the sync was successful or not. */ suspend fun syncWith(synchronizer: Synchronizer): Boolean diff --git a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt index eff0fbe10..f44ff986e 100644 --- a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt +++ b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt @@ -17,10 +17,10 @@ package com.google.samples.apps.nowinandroid.core.data.di import com.google.samples.apps.nowinandroid.core.data.repository.AuthorsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.LocalAuthorsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.LocalNewsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.LocalTopicsRepository import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository +import com.google.samples.apps.nowinandroid.core.data.repository.OfflineFirstAuthorsRepository +import com.google.samples.apps.nowinandroid.core.data.repository.OfflineFirstNewsRepository +import com.google.samples.apps.nowinandroid.core.data.repository.OfflineFirstTopicsRepository import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository import dagger.Binds import dagger.Module @@ -33,16 +33,16 @@ interface DataModule { @Binds fun bindsTopicRepository( - topicsRepository: LocalTopicsRepository + topicsRepository: OfflineFirstTopicsRepository ): TopicsRepository @Binds fun bindsAuthorsRepository( - authorsRepository: LocalAuthorsRepository + authorsRepository: OfflineFirstAuthorsRepository ): AuthorsRepository @Binds fun bindsNewsResourceRepository( - newsRepository: LocalNewsRepository + newsRepository: OfflineFirstNewsRepository ): NewsRepository } diff --git a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepository.kt b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepository.kt similarity index 94% rename from core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepository.kt rename to core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepository.kt index a308c1856..1ff540180 100644 --- a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepository.kt +++ b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepository.kt @@ -32,9 +32,10 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map /** - * Room database backed implementation of the [AuthorsRepository]. + * Disk storage backed implementation of the [AuthorsRepository]. + * Reads are exclusively from local storage to support offline access. */ -class LocalAuthorsRepository @Inject constructor( +class OfflineFirstAuthorsRepository @Inject constructor( private val authorDao: AuthorDao, private val network: NiANetwork, private val niaPreferences: NiaPreferences, diff --git a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepository.kt b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt similarity index 96% rename from core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepository.kt rename to core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt index 11fa39962..896c6e5d2 100644 --- a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepository.kt +++ b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt @@ -42,9 +42,10 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map /** - * Room database backed implementation of the [NewsRepository]. + * Disk storage backed implementation of the [NewsRepository]. + * Reads are exclusively from local storage to support offline access. */ -class LocalNewsRepository @Inject constructor( +class OfflineFirstNewsRepository @Inject constructor( private val newsResourceDao: NewsResourceDao, private val episodeDao: EpisodeDao, private val authorDao: AuthorDao, diff --git a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepository.kt b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt similarity index 94% rename from core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepository.kt rename to core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt index 98f20e10b..95fdfc139 100644 --- a/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepository.kt +++ b/core-data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt @@ -32,9 +32,10 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map /** - * Room database backed implementation of the [TopicsRepository]. + * Disk storage backed implementation of the [TopicsRepository]. + * Reads are exclusively from local storage to support offline access. */ -class LocalTopicsRepository @Inject constructor( +class OfflineFirstTopicsRepository @Inject constructor( private val topicDao: TopicDao, private val network: NiANetwork, private val niaPreferences: NiaPreferences, diff --git a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepositoryTest.kt b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepositoryTest.kt similarity index 92% rename from core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepositoryTest.kt rename to core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepositoryTest.kt index 0bd8efe2a..9ed4ea9d0 100644 --- a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalAuthorsRepositoryTest.kt +++ b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstAuthorsRepositoryTest.kt @@ -37,9 +37,9 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -class LocalAuthorsRepositoryTest { +class OfflineFirstAuthorsRepositoryTest { - private lateinit var subject: LocalAuthorsRepository + private lateinit var subject: OfflineFirstAuthorsRepository private lateinit var authorDao: AuthorDao @@ -59,7 +59,7 @@ class LocalAuthorsRepositoryTest { ) synchronizer = TestSynchronizer(niaPreferences) - subject = LocalAuthorsRepository( + subject = OfflineFirstAuthorsRepository( authorDao = authorDao, network = network, niaPreferences = niaPreferences, @@ -67,7 +67,7 @@ class LocalAuthorsRepositoryTest { } @Test - fun localAuthorsRepository_Authors_stream_is_backed_by_Authors_dao() = + fun offlineFirstAuthorsRepository_Authors_stream_is_backed_by_Authors_dao() = runTest { Assert.assertEquals( authorDao.getAuthorEntitiesStream() @@ -79,7 +79,7 @@ class LocalAuthorsRepositoryTest { } @Test - fun localAuthorsRepository_sync_pulls_from_network() = + fun offlineFirstAuthorsRepository_sync_pulls_from_network() = runTest { subject.syncWith(synchronizer) @@ -102,7 +102,7 @@ class LocalAuthorsRepositoryTest { } @Test - fun localAuthorsRepository_incremental_sync_pulls_from_network() = + fun offlineFirstAuthorsRepository_incremental_sync_pulls_from_network() = runTest { // Set author version to 5 synchronizer.updateChangeListVersions { @@ -139,7 +139,7 @@ class LocalAuthorsRepositoryTest { } @Test - fun localAuthorsRepository_sync_deletes_items_marked_deleted_on_network() = + fun offlineFirstAuthorsRepository_sync_deletes_items_marked_deleted_on_network() = runTest { val networkAuthors = network.getAuthors() .map(NetworkAuthor::asEntity) diff --git a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepositoryTest.kt b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt similarity index 91% rename from core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepositoryTest.kt rename to core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt index 0b78979f5..a73a1c13a 100644 --- a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalNewsRepositoryTest.kt +++ b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt @@ -51,9 +51,9 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -class LocalNewsRepositoryTest { +class OfflineFirstNewsRepositoryTest { - private lateinit var subject: LocalNewsRepository + private lateinit var subject: OfflineFirstNewsRepository private lateinit var newsResourceDao: TestNewsResourceDao @@ -83,7 +83,7 @@ class LocalNewsRepositoryTest { ) ) - subject = LocalNewsRepository( + subject = OfflineFirstNewsRepository( newsResourceDao = newsResourceDao, episodeDao = episodeDao, authorDao = authorDao, @@ -93,7 +93,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_news_resources_stream_is_backed_by_news_resource_dao() = + fun offlineFirstNewsRepository_news_resources_stream_is_backed_by_news_resource_dao() = runTest { assertEquals( newsResourceDao.getNewsResourcesStream() @@ -105,7 +105,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_news_resources_topic_filtered_stream_is_backed_by_news_resource_dao() = + fun offlineFirstNewsRepository_news_resources_for_topic_is_backed_by_news_resource_dao() = runTest { assertEquals( newsResourceDao.getNewsResourcesStream( @@ -129,7 +129,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_news_resources_author_filtered_stream_is_backed_by_news_resource_dao() = + fun offlineFirstNewsRepository_news_resources_for_author_is_backed_by_news_resource_dao() = runTest { assertEquals( newsResourceDao.getNewsResourcesStream( @@ -153,7 +153,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_pulls_from_network() = + fun offlineFirstNewsRepository_sync_pulls_from_network() = runTest { subject.syncWith(synchronizer) @@ -178,7 +178,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_deletes_items_marked_deleted_on_network() = + fun offlineFirstNewsRepository_sync_deletes_items_marked_deleted_on_network() = runTest { val newsResourcesFromNetwork = network.getNewsResources() .map(NetworkNewsResource::asEntity) @@ -219,7 +219,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_incremental_sync_pulls_from_network() = + fun offlineFirstNewsRepository_incremental_sync_pulls_from_network() = runTest { // Set news version to 7 synchronizer.updateChangeListVersions { @@ -258,7 +258,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_saves_shell_topic_entities() = + fun offlineFirstNewsRepository_sync_saves_shell_topic_entities() = runTest { subject.syncWith(synchronizer) @@ -273,7 +273,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_saves_shell_author_entities() = + fun offlineFirstNewsRepository_sync_saves_shell_author_entities() = runTest { subject.syncWith(synchronizer) @@ -288,7 +288,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_saves_shell_episode_entities() = + fun offlineFirstNewsRepository_sync_saves_shell_episode_entities() = runTest { subject.syncWith(synchronizer) @@ -303,7 +303,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_saves_topic_cross_references() = + fun offlineFirstNewsRepository_sync_saves_topic_cross_references() = runTest { subject.syncWith(synchronizer) @@ -317,7 +317,7 @@ class LocalNewsRepositoryTest { } @Test - fun localNewsRepository_sync_saves_author_cross_references() = + fun offlineFirstNewsRepository_sync_saves_author_cross_references() = runTest { subject.syncWith(synchronizer) diff --git a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepositoryTest.kt b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt similarity index 90% rename from core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepositoryTest.kt rename to core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt index 71ff19ebf..e8ab276a2 100644 --- a/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/LocalTopicsRepositoryTest.kt +++ b/core-data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt @@ -36,9 +36,9 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -class LocalTopicsRepositoryTest { +class OfflineFirstTopicsRepositoryTest { - private lateinit var subject: LocalTopicsRepository + private lateinit var subject: OfflineFirstTopicsRepository private lateinit var topicDao: TopicDao @@ -60,7 +60,7 @@ class LocalTopicsRepositoryTest { ) synchronizer = TestSynchronizer(niaPreferences) - subject = LocalTopicsRepository( + subject = OfflineFirstTopicsRepository( topicDao = topicDao, network = network, niaPreferences = niaPreferences @@ -68,7 +68,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_topics_stream_is_backed_by_topics_dao() = + fun offlineFirstTopicsRepository_topics_stream_is_backed_by_topics_dao() = runTest { Assert.assertEquals( topicDao.getTopicEntitiesStream() @@ -80,7 +80,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_news_resources_filtered_stream_is_backed_by_news_resource_dao() = + fun offlineFirstTopicsRepository_news_resources_for_interests_is_backed_by_news_resource_dao() = runTest { Assert.assertEquals( niaPreferences.followedTopicIds @@ -91,7 +91,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_sync_pulls_from_network() = + fun offlineFirstTopicsRepository_sync_pulls_from_network() = runTest { subject.syncWith(synchronizer) @@ -114,7 +114,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_incremental_sync_pulls_from_network() = + fun offlineFirstTopicsRepository_incremental_sync_pulls_from_network() = runTest { // Set topics version to 10 synchronizer.updateChangeListVersions { @@ -144,7 +144,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_sync_deletes_items_marked_deleted_on_network() = + fun offlineFirstTopicsRepository_sync_deletes_items_marked_deleted_on_network() = runTest { val networkTopics = network.getTopics() .map(NetworkTopic::asEntity) @@ -185,7 +185,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_toggle_followed_topics_logic_delegates_to_nia_preferences() = + fun offlineFirstTopicsRepository_toggle_followed_topics_logic_delegates_to_nia_preferences() = runTest { subject.toggleFollowedTopicId(followedTopicId = "0", followed = true) @@ -212,7 +212,7 @@ class LocalTopicsRepositoryTest { } @Test - fun localTopicsRepository_set_followed_topics_logic_delegates_to_nia_preferences() = + fun offlineFirstTopicsRepository_set_followed_topics_logic_delegates_to_nia_preferences() = runTest { subject.setFollowedTopicIds(followedTopicIds = setOf("1", "2"))