├── .gitignore
├── HOW-IT-WORKS.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.txt
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── antonioleiva
│ │ │ └── mvpexample
│ │ │ └── app
│ │ │ ├── login
│ │ │ ├── LoginActivity.java
│ │ │ ├── LoginInteractor.java
│ │ │ ├── LoginPresenter.java
│ │ │ └── LoginView.java
│ │ │ └── main
│ │ │ ├── FindItemsInteractor.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MainAdapter.java
│ │ │ ├── MainPresenter.java
│ │ │ └── MainView.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable
│ │ ├── ic_password.xml
│ │ └── ic_username.xml
│ │ ├── layout
│ │ ├── activity_login.xml
│ │ ├── activity_main.xml
│ │ └── view_main_item.xml
│ │ ├── menu
│ │ ├── login.xml
│ │ └── main.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── antonioleiva
│ └── mvpexample
│ └── app
│ └── main
│ └── MainPresenterTest.java
├── appkotlin
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── antonioleiva
│ │ └── com
│ │ └── appkotlin
│ │ ├── Extensions.kt
│ │ ├── login
│ │ ├── LoginActivity.kt
│ │ ├── LoginInteractor.kt
│ │ ├── LoginPresenter.kt
│ │ └── LoginView.kt
│ │ └── main
│ │ ├── FindItemsInteractor.kt
│ │ ├── MainActivity.kt
│ │ ├── MainAdapter.kt
│ │ ├── MainPresenter.kt
│ │ └── MainView.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ ├── ic_launcher_background.xml
│ ├── ic_password.xml
│ └── ic_username.xml
│ ├── layout
│ ├── activity_login.xml
│ ├── activity_main.xml
│ └── view_main_item.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── login-classes.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | ./gradlew.bat
18 | ./gradlew
19 | build/
20 |
21 | # Mirror files
22 | mirror/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Intellij project files
31 | *.iws
32 | .idea/workspace.xml
33 | .idea/tasks.xml
34 | .idea
35 |
36 | *.iml
37 |
38 | # OS
39 | .DS_Store
--------------------------------------------------------------------------------
/HOW-IT-WORKS.md:
--------------------------------------------------------------------------------
1 | How it Works
2 | ==========
3 | 
4 |
5 | 1. View(Activity, Fragment, ...) calls presenter methods whenever there're user interaction
6 | 2. Presenter implementation calls the interactor(use case handler) to get results from business/domain layer
7 | 3. Interactor implementation returns the results or just returns the control to presenter implementation by calling listener methods
8 | 4. Presenter implementation calls view methods to update the UI by calling view interface.
9 |
10 | View, Presenter, Interactor and Listener interfaces are used to remove tight coupling.
11 |
12 | View becomes too humble to test. We can use fake(simulator) presenter to test view.
13 |
14 | Presenter and Interactor can be tested.
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | androidmvp
2 | ==========
3 |
4 | MVP Android Example used to explain how to use this pattern in our Android apps. This code was created to support an article explanation:
5 |
6 | [Android MVP @ antonioleiva.com (English)](http://antonioleiva.com/mvp-android)
7 |
8 | [](https://android-arsenal.com/details/3/1514)
9 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.antonioleiva.mvpexample.app"
7 | minSdkVersion 21
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility JavaVersion.VERSION_1_8
21 | targetCompatibility JavaVersion.VERSION_1_8
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation 'com.android.support:appcompat-v7:27.1.1'
27 | implementation 'com.android.support:recyclerview-v7:27.1.1'
28 | testImplementation 'junit:junit:4.12'
29 | testImplementation 'org.mockito:mockito-core:2.15.0'
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Desarrollo/Entorno Android/01 Entorno de Desarrollo/adt-bundle-windows/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.login;
20 |
21 | import android.content.Intent;
22 | import android.os.Bundle;
23 | import android.support.v7.app.AppCompatActivity;
24 | import android.view.View;
25 | import android.widget.EditText;
26 | import android.widget.ProgressBar;
27 |
28 | import com.antonioleiva.mvpexample.app.R;
29 | import com.antonioleiva.mvpexample.app.main.MainActivity;
30 |
31 | public class LoginActivity extends AppCompatActivity implements LoginView {
32 |
33 | private ProgressBar progressBar;
34 | private EditText username;
35 | private EditText password;
36 | private LoginPresenter presenter;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_login);
42 |
43 | progressBar = findViewById(R.id.progress);
44 | username = findViewById(R.id.username);
45 | password = findViewById(R.id.password);
46 | findViewById(R.id.button).setOnClickListener(v -> validateCredentials());
47 |
48 | presenter = new LoginPresenter(this, new LoginInteractor());
49 | }
50 |
51 | @Override
52 | protected void onDestroy() {
53 | presenter.onDestroy();
54 | super.onDestroy();
55 | }
56 |
57 | @Override
58 | public void showProgress() {
59 | progressBar.setVisibility(View.VISIBLE);
60 | }
61 |
62 | @Override
63 | public void hideProgress() {
64 | progressBar.setVisibility(View.GONE);
65 | }
66 |
67 | @Override
68 | public void setUsernameError() {
69 | username.setError(getString(R.string.username_error));
70 | }
71 |
72 | @Override
73 | public void setPasswordError() {
74 | password.setError(getString(R.string.password_error));
75 | }
76 |
77 | @Override
78 | public void navigateToHome() {
79 | startActivity(new Intent(this, MainActivity.class));
80 | finish();
81 | }
82 |
83 | private void validateCredentials() {
84 | presenter.validateCredentials(username.getText().toString(), password.getText().toString());
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/login/LoginInteractor.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.mvpexample.app.login;
2 |
3 | import android.os.Handler;
4 | import android.text.TextUtils;
5 |
6 | public class LoginInteractor {
7 |
8 | interface OnLoginFinishedListener {
9 | void onUsernameError();
10 |
11 | void onPasswordError();
12 |
13 | void onSuccess();
14 | }
15 |
16 | public void login(final String username, final String password, final OnLoginFinishedListener listener) {
17 | // Mock login. I'm creating a handler to delay the answer a couple of seconds
18 | new Handler().postDelayed(() -> {
19 | if (TextUtils.isEmpty(username)) {
20 | listener.onUsernameError();
21 | return;
22 | }
23 | if (TextUtils.isEmpty(password)) {
24 | listener.onPasswordError();
25 | return;
26 | }
27 | listener.onSuccess();
28 | }, 2000);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.login;
20 |
21 | public class LoginPresenter implements LoginInteractor.OnLoginFinishedListener {
22 |
23 | private LoginView loginView;
24 | private LoginInteractor loginInteractor;
25 |
26 | LoginPresenter(LoginView loginView, LoginInteractor loginInteractor) {
27 | this.loginView = loginView;
28 | this.loginInteractor = loginInteractor;
29 | }
30 |
31 | public void validateCredentials(String username, String password) {
32 | if (loginView != null) {
33 | loginView.showProgress();
34 | }
35 |
36 | loginInteractor.login(username, password, this);
37 | }
38 |
39 | public void onDestroy() {
40 | loginView = null;
41 | }
42 |
43 | @Override
44 | public void onUsernameError() {
45 | if (loginView != null) {
46 | loginView.setUsernameError();
47 | loginView.hideProgress();
48 | }
49 | }
50 |
51 | @Override
52 | public void onPasswordError() {
53 | if (loginView != null) {
54 | loginView.setPasswordError();
55 | loginView.hideProgress();
56 | }
57 | }
58 |
59 | @Override
60 | public void onSuccess() {
61 | if (loginView != null) {
62 | loginView.navigateToHome();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/login/LoginView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.login;
20 |
21 | public interface LoginView {
22 | void showProgress();
23 |
24 | void hideProgress();
25 |
26 | void setUsernameError();
27 |
28 | void setPasswordError();
29 |
30 | void navigateToHome();
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/main/FindItemsInteractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.main;
20 |
21 | import android.os.Handler;
22 |
23 | import java.util.Arrays;
24 | import java.util.List;
25 |
26 | public class FindItemsInteractor {
27 |
28 | interface OnFinishedListener {
29 | void onFinished(List items);
30 | }
31 |
32 | public void findItems(final OnFinishedListener listener) {
33 | new Handler().postDelayed(() -> listener.onFinished(createArrayList()), 2000);
34 | }
35 |
36 | private List createArrayList() {
37 | return Arrays.asList(
38 | "Item 1",
39 | "Item 2",
40 | "Item 3",
41 | "Item 4",
42 | "Item 5",
43 | "Item 6",
44 | "Item 7",
45 | "Item 8",
46 | "Item 9",
47 | "Item 10"
48 | );
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/main/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.main;
20 |
21 | import android.os.Bundle;
22 | import android.support.v7.app.AppCompatActivity;
23 | import android.support.v7.widget.RecyclerView;
24 | import android.view.Menu;
25 | import android.view.MenuItem;
26 | import android.view.View;
27 | import android.widget.ProgressBar;
28 | import android.widget.Toast;
29 |
30 | import com.antonioleiva.mvpexample.app.R;
31 |
32 | import java.util.List;
33 |
34 | public class MainActivity extends AppCompatActivity implements MainView {
35 |
36 | private RecyclerView recyclerView;
37 | private ProgressBar progressBar;
38 | private MainPresenter presenter;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 | recyclerView = findViewById(R.id.list);
45 | progressBar = findViewById(R.id.progress);
46 | presenter = new MainPresenter(this, new FindItemsInteractor());
47 | }
48 |
49 | @Override
50 | protected void onResume() {
51 | super.onResume();
52 | presenter.onResume();
53 | }
54 |
55 | @Override
56 | public boolean onCreateOptionsMenu(Menu menu) {
57 | getMenuInflater().inflate(R.menu.main, menu);
58 | return true;
59 | }
60 |
61 | @Override
62 | public boolean onOptionsItemSelected(MenuItem item) {
63 | switch (item.getItemId()) {
64 | case R.id.action_settings:
65 | return true;
66 | default:
67 | return super.onOptionsItemSelected(item);
68 | }
69 | }
70 |
71 | @Override
72 | protected void onDestroy() {
73 | presenter.onDestroy();
74 | super.onDestroy();
75 | }
76 |
77 | @Override
78 | public void showProgress() {
79 | progressBar.setVisibility(View.VISIBLE);
80 | recyclerView.setVisibility(View.INVISIBLE);
81 | }
82 |
83 | @Override
84 | public void hideProgress() {
85 | progressBar.setVisibility(View.INVISIBLE);
86 | recyclerView.setVisibility(View.VISIBLE);
87 | }
88 |
89 | @Override
90 | public void setItems(List items) {
91 | recyclerView.setAdapter(new MainAdapter(items, presenter::onItemClicked));
92 | }
93 |
94 | @Override
95 | public void showMessage(String message) {
96 | Toast.makeText(this, message, Toast.LENGTH_LONG).show();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/main/MainAdapter.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.mvpexample.app.main;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.antonioleiva.mvpexample.app.R;
10 |
11 | import java.util.List;
12 |
13 | public class MainAdapter extends RecyclerView.Adapter {
14 |
15 | public MainAdapter(List items, Listener listener) {
16 | this.items = items;
17 | this.listener = listener;
18 | }
19 |
20 | interface Listener {
21 | void onItemClicked(String item);
22 | }
23 |
24 | private List items;
25 | private Listener listener;
26 |
27 | @NonNull
28 | @Override
29 | public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
30 | TextView v = (TextView) LayoutInflater.from(parent.getContext())
31 | .inflate(R.layout.view_main_item, parent, false);
32 | return new MainViewHolder(v);
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
37 | final String item = items.get(position);
38 | holder.textView.setText(item);
39 | holder.textView.setOnClickListener(v -> listener.onItemClicked(item));
40 | }
41 |
42 | @Override
43 | public int getItemCount() {
44 | return items.size();
45 | }
46 |
47 | static class MainViewHolder extends RecyclerView.ViewHolder {
48 |
49 | TextView textView;
50 |
51 | MainViewHolder(TextView textView) {
52 | super(textView);
53 | this.textView = textView;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/main/MainPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.main;
20 |
21 | import java.util.List;
22 |
23 | class MainPresenter {
24 |
25 | private MainView mainView;
26 | private FindItemsInteractor findItemsInteractor;
27 |
28 | MainPresenter(MainView mainView, FindItemsInteractor findItemsInteractor) {
29 | this.mainView = mainView;
30 | this.findItemsInteractor = findItemsInteractor;
31 | }
32 |
33 | void onResume() {
34 | if (mainView != null) {
35 | mainView.showProgress();
36 | }
37 |
38 | findItemsInteractor.findItems(this::onFinished);
39 | }
40 |
41 | void onItemClicked(String item) {
42 | if (mainView != null) {
43 | mainView.showMessage(String.format("%s clicked", item));
44 | }
45 | }
46 |
47 | void onDestroy() {
48 | mainView = null;
49 | }
50 |
51 | public void onFinished(List items) {
52 | if (mainView != null) {
53 | mainView.setItems(items);
54 | mainView.hideProgress();
55 | }
56 | }
57 |
58 | public MainView getMainView() {
59 | return mainView;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/antonioleiva/mvpexample/app/main/MainView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2018 Antonio Leiva Gordillo.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.antonioleiva.mvpexample.app.main;
20 |
21 | import java.util.List;
22 |
23 | public interface MainView {
24 |
25 | void showProgress();
26 |
27 | void hideProgress();
28 |
29 | void setItems(List items);
30 |
31 | void showMessage(String message);
32 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_password.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_username.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
34 |
35 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_main_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/login.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/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 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MVP Example
5 | Hello world!
6 | Settings
7 | username
8 | password
9 | Log in
10 | MVP Example
11 | Username cannot be empty
12 | Password cannot be empty
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/antonioleiva/mvpexample/app/main/MainPresenterTest.java:
--------------------------------------------------------------------------------
1 | package com.antonioleiva.mvpexample.app.main;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.mockito.ArgumentCaptor;
7 | import org.mockito.Mock;
8 | import org.mockito.runners.MockitoJUnitRunner;
9 |
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | import static org.hamcrest.CoreMatchers.is;
14 | import static org.hamcrest.MatcherAssert.assertThat;
15 | import static org.junit.Assert.assertNull;
16 | import static org.mockito.ArgumentCaptor.forClass;
17 | import static org.mockito.Matchers.anyString;
18 | import static org.mockito.Mockito.times;
19 | import static org.mockito.Mockito.verify;
20 |
21 | @RunWith(MockitoJUnitRunner.class)
22 | public class MainPresenterTest {
23 |
24 | @Mock
25 | MainView view;
26 | @Mock
27 | FindItemsInteractor interactor;
28 |
29 | private MainPresenter presenter;
30 |
31 | @Before
32 | public void setUp() throws Exception {
33 | presenter = new MainPresenter(view, interactor);
34 | }
35 |
36 | @Test
37 | public void checkIfShowsProgressOnResume() {
38 | presenter.onResume();
39 | verify(view, times(1)).showProgress();
40 | }
41 |
42 | @Test
43 | public void checkIfShowsMessageOnItemClick() {
44 | presenter.onItemClicked(1);
45 | verify(view, times(1)).showMessage(anyString());
46 | }
47 |
48 | @Test
49 | public void checkIfRightMessageIsDisplayed() {
50 | ArgumentCaptor captor = forClass(String.class);
51 | presenter.onItemClicked(1);
52 | verify(view, times(1)).showMessage(captor.capture());
53 | assertThat(captor.getValue(), is("Position 2 clicked"));
54 | }
55 |
56 | @Test
57 | public void checkIfViewIsReleasedOnDestroy() {
58 | presenter.onDestroy();
59 | assertNull(presenter.getMainView());
60 | }
61 |
62 | @Test
63 | public void checkIfItemsArePassedToView() {
64 | List items = Arrays.asList("Model", "View", "Controller");
65 | presenter.onFinished(items);
66 | verify(view, times(1)).setItems(items);
67 | verify(view, times(1)).hideProgress();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/appkotlin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/appkotlin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | android {
5 | compileSdkVersion 27
6 |
7 |
8 |
9 | defaultConfig {
10 | applicationId "antonioleiva.com.appkotlin"
11 | minSdkVersion 21
12 | targetSdkVersion 27
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | implementation 'com.android.support:appcompat-v7:27.1.1'
33 | implementation 'com.android.support:recyclerview-v7:27.1.1'
34 | }
35 |
--------------------------------------------------------------------------------
/appkotlin/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/appkotlin/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/Extensions.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin
2 |
3 | import android.os.Handler
4 |
5 | fun postDelayed(delayMillis: Long, task: () -> Unit) {
6 | Handler().postDelayed(task, delayMillis)
7 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/login/LoginActivity.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.login
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import antonioleiva.com.appkotlin.R
8 | import antonioleiva.com.appkotlin.main.MainActivity
9 | import kotlinx.android.synthetic.main.activity_login.*
10 |
11 | class LoginActivity : AppCompatActivity(), LoginView {
12 |
13 | private val presenter = LoginPresenter(this, LoginInteractor())
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_login)
18 |
19 | button.setOnClickListener { validateCredentials() }
20 | }
21 |
22 | private fun validateCredentials() {
23 | presenter.validateCredentials(username.text.toString(), password.text.toString())
24 | }
25 |
26 | override fun onDestroy() {
27 | presenter.onDestroy()
28 | super.onDestroy()
29 | }
30 |
31 | override fun showProgress() {
32 | progress.visibility = View.VISIBLE
33 | }
34 |
35 | override fun hideProgress() {
36 | progress.visibility = View.GONE
37 | }
38 |
39 | override fun setUsernameError() {
40 | username.error = getString(R.string.username_error)
41 | }
42 |
43 | override fun setPasswordError() {
44 | password.error = getString(R.string.password_error)
45 | }
46 |
47 | override fun navigateToHome() {
48 | startActivity(Intent(this, MainActivity::class.java))
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/login/LoginInteractor.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.login
2 |
3 | import antonioleiva.com.appkotlin.postDelayed
4 |
5 | class LoginInteractor {
6 |
7 | interface OnLoginFinishedListener {
8 | fun onUsernameError()
9 | fun onPasswordError()
10 | fun onSuccess()
11 | }
12 |
13 | fun login(username: String, password: String, listener: OnLoginFinishedListener) {
14 | // Mock login. I'm creating a handler to delay the answer a couple of seconds
15 | postDelayed(2000) {
16 | when {
17 | username.isEmpty() -> listener.onUsernameError()
18 | password.isEmpty() -> listener.onPasswordError()
19 | else -> listener.onSuccess()
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/login/LoginPresenter.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.login
2 |
3 | class LoginPresenter(var loginView: LoginView?, val loginInteractor: LoginInteractor) :
4 | LoginInteractor.OnLoginFinishedListener {
5 |
6 | fun validateCredentials(username: String, password: String) {
7 | loginView?.showProgress()
8 | loginInteractor.login(username, password, this)
9 | }
10 |
11 | fun onDestroy() {
12 | loginView = null
13 | }
14 |
15 | override fun onUsernameError() {
16 | loginView?.apply {
17 | setUsernameError()
18 | hideProgress()
19 | }
20 | }
21 |
22 | override fun onPasswordError() {
23 | loginView?.apply {
24 | setPasswordError()
25 | hideProgress()
26 | }
27 | }
28 |
29 | override fun onSuccess() {
30 | loginView?.navigateToHome()
31 | }
32 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/login/LoginView.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.login
2 |
3 | interface LoginView {
4 | fun showProgress()
5 | fun hideProgress()
6 | fun setUsernameError()
7 | fun setPasswordError()
8 | fun navigateToHome()
9 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/main/FindItemsInteractor.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.main
2 |
3 | import antonioleiva.com.appkotlin.postDelayed
4 |
5 | class FindItemsInteractor {
6 |
7 | fun findItems(callback: (List) -> Unit) {
8 | postDelayed(2000) { callback(createArrayList()) }
9 | }
10 |
11 | private fun createArrayList(): List = (1..10).map { "Item $it" }
12 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.main
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.View
6 | import android.widget.Toast
7 | import antonioleiva.com.appkotlin.R
8 | import kotlinx.android.synthetic.main.activity_main.*
9 |
10 | class MainActivity : AppCompatActivity(), MainView {
11 |
12 | private val presenter = MainPresenter(this, FindItemsInteractor())
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(R.layout.activity_main)
17 | }
18 |
19 | override fun onResume() {
20 | super.onResume()
21 | presenter.onResume()
22 | }
23 |
24 | override fun onDestroy() {
25 | super.onDestroy()
26 | presenter.onDestroy()
27 | }
28 |
29 | override fun showProgress() {
30 | progress.visibility = View.VISIBLE
31 | list.visibility = View.GONE
32 | }
33 |
34 | override fun hideProgress() {
35 | progress.visibility = View.GONE
36 | list.visibility = View.VISIBLE
37 | }
38 |
39 | override fun setItems(items: List) {
40 | list.adapter = MainAdapter(items, presenter::onItemClicked)
41 | }
42 |
43 | override fun showMessage(message: String) {
44 | Toast.makeText(this, message, Toast.LENGTH_LONG).show()
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/main/MainAdapter.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.main
2 |
3 | import android.support.v7.widget.RecyclerView
4 | import android.view.LayoutInflater
5 | import android.view.ViewGroup
6 | import android.widget.TextView
7 | import antonioleiva.com.appkotlin.R
8 |
9 | class MainAdapter(private val items: List, private val listener: (String) -> Unit) :
10 | RecyclerView.Adapter() {
11 |
12 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainViewHolder {
13 | val v = LayoutInflater.from(parent.context)
14 | .inflate(R.layout.view_main_item, parent, false) as TextView
15 |
16 | return MainViewHolder(v)
17 | }
18 |
19 | override fun onBindViewHolder(holder: MainViewHolder, position: Int) {
20 | val item = items[position]
21 | holder.textView.text = item
22 | holder.textView.setOnClickListener { listener(item) }
23 | }
24 |
25 | override fun getItemCount(): Int = items.size
26 |
27 | class MainViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) {
28 |
29 | }
30 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/main/MainPresenter.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.main
2 |
3 | class MainPresenter(var mainView: MainView?, val findItemsInteractor: FindItemsInteractor) {
4 |
5 | fun onResume() {
6 | mainView?.showProgress()
7 | findItemsInteractor.findItems(::onItemsLoaded)
8 | }
9 |
10 | private fun onItemsLoaded(items: List) {
11 | mainView?.apply {
12 | setItems(items)
13 | hideProgress()
14 | }
15 | }
16 |
17 | fun onItemClicked(item: String) {
18 | mainView?.showMessage(item)
19 | }
20 |
21 | fun onDestroy() {
22 | mainView = null
23 | }
24 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/java/antonioleiva/com/appkotlin/main/MainView.kt:
--------------------------------------------------------------------------------
1 | package antonioleiva.com.appkotlin.main
2 |
3 | interface MainView {
4 | fun showProgress()
5 | fun hideProgress()
6 | fun setItems(items: List)
7 | fun showMessage(message: String)
8 | }
--------------------------------------------------------------------------------
/appkotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/drawable/ic_password.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/drawable/ic_username.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
34 |
35 |
41 |
42 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/layout/view_main_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/appkotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appkotlin/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MVP Example Kotlin
5 | Hello world!
6 | Settings
7 | username
8 | password
9 | Log in
10 | MVP Example
11 | Username cannot be empty
12 | Password cannot be empty
13 |
14 |
15 |
--------------------------------------------------------------------------------
/appkotlin/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.2.51'
3 |
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.1.3'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
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/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 13 09:12:34 PST 2018
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-4.4.1-all.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/login-classes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoniolg/androidmvp/b7056a68806f723885c4c0e83853b7fdfc34e9ce/login-classes.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':appkotlin'
2 |
--------------------------------------------------------------------------------