Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger android #5

Merged
merged 21 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions networking/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,33 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
consumerProguardFiles 'proguard-joda-time.pro', 'proguard-retrofit.pro',
'proguard-okhttp.pro'
consumerProguardFiles 'proguard-retrofit.pro', 'proguard-okhttp.pro', 'proguard-gson.pro'
}

lintOptions {
abortOnError false
}
}

buildscript {
ext.dagger_version = '2.11-rc2'
ext.retrofit_version = '2.2.0'
ext.okhttp_version = '3.7.0'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// Wolmo
compile 'com.github.Wolox:wolmo-core-android:v1.0.0'
compile 'com.github.Wolox:wolmo-core-android:dagger-android-SNAPSHOT'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change the dagger-android-SNAPSHOT to the corresponding version when merging the PR. Maybe put a TODO 🤔?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I'll add it 😄


// Dagger
provided "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"

// Third party
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.7.0'
compile 'com.squareup.okhttp3:okhttp:3.7.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.7.0'
compile 'joda-time:joda-time:2.9.9'
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.okhttp3:okhttp-urlconnection:$okhttp_version"
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
}
17 changes: 17 additions & 0 deletions networking/proguard-gson.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
6 changes: 0 additions & 6 deletions networking/proguard-joda-time.pro

This file was deleted.

9 changes: 4 additions & 5 deletions networking/proguard-okhttp.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**

-keepattributes Annotation
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
8 changes: 4 additions & 4 deletions networking/proguard-retrofit.pro
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Retrofit 2.X
## https://square.github.io/retrofit/ ##

-dontwarn retrofit.**
-keep class retrofit.** { *; }
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
@retrofit2.http.* <methods>;
}
17 changes: 0 additions & 17 deletions networking/proguard-rules.pro

This file was deleted.

3 changes: 1 addition & 2 deletions networking/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"/>
android:supportsRtl="true" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package ar.com.wolox.wolmo.networking.di;

import android.support.annotation.Nullable;

import com.google.gson.FieldNamingPolicy;

import ar.com.wolox.wolmo.networking.di.modules.GsonModule;
import ar.com.wolox.wolmo.networking.di.modules.NetworkingModule;
import ar.com.wolox.wolmo.networking.di.modules.OkHttpClientModule;
import ar.com.wolox.wolmo.networking.di.scopes.NetworkingScope;
import ar.com.wolox.wolmo.networking.retrofit.RetrofitServices;
import ar.com.wolox.wolmo.networking.utils.GsonTypeAdapter;

import dagger.BindsInstance;
import dagger.Component;
import okhttp3.Interceptor;

@NetworkingScope
@Component(modules = { GsonModule.class, OkHttpClientModule.class, NetworkingModule.class })
public interface NetworkingComponent {

RetrofitServices retrofitServices();

@Component.Builder
interface Builder {

@BindsInstance
Builder baseUrl(String baseUrl);

@BindsInstance
Builder okHttpInterceptors(@Nullable Interceptor... interceptors);

@BindsInstance
Builder gsonNamingPolicy(FieldNamingPolicy namingPolicy);

@BindsInstance
Builder gsonTypeAdapters(@Nullable GsonTypeAdapter... typeAdapters);

NetworkingComponent build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package ar.com.wolox.wolmo.networking.di.modules;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import ar.com.wolox.wolmo.networking.retrofit.serializer.LocalDateSerializer;
import ar.com.wolox.wolmo.networking.utils.GsonTypeAdapter;

import org.joda.time.LocalDate;

import dagger.Module;
import dagger.Provides;
import retrofit2.converter.gson.GsonConverterFactory;

@Module
public class GsonModule {

@Provides
GsonConverterFactory provideGsonConverterFactory(Gson gson) {
return GsonConverterFactory.create(gson);
}

@Provides
Gson provideGson(GsonBuilder gsonBuilder) {
return gsonBuilder.create();
}

@Provides
GsonBuilder provideGsonBuilder(@NonNull FieldNamingPolicy namingPolicy,
@Nullable GsonTypeAdapter... typeAdapters) {

GsonBuilder builder = new GsonBuilder();
builder.setFieldNamingPolicy(namingPolicy);

if (typeAdapters != null) {
for (GsonTypeAdapter typeAdapter : typeAdapters) {
builder.registerTypeAdapter(typeAdapter.getType(), typeAdapter.getTypeAdapter());
}
} else {
builder.registerTypeAdapter(LocalDate.class, new LocalDateSerializer());
}

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package ar.com.wolox.wolmo.networking.di.modules;

import ar.com.wolox.wolmo.networking.di.scopes.NetworkingScope;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

@Module
public class NetworkingModule {

@Provides
@NetworkingScope
Retrofit provideRetrofit(String baseUrl, GsonConverterFactory gsonConverterFactory, OkHttpClient client) {
return new Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(gsonConverterFactory)
.client(client).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package ar.com.wolox.wolmo.networking.di.modules;

import android.support.annotation.Nullable;

import dagger.Module;
import dagger.Provides;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;

@Module
public class OkHttpClientModule {

@Provides
OkHttpClient provideOkHttpClient(OkHttpClient.Builder okHttpBuilder, @Nullable Interceptor... interceptors) {
if (interceptors != null) {
for (Interceptor interceptor : interceptors) {
okHttpBuilder.addInterceptor(interceptor);
}
}
return okHttpBuilder.build();
}

@Provides
OkHttpClient.Builder provideOkHttpClientBuilder() {
return new OkHttpClient.Builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package ar.com.wolox.wolmo.networking.di.scopes;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.inject.Scope;

@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface NetworkingScope {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* MIT License
* <p>
* Copyright (c) 2017 Wolox S.A
Expand Down
Loading