├── .gitignore
├── README.md
├── app
├── build.gradle
├── proguard-rules.txt
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── antonioleiva
│ │ └── daggerexample
│ │ └── app
│ │ ├── ActivityScope.java
│ │ ├── App.java
│ │ ├── AppComponent.java
│ │ ├── AppModule.java
│ │ ├── domain
│ │ ├── AnalyticsManager.java
│ │ └── DomainModule.java
│ │ ├── interactors
│ │ ├── FindItemsInteractor.java
│ │ ├── FindItemsInteractorImpl.java
│ │ ├── InteractorsModule.java
│ │ ├── LoginInteractor.java
│ │ └── LoginInteractorImpl.java
│ │ └── ui
│ │ ├── common
│ │ └── BaseActivity.java
│ │ ├── login
│ │ ├── LoginActivity.java
│ │ ├── LoginComponent.java
│ │ ├── LoginModule.java
│ │ ├── LoginPresenter.java
│ │ ├── LoginPresenterImpl.java
│ │ ├── LoginView.java
│ │ └── OnLoginFinishedListener.java
│ │ └── main
│ │ ├── MainActivity.java
│ │ ├── MainComponent.java
│ │ ├── MainModule.java
│ │ ├── MainPresenter.java
│ │ ├── MainPresenterImpl.java
│ │ ├── MainView.java
│ │ └── OnFinishedListener.java
│ └── res
│ ├── drawable-hdpi
│ ├── ic_action_accept.png
│ ├── ic_action_accounts.png
│ ├── ic_action_person.png
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ ├── ic_action_accept.png
│ ├── ic_action_accounts.png
│ ├── ic_action_person.png
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ ├── ic_action_accept.png
│ ├── ic_action_accounts.png
│ ├── ic_action_person.png
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ ├── ic_action_accept.png
│ ├── ic_action_accounts.png
│ ├── ic_action_person.png
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_login.xml
│ └── activity_main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | ./gradlew.bat
18 | ./gradlew
19 | build/
20 |
21 | # Mirror files
22 | mirror/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Intellij project files
31 | *.iws
32 | .idea/workspace.xml
33 | .idea/tasks.xml
34 | .idea
35 |
36 | *.iml
37 |
38 | # OS
39 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DaggerExample
2 | =============
3 |
4 | Android project using Dagger library. This code was created to support this set of articles:
5 |
6 | [Dependency injection using Dagger (Part 1) @ antonioleiva.com](http://antonioleiva.com/dependency-injection-android-dagger-part-1/)
7 |
8 | [Dependency injection using Dagger (Part 2) @ antonioleiva.com](http://antonioleiva.com/dagger-android-part-2/)
9 |
10 | [Dependency injection using Dagger (Part 3) @ antonioleiva.com](http://antonioleiva.com/dagger-3/)
11 |
12 | ### Dagger 2
13 |
14 | [Migration process from Dagger 1 to Dagger 2 @ frogermcs.github.io](http://frogermcs.github.io/dagger-1-to-2-migration/)
15 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | apply plugin: 'com.android.application'
22 | apply plugin: 'com.neenbedankt.android-apt'
23 |
24 | android {
25 | compileSdkVersion 22
26 | buildToolsVersion "22.0.1"
27 |
28 | defaultConfig {
29 | minSdkVersion 14
30 | targetSdkVersion 22
31 | versionCode 1
32 | versionName "1.0"
33 | }
34 |
35 | compileOptions {
36 | sourceCompatibility JavaVersion.VERSION_1_7
37 | targetCompatibility JavaVersion.VERSION_1_7
38 | }
39 | buildTypes {
40 | release {
41 | minifyEnabled false
42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
43 | }
44 | }
45 | }
46 |
47 | dependencies {
48 | compile fileTree(dir: 'libs', include: ['*.jar'])
49 | compile 'com.google.dagger:dagger:2.0'
50 | apt 'com.google.dagger:dagger-compiler:2.0'
51 | provided 'org.glassfish:javax.annotation:10.0-b28'
52 | }
--------------------------------------------------------------------------------
/app/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Desarrollo/Entorno Android/01 Entorno de Desarrollo/adt-bundle-windows/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
24 |
25 |
31 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.daggerexample.app;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | import javax.inject.Scope;
7 |
8 | @Scope
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface ActivityScope {
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/App.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | *
4 | * *
5 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
6 | * * *
7 | * * * Licensed under the Apache License, Version 2.0 (the "License");
8 | * * * you may not use this file except in compliance with the License.
9 | * * * You may obtain a copy of the License at
10 | * * *
11 | * * * http://www.apache.org/licenses/LICENSE-2.0
12 | * * *
13 | * * * Unless required by applicable law or agreed to in writing, software
14 | * * * distributed under the License is distributed on an "AS IS" BASIS,
15 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * * * See the License for the specific language governing permissions and
17 | * * * limitations under the License.
18 | * *
19 | *
20 | */
21 |
22 | package com.antonioleiva.daggerexample.app;
23 |
24 | import android.app.Application;
25 | import android.content.Context;
26 |
27 | import com.antonioleiva.daggerexample.app.domain.AnalyticsManager;
28 |
29 | import javax.inject.Inject;
30 |
31 |
32 | public class App extends Application {
33 |
34 | private AppComponent component;
35 |
36 | @Inject
37 | AnalyticsManager analyticsManager;
38 |
39 | @Override
40 | public void onCreate() {
41 | super.onCreate();
42 | setupGraph();
43 | analyticsManager.registerAppEnter();
44 | }
45 |
46 | private void setupGraph() {
47 | component = DaggerAppComponent.builder()
48 | .appModule(new AppModule(this))
49 | .build();
50 | component.inject(this);
51 | }
52 |
53 | public AppComponent component() {
54 | return component;
55 | }
56 |
57 | public static App get(Context context) {
58 | return (App) context.getApplicationContext();
59 | }
60 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/AppComponent.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.daggerexample.app;
2 |
3 | import com.antonioleiva.daggerexample.app.domain.AnalyticsManager;
4 | import com.antonioleiva.daggerexample.app.domain.DomainModule;
5 | import com.antonioleiva.daggerexample.app.interactors.FindItemsInteractor;
6 | import com.antonioleiva.daggerexample.app.interactors.InteractorsModule;
7 | import com.antonioleiva.daggerexample.app.interactors.LoginInteractor;
8 |
9 | import javax.inject.Singleton;
10 |
11 | import dagger.Component;
12 |
13 | /**
14 | * Created by Miroslaw Stanek on 17.03.15.
15 | */
16 | @Singleton
17 | @Component(
18 | modules = {
19 | AppModule.class,
20 | DomainModule.class,
21 | InteractorsModule.class
22 | }
23 | )
24 | public interface AppComponent {
25 | void inject(App app);
26 |
27 | AnalyticsManager getAnalyticsManager();
28 | LoginInteractor getLoginInteractor();
29 | FindItemsInteractor getFindItemsInteractor();
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/AppModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app;
22 |
23 | import android.app.Application;
24 |
25 | import javax.inject.Singleton;
26 |
27 | import dagger.Module;
28 | import dagger.Provides;
29 |
30 | @Module
31 | public class AppModule {
32 |
33 | private App app;
34 |
35 | public AppModule(App app) {
36 | this.app = app;
37 | }
38 |
39 | @Provides
40 | @Singleton
41 | public Application provideApplication() {
42 | return app;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/domain/AnalyticsManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.domain;
22 |
23 | import android.app.Application;
24 | import android.widget.Toast;
25 |
26 | public class AnalyticsManager {
27 |
28 | private Application app;
29 |
30 | public AnalyticsManager(Application app) {
31 | this.app = app;
32 | }
33 |
34 | public void registerAppEnter() {
35 | Toast.makeText(app, "App enter", Toast.LENGTH_LONG).show();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/domain/DomainModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.domain;
22 |
23 | import android.app.Application;
24 |
25 | import javax.inject.Singleton;
26 |
27 | import dagger.Module;
28 | import dagger.Provides;
29 |
30 | @Module
31 | public class DomainModule {
32 |
33 | @Provides @Singleton public AnalyticsManager provideAnalyticsManager(Application app){
34 | return new AnalyticsManager(app);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/interactors/FindItemsInteractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.interactors;
22 |
23 | import com.antonioleiva.daggerexample.app.ui.main.OnFinishedListener;
24 |
25 | public interface FindItemsInteractor {
26 |
27 | public void findItems(OnFinishedListener listener);
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/interactors/FindItemsInteractorImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.interactors;
22 |
23 | import android.os.Handler;
24 |
25 | import com.antonioleiva.daggerexample.app.ui.main.OnFinishedListener;
26 |
27 | import java.util.Arrays;
28 | import java.util.List;
29 |
30 | public class FindItemsInteractorImpl implements FindItemsInteractor {
31 | @Override public void findItems(final OnFinishedListener listener) {
32 | new Handler().postDelayed(new Runnable() {
33 | @Override public void run() {
34 | listener.onFinished(createArrayList());
35 | }
36 | }, 2000);
37 | }
38 |
39 | private List createArrayList() {
40 | return Arrays.asList(
41 | "Item 1",
42 | "Item 2",
43 | "Item 3",
44 | "Item 4",
45 | "Item 5",
46 | "Item 6",
47 | "Item 7",
48 | "Item 8",
49 | "Item 9",
50 | "Item 10"
51 | );
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/interactors/InteractorsModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.interactors;
22 |
23 | import dagger.Module;
24 | import dagger.Provides;
25 |
26 | @Module
27 | public class InteractorsModule {
28 |
29 | @Provides public FindItemsInteractor provideFindItemsInteractor() {
30 | return new FindItemsInteractorImpl();
31 | }
32 |
33 | @Provides public LoginInteractor provideLoginInteractor() {
34 | return new LoginInteractorImpl();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/interactors/LoginInteractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.interactors;
22 |
23 | import com.antonioleiva.daggerexample.app.ui.login.OnLoginFinishedListener;
24 |
25 | public interface LoginInteractor {
26 | public void login(String username, String password, OnLoginFinishedListener listener);
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/interactors/LoginInteractorImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.interactors;
22 |
23 | import android.os.Handler;
24 | import android.text.TextUtils;
25 |
26 | import com.antonioleiva.daggerexample.app.ui.login.OnLoginFinishedListener;
27 |
28 | public class LoginInteractorImpl implements LoginInteractor {
29 |
30 | @Override
31 | public void login(final String username, final String password, final OnLoginFinishedListener listener) {
32 | // Mock login. I'm creating a handler to delay the answer a couple of seconds
33 | new Handler().postDelayed(new Runnable() {
34 | @Override public void run() {
35 | boolean error = false;
36 | if (TextUtils.isEmpty(username)){
37 | listener.onUsernameError();
38 | error = true;
39 | }
40 | if (TextUtils.isEmpty(password)){
41 | listener.onPasswordError();
42 | error = true;
43 | }
44 | if (!error){
45 | listener.onSuccess();
46 | }
47 | }
48 | }, 2000);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/common/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.common;
22 |
23 | import android.app.Activity;
24 | import android.os.Bundle;
25 |
26 | import com.antonioleiva.daggerexample.app.App;
27 | import com.antonioleiva.daggerexample.app.AppComponent;
28 |
29 | public abstract class BaseActivity extends Activity {
30 |
31 |
32 | @Override protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setupComponent((AppComponent) App.get(this).component());
35 | }
36 |
37 | protected abstract void setupComponent(AppComponent appComponent);
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | import android.content.Intent;
24 | import android.os.Bundle;
25 | import android.view.View;
26 | import android.widget.EditText;
27 | import android.widget.ProgressBar;
28 |
29 | import com.antonioleiva.daggerexample.app.AppComponent;
30 | import com.antonioleiva.daggerexample.app.R;
31 | import com.antonioleiva.daggerexample.app.ui.common.BaseActivity;
32 | import com.antonioleiva.daggerexample.app.ui.main.MainActivity;
33 |
34 | import javax.inject.Inject;
35 |
36 | public class LoginActivity extends BaseActivity implements LoginView, View.OnClickListener {
37 |
38 | @Inject LoginPresenter presenter;
39 |
40 | private ProgressBar progressBar;
41 | private EditText username;
42 | private EditText password;
43 |
44 | @Override
45 | protected void setupComponent(AppComponent appComponent) {
46 | DaggerLoginComponent.builder()
47 | .appComponent(appComponent)
48 | .loginModule(new LoginModule(this))
49 | .build()
50 | .inject(this);
51 | }
52 |
53 | @Override
54 | protected void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(R.layout.activity_login);
57 | progressBar = (ProgressBar) findViewById(R.id.progress);
58 | username = (EditText) findViewById(R.id.username);
59 | password = (EditText) findViewById(R.id.password);
60 | findViewById(R.id.button).setOnClickListener(this);
61 | }
62 |
63 | @Override public void showProgress() {
64 | progressBar.setVisibility(View.VISIBLE);
65 | }
66 |
67 | @Override public void hideProgress() {
68 | progressBar.setVisibility(View.GONE);
69 | }
70 |
71 | @Override public void setUsernameError() {
72 | username.setError(getString(R.string.username_error));
73 | }
74 |
75 | @Override public void setPasswordError() {
76 | password.setError(getString(R.string.password_error));
77 | }
78 |
79 | @Override public void navigateToHome() {
80 | startActivity(new Intent(this, MainActivity.class));
81 | finish();
82 | }
83 |
84 | @Override public void onClick(View v) {
85 | presenter.validateCredentials(username.getText().toString(), password.getText().toString());
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginComponent.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.daggerexample.app.ui.login;
2 |
3 | import com.antonioleiva.daggerexample.app.ActivityScope;
4 | import com.antonioleiva.daggerexample.app.AppComponent;
5 | import com.antonioleiva.daggerexample.app.ui.main.MainActivity;
6 |
7 | import dagger.Component;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 17.03.15.
11 | */
12 | @ActivityScope
13 | @Component(
14 | dependencies = AppComponent.class,
15 | modules = LoginModule.class
16 | )
17 | public interface LoginComponent {
18 | void inject(LoginActivity activity);
19 |
20 | LoginPresenter getLoginPresenter();
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | import com.antonioleiva.daggerexample.app.interactors.LoginInteractor;
24 |
25 | import dagger.Module;
26 | import dagger.Provides;
27 |
28 | @Module
29 | public class LoginModule {
30 |
31 | private LoginView view;
32 |
33 | public LoginModule(LoginView view) {
34 | this.view = view;
35 | }
36 |
37 | @Provides
38 | public LoginView provideView() {
39 | return view;
40 | }
41 |
42 | @Provides
43 | public LoginPresenter providePresenter(LoginView loginView, LoginInteractor loginInteractor) {
44 | return new LoginPresenterImpl(loginView, loginInteractor);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | public interface LoginPresenter {
24 | public void validateCredentials(String username, String password);
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginPresenterImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | import com.antonioleiva.daggerexample.app.interactors.LoginInteractor;
24 |
25 | public class LoginPresenterImpl implements LoginPresenter, OnLoginFinishedListener {
26 |
27 | private LoginView loginView;
28 | private LoginInteractor loginInteractor;
29 |
30 | public LoginPresenterImpl(LoginView loginView, LoginInteractor loginInteractor) {
31 | this.loginView = loginView;
32 | this.loginInteractor = loginInteractor;
33 | }
34 |
35 | @Override public void validateCredentials(String username, String password) {
36 | loginView.showProgress();
37 | loginInteractor.login(username, password, this);
38 | }
39 |
40 | @Override public void onUsernameError() {
41 | loginView.setUsernameError();
42 | loginView.hideProgress();
43 | }
44 |
45 | @Override public void onPasswordError() {
46 | loginView.setPasswordError();
47 | loginView.hideProgress();
48 | }
49 |
50 | @Override public void onSuccess() {
51 | loginView.navigateToHome();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/LoginView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | public interface LoginView {
24 | public void showProgress();
25 |
26 | public void hideProgress();
27 |
28 | public void setUsernameError();
29 |
30 | public void setPasswordError();
31 |
32 | public void navigateToHome();
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/login/OnLoginFinishedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.login;
22 |
23 | public interface OnLoginFinishedListener {
24 |
25 | public void onUsernameError();
26 |
27 | public void onPasswordError();
28 |
29 | public void onSuccess();
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | import android.os.Bundle;
24 | import android.view.View;
25 | import android.widget.AdapterView;
26 | import android.widget.ArrayAdapter;
27 | import android.widget.ListView;
28 | import android.widget.ProgressBar;
29 | import android.widget.Toast;
30 |
31 | import com.antonioleiva.daggerexample.app.AppComponent;
32 | import com.antonioleiva.daggerexample.app.R;
33 | import com.antonioleiva.daggerexample.app.ui.common.BaseActivity;
34 |
35 | import java.util.List;
36 |
37 | import javax.inject.Inject;
38 |
39 | public class MainActivity extends BaseActivity implements MainView, AdapterView.OnItemClickListener {
40 |
41 | @Inject MainPresenter presenter;
42 | private ListView listView;
43 | private ProgressBar progressBar;
44 |
45 | @Override
46 | protected void setupComponent(AppComponent appComponent) {
47 | DaggerMainComponent.builder()
48 | .appComponent(appComponent)
49 | .mainModule(new MainModule(this))
50 | .build()
51 | .inject(this);
52 | }
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_main);
58 | listView = (ListView) findViewById(R.id.list);
59 | listView.setOnItemClickListener(this);
60 | progressBar = (ProgressBar) findViewById(R.id.progress);
61 | }
62 |
63 | @Override protected void onResume() {
64 | super.onResume();
65 | presenter.onResume();
66 | }
67 |
68 | @Override public void showProgress() {
69 | progressBar.setVisibility(View.VISIBLE);
70 | listView.setVisibility(View.INVISIBLE);
71 | }
72 |
73 | @Override public void hideProgress() {
74 | progressBar.setVisibility(View.INVISIBLE);
75 | listView.setVisibility(View.VISIBLE);
76 | }
77 |
78 | @Override public void setItems(List items) {
79 | listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, items));
80 | }
81 |
82 | @Override public void showMessage(String message) {
83 | Toast.makeText(this, message, Toast.LENGTH_LONG).show();
84 | }
85 |
86 | @Override public void onItemClick(AdapterView> parent, View view, int position, long id) {
87 | presenter.onItemClicked(position);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainComponent.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.daggerexample.app.ui.main;
2 |
3 | import com.antonioleiva.daggerexample.app.ActivityScope;
4 | import com.antonioleiva.daggerexample.app.AppComponent;
5 |
6 | import dagger.Component;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 17.03.15.
10 | */
11 | @ActivityScope
12 | @Component(
13 | dependencies = AppComponent.class,
14 | modules = MainModule.class
15 | )
16 | public interface MainComponent {
17 | void inject(MainActivity activity);
18 |
19 | MainPresenter getLoginPresenter();
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | import com.antonioleiva.daggerexample.app.interactors.FindItemsInteractor;
24 |
25 | import dagger.Module;
26 | import dagger.Provides;
27 |
28 | @Module
29 | public class MainModule {
30 |
31 | private MainView view;
32 |
33 | public MainModule(MainView view) {
34 | this.view = view;
35 | }
36 |
37 | @Provides
38 | public MainView provideView() {
39 | return view;
40 | }
41 |
42 | @Provides
43 | public MainPresenter providePresenter(MainView mainView, FindItemsInteractor findItemsInteractor) {
44 | return new MainPresenterImpl(mainView, findItemsInteractor);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | public interface MainPresenter {
24 |
25 | public void onResume();
26 |
27 | public void onItemClicked(int position);
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainPresenterImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | import com.antonioleiva.daggerexample.app.interactors.FindItemsInteractor;
24 |
25 | import java.util.List;
26 |
27 | public class MainPresenterImpl implements MainPresenter, OnFinishedListener {
28 |
29 | private MainView mainView;
30 | private FindItemsInteractor findItemsInteractor;
31 |
32 | public MainPresenterImpl(MainView mainView, FindItemsInteractor findItemsInteractor) {
33 | this.mainView = mainView;
34 | this.findItemsInteractor = findItemsInteractor;
35 | }
36 |
37 | @Override public void onResume() {
38 | mainView.showProgress();
39 | findItemsInteractor.findItems(this);
40 | }
41 |
42 | @Override public void onItemClicked(int position) {
43 | mainView.showMessage(String.format("Position %d clicked", position + 1));
44 | }
45 |
46 | @Override public void onFinished(List items) {
47 | mainView.setItems(items);
48 | mainView.hideProgress();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/MainView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | import java.util.List;
24 |
25 | public interface MainView {
26 |
27 | public void showProgress();
28 |
29 | public void hideProgress();
30 |
31 | public void setItems(List items);
32 |
33 | public void showMessage(String message);
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/daggerexample/app/ui/main/OnFinishedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.antonioleiva.daggerexample.app.ui.main;
22 |
23 | import java.util.List;
24 |
25 | public interface OnFinishedListener {
26 |
27 | void onFinished(List items);
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-hdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_accounts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-hdpi/ic_action_accounts.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-hdpi/ic_action_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-mdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_accounts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-mdpi/ic_action_accounts.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-mdpi/ic_action_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_accounts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xhdpi/ic_action_accounts.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xhdpi/ic_action_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xxhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_accounts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xxhdpi/ic_action_accounts.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xxhdpi/ic_action_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
29 |
30 |
39 |
49 |
56 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
26 |
27 |
38 |
39 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
25 | 64dp
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 | 16dp
24 | 16dp
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 |
24 | Dagger Example
25 | Hello world!
26 | Settings
27 | username
28 | password
29 | Log in
30 | Dagger Example
31 | Username cannot be empty
32 | Password cannot be empty
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
22 |
23 | buildscript {
24 | repositories {
25 | mavenCentral()
26 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
27 | }
28 | dependencies {
29 | classpath 'com.android.tools.build:gradle:1.1.3'
30 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
31 | }
32 | }
33 |
34 | allprojects {
35 | repositories {
36 | mavenCentral()
37 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
38 | }
39 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # /*
3 | # *
4 | # * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | # * *
6 | # * * Licensed under the Apache License, Version 2.0 (the "License");
7 | # * * you may not use this file except in compliance with the License.
8 | # * * You may obtain a copy of the License at
9 | # * *
10 | # * * http://www.apache.org/licenses/LICENSE-2.0
11 | # * *
12 | # * * Unless required by applicable law or agreed to in writing, software
13 | # * * distributed under the License is distributed on an "AS IS" BASIS,
14 | # * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # * * See the License for the specific language governing permissions and
16 | # * * limitations under the License.
17 | # *
18 | # */
19 | #
20 |
21 | # Project-wide Gradle settings.
22 |
23 | # IDE (e.g. Android Studio) users:
24 | # Settings specified in this file will override any Gradle settings
25 | # configured through the IDE.
26 |
27 | # For more details on how to configure your build environment visit
28 | # http://www.gradle.org/docs/current/userguide/build_environment.html
29 |
30 | # Specifies the JVM arguments used for the daemon process.
31 | # The setting is particularly useful for tweaking memory settings.
32 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
33 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
34 |
35 | # When configured, Gradle will run in incubating parallel mode.
36 | # This option should only be used with decoupled projects. More details, visit
37 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
38 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/DaggerExample/acacf91daf1ef61fa13767f934abfb634cae3179/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 18 14:31:43 GMT 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2014 Antonio Leiva Gordillo.
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | include ':app'
22 |
--------------------------------------------------------------------------------