Skip to content

Commit

Permalink
Merge pull request #1 from Arello-Mobile/master
Browse files Browse the repository at this point in the history
Update fork
  • Loading branch information
terrakok committed Oct 23, 2016
2 parents 6afde0b + cecdce6 commit d499cd5
Show file tree
Hide file tree
Showing 160 changed files with 2,491 additions and 2,103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Android Studio modile config file

# Android Studio captures folder
captures/
.idea/
132 changes: 90 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# Moxy
Moxy is Android library based on MVP pattern.
Moxy is a library that help to use MVP pattern when you do the Android Application. _Without problems of lifecycle and boilerplate code!_

Main idea of using Moxy:
![schemmatic using](https://habrastorage.org/files/ac7/e3c/6f5/ac7e3c6f5eec4f498ab50e597606faa5.gif)
What's happened here:

1. At _View_ happened action ![blue square](https://habrastorage.org/files/88e/47f/0d5/88e47f0d5767494c9dc56879b2281d28.png), that is passed to _Presenter_
2. _Presenter_ sends command ![red circle](https://habrastorage.org/files/b0c/d57/199/b0cd57199d4f4bcea465aefb21061461.png) in _ViewState_
3. _Presenter_ starts async request ![green square](https://habrastorage.org/files/998/8b1/57f/9988b157f9b544fd89b4af4aea061f87.png) to _Model_
4. _ViewState_ adds a command ![red circle](https://habrastorage.org/files/b0c/d57/199/b0cd57199d4f4bcea465aefb21061461.png) in commands queue, and then passes it in _View_
5. _View_ brings itself into a state specified in the command ![red circle](https://habrastorage.org/files/b0c/d57/199/b0cd57199d4f4bcea465aefb21061461.png)</li>
6. _Presenter_ receives result of request ![green square](https://habrastorage.org/files/998/8b1/57f/9988b157f9b544fd89b4af4aea061f87.png) from _Model_
7. _Presenter_ sends two commands ![green circle](https://habrastorage.org/files/9bd/23f/e0c/9bd23fe0c88c4d8f8b4a498474a6ad09.png) and ![blue circle](https://habrastorage.org/files/70c/231/d6b/70c231d6bf6b432ba83d5ecf2e97aafd.png) in _ViewState_
8. _ViewState_ saves commands ![green circle](https://habrastorage.org/files/9bd/23f/e0c/9bd23fe0c88c4d8f8b4a498474a6ad09.png) and ![blue circle](https://habrastorage.org/files/70c/231/d6b/70c231d6bf6b432ba83d5ecf2e97aafd.png) in commads queue and send them in _View_
9. _View_ brings itself into a state specified in the commands ![green circle](https://habrastorage.org/files/9bd/23f/e0c/9bd23fe0c88c4d8f8b4a498474a6ad09.png) and ![blue circle](https://habrastorage.org/files/70c/231/d6b/70c231d6bf6b432ba83d5ecf2e97aafd.png)</li>
10. New/recreated _View_ attach to existing _Presenter_
11. _ViewState_ sends queue of saved commands to new/recreate _View_
12. New/recreated _View_ brings itself into a state specified in the commands ![red circle](https://habrastorage.org/files/b0c/d57/199/b0cd57199d4f4bcea465aefb21061461.png), ![green circle](https://habrastorage.org/files/9bd/23f/e0c/9bd23fe0c88c4d8f8b4a498474a6ad09.png) and ![blue circle](https://habrastorage.org/files/70c/231/d6b/70c231d6bf6b432ba83d5ecf2e97aafd.png)
![schematic_using](https://habrastorage.org/files/a2e/b51/8b4/a2eb518b465a4df9b47e68794519270d.gif)
See what's happening here in the [wiki](https://github.com/Arello-Mobile/Moxy/wiki).

## Capabilities

Expand All @@ -26,45 +13,106 @@ Moxy has a few killer features on other ways:
- Capability to changes of many _Views_ from one _Presenter_

## Sample
You can find the sample project [here](https://github.com/Arello-Mobile/MoxySample)

View interface
```java
public interface HelloWorldView extends MvpView {
void showMessage(int message);
}
```
Presenter
```java
@InjectViewState
public class HelloWorldPresenter extends MvpPresenter<HelloWorldView> {
public HelloWorldPresenter() {
getViewState().showMessage(R.string.hello_world);
}
}
```
View implementation
```java
public class HelloWorldActivity extends MvpAppCompatActivity implements HelloWorldView {

@InjectPresenter
HelloWorldPresenter mHelloWorldPresenter;

private TextView mHelloWorldTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);

mHelloWorldTextView = ((TextView) findViewById(R.id.activity_hello_world_text_view_message));
}

@Override
public void showMessage(int message) {
mHelloWorldTextView.setText(message);
}
}
```
More extensive example [here](https://github.com/Arello-Mobile/MoxySample)

## Wiki
For all information check [Moxy Wiki](https://github.com/Arello-Mobile/Moxy/wiki)

## Android studio templates
In order to avoid boilerplate code creating for binding activity,fragments and its presentation part, we propose to use Android Studio templates for Moxy.

Templates located in [/moxy-templates](https://github.com/Arello-Mobile/Moxy/tree/master/moxy-templates)

## References
[_EN_] [Android without Lifecycle: MPVsV approach with Moxy](https://medium.com/@xanderblinov/6a3ae33521e)

[_RU_] [Moxy — реализация MVP под Android с щепоткой магии](https://habrahabr.ru/post/276189/)

## Integration
[_RU_] [MVP на стероидах: заставляем робота писать код за вас](https://habrahabr.ru/company/redmadrobot/blog/305798/)

Maven integration:
[_RU_] [Moxy. Из чего состоит и как этим пользоваться](http://www.slideshare.net/YuriShmakov/moxy)

[_EN_] [MVP on steroids - how we force the robot to write code for you](https://medium.com/@xanderblinov/mvp-on-steroids-how-we-force-the-robot-to-write-code-for-you-56fbc8ecefce#.5btn77voh)

## Integration
Base modules integration:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy:1.1.0'
provided 'com.arello-mobile:moxy-compiler:1.1.0'
}
```
<dependencies>
<dependency>
<groupId>com.arello-mobile</groupId>
<artifactId>moxy</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>com.arello-mobile</groupId>
<artifactId>moxy-android</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>com.arello-mobile</groupId>
<artifactId>moxy-compiler</artifactId>
<version>0.5.2</version>
<optional>true</optional>
</dependency>
</dependencies>
If you want to see generated code, use `apt` instead of `provided` dependency type:
```groovy
dependencies {
...
apt 'com.arello-mobile:moxy-compiler:1.1.0'
}
```

Gradle integration:
For additional base view classes `MvpActivity` and `MvpFragment` add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy-android:1.1.0'
}
```
If you planing to use AppCompat, then you can use `MvpAppCompatActivity` and `MvpAppCompatFragment`. Then add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy:0.5.2'
compile 'com.arello-mobile:moxy-android:0.5.2'
provided 'com.arello-mobile:moxy-compiler:0.5.2'
compile 'com.arello-mobile:moxy-app-compat:1.1.0'
}
```

## ProGuard
If you are using ProGuard you might need to add the following option:
```
-keep class **$$PresentersBinder
-keep class **$$State
-keep class **$$ViewStateClassNameProvider
-keepnames class * extends com.arellomobile.mvp.*
```

## License
```
The MIT License (MIT)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
Expand All @@ -20,8 +20,8 @@ allprojects {
}

ext {
targetVersionCode = 18
targetVersionName = "0.5.2"
targetVersionCode = 25
targetVersionName = "1.1.0"
}

task clean(type: Delete) {
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Jan 20 15:14:21 NOVT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
44 changes: 6 additions & 38 deletions moxy-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ task copyJars << {
}

copy {
from (buildDir)
from(buildDir)
{
rename targetArtefactId+'(.*)', targetArtefactIdDev + '$1'
rename targetArtefactId + '(.*)', targetArtefactIdDev + '$1'
}
into publishDir
}
Expand All @@ -152,23 +152,6 @@ task createPomXml << {

getBasePom('moxy-dev').withXml {
asNode().appendNode('build').appendNode('plugins').with {
appendNode('plugin').with {
appendNode('artifactId', 'maven-android-plugin')
appendNode('executions').with {
appendNode('execution').with {
appendNode('id', 'default-compile')
appendNode('goals').with {
appendNode('goal', 'compile')
}
appendNode('configuration').with {
appendNode('annotationProcessors').with {
appendNode('annotationProcessor', 'com.google.auto.value.processor.AutoValueProcessor')
appendNode('annotationProcessor', 'com.google.auto.service.processor.AutoServiceProcessor')
}
}
}
}
}
appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-gpg-plugin')
Expand Down Expand Up @@ -205,23 +188,6 @@ task createPomXml << {

asNode().appendNode('build')
.appendNode('plugins')
.appendNode('plugin').with {
appendNode('artifactId', 'maven-android-plugin')
appendNode('executions').with {
appendNode('execution').with {
appendNode('id', 'default-compile')
appendNode('goals').with {
appendNode('goal', 'compile')
}
appendNode('configuration').with {
appendNode('annotationProcessors').with {
appendNode('annotationProcessor', 'com.google.auto.value.processor.AutoValueProcessor')
appendNode('annotationProcessor', 'com.google.auto.service.processor.AutoServiceProcessor')
}
}
}
}
}


}.writeTo(publishMavenDir + "/" + targetArtefactId + ".pom")
Expand Down Expand Up @@ -274,6 +240,8 @@ dependencies {
compile project(':moxy')
runtime project(':moxy')
javadocDeps project(':moxy')
compile 'com.google.android:android:4.0.1.2'
javadocDeps 'com.google.android:android:4.0.1.2'
compileOnly 'com.google.android:android:1.6_r2'
javadocDeps 'com.google.android:android:1.6_r2'
compileOnly project(':stub-android')
javadocDeps project(':stub-android')
}
26 changes: 11 additions & 15 deletions moxy-android/src/main/java/com/arellomobile/mvp/MvpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,37 @@
* @author Alexander Bliniov
* @author Konstantin Tckhovrebov
*/
public class MvpActivity extends Activity
{
public class MvpActivity extends Activity {
private MvpDelegate<? extends MvpActivity> mMvpDelegate;

@Override
protected void onCreate(Bundle savedInstanceState)
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getMvpDelegate().onCreate(savedInstanceState);
}

@Override
protected void onDestroy()
{
protected void onDestroy() {
super.onDestroy();

getMvpDelegate().onDetach();
getMvpDelegate().onDestroy();

if (isFinishing()) {
getMvpDelegate().onDestroy();
}
}


@Override
protected void onSaveInstanceState(Bundle outState)
{
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

getMvpDelegate().onSaveInstanceState(outState);
}

@Override
protected void onStart()
{
protected void onStart() {
super.onStart();

getMvpDelegate().onAttach();
Expand All @@ -52,10 +50,8 @@ protected void onStart()
/**
* @return The {@link MvpDelegate} being used by this Activity.
*/
public MvpDelegate getMvpDelegate()
{
if (mMvpDelegate == null)
{
public MvpDelegate getMvpDelegate() {
if (mMvpDelegate == null) {
mMvpDelegate = new MvpDelegate<>(this);
}
return mMvpDelegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
*
* @author Alexander Blinov
*/
public class MvpApplication extends Application
{
public class MvpApplication extends Application {
@Override
public void onCreate()
{
public void onCreate() {
super.onCreate();
MvpFacade.init();
}
Expand Down
Loading

0 comments on commit d499cd5

Please sign in to comment.