diff --git a/README.md b/README.md index feedf887..608c6403 100644 --- a/README.md +++ b/README.md @@ -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' } ``` @@ -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 diff --git a/build.gradle b/build.gradle index a5959b99..bfbdce44 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } @@ -19,8 +19,8 @@ allprojects { } ext { - targetVersionCode = 41 - targetVersionName = "1.5.1" + targetVersionCode = 42 + targetVersionName = "1.5.2" } task clean(type: Delete) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48ced06c..a4160ac2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/moxy-android/src/main/java/com/arellomobile/mvp/MvpActivity.java b/moxy-android/src/main/java/com/arellomobile/mvp/MvpActivity.java index 8dc9516c..ad577c76 100644 --- a/moxy-android/src/main/java/com/arellomobile/mvp/MvpActivity.java +++ b/moxy-android/src/main/java/com/arellomobile/mvp/MvpActivity.java @@ -54,6 +54,8 @@ protected void onStop() { protected void onDestroy() { super.onDestroy(); + getMvpDelegate().onDestroyView(); + if (isFinishing()) { getMvpDelegate().onDestroy(); } diff --git a/moxy-app-compat/src/main/java/com/arellomobile/mvp/MvpAppCompatActivity.java b/moxy-app-compat/src/main/java/com/arellomobile/mvp/MvpAppCompatActivity.java index ff8d7408..c464e4b8 100644 --- a/moxy-app-compat/src/main/java/com/arellomobile/mvp/MvpAppCompatActivity.java +++ b/moxy-app-compat/src/main/java/com/arellomobile/mvp/MvpAppCompatActivity.java @@ -55,6 +55,8 @@ protected void onStop() { protected void onDestroy() { super.onDestroy(); + getMvpDelegate().onDestroyView(); + if (isFinishing()) { getMvpDelegate().onDestroy(); } diff --git a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/ViewStateClassGenerator.java b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/ViewStateClassGenerator.java index 6570361d..a2b9f57a 100644 --- a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/ViewStateClassGenerator.java +++ b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/ViewStateClassGenerator.java @@ -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; @@ -26,6 +25,7 @@ import javax.lang.model.type.TypeVariable; import javax.tools.Diagnostic; + import static com.arellomobile.mvp.compiler.Util.fillGenerics; /** @@ -72,16 +72,6 @@ public boolean generate(TypeElement typeElement, List 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> 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 methods = new ArrayList<>(); @@ -164,7 +154,6 @@ public boolean generate(TypeElement typeElement, List 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" + @@ -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"; } diff --git a/moxy/src/main/java/com/arellomobile/mvp/DefaultViewState.java b/moxy/src/main/java/com/arellomobile/mvp/DefaultViewState.java index f5deb76d..f0c2bf88 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/DefaultViewState.java +++ b/moxy/src/main/java/com/arellomobile/mvp/DefaultViewState.java @@ -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 @@ -12,9 +9,4 @@ * @author Yuri Shmakov */ public final class DefaultViewState extends MvpViewState { - - @Override - protected void restoreState(MvpView view, Set> currentState) { - // Stub! - } } diff --git a/moxy/src/main/java/com/arellomobile/mvp/viewstate/MvpViewState.java b/moxy/src/main/java/com/arellomobile/mvp/viewstate/MvpViewState.java index 8ee5bff0..99bc644e 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/viewstate/MvpViewState.java +++ b/moxy/src/main/java/com/arellomobile/mvp/viewstate/MvpViewState.java @@ -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; @@ -17,6 +16,7 @@ */ @SuppressWarnings("WeakerAccess") public abstract class MvpViewState { + protected ViewCommands mViewCommands = new ViewCommands<>(); protected Set mViews; protected Set mInRestoreState; protected Map>> mViewStates; @@ -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> currentState); + protected void restoreState(View view, Set> currentState) { + if (mViewCommands.isEmpty()) { + return; + } + + mViewCommands.reapply(view, currentState); + } /** * Attach view to view state and apply saves state @@ -53,7 +59,12 @@ public void attachView(View view) { mInRestoreState.add(view); - restoreState(view, getCurrentState(view)); + Set> currentState = mViewStates.get(view); + currentState = currentState == null ? Collections.>emptySet() : currentState; + + restoreState(view, currentState); + + mViewStates.remove(view); mInRestoreState.remove(view); } @@ -68,26 +79,16 @@ public void attachView(View view) { public void detachView(View view) { mViews.remove(view); mInRestoreState.remove(view); + + Set> currentState = Collections.newSetFromMap(new WeakHashMap, 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> getCurrentState(View view) { - Set> currentState = mViewStates.get(view); - if (currentState == null) { - currentState = new HashSet<>(); - mViewStates.put(view, currentState); - } - - return currentState; - } - /** * @return views, attached to this view state instance */ diff --git a/moxy/src/main/java/com/arellomobile/mvp/viewstate/ViewCommands.java b/moxy/src/main/java/com/arellomobile/mvp/viewstate/ViewCommands.java index c6a15754..044d0aad 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/viewstate/ViewCommands.java +++ b/moxy/src/main/java/com/arellomobile/mvp/viewstate/ViewCommands.java @@ -68,4 +68,8 @@ public void reapply(View view, Set> currentState) { afterApply(command); } } + + public List> getCurrentState() { + return mState; + } } diff --git a/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/SingleStateStrategy.java b/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/SingleStateStrategy.java index 02071d55..f997e6cc 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/SingleStateStrategy.java +++ b/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/SingleStateStrategy.java @@ -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 * diff --git a/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/StateStrategy.java b/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/StateStrategy.java index 5a7f5c0a..84ffbcab 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/StateStrategy.java +++ b/moxy/src/main/java/com/arellomobile/mvp/viewstate/strategy/StateStrategy.java @@ -6,6 +6,13 @@ import com.arellomobile.mvp.viewstate.ViewCommand; /** + * Cautions: + *
    + *
  • Don't rearrange current state
  • + *
  • Don't insert commands inside existing current state – only put to end of it
  • + *
  • Be careful if remove commands by another type. If you make it, be sure that inside your view method you fully override view changes
  • + *
+ * * Date: 17.12.2015 * Time: 11:21 * diff --git a/sample-github/build.gradle b/sample-github/build.gradle index d0ff6b96..a9ecbdfa 100644 --- a/sample-github/build.gradle +++ b/sample-github/build.gradle @@ -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' } \ No newline at end of file diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index 3a69fc72..59e4366a 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -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" }