├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── dalol
│ │ └── dagger_rx_database_mvp
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── org
│ │ │ └── dalol
│ │ │ └── dagger_rx_database_mvp
│ │ │ ├── api
│ │ │ └── CakeApiService.java
│ │ │ ├── application
│ │ │ └── CakeApplication.java
│ │ │ ├── base
│ │ │ ├── BaseActivity.java
│ │ │ └── BasePresenter.java
│ │ │ ├── di
│ │ │ ├── components
│ │ │ │ ├── ApplicationComponent.java
│ │ │ │ └── CakeComponent.java
│ │ │ ├── module
│ │ │ │ ├── ApplicationModule.java
│ │ │ │ └── CakeModule.java
│ │ │ └── scope
│ │ │ │ └── PerActivity.java
│ │ │ ├── helper
│ │ │ └── ImageHandler.java
│ │ │ ├── mapper
│ │ │ └── CakeMapper.java
│ │ │ ├── modules
│ │ │ ├── details
│ │ │ │ └── DetailActivity.java
│ │ │ └── home
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── adapter
│ │ │ │ └── CakeAdapter.java
│ │ │ ├── mvp
│ │ │ ├── model
│ │ │ │ ├── Cake.java
│ │ │ │ ├── CakesResponse.java
│ │ │ │ ├── CakesResponseCakes.java
│ │ │ │ ├── CakesResponseStaffContacts.java
│ │ │ │ ├── CakesResponseStaffContactsPhones.java
│ │ │ │ └── Storage.java
│ │ │ ├── presenter
│ │ │ │ └── CakePresenter.java
│ │ │ └── view
│ │ │ │ ├── BaseView.java
│ │ │ │ └── MainView.java
│ │ │ └── utilities
│ │ │ ├── ImageUtils.java
│ │ │ └── NetworkUtils.java
│ └── res
│ │ ├── layout
│ │ ├── activity_detail.xml
│ │ ├── activity_main.xml
│ │ └── list_item_layout.xml
│ │ ├── menu
│ │ └── main_menu.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_info_white_24dp.png
│ │ ├── ic_launcher.png
│ │ ├── ic_play_arrow_white_24dp.png
│ │ └── ic_refresh_white_24dp.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_info_white_24dp.png
│ │ ├── ic_launcher.png
│ │ ├── ic_play_arrow_white_24dp.png
│ │ └── ic_refresh_white_24dp.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_info_white_24dp.png
│ │ ├── ic_launcher.png
│ │ ├── ic_play_arrow_white_24dp.png
│ │ └── ic_refresh_white_24dp.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_info_white_24dp.png
│ │ ├── ic_launcher.png
│ │ ├── ic_play_arrow_white_24dp.png
│ │ └── ic_refresh_white_24dp.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_info_white_24dp.png
│ │ ├── ic_launcher.png
│ │ ├── ic_play_arrow_white_24dp.png
│ │ └── ic_refresh_white_24dp.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── org
│ └── dalol
│ └── dagger_rx_database_mvp
│ ├── ExampleUnitTest.java
│ └── mvp
│ └── presenter
│ └── CakePresenterTest.java
├── build.gradle
├── cakes
├── apple_cake.JPG
├── avocado_cake.jpg
├── banana_cake.jpg
├── birthday_cake.JPG
├── bulla_cake.jpg
├── carrot_cake.jpg
├── chocolate_cake.jpg
├── clementine_cake.png
├── fudge_cake.jpg
├── jaffa_cake.png
├── jewish_apple_cake.jpg
├── lemoncheese_cake.jpg
├── plum_cake.jpg
├── spice_cake.jpg
├── strawberry_cake.jpg
└── victoria_sponge.jpg
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dagger-Rx-Database-MVP
2 |
3 | Like/Star the project if you liked and used the code, make sure to follow me on git and subscribe on my youtube channel.
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 24
6 | buildToolsVersion '25.0.0'
7 |
8 | defaultConfig {
9 | applicationId "org.dalol.dagger_rx_database_mvp"
10 | minSdkVersion 15
11 | targetSdkVersion 24
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(include: ['*.jar'], dir: 'libs')
26 | //Unit Testing
27 | testCompile 'junit:junit:4.12'
28 | testCompile 'org.mockito:mockito-core:1.10.19'
29 | testCompile 'org.powermock:powermock-module-junit4:1.6.2'
30 | testCompile 'org.powermock:powermock-api-mockito:1.6.2'
31 |
32 | compile 'com.android.support:appcompat-v7:24.2.0'
33 | compile 'com.android.support:recyclerview-v7:24.2.0'
34 | compile 'com.android.support:cardview-v7:24.2.0'
35 | compile 'com.squareup.retrofit2:retrofit:2.+'
36 | compile 'com.squareup.retrofit2:converter-gson:2.+'
37 | compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
38 | compile 'io.reactivex:rxjava:1.0.4'
39 | compile 'io.reactivex:rxandroid:0.24.0'
40 | compile 'com.github.bumptech.glide:glide:3.7.0'
41 | provided 'com.google.dagger:dagger-compiler:2.1'
42 | compile 'com.google.dagger:dagger:2.1'
43 | provided 'org.glassfish:javax.annotation:10.0-b28'
44 | compile 'com.jakewharton:butterknife:7.0.1'
45 | compile 'com.google.code.gson:gson:2.6.2'
46 | // compile 'org.powermock:powermock-api-mockito:1.6.2'
47 |
48 | //UI Testing
49 | // androidTestCompile 'com.android.support:support-annotations:24.2.0'
50 | // androidTestCompile 'junit:junit:4.12'
51 | //
52 | // testCompile 'com.google.dexmaker:dexmaker:1.2'
53 | // testCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
54 | // androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
55 | // exclude module: 'support-annotations'
56 | // }
57 | // androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
58 | // exclude module: 'support-annotations'
59 | // exclude module: 'appcompat-v7'
60 | // exclude module: 'support-v4'
61 | // exclude module: 'support-v13'
62 | // exclude module: 'recyclerview-v7'
63 | // exclude module: 'design'
64 | // }
65 | // androidTestCompile('com.android.support.test:runner:0.3') {
66 | // exclude module: 'support-annotations'
67 | // }
68 | // androidTestCompile('com.android.support.test:rules:0.3') {
69 | // exclude module: 'support-annotations'
70 | // }
71 | }
72 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Filippo\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
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 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/dalol/dagger_rx_database_mvp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.dalol.dagger_rx_database_mvp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/api/CakeApiService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.api;
18 |
19 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponse;
20 |
21 | import retrofit2.Call;
22 | import retrofit2.http.GET;
23 | import rx.Observable;
24 |
25 | /**
26 | * @author Filippo Engidashet
27 | * @version 1.0.0
28 | * @since 9/24/2016
29 | */
30 | public interface CakeApiService {
31 |
32 | @GET("/filippella/a728a34822a3bc7add98e477a4057b69/raw/310d712e87941f569074a63fedb675d2b611342a/cakes")
33 | Observable getCakes();
34 |
35 | @GET("/filippella/a728a34822a3bc7add98e477a4057b69/raw/310d712e87941f569074a63fedb675d2b611342a/cakes")
36 | Call getTheCakes();
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/application/CakeApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.application;
18 |
19 | import android.app.Application;
20 |
21 | import org.dalol.dagger_rx_database_mvp.di.components.ApplicationComponent;
22 | import org.dalol.dagger_rx_database_mvp.di.components.DaggerApplicationComponent;
23 | import org.dalol.dagger_rx_database_mvp.di.module.ApplicationModule;
24 |
25 | /**
26 | * @author Filippo Engidashet
27 | * @version 1.0.0
28 | * @since 9/24/2016
29 | */
30 | public class CakeApplication extends Application {
31 |
32 | private ApplicationComponent mApplicationComponent;
33 |
34 | @Override
35 | public void onCreate() {
36 | super.onCreate();
37 | initializeApplicationComponent();
38 | }
39 |
40 | private void initializeApplicationComponent() {
41 | mApplicationComponent = DaggerApplicationComponent
42 | .builder()
43 | .applicationModule(new ApplicationModule(this, "https://gist.githubusercontent.com"))
44 | .build();
45 | }
46 |
47 | public ApplicationComponent getApplicationComponent() {
48 | return mApplicationComponent;
49 | }
50 |
51 | @Override
52 | public void onTerminate() {
53 | super.onTerminate();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.base;
18 |
19 | import android.app.Application;
20 | import android.app.ProgressDialog;
21 | import android.content.Intent;
22 | import android.os.Bundle;
23 | import android.support.annotation.CallSuper;
24 | import android.support.annotation.Nullable;
25 | import android.support.v7.app.ActionBar;
26 | import android.support.v7.app.AppCompatActivity;
27 |
28 | import org.dalol.dagger_rx_database_mvp.application.CakeApplication;
29 | import org.dalol.dagger_rx_database_mvp.di.components.ApplicationComponent;
30 |
31 | import butterknife.ButterKnife;
32 |
33 | /**
34 | * @author Filippo Engidashet
35 | * @version 1.0.0
36 | * @since 9/24/2016
37 | */
38 | public abstract class BaseActivity extends AppCompatActivity {
39 |
40 | private ProgressDialog mProgressDialog;
41 |
42 | @Override
43 | protected void onCreate(@Nullable Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(getContentView());
46 | ButterKnife.bind(this);
47 | onViewReady(savedInstanceState, getIntent());
48 | }
49 |
50 | @CallSuper
51 | protected void onViewReady(Bundle savedInstanceState, Intent intent) {
52 | resolveDaggerDependency();
53 | //To be used by child activities
54 | }
55 |
56 | @Override
57 | protected void onDestroy() {
58 | ButterKnife.unbind(this);
59 | super.onDestroy();
60 | }
61 |
62 | protected void resolveDaggerDependency() {}
63 |
64 | protected void showBackArrow() {
65 | ActionBar supportActionBar = getSupportActionBar();
66 | if (supportActionBar != null) {
67 | supportActionBar.setDisplayHomeAsUpEnabled(true);
68 | supportActionBar.setDisplayShowHomeEnabled(true);
69 | }
70 | }
71 |
72 | protected void showDialog(String message) {
73 | if (mProgressDialog == null) {
74 | mProgressDialog = new ProgressDialog(this);
75 | mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
76 | mProgressDialog.setCancelable(true);
77 | }
78 | mProgressDialog.setMessage(message);
79 | mProgressDialog.show();
80 | }
81 |
82 | protected void hideDialog() {
83 | if (mProgressDialog != null && mProgressDialog.isShowing()) {
84 | mProgressDialog.dismiss();
85 | }
86 | }
87 |
88 | protected ApplicationComponent getApplicationComponent() {
89 | return ((CakeApplication) getApplication()).getApplicationComponent();
90 | }
91 |
92 | protected abstract int getContentView();
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/base/BasePresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.base;
18 |
19 | import org.dalol.dagger_rx_database_mvp.mvp.view.BaseView;
20 |
21 | import javax.inject.Inject;
22 |
23 | import rx.Observable;
24 | import rx.Observer;
25 | import rx.android.schedulers.AndroidSchedulers;
26 | import rx.schedulers.Schedulers;
27 |
28 | /**
29 | * @author Filippo Engidashet
30 | * @version 1.0.0
31 | * @since 9/24/2016
32 | */
33 | public class BasePresenter {
34 |
35 | @Inject protected V mView;
36 |
37 | protected V getView() {
38 | return mView;
39 | }
40 |
41 | protected void subscribe(Observable observable, Observer observer) {
42 | observable.subscribeOn(Schedulers.newThread())
43 | .toSingle()
44 | .observeOn(AndroidSchedulers.mainThread())
45 | .subscribe(observer);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/di/components/ApplicationComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.di.components;
18 |
19 | import android.content.Context;
20 |
21 | import org.dalol.dagger_rx_database_mvp.di.module.ApplicationModule;
22 |
23 | import javax.inject.Singleton;
24 |
25 | import dagger.Component;
26 | import retrofit2.Retrofit;
27 |
28 | /**
29 | * @author Filippo Engidashet
30 | * @version 1.0.0
31 | * @since 9/24/2016
32 | */
33 | @Singleton
34 | @Component(modules = ApplicationModule.class)
35 | public interface ApplicationComponent {
36 |
37 | Retrofit exposeRetrofit();
38 |
39 | Context exposeContext();
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/di/components/CakeComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.di.components;
18 |
19 | import org.dalol.dagger_rx_database_mvp.di.module.CakeModule;
20 | import org.dalol.dagger_rx_database_mvp.di.scope.PerActivity;
21 | import org.dalol.dagger_rx_database_mvp.modules.home.MainActivity;
22 |
23 | import dagger.Component;
24 |
25 | /**
26 | * @author Filippo Engidashet
27 | * @version 1.0.0
28 | * @since 9/24/2016
29 | */
30 | @PerActivity
31 | @Component(modules = CakeModule.class, dependencies = ApplicationComponent.class)
32 | public interface CakeComponent {
33 |
34 | void inject(MainActivity activity);
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/di/module/ApplicationModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.di.module;
18 |
19 | import android.content.Context;
20 |
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import javax.inject.Named;
24 | import javax.inject.Singleton;
25 |
26 | import dagger.Module;
27 | import dagger.Provides;
28 | import okhttp3.OkHttpClient;
29 | import retrofit2.Retrofit;
30 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
31 | import retrofit2.converter.gson.GsonConverterFactory;
32 |
33 | /**
34 | * @author Filippo Engidashet
35 | * @version 1.0.0
36 | * @since 9/24/2016
37 | */
38 | @Module
39 | public class ApplicationModule {
40 |
41 | private String mBaseUrl;
42 | private Context mContext;
43 |
44 | public ApplicationModule(Context context, String baseUrl) {
45 | mContext = context;
46 | mBaseUrl = baseUrl;
47 | }
48 |
49 | @Singleton
50 | @Provides
51 | GsonConverterFactory provideGsonConverterFactory() {
52 | return GsonConverterFactory.create();
53 | }
54 |
55 | @Singleton
56 | @Provides
57 | @Named("ok-1")
58 | OkHttpClient provideOkHttpClient1() {
59 | return new OkHttpClient.Builder()
60 | .connectTimeout(20, TimeUnit.SECONDS)
61 | .readTimeout(20, TimeUnit.SECONDS)
62 | .build();
63 | }
64 |
65 | @Singleton
66 | @Provides
67 | @Named("ok-2")
68 | OkHttpClient provideOkHttpClient2() {
69 | return new OkHttpClient.Builder()
70 | .connectTimeout(60, TimeUnit.SECONDS)
71 | .readTimeout(60, TimeUnit.SECONDS)
72 | .build();
73 | }
74 |
75 | @Singleton
76 | @Provides
77 | RxJavaCallAdapterFactory provideRxJavaCallAdapterFactory() {
78 | return RxJavaCallAdapterFactory.create();
79 | }
80 |
81 | @Singleton
82 | @Provides
83 | Retrofit provideRetrofit(@Named("ok-1") OkHttpClient client, GsonConverterFactory converterFactory, RxJavaCallAdapterFactory adapterFactory) {
84 | return new Retrofit.Builder()
85 | .baseUrl(mBaseUrl)
86 | .addConverterFactory(converterFactory)
87 | .addCallAdapterFactory(adapterFactory)
88 | .client(client)
89 | .build();
90 | }
91 |
92 | @Provides
93 | @Singleton
94 | Context provideContext() {
95 | return mContext;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/di/module/CakeModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.di.module;
18 |
19 | import org.dalol.dagger_rx_database_mvp.api.CakeApiService;
20 | import org.dalol.dagger_rx_database_mvp.di.scope.PerActivity;
21 | import org.dalol.dagger_rx_database_mvp.mvp.view.MainView;
22 |
23 | import dagger.Module;
24 | import dagger.Provides;
25 | import retrofit2.Retrofit;
26 |
27 | /**
28 | * @author Filippo Engidashet
29 | * @version 1.0.0
30 | * @since 9/24/2016
31 | */
32 | @Module
33 | public class CakeModule {
34 |
35 | private MainView mView;
36 |
37 | public CakeModule(MainView view) {
38 | mView = view;
39 | }
40 |
41 | @PerActivity
42 | @Provides
43 | CakeApiService provideApiService(Retrofit retrofit) {
44 | return retrofit.create(CakeApiService.class);
45 | }
46 |
47 | @PerActivity
48 | @Provides
49 | MainView provideView() {
50 | return mView;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/di/scope/PerActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.di.scope;
18 |
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 |
22 | import javax.inject.Scope;
23 |
24 | /**
25 | * @author Filippo Engidashet
26 | * @version 1.0.0
27 | * @since 9/24/2016
28 | */
29 | @Scope
30 | @Retention(RetentionPolicy.RUNTIME)
31 | public @interface PerActivity {
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/helper/ImageHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.helper;
18 |
19 | import android.graphics.Bitmap;
20 | import android.widget.ImageView;
21 |
22 | import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
23 | import com.bumptech.glide.load.resource.drawable.GlideDrawable;
24 | import com.bumptech.glide.request.animation.GlideAnimation;
25 | import com.bumptech.glide.request.target.SimpleTarget;
26 |
27 | /**
28 | * @author Filippo Engidashet
29 | * @version 1.0.0
30 | * @since 9/24/2016
31 | */
32 | public class ImageHandler extends SimpleTarget {
33 |
34 | private ImageView mImageIcon;
35 |
36 | public ImageHandler(ImageView imageIcon) {
37 | mImageIcon = imageIcon;
38 | }
39 |
40 | @Override
41 | public void onResourceReady(GlideDrawable resource, GlideAnimation super GlideDrawable> glideAnimation) {
42 | mImageIcon.setImageDrawable(resource);
43 | GlideBitmapDrawable drawable = (GlideBitmapDrawable) mImageIcon.getDrawable().getCurrent();
44 | Bitmap bitmap = drawable.getBitmap();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mapper/CakeMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mapper;
18 |
19 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
20 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponse;
21 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponseCakes;
22 | import org.dalol.dagger_rx_database_mvp.mvp.model.Storage;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import javax.inject.Inject;
28 |
29 | /**
30 | * @author Filippo Engidashet
31 | * @version 1.0.0
32 | * @since 9/24/2016
33 | */
34 | public class CakeMapper {
35 |
36 | @Inject
37 | public CakeMapper() {
38 | }
39 |
40 | public List mapCakes(Storage storage, CakesResponse response) {
41 | List cakeList = new ArrayList<>();
42 |
43 | if (response != null) {
44 | CakesResponseCakes[] responseCakes = response.getCakes();
45 | if (responseCakes != null) {
46 | for (CakesResponseCakes cake : responseCakes) {
47 | Cake myCake = new Cake();
48 | myCake.setId(cake.getId());
49 | myCake.setTitle(cake.getTitle());
50 | myCake.setDetailDescription(cake.getDetailDescription());
51 | myCake.setPreviewDescription(cake.getPreviewDescription());
52 | myCake.setImageUrl(cake.getImage());
53 | storage.addCake(myCake);
54 | cakeList.add(myCake);
55 | }
56 | }
57 | }
58 | return cakeList;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/modules/details/DetailActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.modules.details;
18 |
19 | import android.content.Intent;
20 | import android.os.Build;
21 | import android.os.Bundle;
22 | import android.view.MenuItem;
23 | import android.widget.ImageView;
24 | import android.widget.TextView;
25 |
26 | import com.bumptech.glide.Glide;
27 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
28 |
29 | import org.dalol.dagger_rx_database_mvp.R;
30 | import org.dalol.dagger_rx_database_mvp.base.BaseActivity;
31 | import org.dalol.dagger_rx_database_mvp.helper.ImageHandler;
32 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
33 |
34 | import butterknife.Bind;
35 |
36 | /**
37 | * @author Filippo Engidashet
38 | * @version 1.0.0
39 | * @since 9/24/2016
40 | */
41 | public class DetailActivity extends BaseActivity {
42 |
43 | public static final String CAKE = "cake";
44 |
45 | @Bind(R.id.cakeImage) protected ImageView mCakeImage;
46 | @Bind(R.id.cakeTitle) protected TextView mCakeTitle;
47 | @Bind(R.id.cakeDescription) protected TextView mCakeDescription;
48 |
49 | @Override
50 | protected void onViewReady(Bundle savedInstanceState, Intent intent) {
51 | super.onViewReady(savedInstanceState, intent);
52 |
53 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
54 | mCakeImage.setTransitionName("cakeImageAnimation");
55 | }
56 |
57 | showBackArrow();
58 |
59 | Cake cake = (Cake) intent.getSerializableExtra(CAKE);
60 | setTitle("Cake Detail");
61 |
62 | mCakeTitle.setText(cake.getTitle());
63 | mCakeDescription.setText(cake.getDetailDescription());
64 |
65 | Glide.with(this).load(cake.getImageUrl())
66 | .diskCacheStrategy(DiskCacheStrategy.SOURCE)
67 | .into(new ImageHandler(mCakeImage));
68 | }
69 |
70 | @Override
71 | protected int getContentView() {
72 | return R.layout.activity_detail;
73 | }
74 |
75 | @Override
76 | public boolean onOptionsItemSelected(MenuItem item) {
77 | switch (item.getItemId()) {
78 | case android.R.id.home:
79 | onBackPressed();
80 | return true;
81 | }
82 | return super.onOptionsItemSelected(item);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/modules/home/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.modules.home;
18 |
19 | import android.app.ActivityOptions;
20 | import android.content.DialogInterface;
21 | import android.content.Intent;
22 | import android.net.Uri;
23 | import android.os.Bundle;
24 | import android.support.v7.app.AlertDialog;
25 | import android.support.v7.widget.LinearLayoutManager;
26 | import android.support.v7.widget.RecyclerView;
27 | import android.view.Menu;
28 | import android.view.MenuItem;
29 | import android.view.View;
30 | import android.widget.Toast;
31 |
32 | import org.dalol.dagger_rx_database_mvp.R;
33 | import org.dalol.dagger_rx_database_mvp.base.BaseActivity;
34 | import org.dalol.dagger_rx_database_mvp.di.components.DaggerCakeComponent;
35 | import org.dalol.dagger_rx_database_mvp.di.module.CakeModule;
36 | import org.dalol.dagger_rx_database_mvp.modules.details.DetailActivity;
37 | import org.dalol.dagger_rx_database_mvp.modules.home.adapter.CakeAdapter;
38 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
39 | import org.dalol.dagger_rx_database_mvp.mvp.presenter.CakePresenter;
40 | import org.dalol.dagger_rx_database_mvp.mvp.view.MainView;
41 | import org.dalol.dagger_rx_database_mvp.utilities.NetworkUtils;
42 |
43 | import java.util.List;
44 |
45 | import javax.inject.Inject;
46 |
47 | import butterknife.Bind;
48 |
49 | public class MainActivity extends BaseActivity implements MainView {
50 |
51 | @Bind(R.id.cake_list) protected RecyclerView mCakeList;
52 | @Inject protected CakePresenter mPresenter;
53 | private CakeAdapter mCakeAdapter;
54 |
55 | @Override
56 | protected void onViewReady(Bundle savedInstanceState, Intent intent) {
57 | super.onViewReady(savedInstanceState, intent);
58 | initializeList();
59 | loadCakes();
60 | }
61 |
62 | private void loadCakes() {
63 | if(NetworkUtils.isNetAvailable(this)) {
64 | mPresenter.getCakes();
65 | } else {
66 | mPresenter.getCakesFromDatabase();
67 | }
68 | }
69 |
70 | private void initializeList() {
71 | mCakeList.setHasFixedSize(true);
72 | mCakeList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
73 | mCakeAdapter = new CakeAdapter(getLayoutInflater());
74 | mCakeAdapter.setCakeClickListener(mCakeClickListener);
75 | mCakeList.setAdapter(mCakeAdapter);
76 | }
77 |
78 | @Override
79 | protected int getContentView() {
80 | return R.layout.activity_main;
81 | }
82 |
83 | @Override
84 | public boolean onCreateOptionsMenu(Menu menu) {
85 | getMenuInflater().inflate(R.menu.main_menu, menu);
86 | return super.onCreateOptionsMenu(menu);
87 | }
88 |
89 | @Override
90 | public boolean onOptionsItemSelected(MenuItem item) {
91 | switch (item.getItemId()) {
92 | case R.id.action_reload:
93 | loadCakes();
94 | return true;
95 | case R.id.action_about:
96 | showAbout();
97 | return true;
98 | }
99 | return super.onOptionsItemSelected(item);
100 | }
101 |
102 | private void showAbout() {
103 | AlertDialog dialog = new AlertDialog.Builder(this)
104 | .setMessage("Developed by Filippo Engidashet on 24/09/2016. \n\nGet the code and follow me on github!")
105 | .setCancelable(true)
106 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
107 | @Override
108 | public void onClick(DialogInterface dialog, int which) {
109 | dialog.dismiss();
110 | }
111 | })
112 | .setNegativeButton("Get Code", new DialogInterface.OnClickListener() {
113 | @Override
114 | public void onClick(DialogInterface dialog, int which) {
115 | Intent intent = new Intent(Intent.ACTION_VIEW);
116 | intent.setData(Uri.parse("https://github.com/filippella/Dagger-Rx-Database-MVP"));
117 | startActivity(intent);
118 | dialog.dismiss();
119 | }
120 | })
121 | .create();
122 | dialog.show();
123 | }
124 |
125 | @Override
126 | protected void resolveDaggerDependency() {
127 | DaggerCakeComponent.builder()
128 | .applicationComponent(getApplicationComponent())
129 | .cakeModule(new CakeModule(this))
130 | .build().inject(this);
131 | }
132 |
133 | @Override
134 | public void onCakeLoaded(List cakes) {
135 | mCakeAdapter.addCakes(cakes);
136 | }
137 |
138 | @Override
139 | public void onShowDialog(String message) {
140 | showDialog(message);
141 | }
142 |
143 | @Override
144 | public void onHideDialog() {
145 | hideDialog();
146 | }
147 |
148 | @Override
149 | public void onShowToast(String message) {
150 | Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
151 | }
152 |
153 | @Override
154 | public void onClearItems() {
155 | mCakeAdapter.clearCakes();
156 | }
157 |
158 | private CakeAdapter.OnCakeClickListener mCakeClickListener = new CakeAdapter.OnCakeClickListener() {
159 | @Override
160 | public void onClick(View v, Cake cake, int position) {
161 | Intent intent = new Intent(MainActivity.this, DetailActivity.class);
162 | intent.putExtra(DetailActivity.CAKE, cake);
163 |
164 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
165 | ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, v, "cakeImageAnimation");
166 | startActivity(intent, options.toBundle());
167 | } else {
168 | startActivity(intent);
169 | }
170 | }
171 | };
172 | }
173 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/modules/home/adapter/CakeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.modules.home.adapter;
18 |
19 | import android.content.Context;
20 | import android.support.v7.widget.RecyclerView;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.ImageView;
25 | import android.widget.TextView;
26 |
27 | import com.bumptech.glide.Glide;
28 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
29 |
30 | import org.dalol.dagger_rx_database_mvp.R;
31 | import org.dalol.dagger_rx_database_mvp.helper.ImageHandler;
32 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | import javax.inject.Inject;
38 |
39 | import butterknife.Bind;
40 | import butterknife.ButterKnife;
41 |
42 | /**
43 | * @author Filippo Engidashet
44 | * @version 1.0.0
45 | * @since 9/24/2016
46 | */
47 | public class CakeAdapter extends RecyclerView.Adapter {
48 |
49 | private LayoutInflater mLayoutInflater;
50 | private List mCakeList = new ArrayList<>();
51 |
52 | public CakeAdapter(LayoutInflater inflater) {
53 | mLayoutInflater = inflater;
54 | }
55 |
56 | @Override
57 | public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
58 | View view = mLayoutInflater.inflate(R.layout.list_item_layout, parent, false);
59 | return new Holder(view);
60 | }
61 |
62 | @Override
63 | public void onBindViewHolder(Holder holder, int position) {
64 | holder.bind(mCakeList.get(position));
65 | }
66 |
67 | @Override
68 | public int getItemCount() {
69 | return mCakeList.size();
70 | }
71 |
72 | public void addCakes(List cakes) {
73 | mCakeList.addAll(cakes);
74 | notifyDataSetChanged();
75 | }
76 |
77 | public void clearCakes() {
78 | mCakeList.clear();
79 | notifyDataSetChanged();
80 | }
81 |
82 | public class Holder extends RecyclerView.ViewHolder implements View.OnClickListener {
83 |
84 | @Bind(R.id.cake_icon) protected ImageView mCakeIcon;
85 | @Bind(R.id.textview_title) protected TextView mCakeTitle;
86 | @Bind(R.id.textview_preview_description) protected TextView mCakePreviewDescription;
87 |
88 | private Context mContext;
89 | private Cake mCake;
90 |
91 | public Holder(View itemView) {
92 | super(itemView);
93 | itemView.setOnClickListener(this);
94 | mContext = itemView.getContext();
95 | ButterKnife.bind(this, itemView);
96 | }
97 |
98 | public void bind(Cake cake) {
99 | mCake = cake;
100 | mCakeTitle.setText(cake.getTitle());
101 | mCakePreviewDescription.setText(cake.getPreviewDescription());
102 |
103 | Glide.with(mContext).load(cake.getImageUrl())
104 | .diskCacheStrategy(DiskCacheStrategy.SOURCE)
105 | .into(new ImageHandler(mCakeIcon));
106 | }
107 |
108 | @Override
109 | public void onClick(View v) {
110 | if (mCakeClickListener != null) {
111 | mCakeClickListener.onClick(mCakeIcon, mCake, getAdapterPosition());
112 | }
113 | }
114 | }
115 |
116 | public void setCakeClickListener(OnCakeClickListener listener) {
117 | mCakeClickListener = listener;
118 | }
119 |
120 | private OnCakeClickListener mCakeClickListener;
121 |
122 | public interface OnCakeClickListener {
123 |
124 | void onClick(View v, Cake cake, int position);
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/Cake.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | import java.io.Serializable;
20 |
21 | /**
22 | * @author Filippo Engidashet
23 | * @version 1.0.0
24 | * @since 9/24/2016
25 | */
26 | public class Cake implements Serializable {
27 |
28 | private int id;
29 | private String title;
30 | private String previewDescription;
31 | private String detailDescription;
32 | private String imageUrl;
33 |
34 | public int getId() {
35 | return id;
36 | }
37 |
38 | public void setId(int id) {
39 | this.id = id;
40 | }
41 |
42 | public String getTitle() {
43 | return title;
44 | }
45 |
46 | public void setTitle(String title) {
47 | this.title = title;
48 | }
49 |
50 | public String getPreviewDescription() {
51 | return previewDescription;
52 | }
53 |
54 | public void setPreviewDescription(String previewDescription) {
55 | this.previewDescription = previewDescription;
56 | }
57 |
58 | public String getDetailDescription() {
59 | return detailDescription;
60 | }
61 |
62 | public void setDetailDescription(String detailDescription) {
63 | this.detailDescription = detailDescription;
64 | }
65 |
66 | public String getImageUrl() {
67 | return imageUrl;
68 | }
69 |
70 | public void setImageUrl(String imageUrl) {
71 | this.imageUrl = imageUrl;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/CakesResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | public class CakesResponse {
20 |
21 | private String product;
22 | private CakesResponseStaffContacts[] staffContacts;
23 | private String releaseDate;
24 | private CakesResponseCakes[] cakes;
25 | private int version;
26 |
27 | public String getProduct() {
28 | return this.product;
29 | }
30 |
31 | public void setProduct(String product) {
32 | this.product = product;
33 | }
34 |
35 | public CakesResponseStaffContacts[] getStaffContacts() {
36 | return this.staffContacts;
37 | }
38 |
39 | public void setStaffContacts(CakesResponseStaffContacts[] staffContacts) {
40 | this.staffContacts = staffContacts;
41 | }
42 |
43 | public String getReleaseDate() {
44 | return this.releaseDate;
45 | }
46 |
47 | public void setReleaseDate(String releaseDate) {
48 | this.releaseDate = releaseDate;
49 | }
50 |
51 | public CakesResponseCakes[] getCakes() {
52 | return this.cakes;
53 | }
54 |
55 | public void setCakes(CakesResponseCakes[] cakes) {
56 | this.cakes = cakes;
57 | }
58 |
59 | public int getVersion() {
60 | return this.version;
61 | }
62 |
63 | public void setVersion(int version) {
64 | this.version = version;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/CakesResponseCakes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | public class CakesResponseCakes {
20 | private String detailDescription;
21 | private String image;
22 | private String previewDescription;
23 | private int id;
24 | private String title;
25 |
26 | public String getDetailDescription() {
27 | return this.detailDescription;
28 | }
29 |
30 | public void setDetailDescription(String detailDescription) {
31 | this.detailDescription = detailDescription;
32 | }
33 |
34 | public String getImage() {
35 | return this.image;
36 | }
37 |
38 | public void setImage(String image) {
39 | this.image = image;
40 | }
41 |
42 | public String getPreviewDescription() {
43 | return this.previewDescription;
44 | }
45 |
46 | public void setPreviewDescription(String previewDescription) {
47 | this.previewDescription = previewDescription;
48 | }
49 |
50 | public int getId() {
51 | return this.id;
52 | }
53 |
54 | public void setId(int id) {
55 | this.id = id;
56 | }
57 |
58 | public String getTitle() {
59 | return this.title;
60 | }
61 |
62 | public void setTitle(String title) {
63 | this.title = title;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/CakesResponseStaffContacts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | public class CakesResponseStaffContacts {
20 | private String role;
21 | private String name;
22 | private CakesResponseStaffContactsPhones phones;
23 | private String dateOfBirth;
24 | private int id;
25 | private String[] email;
26 |
27 | public String getRole() {
28 | return this.role;
29 | }
30 |
31 | public void setRole(String role) {
32 | this.role = role;
33 | }
34 |
35 | public String getName() {
36 | return this.name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public CakesResponseStaffContactsPhones getPhones() {
44 | return this.phones;
45 | }
46 |
47 | public void setPhones(CakesResponseStaffContactsPhones phones) {
48 | this.phones = phones;
49 | }
50 |
51 | public String getDateOfBirth() {
52 | return this.dateOfBirth;
53 | }
54 |
55 | public void setDateOfBirth(String dateOfBirth) {
56 | this.dateOfBirth = dateOfBirth;
57 | }
58 |
59 | public int getId() {
60 | return this.id;
61 | }
62 |
63 | public void setId(int id) {
64 | this.id = id;
65 | }
66 |
67 | public String[] getEmail() {
68 | return this.email;
69 | }
70 |
71 | public void setEmail(String[] email) {
72 | this.email = email;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/CakesResponseStaffContactsPhones.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | public class CakesResponseStaffContactsPhones {
20 | private String mobile;
21 | private String home;
22 |
23 | public String getMobile() {
24 | return this.mobile;
25 | }
26 |
27 | public void setMobile(String mobile) {
28 | this.mobile = mobile;
29 | }
30 |
31 | public String getHome() {
32 | return this.home;
33 | }
34 |
35 | public void setHome(String home) {
36 | this.home = home;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/model/Storage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.model;
18 |
19 | import android.content.ContentValues;
20 | import android.content.Context;
21 | import android.database.Cursor;
22 | import android.database.SQLException;
23 | import android.database.sqlite.SQLiteDatabase;
24 | import android.database.sqlite.SQLiteOpenHelper;
25 | import android.util.Log;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | import javax.inject.Inject;
31 |
32 | /**
33 | * @author Filippo Engidashet
34 | * @version 1.0.0
35 | * @since 9/24/2016
36 | */
37 | public class Storage extends SQLiteOpenHelper {
38 |
39 | private static final String TAG = Storage.class.getSimpleName();
40 |
41 | @Inject
42 | public Storage(Context context) {
43 | super(context, "cakes_db", null, 1);
44 | }
45 |
46 | @Override
47 | public void onCreate(SQLiteDatabase db) {
48 | try {
49 | db.execSQL(CREATE_TABLE);
50 | } catch(SQLException e) {
51 | Log.d(TAG, e.getMessage());
52 | }
53 | }
54 |
55 | @Override
56 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
57 | db.execSQL(DROP_TABLE);
58 | onCreate(db);
59 | }
60 |
61 | public void addCake(Cake cake) {
62 | SQLiteDatabase db = this.getWritableDatabase();
63 |
64 | ContentValues values = new ContentValues();
65 | values.put(TITLE, cake.getTitle());
66 | values.put(PREVIEW_DESCRIPTION, cake.getPreviewDescription());
67 | values.put(DETAIL_DESCRIPTION, cake.getDetailDescription());
68 | values.put(IMAGE_URL, cake.getImageUrl());
69 |
70 | try {
71 | db.insert(TABLE_NAME, null, values);
72 | } catch(SQLException e) {
73 | Log.d(TAG, e.getMessage());
74 | }
75 |
76 | db.close();
77 | }
78 |
79 | public List getSavedCakes() {
80 | List cakeList = new ArrayList<>();
81 | SQLiteDatabase db = this.getWritableDatabase();
82 |
83 | try {
84 | Cursor cursor = db.rawQuery(SELECT_QUERY, null);
85 | if (cursor != null) {
86 | if (cursor.getCount() > 0) {
87 | if (cursor.moveToFirst()) {
88 | do {
89 | Cake cake = new Cake();
90 | cake.setTitle(cursor.getString(cursor.getColumnIndex(TITLE)));
91 | cake.setPreviewDescription(cursor.getString(cursor.getColumnIndex(PREVIEW_DESCRIPTION)));
92 | cake.setDetailDescription(cursor.getString(cursor.getColumnIndex(DETAIL_DESCRIPTION)));
93 | cake.setImageUrl(cursor.getString(cursor.getColumnIndex(IMAGE_URL)));
94 |
95 | cakeList.add(cake);
96 |
97 | } while (cursor.moveToNext());
98 | }
99 | }
100 | }
101 | } catch (SQLException e) {
102 | Log.d(TAG, e.getMessage());
103 | }
104 | return cakeList;
105 | }
106 |
107 | private static final String ID = "id";
108 | private static final String TITLE = "title";
109 | private static final String PREVIEW_DESCRIPTION = "previewDescription";
110 | private static final String DETAIL_DESCRIPTION = "detailDescription";
111 | private static final String IMAGE_URL = "imageUrl";
112 | private static final String TABLE_NAME = "cakes";
113 |
114 | private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
115 | private static final String SELECT_QUERY = "SELECT * FROM " + TABLE_NAME;
116 |
117 | public static final String CREATE_TABLE = "create table " + TABLE_NAME + "(" +
118 | ID + " integer primary key autoincrement not null," +
119 | TITLE + " text not null," +
120 | PREVIEW_DESCRIPTION + " text not null," +
121 | DETAIL_DESCRIPTION + " text not null," +
122 | IMAGE_URL + " text not null)";
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/presenter/CakePresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.presenter;
18 |
19 | import org.dalol.dagger_rx_database_mvp.api.CakeApiService;
20 | import org.dalol.dagger_rx_database_mvp.base.BasePresenter;
21 | import org.dalol.dagger_rx_database_mvp.mapper.CakeMapper;
22 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
23 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponse;
24 | import org.dalol.dagger_rx_database_mvp.mvp.model.Storage;
25 | import org.dalol.dagger_rx_database_mvp.mvp.view.MainView;
26 |
27 | import java.util.List;
28 |
29 | import javax.inject.Inject;
30 |
31 | import rx.Observable;
32 | import rx.Observer;
33 |
34 | /**
35 | * @author Filippo Engidashet
36 | * @version 1.0.0
37 | * @since 9/24/2016
38 | */
39 | public class CakePresenter extends BasePresenter implements Observer {
40 |
41 | @Inject protected CakeApiService mApiService;
42 | @Inject protected CakeMapper mCakeMapper;
43 | @Inject protected Storage mStorage;
44 |
45 | @Inject
46 | public CakePresenter() {
47 | }
48 |
49 | public void getCakes() {
50 | getView().onShowDialog("Loading cakes....");
51 | Observable cakesResponseObservable = mApiService.getCakes();
52 | subscribe(cakesResponseObservable, this);
53 | }
54 |
55 | @Override
56 | public void onCompleted() {
57 | getView().onHideDialog();
58 | getView().onShowToast("Cakes loading complete!");
59 | }
60 |
61 | @Override
62 | public void onError(Throwable e) {
63 | getView().onHideDialog();
64 | getView().onShowToast("Error loading cakes " + e.getMessage());
65 | }
66 |
67 | @Override
68 | public void onNext(CakesResponse cakesResponse) {
69 | List cakes = mCakeMapper.mapCakes(mStorage, cakesResponse);
70 | getView().onClearItems();
71 | getView().onCakeLoaded(cakes);
72 | }
73 |
74 | public void getCakesFromDatabase() {
75 | List cakes = mStorage.getSavedCakes();
76 | getView().onClearItems();
77 | getView().onCakeLoaded(cakes);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/view/BaseView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.view;
18 |
19 | /**
20 | * @author Filippo Engidashet
21 | * @version 1.0.0
22 | * @since 9/24/2016
23 | */
24 | public interface BaseView {
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/mvp/view/MainView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.mvp.view;
18 |
19 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * @author Filippo Engidashet
25 | * @version 1.0.0
26 | * @since 9/24/2016
27 | */
28 | public interface MainView extends BaseView {
29 |
30 | void onCakeLoaded(List cakes);
31 |
32 | void onShowDialog(String message);
33 |
34 | void onHideDialog();
35 |
36 | void onShowToast(String message);
37 |
38 | void onClearItems();
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/utilities/ImageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.utilities;
18 |
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 |
22 | import java.io.ByteArrayOutputStream;
23 |
24 | /**
25 | * @author Filippo Engidashet
26 | * @version 1.0.0
27 | * @since 9/24/2016
28 | */
29 | public class ImageUtils {
30 |
31 | public static byte[] convertBitmapToByteArray(Bitmap bitmap) {
32 | ByteArrayOutputStream stream = new ByteArrayOutputStream();
33 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
34 | return stream.toByteArray();
35 | }
36 |
37 | public static Bitmap convertByteArrayToBitmap(byte[] bitmapArray) {
38 | return BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/org/dalol/dagger_rx_database_mvp/utilities/NetworkUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Filippo Engidashet
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dalol.dagger_rx_database_mvp.utilities;
18 |
19 | import android.content.Context;
20 | import android.net.ConnectivityManager;
21 | import android.net.NetworkInfo;
22 |
23 | /**
24 | * @author Filippo Engidashet
25 | * @version 1.0.0
26 | * @since 9/24/2016
27 | */
28 | public class NetworkUtils {
29 |
30 | public static boolean isNetAvailable(Context context) {
31 | ConnectivityManager connectivityManager
32 | = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
33 | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
34 | return activeNetworkInfo != null && activeNetworkInfo.isConnected();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_detail.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
23 |
31 |
32 |
36 |
37 |
42 |
43 |
52 |
53 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_layout.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
31 |
32 |
37 |
38 |
45 |
46 |
52 |
53 |
54 |
55 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_info_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-hdpi/ic_info_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_play_arrow_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-hdpi/ic_play_arrow_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-hdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_info_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-mdpi/ic_info_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_play_arrow_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-mdpi/ic_play_arrow_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-mdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_info_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xhdpi/ic_info_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_play_arrow_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xhdpi/ic_play_arrow_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xhdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_info_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxhdpi/ic_info_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_play_arrow_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxhdpi/ic_play_arrow_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxhdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_info_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxxhdpi/ic_info_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_play_arrow_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxxhdpi/ic_play_arrow_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/app/src/main/res/mipmap-xxxhdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Dagger-Rx-Database-MVP
3 | Reload
4 | About
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/org/dalol/dagger_rx_database_mvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.dalol.dagger_rx_database_mvp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/test/java/org/dalol/dagger_rx_database_mvp/mvp/presenter/CakePresenterTest.java:
--------------------------------------------------------------------------------
1 | package org.dalol.dagger_rx_database_mvp.mvp.presenter;
2 |
3 | import android.os.Looper;
4 |
5 | import org.dalol.dagger_rx_database_mvp.api.CakeApiService;
6 | import org.dalol.dagger_rx_database_mvp.mapper.CakeMapper;
7 | import org.dalol.dagger_rx_database_mvp.mvp.model.Cake;
8 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponse;
9 | import org.dalol.dagger_rx_database_mvp.mvp.model.CakesResponseCakes;
10 | import org.dalol.dagger_rx_database_mvp.mvp.model.Storage;
11 | import org.dalol.dagger_rx_database_mvp.mvp.view.MainView;
12 | import org.junit.Before;
13 | import org.junit.Test;
14 | import org.junit.runner.RunWith;
15 | import org.mockito.ArgumentCaptor;
16 | import org.mockito.Captor;
17 | import org.mockito.InjectMocks;
18 | import org.mockito.Mock;
19 | import org.powermock.api.mockito.PowerMockito;
20 | import org.powermock.core.classloader.annotations.PrepareForTest;
21 | import org.powermock.modules.junit4.PowerMockRunner;
22 |
23 | import java.util.ArrayList;
24 |
25 | import rx.Observable;
26 | import rx.Scheduler;
27 | import rx.Subscriber;
28 | import rx.android.schedulers.AndroidSchedulers;
29 | import rx.plugins.RxJavaSchedulersHook;
30 | import rx.schedulers.Schedulers;
31 |
32 | import static org.mockito.Mockito.anyList;
33 | import static org.mockito.Mockito.atLeastOnce;
34 | import static org.mockito.Mockito.mock;
35 | import static org.mockito.Mockito.times;
36 | import static org.mockito.Mockito.verify;
37 | import static org.mockito.Mockito.when;
38 | import static org.mockito.MockitoAnnotations.initMocks;
39 |
40 | /**
41 | * @author Filippo Engidashet
42 | * @version 1.0.0
43 | * @since 11/28/2016
44 | */
45 | @RunWith(PowerMockRunner.class)
46 | @PrepareForTest({Observable.class, AndroidSchedulers.class, Looper.class, CakesResponse.class})
47 | public class CakePresenterTest {
48 |
49 | public static final String TEST_ERROR_MESSAGE = "error_message";
50 |
51 | @InjectMocks private CakePresenter presenter;
52 | @Mock private CakeApiService mApiService;
53 | @Mock private CakeMapper mCakeMapper;
54 | @Mock private Storage mStorage;
55 | @Mock private MainView mView;
56 | @Mock private Observable mObservable;
57 |
58 | @Captor private ArgumentCaptor> captor;
59 |
60 | private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
61 | @Override
62 | public Scheduler getIOScheduler() {
63 | return Schedulers.immediate();
64 | }
65 |
66 | @Override
67 | public Scheduler getNewThreadScheduler() {
68 | return Schedulers.immediate();
69 | }
70 | };
71 |
72 | @Before
73 | public void setUp() throws Exception {
74 | initMocks(this);
75 |
76 | ArrayList cakes = new ArrayList<>();
77 | cakes.add(new Cake());
78 | when(mStorage.getSavedCakes()).thenReturn(cakes);
79 | }
80 |
81 | @Test
82 | public void getCakes() throws Exception {
83 | PowerMockito.mockStatic(Looper.class);
84 | when(AndroidSchedulers.mainThread()).thenReturn(mRxJavaSchedulersHook.getComputationScheduler());
85 |
86 | when(mApiService.getCakes()).thenReturn(mObservable);
87 | // when(observable.subscribeOn(Schedulers.newThread())).thenReturn(observable);
88 | // when(observable.observeOn(AndroidSchedulers.mainThread())).thenReturn(observable);
89 |
90 | presenter.getCakes();
91 | verify(mView, atLeastOnce()).onShowDialog("Loading cakes....");
92 | }
93 |
94 | @Test
95 | public void onCompleted() throws Exception {
96 | presenter.onCompleted();
97 | verify(mView, times(1)).onHideDialog();
98 | verify(mView, times(1)).onShowToast("Cakes loading complete!");
99 | }
100 |
101 | @Test
102 | public void onError() throws Exception {
103 | presenter.onError(new Throwable(TEST_ERROR_MESSAGE));
104 | verify(mView, times(1)).onHideDialog();
105 | verify(mView, times(1)).onShowToast("Error loading cakes " + TEST_ERROR_MESSAGE);
106 | }
107 |
108 | @Test
109 | public void onNext() throws Exception {
110 | CakesResponse response = mock(CakesResponse.class);
111 | CakesResponseCakes[] responseCakes = new CakesResponseCakes[1];
112 | when(response.getCakes()).thenReturn(responseCakes);
113 | presenter.onNext(response);
114 |
115 | verify(mCakeMapper, times(1)).mapCakes(mStorage, response);
116 | verify(mView, times(1)).onClearItems();
117 | verify(mView, times(1)).onCakeLoaded(anyList());
118 | }
119 |
120 | @Test
121 | public void getCakesFromDatabase() throws Exception {
122 | presenter.getCakesFromDatabase();
123 | verify(mView, times(1)).onClearItems();
124 | verify(mView, times(1)).onCakeLoaded(anyList());
125 | }
126 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/cakes/apple_cake.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/apple_cake.JPG
--------------------------------------------------------------------------------
/cakes/avocado_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/avocado_cake.jpg
--------------------------------------------------------------------------------
/cakes/banana_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/banana_cake.jpg
--------------------------------------------------------------------------------
/cakes/birthday_cake.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/birthday_cake.JPG
--------------------------------------------------------------------------------
/cakes/bulla_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/bulla_cake.jpg
--------------------------------------------------------------------------------
/cakes/carrot_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/carrot_cake.jpg
--------------------------------------------------------------------------------
/cakes/chocolate_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/chocolate_cake.jpg
--------------------------------------------------------------------------------
/cakes/clementine_cake.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/clementine_cake.png
--------------------------------------------------------------------------------
/cakes/fudge_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/fudge_cake.jpg
--------------------------------------------------------------------------------
/cakes/jaffa_cake.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/jaffa_cake.png
--------------------------------------------------------------------------------
/cakes/jewish_apple_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/jewish_apple_cake.jpg
--------------------------------------------------------------------------------
/cakes/lemoncheese_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/lemoncheese_cake.jpg
--------------------------------------------------------------------------------
/cakes/plum_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/plum_cake.jpg
--------------------------------------------------------------------------------
/cakes/spice_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/spice_cake.jpg
--------------------------------------------------------------------------------
/cakes/strawberry_cake.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/strawberry_cake.jpg
--------------------------------------------------------------------------------
/cakes/victoria_sponge.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/cakes/victoria_sponge.jpg
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/filippoengidashet/Dagger-Rx-Database-MVP/dc9c262ce9ee051098112fb0b25cdad19ad90722/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 24 16:18:42 BST 2016
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.14.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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | include ':app'
2 |
--------------------------------------------------------------------------------