Skip to content

Commit

Permalink
Fix crash in UpvoteService due to incorrect injection
Browse files Browse the repository at this point in the history
  • Loading branch information
florina-muntenescu committed Nov 15, 2018
1 parent 83c6a10 commit 9529074
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

@file:JvmName("Injector")

package io.plaidapp.core.dagger.designernews

import io.plaidapp.core.dagger.CoreDataModule
import io.plaidapp.core.dagger.CoroutinesDispatcherProviderModule
import io.plaidapp.core.dagger.SharedPreferencesModule
import io.plaidapp.core.designernews.data.api.DesignerNewsService
import io.plaidapp.core.designernews.data.login.LoginLocalDataSource
import io.plaidapp.core.designernews.data.votes.UpvoteStoryService
import retrofit2.converter.gson.GsonConverterFactory

/**
* Injector for [UpvoteStoryService].
*/

fun inject(service: UpvoteStoryService) {
val coreDataModule =
CoreDataModule(DesignerNewsService.ENDPOINT, GsonConverterFactory.create())

DaggerUpvoteStoryServiceComponent.builder()
.coroutinesDispatcherProviderModule(CoroutinesDispatcherProviderModule())
.coreDataModule(coreDataModule)
.sharedPreferencesModule(
SharedPreferencesModule(service, LoginLocalDataSource.DESIGNER_NEWS_PREF)
)
.build()
.inject(service)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.core.dagger.designernews

import dagger.Component
import io.plaidapp.core.dagger.CoreDataModule
import io.plaidapp.core.dagger.CoroutinesDispatcherProviderModule
import io.plaidapp.core.dagger.SharedPreferencesModule
import io.plaidapp.core.designernews.data.votes.UpvoteStoryService

/**
* Dagger component for the [UpvoteStoryServiceModule].
*/
@Component(modules = [UpvoteStoryServiceModule::class, CoreDataModule::class,
DesignerNewsDataModule::class])
interface UpvoteStoryServiceComponent {

fun inject(service: UpvoteStoryService)

@Component.Builder
interface Builder {

fun build(): UpvoteStoryServiceComponent
fun coroutinesDispatcherProviderModule(module: CoroutinesDispatcherProviderModule): Builder
fun coreDataModule(module: CoreDataModule): Builder
fun sharedPreferencesModule(module: SharedPreferencesModule): Builder
fun upvoteServiceModule(module: UpvoteStoryServiceModule): Builder
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.core.dagger.designernews

import android.app.Service
import android.content.Context
import dagger.Module
import dagger.Provides
import io.plaidapp.core.designernews.data.votes.UpvoteStoryService

/**
* Dagger module for [UpvoteStoryService].
*/
@Module(includes = [DesignerNewsDataModule::class])
class UpvoteStoryServiceModule(private val service: UpvoteStoryService) {

@Provides
fun context(): Context = service

@Provides
fun service(): Service = service
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import io.plaidapp.core.dagger.designernews.Injector;
import io.plaidapp.core.designernews.data.api.DesignerNewsService;
import io.plaidapp.core.designernews.data.login.LoginRepository;
import io.plaidapp.core.designernews.data.stories.model.Story;
Expand All @@ -36,6 +37,7 @@ public class UpvoteStoryService extends IntentService {

public UpvoteStoryService() {
super("UpvoteStoryService");
Injector.inject(this);
}

@Inject DesignerNewsService service;
Expand Down

0 comments on commit 9529074

Please sign in to comment.