/* * Copyright (c) 2016 Ha Duy Trung * * 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.github.hidroh.materialistic; import javax.inject.Named; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import io.github.hidroh.materialistic.accounts.UserServices; import io.github.hidroh.materialistic.accounts.UserServicesClient; import io.github.hidroh.materialistic.data.AlgoliaClient; import io.github.hidroh.materialistic.data.AlgoliaPopularClient; import io.github.hidroh.materialistic.data.FavoriteManager; import io.github.hidroh.materialistic.data.FeedbackClient; import io.github.hidroh.materialistic.data.HackerNewsClient; import io.github.hidroh.materialistic.data.ItemManager; import io.github.hidroh.materialistic.data.ReadabilityClient; import io.github.hidroh.materialistic.data.SessionManager; import io.github.hidroh.materialistic.data.UserManager; import okhttp3.Call; import rx.Scheduler; import rx.schedulers.Schedulers; import static io.github.hidroh.materialistic.ActivityModule.ALGOLIA; import static io.github.hidroh.materialistic.ActivityModule.HN; import static io.github.hidroh.materialistic.ActivityModule.POPULAR; @Module(library = true, complete = false, includes = NetworkModule.class) class DataModule { @Provides @Singleton @Named(HN) public ItemManager provideHackerNewsClient(HackerNewsClient client) { return client; } @Provides @Singleton @Named(ALGOLIA) public ItemManager provideAlgoliaClient(AlgoliaClient client) { return client; } @Provides @Singleton @Named(POPULAR) public ItemManager provideAlgoliaPopularClient(AlgoliaPopularClient client) { return client; } @Provides @Singleton public UserManager provideUserManager(HackerNewsClient client) { return client; } @Provides @Singleton public FeedbackClient provideFeedbackClient(FeedbackClient.Impl client) { return client; } @Provides @Singleton public ReadabilityClient provideReadabilityClient(ReadabilityClient.Impl client) { return client; } @Provides @Singleton public FavoriteManager provideFavoriteManager(Scheduler ioScheduler) { return new FavoriteManager(ioScheduler); } @Provides @Singleton public SessionManager provideSessionManager(Scheduler ioScheduler) { return new SessionManager(ioScheduler); } @Provides @Singleton public UserServices provideUserServices(Call.Factory callFactory, Scheduler ioScheduler) { return new UserServicesClient(callFactory, ioScheduler); } @Provides @Singleton public Scheduler provideIoScheduler() { return Schedulers.io(); } }