Skip to content

Commit

Permalink
Merge branch 'release/1.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
senneco committed May 3, 2017
2 parents 7ddb348 + e5e2c0a commit 6e0f0cc
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 53 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ Base modules integration:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy:1.5.1'
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.1'
compile 'com.arello-mobile:moxy:1.5.2'
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.2'
}
```
For additional base view classes `MvpActivity` and `MvpFragment` add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy-android:1.5.1'
compile 'com.arello-mobile:moxy-android:1.5.2'
}
```
If you are planing to use AppCompat, then you can use `MvpAppCompatActivity` and `MvpAppCompatFragment`. Then add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy-app-compat:1.5.1'
compile 'com.arello-mobile:moxy-app-compat:1.5.2'
compile 'com.android.support:appcompat-v7:$support_version'
}
```
Expand All @@ -100,7 +100,7 @@ If you are using kotlin, use `kapt` instead of `provided`/`apt` dependency type
```groovy
dependencies {
...
kapt 'com.arello-mobile:moxy-compiler:1.5.1'
kapt 'com.arello-mobile:moxy-compiler:1.5.2'
}
kapt {
generateStubs = true
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:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
}
}
Expand All @@ -19,8 +19,8 @@ allprojects {
}

ext {
targetVersionCode = 41
targetVersionName = "1.5.1"
targetVersionCode = 42
targetVersionName = "1.5.2"
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ 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
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected void onStop() {
protected void onDestroy() {
super.onDestroy();

getMvpDelegate().onDestroyView();

if (isFinishing()) {
getMvpDelegate().onDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ protected void onStop() {
protected void onDestroy() {
super.onDestroy();

getMvpDelegate().onDestroyView();

if (isFinishing()) {
getMvpDelegate().onDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
Expand All @@ -26,6 +25,7 @@
import javax.lang.model.type.TypeVariable;
import javax.tools.Diagnostic;


import static com.arellomobile.mvp.compiler.Util.fillGenerics;

/**
Expand Down Expand Up @@ -72,16 +72,6 @@ public boolean generate(TypeElement typeElement, List<ClassGeneratingParams> cla
"import com.arellomobile.mvp.viewstate.strategy.StateStrategy;\n" +
"\n" +
"public class " + fullClassName.substring(fullClassName.lastIndexOf(".") + 1) + "$$State" + generic + " extends MvpViewState<" + mViewClassName + "> implements " + mViewClassName + " {\n" +
"\tprivate ViewCommands<" + mViewClassName + "> mViewCommands = new ViewCommands<>();\n" +
"\n" +
"\t@Override\n" +
"\tpublic void restoreState(" + mViewClassName + " view, Set<ViewCommand<" + mViewClassName + ">> currentState) {\n" +
"\t\tif (mViewCommands.isEmpty()) {\n" +
"\t\t\treturn;\n" +
"\t\t}\n" +
"\n" +
"\t\tmViewCommands.reapply(view, currentState);\n" +
"\t}\n" +
"\n";

List<Method> methods = new ArrayList<>();
Expand Down Expand Up @@ -164,7 +154,6 @@ public boolean generate(TypeElement typeElement, List<ClassGeneratingParams> cla
"\t\t}\n" +
"\n" +
"\t\tfor(" + mViewClassName + " view : mViews) {\n" +
"\t\t\tgetCurrentState(view).add(" + commandFieldName + ");\n" +
"\t\t\tview." + method.name + "(" + argumentsString + ");\n" +
"\t\t}\n" +
"\n" +
Expand Down Expand Up @@ -366,7 +355,6 @@ private String generateLocalViewCommand(String viewClassName, String builder, Li
"\t\t@Override\n" +
"\t\tpublic void apply(" + viewClassName + " mvpView) {\n" +
"\t\t\tmvpView." + method.name + "(" + argumentsString + ");\n" +
"\t\t\tgetCurrentState(mvpView).add(this);\n" +
"\t\t}\n" +
"\t}\n";
}
Expand Down
8 changes: 0 additions & 8 deletions moxy/src/main/java/com/arellomobile/mvp/DefaultViewState.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.arellomobile.mvp;

import java.util.Set;

import com.arellomobile.mvp.viewstate.MvpViewState;
import com.arellomobile.mvp.viewstate.ViewCommand;

/**
* Date: 19.12.2015
Expand All @@ -12,9 +9,4 @@
* @author Yuri Shmakov
*/
public final class DefaultViewState extends MvpViewState<MvpView> {

@Override
protected void restoreState(MvpView view, Set<ViewCommand<MvpView>> currentState) {
// Stub!
}
}
35 changes: 18 additions & 17 deletions moxy/src/main/java/com/arellomobile/mvp/viewstate/MvpViewState.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.arellomobile.mvp.viewstate;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -17,6 +16,7 @@
*/
@SuppressWarnings("WeakerAccess")
public abstract class MvpViewState<View extends MvpView> {
protected ViewCommands<View> mViewCommands = new ViewCommands<>();
protected Set<View> mViews;
protected Set<View> mInRestoreState;
protected Map<View, Set<ViewCommand<View>>> mViewStates;
Expand All @@ -33,7 +33,13 @@ public MvpViewState() {
* @param view mvp view to restore state
* @param currentState commands that was applied already
*/
protected abstract void restoreState(View view, Set<ViewCommand<View>> currentState);
protected void restoreState(View view, Set<ViewCommand<View>> currentState) {
if (mViewCommands.isEmpty()) {
return;
}

mViewCommands.reapply(view, currentState);
}

/**
* Attach view to view state and apply saves state
Expand All @@ -53,7 +59,12 @@ public void attachView(View view) {

mInRestoreState.add(view);

restoreState(view, getCurrentState(view));
Set<ViewCommand<View>> currentState = mViewStates.get(view);
currentState = currentState == null ? Collections.<ViewCommand<View>>emptySet() : currentState;

restoreState(view, currentState);

mViewStates.remove(view);

mInRestoreState.remove(view);
}
Expand All @@ -68,26 +79,16 @@ public void attachView(View view) {
public void detachView(View view) {
mViews.remove(view);
mInRestoreState.remove(view);

Set<ViewCommand<View>> currentState = Collections.newSetFromMap(new WeakHashMap<ViewCommand<View>, Boolean>());
currentState.addAll(mViewCommands.getCurrentState());
mViewStates.put(view, currentState);
}

public void destroyView(View view) {
mViewStates.remove(view);
}

/**
* @param view target view
* @return commands that was applied already
*/
protected Set<ViewCommand<View>> getCurrentState(View view) {
Set<ViewCommand<View>> currentState = mViewStates.get(view);
if (currentState == null) {
currentState = new HashSet<>();
mViewStates.put(view, currentState);
}

return currentState;
}

/**
* @return views, attached to this view state instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ public void reapply(View view, Set<ViewCommand<View>> currentState) {
afterApply(command);
}
}

public List<ViewCommand<View>> getCurrentState() {
return mState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/**
* This strategy will clear current commands queue and then incoming command will be put in.
*
* Caution! Be sure that you fully set view to initial state inside this command.
*
* Date: 19-Dec-15
* Time: 14:34
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
import com.arellomobile.mvp.viewstate.ViewCommand;

/**
* Cautions:
* <ul>
* <li>Don't rearrange current state</li>
* <li>Don't insert commands inside existing current state – only put to end of it</li>
* <li>Be careful if remove commands by another type. If you make it, be sure that inside your view method you fully override view changes</li>
* </ul>
*
* Date: 17.12.2015
* Time: 11:21
*
Expand Down
6 changes: 3 additions & 3 deletions sample-github/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile "org.robolectric:robolectric:3.1-rc1"

compile 'com.arello-mobile:moxy:1.5.1'
compile 'com.arello-mobile:moxy-app-compat:1.5.1'
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.1'
compile 'com.arello-mobile:moxy:1.5.2'
compile 'com.arello-mobile:moxy-app-compat:1.5.2'
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.2'
}
6 changes: 3 additions & 3 deletions sample-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'

compile 'com.arello-mobile:moxy:1.5.1'
compile 'com.arello-mobile:moxy-app-compat:1.5.1'
kapt 'com.arello-mobile:moxy-compiler:1.5.1'
compile 'com.arello-mobile:moxy:1.5.2'
compile 'com.arello-mobile:moxy-app-compat:1.5.2'
kapt 'com.arello-mobile:moxy-compiler:1.5.2'

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

0 comments on commit 6e0f0cc

Please sign in to comment.