forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce multiple dagger components and modules
This started off as a quick way to adding dagger to :dribbble but then got a little out of hand due to dependencies into :core and :app, especially within DataManager. Also there are still issues with application wide singletons.
- Loading branch information
1 parent
f7ab649
commit 7513172
Showing
46 changed files
with
937 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.dagger | ||
|
||
import android.content.Context | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import io.plaidapp.core.dagger.CoroutinesContextProviderModule | ||
import io.plaidapp.core.dagger.DataManagerModule | ||
import io.plaidapp.core.dagger.DribbbleDataModule | ||
import io.plaidapp.core.dagger.DribbbleRetrofitModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.core.dagger.DribbleSearchServiceProvider | ||
import io.plaidapp.core.dagger.ShotsRepositoryModule | ||
import io.plaidapp.ui.HomeActivity | ||
|
||
@Component(modules = [HomeModule::class, ShotsRepositoryModule::class]) | ||
interface HomeComponent { | ||
|
||
fun inject(activity: HomeActivity) | ||
|
||
@Component.Builder | ||
interface Builder { | ||
fun build(): HomeComponent | ||
|
||
@BindsInstance | ||
fun context(context: Context): Builder | ||
|
||
fun coroutinesContextProviderModule(module: CoroutinesContextProviderModule): Builder | ||
fun dataLoadedModule(module: OnDataLoadedModule): Builder | ||
fun dataManagerModule(module: DataManagerModule): Builder | ||
fun dribbbleDataModule(module: DribbbleDataModule): Builder | ||
fun retrofitModule(module: DribbbleRetrofitModule): Builder | ||
fun homeModule(module: HomeModule): Builder | ||
fun filterAdapterModule(module: FilterAdapterModule): Builder | ||
fun searchRemoteDataSourceModule(module: DribbleSearchServiceProvider): Builder | ||
fun shotsRepositoryModule(module: ShotsRepositoryModule): Builder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.dagger | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import com.bumptech.glide.util.ViewPreloadSizeProvider | ||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.R | ||
import io.plaidapp.core.dagger.CoroutinesContextProviderModule | ||
import io.plaidapp.core.dagger.DataManagerModule | ||
import io.plaidapp.core.dagger.DribbbleDataModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.core.dagger.ShotsRepositoryModule | ||
import io.plaidapp.core.data.pocket.PocketUtils | ||
import io.plaidapp.core.dribbble.data.api.model.Shot | ||
|
||
@Module( | ||
includes = [ | ||
CoroutinesContextProviderModule::class, | ||
DataManagerModule::class, | ||
DribbbleDataModule::class, | ||
FilterAdapterModule::class, | ||
ShotsRepositoryModule::class, | ||
OnDataLoadedModule::class | ||
] | ||
) | ||
class HomeModule(private val activity: Activity) { | ||
|
||
@Provides fun context(): Context = activity | ||
|
||
@Provides fun activity(): Activity = activity | ||
|
||
@Provides fun columns(): Int = activity.resources.getInteger(R.integer.num_columns) | ||
|
||
@Provides fun viewPreloadSizeProvider() = ViewPreloadSizeProvider<Shot>() | ||
|
||
@Provides fun isPocketInstalled() = PocketUtils.isPocketInstalled(activity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.dagger | ||
|
||
import io.plaidapp.core.dagger.CoroutinesContextProviderModule | ||
import io.plaidapp.core.dagger.DataManagerModule | ||
import io.plaidapp.core.dagger.DribbbleDataModule | ||
import io.plaidapp.core.dagger.DribbbleRetrofitModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.core.dagger.DribbleSearchServiceProvider | ||
import io.plaidapp.core.dagger.ShotsRepositoryModule | ||
import io.plaidapp.core.data.BaseDataManager | ||
import io.plaidapp.core.data.PlaidItem | ||
import io.plaidapp.ui.HomeActivity | ||
|
||
/** | ||
* Injector for HomeActivity. | ||
* | ||
* TODO: Convert to extension function once [HomeActivity] is converted to Kotlin. | ||
*/ | ||
object Injector { | ||
|
||
@JvmStatic | ||
fun inject( | ||
activity: HomeActivity, | ||
dataLoadedCallback: BaseDataManager.OnDataLoadedCallback<List<PlaidItem>> | ||
) { | ||
DaggerHomeComponent.builder() | ||
.context(activity) | ||
.coroutinesContextProviderModule(CoroutinesContextProviderModule()) | ||
.dataLoadedModule(OnDataLoadedModule(dataLoadedCallback)) | ||
.dataManagerModule(DataManagerModule(activity)) | ||
.dribbbleDataModule(DribbbleDataModule()) | ||
.homeModule(HomeModule(activity)) | ||
.filterAdapterModule(FilterAdapterModule(activity)) | ||
.retrofitModule(DribbbleRetrofitModule()) | ||
.searchRemoteDataSourceModule(DribbleSearchServiceProvider()) | ||
.shotsRepositoryModule(ShotsRepositoryModule()) | ||
.build() | ||
.inject(activity) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.