├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values-w360dp
│ │ │ │ └── dimens.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── list_item_main_list.xml
│ │ │ │ ├── fragment_main_list.xml
│ │ │ │ ├── activity_main_list.xml
│ │ │ │ ├── fragment_login.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── inthecheesefactory
│ │ │ │ └── lab
│ │ │ │ └── mvpstructure
│ │ │ │ ├── activity
│ │ │ │ ├── main
│ │ │ │ │ ├── view
│ │ │ │ │ │ ├── IMainView.java
│ │ │ │ │ │ └── MainActivity.java
│ │ │ │ │ ├── interactor
│ │ │ │ │ │ ├── IMainInteractor.java
│ │ │ │ │ │ ├── OnMainInteractorListener.java
│ │ │ │ │ │ └── MainInteractorImpl.java
│ │ │ │ │ └── presenter
│ │ │ │ │ │ ├── IMainPresenter.java
│ │ │ │ │ │ └── MainPresenterImpl.java
│ │ │ │ └── mainlist
│ │ │ │ │ ├── view
│ │ │ │ │ ├── IMainListView.java
│ │ │ │ │ └── MainListActivity.java
│ │ │ │ │ └── presenter
│ │ │ │ │ ├── IMainListPresenter.java
│ │ │ │ │ └── MainListPresenterImpl.java
│ │ │ │ ├── fragment
│ │ │ │ ├── login
│ │ │ │ │ ├── view
│ │ │ │ │ │ ├── ILoginFragmentView.java
│ │ │ │ │ │ └── LoginFragment.java
│ │ │ │ │ ├── interactor
│ │ │ │ │ │ ├── OnLoginFragmentInteractorListener.java
│ │ │ │ │ │ ├── ILoginFragmentInteractor.java
│ │ │ │ │ │ └── LoginFragmentInteractorImpl.java
│ │ │ │ │ ├── presenter
│ │ │ │ │ │ ├── ILoginFragmentPresenter.java
│ │ │ │ │ │ └── LoginFragmentPresenterImpl.java
│ │ │ │ │ └── model
│ │ │ │ │ │ └── UserModel.java
│ │ │ │ └── mainlist
│ │ │ │ │ ├── presenter
│ │ │ │ │ ├── IMainListFragmentPresenter.java
│ │ │ │ │ └── MainListFragmentPresenterImpl.java
│ │ │ │ │ ├── adapter
│ │ │ │ │ ├── view
│ │ │ │ │ │ ├── IMainListAdapterView.java
│ │ │ │ │ │ └── MainListAdapter.java
│ │ │ │ │ └── presenter
│ │ │ │ │ │ ├── IMainListAdapterPresenter.java
│ │ │ │ │ │ └── MainListAdapterPresenterImpl.java
│ │ │ │ │ ├── view
│ │ │ │ │ ├── IMainListFragmentView.java
│ │ │ │ │ └── MainListFragment.java
│ │ │ │ │ └── interactor
│ │ │ │ │ ├── IMainListFragmentInteractor.java
│ │ │ │ │ └── MainListFragmentInteractorImpl.java
│ │ │ │ ├── base
│ │ │ │ └── BasePresenter.java
│ │ │ │ ├── MainApplication.java
│ │ │ │ ├── manager
│ │ │ │ ├── http
│ │ │ │ │ ├── APIService.java
│ │ │ │ │ └── HTTPManager.java
│ │ │ │ └── Contextor.java
│ │ │ │ ├── dao
│ │ │ │ ├── DessertItemCollectionDao.java
│ │ │ │ └── DessertItemDao.java
│ │ │ │ └── view
│ │ │ │ └── CustomViewTemplate.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── inthecheesefactory
│ │ │ └── lab
│ │ │ └── mvpstructure
│ │ │ ├── ExampleUnitTest.java
│ │ │ └── activity
│ │ │ └── presenter
│ │ │ └── MainPresenterImplTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── inthecheesefactory
│ │ └── lab
│ │ └── mvpstructure
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── demo.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | MVPStructure
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/demo.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values-w360dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 320dp
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuuneoi/MVPStructure/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/view/IMainView.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.view;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface IMainView {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/mainlist/view/IMainListView.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.mainlist.view;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface IMainListView {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/interactor/IMainInteractor.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface IMainInteractor {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
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.8-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/interactor/OnMainInteractorListener.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface OnMainInteractorListener {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/interactor/MainInteractorImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public class MainInteractorImpl implements IMainInteractor {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 240dp
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MVPStructure
2 |
3 | An Android sample code structure in MVP (Model-View-Presenter) with Instance State Saving/Restoring.
4 |
5 | RxAndroid, RxJava, RxBinding, Retrolambda, Butterknife, Parceler and Retrofit are used in this project.
6 |
7 | 
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/view/ILoginFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.view;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface ILoginFragmentView {
7 |
8 | void onClearText();
9 | void onLoginResult(boolean success);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/interactor/OnLoginFragmentInteractorListener.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface OnLoginFragmentInteractorListener {
7 |
8 | void onLoginResult(boolean success);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/presenter/IMainPresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.base.BasePresenter;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public interface IMainPresenter extends BasePresenter {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/interactor/ILoginFragmentInteractor.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public interface ILoginFragmentInteractor {
7 |
8 | void login(String username, String password, OnLoginFragmentInteractorListener listener);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MVPStructure
3 | Username
4 | Password
5 | Login
6 | Clear
7 | Open Menu
8 | Close Menu
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/presenter/IMainListFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.base.BasePresenter;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public interface IMainListFragmentPresenter extends BasePresenter {
9 |
10 | void loadDessertList();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/adapter/view/IMainListAdapterView.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.view;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public interface IMainListAdapterView {
9 |
10 | void showDessertList(DessertItemCollectionDao dao);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/view/IMainListFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.view;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public interface IMainListFragmentView {
9 |
10 | void showDessertList(boolean success, DessertItemCollectionDao dao);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/inthecheesefactory/lab/mvpstructure/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure;
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/main/java/com/inthecheesefactory/lab/mvpstructure/base/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | /**
7 | * Created by nuuneoi on 12/15/2015.
8 | */
9 | public interface BasePresenter {
10 |
11 | void onSaveInstanceState(@NonNull Bundle outState);
12 | void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_main_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/mainlist/presenter/IMainListPresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.mainlist.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.activity.mainlist.view.IMainListView;
4 | import com.inthecheesefactory.lab.mvpstructure.base.BasePresenter;
5 |
6 | /**
7 | * Created by nuuneoi on 12/15/2015.
8 | */
9 | public interface IMainListPresenter extends BasePresenter {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/inthecheesefactory/lab/mvpstructure/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure;
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/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/presenter/ILoginFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.base.BasePresenter;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public interface ILoginFragmentPresenter extends BasePresenter {
9 |
10 | void clear();
11 | void login(String username, String password);
12 |
13 | String getLastUsername();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/interactor/IMainListFragmentInteractor.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.interactor;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
4 |
5 | import rx.Observable;
6 |
7 |
8 | /**
9 | * Created by nuuneoi on 12/15/2015.
10 | */
11 | public interface IMainListFragmentInteractor {
12 |
13 | Observable getLoadDessertListStream();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure;
2 |
3 | import android.app.Application;
4 |
5 | import com.inthecheesefactory.lab.mvpstructure.manager.Contextor;
6 |
7 | /**
8 | * Created by nuuneoi on 12/15/2015.
9 | */
10 | public class MainApplication extends Application {
11 |
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 |
16 | Contextor.getInstance().init(getApplicationContext());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/model/UserModel.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.model;
2 |
3 | import org.parceler.Parcel;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | @Parcel
9 | public class UserModel {
10 |
11 | String username = "";
12 |
13 | public String getUsername() {
14 | return username;
15 | }
16 |
17 | public void setUsername(String username) {
18 | this.username = username;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/adapter/presenter/IMainListAdapterPresenter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.base.BasePresenter;
4 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
5 |
6 | /**
7 | * Created by nuuneoi on 12/15/2015.
8 | */
9 | public interface IMainListAdapterPresenter extends BasePresenter {
10 |
11 | void setData(DessertItemCollectionDao dao);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/manager/http/APIService.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.manager.http;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
4 |
5 | import retrofit.Call;
6 | import retrofit.http.POST;
7 | import rx.Observable;
8 |
9 | /**
10 | * Created by nuuneoi on 10/8/2015 AD.
11 | */
12 | public interface APIService {
13 |
14 | @POST("list")
15 | Call loadDesserts();
16 |
17 | @POST("list")
18 | Observable loadDessertsRx();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/interactor/LoginFragmentInteractorImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor;
2 |
3 | /**
4 | * Created by nuuneoi on 12/15/2015.
5 | */
6 | public class LoginFragmentInteractorImpl implements ILoginFragmentInteractor {
7 |
8 | @Override
9 | public void login(String username, String password, OnLoginFragmentInteractorListener listener) {
10 | if (username.equals("test") && password.equals("12345"))
11 | listener.onLoginResult(true);
12 | else
13 | listener.onLoginResult(false);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/manager/Contextor.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.manager;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by nuuneoi on 12/15/2015.
7 | */
8 | public class Contextor {
9 |
10 | private static Contextor instance;
11 |
12 | public static Contextor getInstance() {
13 | if (instance == null)
14 | instance = new Contextor();
15 | return instance;
16 | }
17 |
18 | private Context mContext;
19 |
20 | public void init(Context context) {
21 | this.mContext = context;
22 | }
23 |
24 | public Context getContext() {
25 | return mContext;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/interactor/MainListFragmentInteractorImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.interactor;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
4 | import com.inthecheesefactory.lab.mvpstructure.manager.http.HTTPManager;
5 |
6 | import rx.Observable;
7 |
8 | /**
9 | * Created by nuuneoi on 12/15/2015.
10 | */
11 | public class MainListFragmentInteractorImpl implements IMainListFragmentInteractor {
12 |
13 | @Override
14 | public Observable getLoadDessertListStream() {
15 | return HTTPManager.getInstance().getService().loadDessertsRx();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/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 D:\Neois\Installer\AndroidSDK\android-sdk-windows/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 |
--------------------------------------------------------------------------------
/.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/gradle.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/dao/DessertItemCollectionDao.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.dao;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import org.parceler.Parcel;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by nuuneoi on 10/8/2015 AD.
11 | */
12 | @Parcel
13 | public class DessertItemCollectionDao {
14 |
15 | @SerializedName("success") boolean success;
16 | @SerializedName("data") List data;
17 |
18 | public boolean isSuccess() {
19 | return success;
20 | }
21 |
22 | public void setSuccess(boolean success) {
23 | this.success = success;
24 | }
25 |
26 | public List getData() {
27 | return data;
28 | }
29 |
30 | public void setData(List data) {
31 | this.data = data;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/mainlist/presenter/MainListPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.mainlist.presenter;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.inthecheesefactory.lab.mvpstructure.activity.mainlist.view.IMainListView;
7 |
8 | /**
9 | * Created by nuuneoi on 12/15/2015.
10 | */
11 | public class MainListPresenterImpl implements IMainListPresenter {
12 |
13 | IMainListView mainListView;
14 |
15 | public MainListPresenterImpl(IMainListView mainListView) {
16 | this.mainListView = mainListView;
17 | }
18 |
19 | @Override
20 | public void onSaveInstanceState(@NonNull Bundle outState) {
21 |
22 | }
23 |
24 | @Override
25 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/presenter/MainPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.presenter;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.inthecheesefactory.lab.mvpstructure.activity.main.interactor.IMainInteractor;
7 | import com.inthecheesefactory.lab.mvpstructure.activity.main.interactor.OnMainInteractorListener;
8 | import com.inthecheesefactory.lab.mvpstructure.activity.main.view.IMainView;
9 |
10 | import org.parceler.Parcels;
11 |
12 | /**
13 | * Created by nuuneoi on 12/15/2015.
14 | */
15 | public class MainPresenterImpl implements IMainPresenter, OnMainInteractorListener {
16 |
17 | private IMainView mainView;
18 | private IMainInteractor mainInteractor;
19 |
20 | public MainPresenterImpl(IMainView mainView, IMainInteractor mainInteractor) {
21 | this.mainView = mainView;
22 | this.mainInteractor = mainInteractor;
23 | }
24 |
25 | @Override
26 | public void onSaveInstanceState(@NonNull Bundle outState) {
27 |
28 | }
29 |
30 | @Override
31 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/manager/http/HTTPManager.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.manager.http;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.Gson;
6 | import com.google.gson.GsonBuilder;
7 |
8 | import retrofit.GsonConverterFactory;
9 | import retrofit.Retrofit;
10 | import retrofit.RxJavaCallAdapterFactory;
11 |
12 | /**
13 | * Created by nuuneoi on 11/16/2014.
14 | */
15 | public class HTTPManager {
16 |
17 | private static HTTPManager instance;
18 |
19 | public static HTTPManager getInstance() {
20 | if (instance == null)
21 | instance = new HTTPManager();
22 | return instance;
23 | }
24 |
25 | private APIService mService;
26 |
27 | private HTTPManager() {
28 | Gson gson = new GsonBuilder()
29 | .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
30 | .create();
31 |
32 | Retrofit retrofit = new Retrofit.Builder()
33 | .baseUrl("http://nuuneoi.com/courses/dessert_maker/")
34 | .addConverterFactory(GsonConverterFactory.create(gson))
35 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
36 | .build();
37 |
38 | mService = retrofit.create(APIService.class);
39 | }
40 |
41 | public APIService getService() {
42 | return mService;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/adapter/presenter/MainListAdapterPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.presenter;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
7 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.view.IMainListAdapterView;
8 |
9 | import org.parceler.Parcels;
10 |
11 | /**
12 | * Created by nuuneoi on 12/15/2015.
13 | */
14 | public class MainListAdapterPresenterImpl implements IMainListAdapterPresenter {
15 |
16 | IMainListAdapterView mainListAdapterView;
17 | DessertItemCollectionDao dao;
18 |
19 | public MainListAdapterPresenterImpl(IMainListAdapterView mainListAdapterView) {
20 | this.mainListAdapterView = mainListAdapterView;
21 | }
22 |
23 | @Override
24 | public void onSaveInstanceState(@NonNull Bundle outState) {
25 | outState.putParcelable("mainListAdapterPresenterDao", Parcels.wrap(dao));
26 | }
27 |
28 | @Override
29 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
30 | dao = Parcels.unwrap(savedInstanceState.getParcelable("mainListAdapterPresenterDao"));
31 | setData(dao);
32 | }
33 |
34 | @Override
35 | public void setData(DessertItemCollectionDao dao) {
36 | this.dao = dao;
37 | mainListAdapterView.showDessertList(dao);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
25 |
26 |
31 |
32 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/test/java/com/inthecheesefactory/lab/mvpstructure/activity/presenter/MainPresenterImplTest.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.presenter;
2 |
3 | import com.inthecheesefactory.lab.mvpstructure.activity.interactor.IMainInteractor;
4 | import com.inthecheesefactory.lab.mvpstructure.activity.interactor.OnMainInteractorListener;
5 | import com.inthecheesefactory.lab.mvpstructure.activity.view.IMainView;
6 |
7 | import junit.framework.TestCase;
8 |
9 | import static org.mockito.Matchers.eq;
10 | import static org.mockito.Mockito.mock;
11 | import static org.mockito.Mockito.verify;
12 | import static org.mockito.Mockito.when;
13 | import static org.mockito.Mockito.any;
14 |
15 | /**
16 | * Created by nuuneoi on 12/15/2015.
17 | */
18 | public class MainPresenterImplTest extends TestCase {
19 |
20 | MainPresenterImpl mainPresenter;
21 | IMainView mainView;
22 | IMainInteractor mainInteractor;
23 |
24 | public void setUp() throws Exception {
25 | super.setUp();
26 |
27 | mainView = mock(IMainView.class);
28 | mainInteractor = mock(IMainInteractor.class);
29 |
30 | mainPresenter = new MainPresenterImpl(mainView, mainInteractor);
31 | }
32 |
33 | public void testClear() throws Exception {
34 | mainPresenter.clear();
35 | verify(mainView).onClearText();
36 | }
37 |
38 | public void testLogin() throws Exception {
39 | mainPresenter.login("nuuneoi", "12345");
40 | verify(mainInteractor).login(eq("nuuneoi"), eq("12345"), any(OnMainInteractorListener.class));
41 | }
42 |
43 | public void testOnLoginResult() throws Exception {
44 |
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 | apply plugin: 'me.tatarka.retrolambda'
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "23.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.inthecheesefactory.lab.mvpstructure"
11 | minSdkVersion 15
12 | targetSdkVersion 23
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | compileOptions {
23 | sourceCompatibility JavaVersion.VERSION_1_8
24 | targetCompatibility JavaVersion.VERSION_1_8
25 | }
26 | }
27 |
28 | repositories {
29 | maven {url "https://clojars.org/repo/"}
30 | }
31 | dependencies {
32 | compile fileTree(include: ['*.jar'], dir: 'libs')
33 | testCompile 'junit:junit:4.12'
34 | testCompile 'org.robolectric:robolectric:3.0'
35 | testCompile 'org.mockito:mockito-core:1.9.5'
36 | compile 'com.android.support:appcompat-v7:23.1.1'
37 | compile 'com.android.support:recyclerview-v7:23.1.1'
38 | compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
39 | compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
40 | compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
41 | compile 'io.reactivex:rxjava:1.1.0'
42 | compile 'io.reactivex:rxandroid:1.1.0'
43 | compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
44 | compile 'com.jakewharton:butterknife:7.0.1'
45 | compile 'org.parceler:parceler-api:1.0.1'
46 | apt "org.parceler:parceler:1.0.1"
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/view/CustomViewTemplate.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.view;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.os.Build;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 |
10 | /**
11 | * Created by nuuneoi on 12/15/2015.
12 | */
13 | public class CustomViewTemplate extends View {
14 |
15 | public CustomViewTemplate(Context context) {
16 | super(context);
17 | init();
18 | }
19 |
20 | public CustomViewTemplate(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | init();
23 | initWithAttrs(attrs, 0, 0);
24 | }
25 |
26 | public CustomViewTemplate(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | init();
29 | initWithAttrs(attrs, defStyleAttr, 0);
30 | }
31 |
32 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
33 | public CustomViewTemplate(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
34 | super(context, attrs, defStyleAttr, defStyleRes);
35 | init();
36 | initWithAttrs(attrs, defStyleAttr, defStyleRes);
37 | }
38 |
39 | private void init() {
40 |
41 | }
42 |
43 | private void initWithAttrs(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
44 | TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs,
45 | null,
46 | defStyleAttr, defStyleRes);
47 |
48 | try {
49 |
50 | } finally {
51 | a.recycle();
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
22 |
23 |
27 |
28 |
29 |
35 |
36 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/mainlist/view/MainListActivity.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.mainlist.view;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.MenuItem;
7 |
8 | import com.inthecheesefactory.lab.mvpstructure.R;
9 | import com.inthecheesefactory.lab.mvpstructure.activity.mainlist.presenter.IMainListPresenter;
10 | import com.inthecheesefactory.lab.mvpstructure.activity.mainlist.presenter.MainListPresenterImpl;
11 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.view.LoginFragment;
12 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.view.MainListFragment;
13 |
14 | import butterknife.Bind;
15 | import butterknife.ButterKnife;
16 |
17 | public class MainListActivity extends AppCompatActivity implements IMainListView {
18 |
19 | @Bind(R.id.toolbar)
20 | Toolbar toolbar;
21 |
22 | IMainListPresenter presenter;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main_list);
28 |
29 | presenter = new MainListPresenterImpl(this);
30 |
31 | initInstances();
32 |
33 | if (savedInstanceState == null) {
34 | getSupportFragmentManager().beginTransaction()
35 | .add(R.id.contentContainer, MainListFragment.newInstance())
36 | .commit();
37 | }
38 | }
39 |
40 | private void initInstances() {
41 | ButterKnife.bind(this);
42 |
43 | setSupportActionBar(toolbar);
44 |
45 | getSupportActionBar().setHomeButtonEnabled(true);
46 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
47 | }
48 |
49 | @Override
50 | public boolean onOptionsItemSelected(MenuItem item) {
51 | switch (item.getItemId()) {
52 | case android.R.id.home:
53 | finish();
54 | return true;
55 | }
56 | return super.onOptionsItemSelected(item);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/adapter/view/MainListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.view;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.inthecheesefactory.lab.mvpstructure.R;
10 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
11 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.presenter.IMainListAdapterPresenter;
12 |
13 | import butterknife.Bind;
14 | import butterknife.ButterKnife;
15 |
16 | /**
17 | * Created by nuuneoi on 12/15/2015.
18 | */
19 | public class MainListAdapter extends RecyclerView.Adapter implements IMainListAdapterView {
20 |
21 | private DessertItemCollectionDao dao;
22 |
23 | public MainListAdapter() {
24 |
25 | }
26 |
27 | @Override
28 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
29 | View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_main_list, parent, false);
30 | return new ViewHolder(itemView);
31 | }
32 |
33 | @Override
34 | public void onBindViewHolder(ViewHolder holder, int position) {
35 | holder.tvName.setText(dao.getData().get(position).getName());
36 | }
37 |
38 | @Override
39 | public int getItemCount() {
40 | if (dao == null)
41 | return 0;
42 | if (dao.getData() == null)
43 | return 0;
44 | return dao.getData().size();
45 | }
46 |
47 | @Override
48 | public void showDessertList(DessertItemCollectionDao dao) {
49 | this.dao = dao;
50 | notifyDataSetChanged();
51 | }
52 |
53 | public static class ViewHolder extends RecyclerView.ViewHolder {
54 |
55 | @Bind(R.id.tvName)
56 | TextView tvName;
57 |
58 | public ViewHolder(View itemView) {
59 | super(itemView);
60 | ButterKnife.bind(this, itemView);
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/presenter/LoginFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.presenter;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor.ILoginFragmentInteractor;
7 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor.OnLoginFragmentInteractorListener;
8 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.model.UserModel;
9 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.view.ILoginFragmentView;
10 |
11 | import org.parceler.Parcels;
12 |
13 | /**
14 | * Created by nuuneoi on 12/15/2015.
15 | */
16 | public class LoginFragmentPresenterImpl implements ILoginFragmentPresenter, OnLoginFragmentInteractorListener {
17 |
18 | ILoginFragmentView loginFragmentView;
19 | ILoginFragmentInteractor loginFragmentInteractor;
20 |
21 | UserModel userModel;
22 |
23 | public LoginFragmentPresenterImpl(ILoginFragmentView loginFragmentView, ILoginFragmentInteractor loginFragmentInteractor) {
24 | this.loginFragmentView = loginFragmentView;
25 | this.loginFragmentInteractor = loginFragmentInteractor;
26 |
27 | userModel = new UserModel();
28 | }
29 |
30 | @Override
31 | public void clear() {
32 | loginFragmentView.onClearText();
33 | }
34 |
35 | @Override
36 | public void login(String username, String password) {
37 | loginFragmentInteractor.login(username, password, this);
38 | userModel.setUsername(username);
39 | }
40 |
41 | @Override
42 | public String getLastUsername() {
43 | return userModel.getUsername();
44 | }
45 |
46 | @Override
47 | public void onLoginResult(boolean success) {
48 | loginFragmentView.onLoginResult(success);
49 | }
50 |
51 | @Override
52 | public void onSaveInstanceState(@NonNull Bundle outState) {
53 | outState.putParcelable("userModel", Parcels.wrap(userModel));
54 | }
55 |
56 | @Override
57 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
58 | userModel = Parcels.unwrap(savedInstanceState.getParcelable("userModel"));
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/presenter/MainListFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.presenter;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
7 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.interactor.IMainListFragmentInteractor;
8 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.view.IMainListFragmentView;
9 |
10 | import rx.Subscriber;
11 | import rx.android.schedulers.AndroidSchedulers;
12 | import rx.schedulers.Schedulers;
13 |
14 | /**
15 | * Created by nuuneoi on 12/15/2015.
16 | */
17 | public class MainListFragmentPresenterImpl implements IMainListFragmentPresenter {
18 |
19 | IMainListFragmentView mainListFragmentView;
20 | IMainListFragmentInteractor mainListFragmentInteractor;
21 |
22 | public MainListFragmentPresenterImpl(IMainListFragmentView mainListFragmentView, IMainListFragmentInteractor mainListFragmentInteractor) {
23 | this.mainListFragmentView = mainListFragmentView;
24 | this.mainListFragmentInteractor = mainListFragmentInteractor;
25 | }
26 |
27 | @Override
28 | public void onSaveInstanceState(@NonNull Bundle outState) {
29 |
30 | }
31 |
32 | @Override
33 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
34 |
35 | }
36 |
37 | @Override
38 | public void loadDessertList() {
39 | mainListFragmentInteractor.getLoadDessertListStream()
40 | .subscribeOn(Schedulers.io())
41 | .observeOn(AndroidSchedulers.mainThread())
42 | .unsubscribeOn(Schedulers.io())
43 | .subscribe(new Subscriber() {
44 | @Override
45 | public void onCompleted() {
46 |
47 | }
48 |
49 | @Override
50 | public void onError(Throwable e) {
51 |
52 | }
53 |
54 | @Override
55 | public void onNext(DessertItemCollectionDao dessertItemCollectionDao) {
56 | mainListFragmentView.showDessertList(true, dessertItemCollectionDao);
57 | }
58 | });
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/dao/DessertItemDao.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.dao;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import org.parceler.Parcel;
6 |
7 | import java.util.Date;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by nuuneoi on 10/8/2015 AD.
12 | */
13 | @Parcel
14 | public class DessertItemDao {
15 |
16 | @SerializedName("menu_id") int menuId;
17 | @SerializedName("name") String name;
18 | @SerializedName("description") String description;
19 | @SerializedName("image_url") String imageUrl;
20 | @SerializedName("prep_time") int prepTime;
21 | @SerializedName("ready_in_time") int readyInTime;
22 | @SerializedName("timestamp") Date timestamp;
23 | @SerializedName("ingredients") List ingredients;
24 | @SerializedName("directions") List directions;
25 |
26 | public int getMenuId() {
27 | return menuId;
28 | }
29 |
30 | public void setMenuId(int menuId) {
31 | this.menuId = menuId;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public String getDescription() {
43 | return description;
44 | }
45 |
46 | public void setDescription(String description) {
47 | this.description = description;
48 | }
49 |
50 | public String getImageUrl() {
51 | return imageUrl;
52 | }
53 |
54 | public void setImageUrl(String imageUrl) {
55 | this.imageUrl = imageUrl;
56 | }
57 |
58 | public int getPrepTime() {
59 | return prepTime;
60 | }
61 |
62 | public void setPrepTime(int prepTime) {
63 | this.prepTime = prepTime;
64 | }
65 |
66 | public int getReadyInTime() {
67 | return readyInTime;
68 | }
69 |
70 | public void setReadyInTime(int readyInTime) {
71 | this.readyInTime = readyInTime;
72 | }
73 |
74 | public Date getTimestamp() {
75 | return timestamp;
76 | }
77 |
78 | public void setTimestamp(Date timestamp) {
79 | this.timestamp = timestamp;
80 | }
81 |
82 | public List getIngredients() {
83 | return ingredients;
84 | }
85 |
86 | public void setIngredients(List ingredients) {
87 | this.ingredients = ingredients;
88 | }
89 |
90 | public List getDirections() {
91 | return directions;
92 | }
93 |
94 | public void setDirections(List directions) {
95 | this.directions = directions;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/activity/main/view/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.activity.main.view;
2 |
3 | import android.content.res.Configuration;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.widget.DrawerLayout;
6 | import android.support.v7.app.ActionBarDrawerToggle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import com.inthecheesefactory.lab.mvpstructure.R;
17 | import com.inthecheesefactory.lab.mvpstructure.activity.main.interactor.MainInteractorImpl;
18 | import com.inthecheesefactory.lab.mvpstructure.activity.main.presenter.MainPresenterImpl;
19 | import com.inthecheesefactory.lab.mvpstructure.activity.main.presenter.IMainPresenter;
20 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.view.LoginFragment;
21 |
22 | import butterknife.Bind;
23 | import butterknife.ButterKnife;
24 | import butterknife.OnClick;
25 |
26 | public class MainActivity extends AppCompatActivity implements IMainView {
27 |
28 | @Bind(R.id.toolbar)
29 | Toolbar toolbar;
30 | @Bind(R.id.drawerLayout)
31 | DrawerLayout drawerLayout;
32 | @Bind(R.id.btnSample)
33 | Button btnSample;
34 |
35 | ActionBarDrawerToggle actionBarDrawerToggle;
36 |
37 | private IMainPresenter presenter;
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_main);
43 |
44 | presenter = new MainPresenterImpl(this, new MainInteractorImpl());
45 |
46 | initInstances();
47 |
48 | if (savedInstanceState == null) {
49 | getSupportFragmentManager().beginTransaction()
50 | .add(R.id.contentContainer, LoginFragment.newInstance())
51 | .commit();
52 | }
53 | }
54 |
55 | private void initInstances() {
56 | ButterKnife.bind(this);
57 |
58 | setSupportActionBar(toolbar);
59 |
60 | actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this,
61 | drawerLayout,
62 | R.string.open_menu,
63 | R.string.close_menu);
64 | drawerLayout.setDrawerListener(actionBarDrawerToggle);
65 |
66 | getSupportActionBar().setHomeButtonEnabled(true);
67 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
68 | }
69 |
70 | @Override
71 | protected void onPostCreate(@Nullable Bundle savedInstanceState) {
72 | super.onPostCreate(savedInstanceState);
73 | actionBarDrawerToggle.syncState();
74 | }
75 |
76 | @Override
77 | public void onConfigurationChanged(Configuration newConfig) {
78 | super.onConfigurationChanged(newConfig);
79 | actionBarDrawerToggle.onConfigurationChanged(newConfig);
80 | }
81 |
82 | @Override
83 | public boolean onOptionsItemSelected(MenuItem item) {
84 | if (actionBarDrawerToggle.onOptionsItemSelected(item))
85 | return true;
86 | return super.onOptionsItemSelected(item);
87 | }
88 |
89 | @Override
90 | protected void onSaveInstanceState(Bundle outState) {
91 | super.onSaveInstanceState(outState);
92 | presenter.onSaveInstanceState(outState);
93 | }
94 |
95 | @Override
96 | protected void onRestoreInstanceState(Bundle savedInstanceState) {
97 | super.onRestoreInstanceState(savedInstanceState);
98 | presenter.onRestoreInstanceState(savedInstanceState);
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/mainlist/view/MainListFragment.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.view;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.DefaultItemAnimator;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.Toast;
14 |
15 | import com.inthecheesefactory.lab.mvpstructure.R;
16 | import com.inthecheesefactory.lab.mvpstructure.dao.DessertItemCollectionDao;
17 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.presenter.IMainListAdapterPresenter;
18 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.presenter.MainListAdapterPresenterImpl;
19 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.adapter.view.MainListAdapter;
20 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.interactor.MainListFragmentInteractorImpl;
21 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.presenter.IMainListFragmentPresenter;
22 | import com.inthecheesefactory.lab.mvpstructure.fragment.mainlist.presenter.MainListFragmentPresenterImpl;
23 | import com.inthecheesefactory.lab.mvpstructure.manager.Contextor;
24 |
25 | import butterknife.Bind;
26 | import butterknife.ButterKnife;
27 |
28 | /**
29 | * Created by nuuneoi on 12/15/2015.
30 | */
31 | public class MainListFragment extends Fragment implements IMainListFragmentView {
32 |
33 | @Bind(R.id.recyclerView)
34 | RecyclerView recyclerView;
35 |
36 | MainListAdapter mainListAdapter;
37 |
38 | IMainListFragmentPresenter presenter;
39 |
40 | IMainListAdapterPresenter mainListPresenter;
41 |
42 | public static MainListFragment newInstance() {
43 | MainListFragment fragment = new MainListFragment();
44 | Bundle args = new Bundle();
45 | fragment.setArguments(args);
46 | return fragment;
47 | }
48 |
49 | @Nullable
50 | @Override
51 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
52 | View rootView = inflater.inflate(R.layout.fragment_main_list, container, false);
53 | initInstances(rootView);
54 | return rootView;
55 | }
56 |
57 | private void initInstances(View rootView) {
58 | ButterKnife.bind(this, rootView);
59 |
60 | presenter = new MainListFragmentPresenterImpl(this, new MainListFragmentInteractorImpl());
61 |
62 | mainListAdapter = new MainListAdapter();
63 | mainListPresenter = new MainListAdapterPresenterImpl(mainListAdapter);
64 |
65 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
66 | recyclerView.setAdapter(mainListAdapter);
67 | recyclerView.setItemAnimator(new DefaultItemAnimator());
68 |
69 | presenter.loadDessertList();
70 | }
71 |
72 | @Override
73 | public void onSaveInstanceState(Bundle outState) {
74 | super.onSaveInstanceState(outState);
75 | presenter.onSaveInstanceState(outState);
76 | mainListPresenter.onSaveInstanceState(outState);
77 | }
78 |
79 | @Override
80 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
81 | super.onActivityCreated(savedInstanceState);
82 | if (savedInstanceState != null) {
83 | presenter.onRestoreInstanceState(savedInstanceState);
84 | mainListPresenter.onRestoreInstanceState(savedInstanceState);
85 | }
86 | }
87 |
88 | @Override
89 | public void showDessertList(boolean success, DessertItemCollectionDao dao) {
90 | if (success) {
91 | mainListPresenter.setData(dao);
92 | Toast.makeText(Contextor.getInstance().getContext(), "Loaded", Toast.LENGTH_SHORT).show();
93 | }
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/inthecheesefactory/lab/mvpstructure/fragment/login/view/LoginFragment.java:
--------------------------------------------------------------------------------
1 | package com.inthecheesefactory.lab.mvpstructure.fragment.login.view;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 | import android.widget.Toast;
13 |
14 | import com.inthecheesefactory.lab.mvpstructure.R;
15 | import com.inthecheesefactory.lab.mvpstructure.activity.mainlist.view.MainListActivity;
16 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.interactor.LoginFragmentInteractorImpl;
17 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.presenter.ILoginFragmentPresenter;
18 | import com.inthecheesefactory.lab.mvpstructure.fragment.login.presenter.LoginFragmentPresenterImpl;
19 | import com.inthecheesefactory.lab.mvpstructure.manager.Contextor;
20 | import com.jakewharton.rxbinding.widget.RxTextView;
21 | import com.jakewharton.rxbinding.widget.TextViewAfterTextChangeEvent;
22 |
23 | import butterknife.Bind;
24 | import butterknife.ButterKnife;
25 | import butterknife.OnClick;
26 | import rx.Observable;
27 |
28 | /**
29 | * Created by nuuneoi on 12/15/2015.
30 | */
31 | public class LoginFragment extends Fragment implements ILoginFragmentView {
32 |
33 | @Bind(R.id.editTextUsername)
34 | EditText editTextUsername;
35 | @Bind(R.id.editTextPassword)
36 | EditText editTextPassword;
37 | @Bind(R.id.btnLogin)
38 | Button btnLogin;
39 | @Bind(R.id.btnClear)
40 | Button btnClear;
41 |
42 | ILoginFragmentPresenter presenter;
43 |
44 | public static LoginFragment newInstance() {
45 | LoginFragment fragment = new LoginFragment();
46 | Bundle args = new Bundle();
47 | fragment.setArguments(args);
48 | return fragment;
49 | }
50 |
51 | @Nullable
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
54 | View rootView = inflater.inflate(R.layout.fragment_login, container, false);
55 | initInstances(rootView);
56 | return rootView;
57 | }
58 |
59 | private void initInstances(View rootView) {
60 | ButterKnife.bind(this, rootView);
61 |
62 | presenter = new LoginFragmentPresenterImpl(this, new LoginFragmentInteractorImpl());
63 |
64 | Observable usernameValid = RxTextView.afterTextChangeEvents(editTextUsername)
65 | .map(e -> e.view().getText().length() > 3 ? true : false);
66 | Observable passwordValid = RxTextView.afterTextChangeEvents(editTextPassword)
67 | .map(e -> e.view().getText().length() > 3 ? true : false);
68 |
69 | Observable loginEnabled = Observable.combineLatest(usernameValid, passwordValid, (a, b) -> a && b);
70 | loginEnabled.subscribe(b -> btnLogin.setEnabled(b));
71 | }
72 |
73 | @Override
74 | public void onResume() {
75 | super.onResume();
76 | Toast.makeText(getActivity(), presenter.getLastUsername(), Toast.LENGTH_LONG).show();
77 | }
78 |
79 | @Override
80 | public void onSaveInstanceState(Bundle outState) {
81 | super.onSaveInstanceState(outState);
82 | presenter.onSaveInstanceState(outState);
83 | }
84 |
85 | @Override
86 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
87 | super.onActivityCreated(savedInstanceState);
88 | if (savedInstanceState != null) {
89 | presenter.onRestoreInstanceState(savedInstanceState);
90 | }
91 | }
92 |
93 | @OnClick(R.id.btnLogin)
94 | public void btnLoginClicked(View view) {
95 | presenter.login(editTextUsername.getText().toString(), editTextPassword.getText().toString());
96 | }
97 |
98 | @OnClick(R.id.btnClear)
99 | public void btnClearClicked(View view) {
100 | presenter.clear();
101 | }
102 |
103 |
104 | @Override
105 | public void onClearText() {
106 | editTextUsername.setText("");
107 | editTextPassword.setText("");
108 | }
109 |
110 | @Override
111 | public void onLoginResult(boolean success) {
112 | Toast.makeText(Contextor.getInstance().getContext(), "Result: " + success, Toast.LENGTH_SHORT)
113 | .show();
114 |
115 | if (success) {
116 | Intent intent = new Intent(getActivity(), MainListActivity.class);
117 | startActivity(intent);
118 | }
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------