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 #23

Merged
merged 34 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7281056
Move example classes to a new package, remove old retrofit services
Jul 5, 2017
71a326a
Update code to add injections
Jul 5, 2017
c96e01e
Add new examples with dagger
Jul 5, 2017
d765e49
Add components and modules for dagger
Jul 5, 2017
a0883eb
Add Shared Preferences key to BaseConfiguration
Jul 7, 2017
0e4ac73
Update fragment examples with new examples
Jul 7, 2017
7e05cd4
Add default dimens.xml used in other projects.
Jul 7, 2017
6e38d98
Add colors.xml with placeholder colors
Jul 7, 2017
720e982
Rename example fragments and activities
Jul 17, 2017
1dc32a1
Add example tests to presenters
Jul 17, 2017
301a16e
Add UserUtils and change scoping
Jul 20, 2017
250b48f
Add model rules examples to proguard
Jul 21, 2017
e0dda24
Add powermock example to mock android's Log
Jul 21, 2017
2270e67
Optimize imports
Jul 24, 2017
d699919
Update build.gradle
juanignaciomolina Aug 25, 2017
7a731d6
Merge pull request #24 from Wolox/api-level-19
juanignaciomolina Aug 25, 2017
1114dea
Update build from changes on wolmo-networking
Aug 31, 2017
b063be9
Update wolmo dependency
Sep 1, 2017
ffcbae6
Add TODO to build.gradle
Sep 1, 2017
ffdcb8d
Update ViewPager activity and fragment to match wolmo core
Oct 18, 2017
4d8947c
Add new default module to AppComponent
Oct 18, 2017
13bb0e9
Update SDK and support version to match wolmo-core
Oct 18, 2017
1a28362
Update dagger and gradle versions
Oct 18, 2017
7da494f
Mayor changes on the README. Also, added a MIT license and a logo for…
juanignaciomolina Oct 26, 2017
44fc1dd
Update README.md
juanignaciomolina Oct 26, 2017
b124e35
Update README.md
juanignaciomolina Oct 26, 2017
e395637
Added WARP to the README
juanignaciomolina Oct 26, 2017
3b17157
Bump wolmo version to v1.3.0, upgrade to gradle plugin 3.0.0 (#25)
SpicyCactuar Oct 30, 2017
3007bf1
Bump Wolmo to v1.3.1 (#26)
SpicyCactuar Nov 24, 2017
f385145
Merge branch 'master' into dagger-android
Nov 27, 2017
a6fa981
Update wolmo dependency
Dec 26, 2017
c79b851
Update gradle and wolmo versions
Apr 3, 2018
4ce3e36
Update README.md
Apr 4, 2018
2e11772
Add jcenter repository
Apr 4, 2018
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
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Wolox S.A

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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.
66 changes: 61 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
<p align="center">
<img height="200px" width="500px" src="https://user-images.githubusercontent.com/4109119/32070030-42060272-ba8b-11e7-8609-469decac7029.png"/>
</p>

# Wolox Android Bootstrap
This is a basic template to kickoff Android projects that includes some common usage libraries and a basic build variant configuration with two flavors for stage and production.

## Usage
This is the base template project that we use at [Wolox](https://www.wolox.com.ar/) for new Android applications.

This project integrates useful libraries and [WOLMO](https://github.com/Wolox/wolmo-core-android), our framework for developing
Android apps.


## Features

These features can be found in Wolox Android Boostrap:

* Fully integrated with [WOLMO](https://github.com/Wolox/wolmo-core-android)
and [WOLMO NETWORKING](https://github.com/Wolox/wolmo-networking-android)
* Usage example of the MVP architecture.
* Usage example of Dagger 2 with WOLMO and WOLMO NETWORKING modules.
* Has [WARP](https://github.com/Wolox/warp) for quick assets creation and optimization.
* Includes [Butterknife](https://github.com/JakeWharton/butterknife) for view binding
* Includes [Chuck](https://github.com/jgilfelt/chuck) for easy HTTP requests logging.
* Includes [Leak Canary](https://github.com/square/leakcanary) for memory leak detection.
* Includes some additional dependencies for testing.
* Base build variants set up for production and development.

### Usage

1. Clone this repository
2. Change the **applicationId** in the *app/build.gradle* file
3. Change the ***WoloxApplication*** class name
4. Setup the API endpoints (if neccesary) in the *Configuration*/*BaseConfiguration* classes
3. Change the ***BootstrapApplication*** class name to the name of your application
4. Setup the API endpoints (if necessary) in the *Configuration*/*BaseConfiguration* classes
5. Change the launcher icons under *main*/*stage* directories
6. Setup the production keystore credentials: run `keystore.sh` or create *app/keystore.gradle* file manually:
6. Setup the production keystore credentials: run `scripts/keystore.sh` from the project root directory or create *app/keystore.gradle* file manually:
```gradle
ext.release_keystore=file('...')
ext.key_alias='...'
ext.key_password='...'
ext.store_password='...'
```

## <a name="topic-about"></a> About

This project is maintained by [Juan Ignacio Molina](https://github.com/juanignaciomolina)
and is developed by [Wolox](http://www.wolox.com.ar).

![Wolox](https://github.com/Wolox/press-kit/master/logos/logo_banner.png)

## <a name="topic-license"></a> License

**WOLOX ANDROID BOOSTRAP** is available under the MIT [license](https://github.com/Wolox/WoloxAndroidBootstrap/master/LICENSE.md).

Copyright (c) Wolox S.A

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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.
76 changes: 47 additions & 29 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
apply from: '../jacoco.gradle'
apply plugin: 'com.android.application'
apply plugin: 'idea'
apply plugin: 'jacoco-android'
apply plugin: 'com.github.kt3k.coveralls'
apply from: 'keystore.gradle'
apply from: '../jacoco.gradle'
apply from: '../quality.gradle'
apply from: '../scripts/warp/warp_task.gradle'
apply plugin: 'idea'

idea {
module {
Expand All @@ -13,13 +15,13 @@ idea {
}

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "ar.com.wolox.android.example"
minSdkVersion 16
targetSdkVersion 25
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0.0"

Expand Down Expand Up @@ -54,6 +56,9 @@ android {
}
}

// Change the "default" to whatever fits. At least one 'dimension' is required by gradle.
flavorDimensions "default"

productFlavors {
stage {
applicationId defaultConfig.applicationId + ".stage"
Expand All @@ -66,45 +71,58 @@ android {
}
}

testOptions {
unitTests.returnDefaultValues = true
}

lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

jacocoAndroidUnitTestReport {
excludes = defaultExcludes + ['**/*_Factory.class']
}

buildscript {
ext.support_library_version = '25.3.1'
ext.butterknife_version = '8.6.0'
ext.chuck_version = '1.0.4'
ext.support_library_version = '27.1.0'
ext.dagger_version = '2.13'
ext.wolmo_version = '2.0.1'
ext.leak_canary_version = '1.5.1'
ext.wolmo_version = 'v1.1.0'
ext.chuck_version = '1.1.0'
ext.powermock_version = '1.7.0'
}

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

// Wolmo
compile "com.github.Wolox:wolmo-core-android:$wolmo_version"
compile "com.github.Wolox:wolmo-networking-android:$wolmo_version"
implementation "com.github.wolox:wolmo-networking-android:$wolmo_version"

// Android support libraries
compile "com.android.support:support-compat:$support_library_version"
compile "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:support-compat:$support_library_version"
implementation "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:design:$support_library_version"

// Dagger
implementation "com.google.dagger:dagger:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"

// Third-party
compile "com.jakewharton:butterknife:$butterknife_version"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife_version"
debugCompile "com.readystatesoftware.chuck:library:$chuck_version"
releaseCompile "com.readystatesoftware.chuck:library-no-op:$chuck_version"
debugCompile "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"
implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT"
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
implementation "com.squareup.okhttp3:logging-interceptor:3.9.0"
debugImplementation "com.readystatesoftware.chuck:library:$chuck_version"
releaseImplementation "com.readystatesoftware.chuck:library-no-op:$chuck_version"
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"

// Testing dependencies
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"
testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-inline:2.13.0"
testImplementation "org.assertj:assertj-core:3.9.0"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"
}
10 changes: 9 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
# public *;
#}

-keepattributes EnclosingMethod
-keepattributes EnclosingMethod


###############################################################################
## Gson models
###############################################################################

# Application classes that will be serialized/deserialized over Gson
-keep class ar.com.wolox.android.example.model.** { *; }
25 changes: 15 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ar.com.wolox.android">
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="ar.com.wolox.android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:name=".example.BootstrapApplication"
android:label="@string/app_name"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name=".example.ui.ExampleActivity"
android:name=".example.ui.example.ExampleActivity"
android:screenOrientation="portrait">

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<activity
android:name=".example.ui.viewpager.ViewpagerActivity"
android:screenOrientation="portrait" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class BaseConfiguration {

public static final String EXAMPLE_CONFIGURAITON_KEY = "http://www.example.com";
public static final String EXAMPLE_CONFIGURAITON_KEY = "https://jsonplaceholder.typicode.com";
public static final String SHARED_PREFERENCES_NAME = "private-shared-prefs";

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package ar.com.wolox.android.example;

import android.support.annotation.NonNull;

import com.google.gson.FieldNamingPolicy;
import com.readystatesoftware.chuck.ChuckInterceptor;
import com.squareup.leakcanary.LeakCanary;

import ar.com.wolox.wolmo.networking.retrofit.NetworkingApplication;
import ar.com.wolox.wolmo.networking.retrofit.RetrofitServices;
import ar.com.wolox.android.BuildConfig;
import ar.com.wolox.android.example.di.DaggerAppComponent;
import ar.com.wolox.wolmo.core.WolmoApplication;
import ar.com.wolox.wolmo.networking.di.DaggerNetworkingComponent;
import ar.com.wolox.wolmo.networking.di.NetworkingComponent;

public class BootstrapApplication extends NetworkingApplication {
import dagger.android.AndroidInjector;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;

@Override
public RetrofitServices getRetrofitServices() {
return new ExampleRetrofitServices();
}
public class BootstrapApplication extends WolmoApplication {

@Override
public void onInit() {
Expand All @@ -21,4 +27,37 @@ public void onInit() {
}
LeakCanary.install(this);
}

@Override
protected AndroidInjector<BootstrapApplication> applicationInjector() {
return DaggerAppComponent.builder().networkingComponent(buildDaggerNetworkingComponent())
.sharedPreferencesName(Configuration.SHARED_PREFERENCES_NAME).application(this)
.create(this);
}

private NetworkingComponent buildDaggerNetworkingComponent() {
NetworkingComponent.Builder builder =
DaggerNetworkingComponent.builder().baseUrl(Configuration.EXAMPLE_CONFIGURAITON_KEY)
.gsonNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

if (BuildConfig.DEBUG) {
builder.okHttpInterceptors(
buildHttpLoggingInterceptor(Level.BODY), new ChuckInterceptor(this));
}

return builder.build();
}

/**
* Returns a {@link HttpLoggingInterceptor} with the level given by <b>level</b>.
*
* @param level - Logging level for the interceptor.
* @return New instance of interceptor
*/
private static HttpLoggingInterceptor buildHttpLoggingInterceptor(
@NonNull HttpLoggingInterceptor.Level level) {
HttpLoggingInterceptor loggerInterceptor = new HttpLoggingInterceptor();
loggerInterceptor.setLevel(level);
return loggerInterceptor;
}
}

This file was deleted.

Loading