-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c969c8d
Removed networking application
2b6dad3
Refactor RetrofitServices to extract dependencies to dagger modules
2c18254
Add GsonTypeAdapter to configure Gson and missing License
8aec2f1
Move LoggingInterceptors to util class
bdc25ff
Update build.gradle config
0044083
Remove joda-time proguard options
55d05e3
Update proguard rules and remove unused ones
336eba8
Update proguard rules and remove unused properties
f396d3a
Remove LoggingUtils and dependencies
06e4992
Add TODO to build.gradle
dbe1648
Merge branch 'master' into dagger-android
f593573
Update dagger version
ac8f50d
Add testing libraries and jacoco plugin
44abd47
Fix bugs in modules and make methods static
77dd400
Fix some issues and documentation in serializers and interceptors
50e9bf1
Add unit tests
6fc3d0f
Merge branch 'master' into dagger-android
427b233
Add unit tests and javadocs for missing classes
5ad9bf6
Add coverage badge
f47ded0
Add new tests to default modules
bc35208
Merge branch 'development' into dagger-android
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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.** |
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 |
---|---|---|
@@ -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>; | ||
} |
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
networking/src/main/java/ar/com/wolox/wolmo/networking/di/NetworkingComponent.java
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,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(); | ||
|
||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
networking/src/main/java/ar/com/wolox/wolmo/networking/di/modules/GsonModule.java
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,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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
networking/src/main/java/ar/com/wolox/wolmo/networking/di/modules/NetworkingModule.java
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,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(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
networking/src/main/java/ar/com/wolox/wolmo/networking/di/modules/OkHttpClientModule.java
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 @@ | ||
/* | ||
* 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(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
networking/src/main/java/ar/com/wolox/wolmo/networking/di/scopes/NetworkingScope.java
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,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 { | ||
} |
2 changes: 1 addition & 1 deletion
2
networking/src/main/java/ar/com/wolox/wolmo/networking/offline/IRepositoryCallback.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2017 Wolox S.A | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 aTODO
🤔?There was a problem hiding this comment.
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 😄