Skip to content

Commit

Permalink
Switching to providing a list of factories, to enable more implementa…
Browse files Browse the repository at this point in the history
…tions of

SearchDataSourceFactory
  • Loading branch information
florina-muntenescu committed Apr 16, 2019
1 parent f1dae3b commit 9d01634
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import javax.inject.Inject
import javax.inject.Provider

class SearchDataSourceFactoriesRegistry @Inject constructor(
defaultFactory: Provider<SearchDataSourceFactory?>
defaultFactories: Provider<List<SearchDataSourceFactory>>
) {
private val _dataSourceFactories = mutableListOf<SearchDataSourceFactory>()

init {
defaultFactory.get()?.apply { add(this) }
defaultFactories.get()?.forEach { add(it) }
}

val dataSourceFactories: List<SearchDataSourceFactory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import io.plaidapp.search.ui.SearchActivity
@FeatureScope
interface SearchComponent : BaseActivityComponent<SearchActivity> {

fun factory(): SearchDataSourceFactory?
fun factories(): List<SearchDataSourceFactory>

@Component.Builder
interface Builder {
Expand Down
12 changes: 9 additions & 3 deletions search/src/main/java/io/plaidapp/search/dagger/SearchModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,21 @@ abstract class SearchModule {

@JvmStatic
@Provides
fun factory(activity: Activity): SearchDataSourceFactory? {
fun factories(activity: Activity): List<SearchDataSourceFactory> {
val factories = mutableListOf<SearchDataSourceFactory>()
try {
val provider = Class
.forName("io.plaidapp.designernews.domain.search.DesignerNewsSearchFactoryProvider")
.kotlin.objectInstance as SearchFactoryProvider
return provider.getFactory(activity.applicationContext)
val factory = provider.getFactory(activity.applicationContext)
factory?.apply {
factories.add(this)
}
} catch (e: ClassNotFoundException) {
return null
// nothing to do
}

return factories
}

@JvmStatic
Expand Down

0 comments on commit 9d01634

Please sign in to comment.