Skip to content

Commit

Permalink
Post dagger cleanup
Browse files Browse the repository at this point in the history
* Remove unused params
* @Inject into FilterAdapter
* Introduce DesignerNewsPreferencesModule
* Fix CoroutinesContextProvider deprecations
  • Loading branch information
keyboardsurfer committed Oct 30, 2018
1 parent fde7533 commit 7644346
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/io/plaidapp/dagger/Injector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun inject(
) {
DaggerHomeComponent.builder()
.coreComponent(PlaidApplication.coreComponent(activity))
.dataManagerModule(DataManagerModule(activity))
.dataManagerModule(DataManagerModule())
.dataLoadedModule(OnDataLoadedModule(dataLoadedCallback))
.filterAdapterModule(FilterAdapterModule(activity))
.homeModule(HomeModule(activity))
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/io/plaidapp/core/dagger/CoreDataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class CoreDataModule(private val baseUrl: String, private val factory: Converter

@Provides
fun provideRetrofit(
baseUrl: String,
factory: Converter.Factory,
okHttpClient: OkHttpClient
): Retrofit {
return Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.plaidapp.core.dagger

import android.content.Context
import dagger.Module
import dagger.Provides
import io.plaidapp.core.dagger.dribbble.DribbbleDataModule
Expand All @@ -33,7 +32,7 @@ import io.plaidapp.core.ui.FilterAdapter
* Module to provide [DataManager].
*/
@Module(includes = [DribbbleDataModule::class])
class DataManagerModule(val context: Context) {
class DataManagerModule {

private lateinit var manager: DataManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ import io.plaidapp.core.ui.FilterAdapter
*/
@Module class FilterAdapterModule(val context: Context) {

@Provides fun provideFilterAdapter() = FilterAdapter(context, provideSources())

@Provides fun provideSources(): MutableList<Source> = SourceManager.getSources(context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import dagger.Provides
/**
* Provide [SharedPreferences] to this app's components.
*/
@Module class SharedPreferencesModule(val context: Context, val name: String) {
@Module open class SharedPreferencesModule(val context: Context, val name: String) {

@Provides fun provideSharedPreferences(): SharedPreferences {
return context.applicationContext.getSharedPreferences(name, Context.MODE_PRIVATE)
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/plaidapp/core/ui/FilterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ import io.plaidapp.core.util.AnimUtils
import io.plaidapp.core.util.ColorUtils
import io.plaidapp.core.util.ViewUtils
import java.util.Collections
import javax.inject.Inject

/**
* Adapter for showing the list of data sources used as filters for the home grid.
*/
class FilterAdapter constructor(
class FilterAdapter @Inject constructor(
context: Context,
val filters: MutableList<Source>
) : RecyclerView.Adapter<FilterViewHolder>(), FilterSwipeDismissListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.designernews.dagger

import android.content.Context
import dagger.Module
import io.plaidapp.core.dagger.SharedPreferencesModule
import io.plaidapp.core.designernews.data.login.LoginLocalDataSource

@Module
class DesignerNewsPreferencesModule(
context: Context
) : SharedPreferencesModule(context, LoginLocalDataSource.DESIGNER_NEWS_PREF)
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import android.util.TypedValue
import io.plaidapp.core.dagger.CoreDataModule
import io.plaidapp.core.dagger.CoroutinesContextProviderModule
import io.plaidapp.core.dagger.MarkdownModule
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.designernews.ui.login.LoginActivity
import io.plaidapp.designernews.ui.story.StoryActivity
import io.plaidapp.ui.PlaidApplication
Expand Down Expand Up @@ -61,7 +59,7 @@ fun inject(storyId: Long, activity: StoryActivity) {
.designerNewsModule(StoryModule(storyId, activity))
.markdownModule(MarkdownModule(activity.resources.displayMetrics, bypassOptions))
.sharedPreferencesModule(
SharedPreferencesModule(activity, LoginLocalDataSource.DESIGNER_NEWS_PREF)
DesignerNewsPreferencesModule(activity)
)
.build()
.inject(activity)
Expand All @@ -72,7 +70,7 @@ fun inject(activity: LoginActivity) {
DaggerLoginComponent.builder()
.coreDataModule(coreDataModule)
.sharedPreferencesModule(
SharedPreferencesModule(activity, LoginLocalDataSource.DESIGNER_NEWS_PREF)
DesignerNewsPreferencesModule(activity)
)
.build()
.inject(activity)
Expand Down

0 comments on commit 7644346

Please sign in to comment.