-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Wolox/development
Dagger android (#5)
- Loading branch information
Showing
46 changed files
with
2,248 additions
and
333 deletions.
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
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 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,6 +1,6 @@ | ||
## Joda Time 2.3 | ||
## Joda Time 2.9 | ||
|
||
-dontwarn org.joda.convert.** | ||
-dontwarn org.joda.time.** | ||
-keep class org.joda.time.** { *; } | ||
-keep interface org.joda.time.** { *; } | ||
-keep interface org.joda.time.** { *; } |
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 |
---|---|---|
@@ -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.
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
/* | ||
* 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(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
networking/src/main/java/ar/com/wolox/wolmo/networking/di/modules/CachingModule.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,21 @@ | ||
package ar.com.wolox.wolmo.networking.di.modules; | ||
|
||
import ar.com.wolox.wolmo.networking.di.scopes.NetworkingScope; | ||
import ar.com.wolox.wolmo.networking.optimizations.BaseCallCollapser; | ||
import ar.com.wolox.wolmo.networking.optimizations.ICallCollapser; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
/** | ||
* Default module with caching dependencies | ||
*/ | ||
@Module | ||
public class CachingModule { | ||
|
||
@Provides | ||
@NetworkingScope | ||
static ICallCollapser provideBaseCallCollapser() { | ||
return new BaseCallCollapser(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
/* | ||
* 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 javax.inject.Named; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
@Module | ||
public class GsonModule { | ||
|
||
@Provides | ||
static GsonConverterFactory provideGsonConverterFactory(Gson gson) { | ||
return GsonConverterFactory.create(gson); | ||
} | ||
|
||
@Provides | ||
static Gson provideGson(GsonBuilder gsonBuilder) { | ||
return gsonBuilder.create(); | ||
} | ||
|
||
@Provides | ||
@Named("newInstance") | ||
static GsonBuilder provideNewGsonBuilder() { | ||
return new GsonBuilder(); | ||
} | ||
|
||
@Provides | ||
static GsonBuilder provideGsonBuilder(@Named("newInstance") GsonBuilder gsonBuilder, | ||
@NonNull FieldNamingPolicy namingPolicy, | ||
@Nullable GsonTypeAdapter... typeAdapters) { | ||
|
||
gsonBuilder.setFieldNamingPolicy(namingPolicy); | ||
|
||
if (typeAdapters != null && typeAdapters.length > 0) { | ||
for (GsonTypeAdapter typeAdapter : typeAdapters) { | ||
gsonBuilder | ||
.registerTypeAdapter(typeAdapter.getType(), typeAdapter.getTypeAdapter()); | ||
} | ||
} else { | ||
gsonBuilder.registerTypeAdapter(LocalDate.class, new LocalDateSerializer()); | ||
} | ||
|
||
return gsonBuilder; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/* | ||
* 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.Retrofit.Builder; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
@Module | ||
public class NetworkingModule { | ||
|
||
@Provides | ||
@NetworkingScope | ||
static Retrofit.Builder provideRetrofitBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
@Provides | ||
@NetworkingScope | ||
static Retrofit provideRetrofit(Retrofit.Builder builder, String baseUrl, | ||
GsonConverterFactory gsonConverterFactory, | ||
OkHttpClient client) { | ||
|
||
return builder.baseUrl(baseUrl).addConverterFactory(gsonConverterFactory).client(client) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.