Skip to content

Commit

Permalink
Making the providers classes instead of objects, using activity conte…
Browse files Browse the repository at this point in the history
…xt instead of app context for creating the graph
  • Loading branch information
florina-muntenescu committed Apr 16, 2019
1 parent 3cfdab2 commit 1e2debf
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ import io.plaidapp.core.interfaces.SearchDataSourceFactory
@FeatureScope
interface DesignerNewsSearchComponent {

@FeatureScope
fun factory(): SearchDataSourceFactory
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.plaidapp.core.interfaces.SearchDataSourceFactoryProvider
import io.plaidapp.designernews.dagger.DaggerDesignerNewsSearchComponent
import io.plaidapp.designernews.dagger.DesignerNewsPreferencesModule

object DesignerNewsSearchDataSourceFactoryProvider : SearchDataSourceFactoryProvider {
class DesignerNewsSearchDataSourceFactoryProvider : SearchDataSourceFactoryProvider {

override fun getFactory(context: Context): SearchDataSourceFactory {
return DaggerDesignerNewsSearchComponent.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ import io.plaidapp.core.interfaces.SearchDataSourceFactory
@FeatureScope
interface DribbbleSearchComponent {

@FeatureScope
fun factory(): SearchDataSourceFactory
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.plaidapp.core.interfaces.SearchDataSourceFactoryProvider
import io.plaidapp.dribbble.dagger.DaggerDribbbleSearchComponent
import io.plaidapp.ui.PlaidApplication.Companion.coreComponent

object DribbbleSearchDataSourceFactoryProvider : SearchDataSourceFactoryProvider {
class DribbbleSearchDataSourceFactoryProvider : SearchDataSourceFactoryProvider {

override fun getFactory(context: Context): SearchDataSourceFactory {
return DaggerDribbbleSearchComponent.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import dagger.Module
import dagger.Provides
import io.plaidapp.R
import io.plaidapp.core.dagger.qualifier.IsPocketInstalled
import io.plaidapp.core.dagger.scope.FeatureScope
import io.plaidapp.core.data.pocket.PocketUtils
import io.plaidapp.core.interfaces.SearchDataSourceFactory
import io.plaidapp.core.interfaces.SearchDataSourceFactoryProvider
import io.plaidapp.search.ui.SearchActivity
import io.plaidapp.search.ui.SearchViewModel
import io.plaidapp.search.ui.SearchViewModelFactory
import kotlin.reflect.full.createInstance

@Module
abstract class SearchModule {
Expand Down Expand Up @@ -58,6 +60,7 @@ abstract class SearchModule {

@JvmStatic
@Provides
@FeatureScope
fun factories(activity: Activity): Set<SearchDataSourceFactory> {
val factories = mutableSetOf<SearchDataSourceFactory>()

Expand All @@ -80,8 +83,8 @@ abstract class SearchModule {
): SearchDataSourceFactory? {
return try {
val provider =
Class.forName(className).kotlin.objectInstance as SearchDataSourceFactoryProvider
provider.getFactory(context.applicationContext)
Class.forName(className).kotlin.createInstance() as SearchDataSourceFactoryProvider
provider.getFactory(context)
} catch (e: ClassNotFoundException) {
null
}
Expand Down

0 comments on commit 1e2debf

Please sign in to comment.