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.
- Loading branch information
1 parent
7b502a5
commit 3f7ae5f
Showing
7 changed files
with
197 additions
and
17 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
48 changes: 48 additions & 0 deletions
48
search/src/main/java/io/plaidapp/search/dagger/Injector.kt
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,48 @@ | ||
/* | ||
* 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.search.dagger | ||
|
||
import io.plaidapp.core.dagger.DataManagerModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.core.data.BaseDataManager | ||
import io.plaidapp.core.data.PlaidItem | ||
import io.plaidapp.ui.PlaidApplication | ||
import io.plaidapp.ui.search.SearchActivity | ||
|
||
/** | ||
* Injector for SearchActivity. | ||
* | ||
* TODO: Convert to extension function once [SearchActivity] is converted to Kotlin. | ||
*/ | ||
object Injector { | ||
|
||
@JvmStatic | ||
fun inject( | ||
activity: SearchActivity, | ||
dataLoadedCallback: BaseDataManager.OnDataLoadedCallback<List<PlaidItem>> | ||
) { | ||
DaggerSearchComponent.builder() | ||
.coreComponent(PlaidApplication.coreComponent(activity)) | ||
.dataManagerModule(DataManagerModule(activity)) | ||
.dataLoadedModule(OnDataLoadedModule(dataLoadedCallback)) | ||
.filterAdapterModule(FilterAdapterModule(activity)) | ||
.searchModule(SearchModule(activity)) | ||
.build() | ||
.inject(activity) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
search/src/main/java/io/plaidapp/search/dagger/SearchComponent.kt
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,44 @@ | ||
/* | ||
* 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.search.dagger | ||
|
||
import dagger.Component | ||
import io.plaidapp.core.dagger.CoreComponent | ||
import io.plaidapp.core.dagger.DataManagerModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.ui.search.SearchActivity | ||
|
||
/** | ||
* Dagger component for the [SearchActivity]. | ||
*/ | ||
@Component(modules = [SearchModule::class], dependencies = [CoreComponent::class]) | ||
interface SearchComponent { | ||
|
||
fun inject(activity: SearchActivity) | ||
|
||
@Component.Builder | ||
interface Builder { | ||
|
||
fun build(): SearchComponent | ||
fun coreComponent(module: CoreComponent): Builder | ||
fun dataManagerModule(module: DataManagerModule): Builder | ||
fun dataLoadedModule(module: OnDataLoadedModule): Builder | ||
fun filterAdapterModule(module: FilterAdapterModule): Builder | ||
fun searchModule(module: SearchModule): Builder | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
search/src/main/java/io/plaidapp/search/dagger/SearchModule.kt
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,65 @@ | ||
/* | ||
* 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.search.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.DataManagerModule | ||
import io.plaidapp.core.dagger.FilterAdapterModule | ||
import io.plaidapp.core.dagger.OnDataLoadedModule | ||
import io.plaidapp.core.dagger.dribbble.DribbbleDataModule | ||
import io.plaidapp.core.data.BaseDataManager | ||
import io.plaidapp.core.data.PlaidItem | ||
import io.plaidapp.core.data.pocket.PocketUtils | ||
import io.plaidapp.core.dribbble.data.ShotsRepository | ||
import io.plaidapp.core.dribbble.data.api.model.Shot | ||
import io.plaidapp.search.SearchDataManager | ||
|
||
@Module( | ||
includes = [ | ||
DataManagerModule::class, | ||
DribbbleDataModule::class, | ||
FilterAdapterModule::class, | ||
OnDataLoadedModule::class | ||
] | ||
) | ||
class SearchModule(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) | ||
|
||
@Provides | ||
fun provideSearchDataManager( | ||
onDataLoadedCallback: BaseDataManager.OnDataLoadedCallback<List<PlaidItem>>, | ||
shotsRepository: ShotsRepository | ||
): SearchDataManager = SearchDataManager(context(), onDataLoadedCallback, shotsRepository) | ||
} |
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