Add 'OfflineFirst' prefix to repository implementations

Change-Id: I6e67373f3d6e04cfe1a45b870c6dfcc04af60e22
pull/2/head
Adetunji Dahunsi 3 years ago committed by Don Turner
parent 4d72950f94
commit f0658e34ee

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

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

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

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

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

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

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

@ -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"))
Loading…
Cancel
Save