diff --git a/.travis.yml b/.travis.yml index 35b99b4..63385af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,10 @@ android: - tools # The BuildTools version used by your project - - build-tools-22.0.1 + - build-tools-23.0.1 # The SDK version used to compile your project - - android-22 + - android-23 # Additional components - extra-google-m2repository @@ -18,11 +18,11 @@ android: # Specify at least one system image, # if you need to run emulator(s) during your tests - # - sys-img-armeabi-v7a-android-22 + # - sys-img-armeabi-v7a-android-23 # Emulator Management: Create, Start and Wait #before_script: - #- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a + #- echo no | android create avd --force -n test -t android-23 --abi armeabi-v7a #- emulator -avd test -no-skin -no-audio -no-window & #- android-wait-for-emulator #- adb shell input keyevent 82 & diff --git a/ChangeLog.md b/ChangeLog.md index 3f79557..909deb6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,10 @@ +Version: 1.4.0 +* Refactor of class AndroidMvc so that controllers can access the MvcGraph +* EventBusV2V is injectable same as EventBusC2V and EventBusC2C +* Add method "use" in MvcGraph to consume an injectable classes which doesn't require a class field marked by @Inject +* Remove BaseControllerImpl.onInitialized and replaced by onConstruct since onInitialized is also called when the controller is restored +* Add call back BaseControllerImpl.onRestored + Version: 1.3.0 * Refactor the MvcFragment.Reason object. * Remove android-mvc-controller-retrofit @@ -24,7 +31,7 @@ Once root fragment is restored, it should notify all nested fragments they are n Fix issue that nested fragments of popping out fragment won't call onReturnFromBackground incorrectly Version: 1.1.6 -Fix issue that onViewReady is called with incorrect reason - RESTORE which should be FIRST_TIME when the fragment is a page and recreated by FragmentStatePagerAdapter +Fix issue that onViewReady is called with incorrect reason - RESTORE which should be FIRST_TIME when the fragment is a page and recreated by FragmentPagerAdapter Version: 1.1.5 Allow remove preference key from SharedPreferenceService diff --git a/README.md b/README.md index 4dea962..27a442f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # AndroidMvc Framework [![Build Status](https://travis-ci.org/kejunxia/AndroidMvc.svg?branch=ci-travis)](https://travis-ci.org/kejunxia/AndroidMvc) [![Coverage Status](https://coveralls.io/repos/kejunxia/AndroidMvc/badge.svg)](https://coveralls.io/r/kejunxia/AndroidMvc) +[![Download](https://api.bintray.com/packages/kejunxia/maven/android-mvc/images/download.svg)](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc) # Website @@ -26,20 +27,22 @@ See [**Source code** here](https://github.com/kejunxia/AndroidMvc/tree/master/samples/note) and download [**Sample APK** here](https://docs.google.com/uc?authuser=0&id=0BwcZml9gnwoZOHcxZFI3Z0ZGUUk&export=download) ## Download -The library is currently release to jCenter and MavenCentral +The library is currently released to both +* jCenter [![Download](https://api.bintray.com/packages/kejunxia/maven/android-mvc/images/download.svg)](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion) +* Maven Central [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc) **Maven:** ```xml com.shipdream android-mvc - 1.3.0 + [LatestVersion] ``` **Gradle:** ```groovy -compile "com.shipdream:android-mvc:1.3.0" +compile "com.shipdream:android-mvc:[LatestVersion]" ``` ## Dependency injection with reference count diff --git a/build.gradle b/build.gradle index 9d51bad..18c29d9 100644 --- a/build.gradle +++ b/build.gradle @@ -29,10 +29,9 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.1.+' + classpath 'com.android.tools.build:gradle:1.3.1' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' - classpath 'com.github.dcendents:android-maven-plugin:1.2' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1' } @@ -74,7 +73,7 @@ ext { gitUrl = 'https://github.com/kejunxia/AndroidMvc.git' // Git repository URL version = [ major: 1, - minor: 3, + minor: 4, patch : 0 ] libGroup = 'com.shipdream' @@ -82,13 +81,13 @@ ext { shouldPublish = false androidMinSdkVersion = 14 - androidCompileSdkVersion = 22 - supportLibVersion = "22.2.1" + androidCompileSdkVersion = 23 + supportLibVersion = "23.1.0" androidTargetSdkVersion = androidCompileSdkVersion lib = [ androidMinSdk: 'com.google.android:android:4.0.1.2', androidSupportLib: "com.android.support:appcompat-v7:$supportLibVersion", - androidBuildToolVersion: "22.0.1", + androidBuildToolVersion: "23.0.1", junit: 'junit:junit:4.12', mokito: 'org.mockito:mockito-core:1.9.5', slf4jApi: "org.slf4j:slf4j-api:$log4jVersion", diff --git a/documents/sites/Site-MarkDown.md b/documents/sites/Site-MarkDown.md index 581cff3..c00d186 100644 --- a/documents/sites/Site-MarkDown.md +++ b/documents/sites/Site-MarkDown.md @@ -33,20 +33,22 @@ First of all, let's look at some problems of the Android development below: - Well tested by jUnit and instrument test with Espresso. ## Download -The library is currently release to jCenter and MavenCentral +The library is currently released to both +* jCenter [![Download](https://api.bintray.com/packages/kejunxia/maven/android-mvc/images/download.svg)](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion) +* Maven Central [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc) **Maven:** ```xml com.shipdream android-mvc - 1.3.0 + [LatestVersion] ``` **Gradle:** ```groovy -compile "com.shipdream:android-mvc:1.3.0" +compile "com.shipdream:android-mvc:[LatestVersion]" ``` ## Samples diff --git a/extension/service-core/build.gradle b/extension/service-core/build.gradle index 44c59ee..2ea8079 100644 --- a/extension/service-core/build.gradle +++ b/extension/service-core/build.gradle @@ -14,9 +14,12 @@ * limitations under the License. */ +plugins { + id "com.jfrog.bintray" version "1.4" +} + apply plugin: 'java' apply plugin: 'maven' -apply plugin: 'com.jfrog.bintray' task sourceJar(type: Jar) { from sourceSets.main.java.srcDirs diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4bd6796..83e4ce0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -19,4 +19,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip +- add org.gradle.daemon=true \ No newline at end of file diff --git a/library/android-mvc-controller/build.gradle b/library/android-mvc-controller/build.gradle index c8fe718..00c5867 100644 --- a/library/android-mvc-controller/build.gradle +++ b/library/android-mvc-controller/build.gradle @@ -14,9 +14,12 @@ * limitations under the License. */ +plugins { + id "com.jfrog.bintray" version "1.4" +} + apply plugin: 'java' apply plugin: 'maven' -apply plugin: 'com.jfrog.bintray' task sourceJar(type: Jar) { from sourceSets.main.java.srcDirs diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Injector.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Injector.java new file mode 100644 index 0000000..615d592 --- /dev/null +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Injector.java @@ -0,0 +1,28 @@ +package com.shipdream.lib.android.mvc; + +import com.shipdream.lib.poke.exception.PokeException; + +public class Injector { + private static MvcGraph mvcGraph; + + /** + * Config the dependencies of MvcGraph. Be careful to use this method because it will dump the + * existing graph and all injectable instances managed by it + * @param dependencies the dependencies. + */ + public static void configGraph(MvcGraph.BaseDependencies dependencies) { + try { + mvcGraph = new MvcGraph(dependencies); + } catch (PokeException e) { + throw new RuntimeException(e); + } + } + + /** + * Get the graph managing injectable objects. + * @return + */ + public static MvcGraph getGraph() { + return mvcGraph; + } +} diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java index 114b8cf..7e6557d 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java @@ -16,7 +16,6 @@ package com.shipdream.lib.android.mvc; -import com.shipdream.lib.android.mvc.controller.BaseController; import com.shipdream.lib.android.mvc.controller.internal.AsyncTask; import com.shipdream.lib.android.mvc.controller.internal.BaseControllerImpl; import com.shipdream.lib.android.mvc.event.bus.EventBus; @@ -24,21 +23,23 @@ import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2V; import com.shipdream.lib.android.mvc.event.bus.internal.EventBusImpl; import com.shipdream.lib.poke.Component; +import com.shipdream.lib.poke.Consumer; import com.shipdream.lib.poke.Graph; import com.shipdream.lib.poke.ImplClassLocator; import com.shipdream.lib.poke.ImplClassLocatorByPattern; import com.shipdream.lib.poke.ImplClassNotFoundException; import com.shipdream.lib.poke.Provider; +import com.shipdream.lib.poke.Provider.OnFreedListener; import com.shipdream.lib.poke.ProviderByClassType; import com.shipdream.lib.poke.ProviderFinderByRegistry; import com.shipdream.lib.poke.Provides; import com.shipdream.lib.poke.ScopeCache; import com.shipdream.lib.poke.SimpleGraph; import com.shipdream.lib.poke.exception.CircularDependenciesException; +import com.shipdream.lib.poke.exception.PokeException; import com.shipdream.lib.poke.exception.ProvideException; import com.shipdream.lib.poke.exception.ProviderConflictException; import com.shipdream.lib.poke.exception.ProviderMissingException; -import com.shipdream.lib.poke.Provider.OnFreedListener; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -172,24 +173,124 @@ public void clearOnProviderFreedListeners() { } /** - * Get an instance matching the type and qualifier. If there is an instance cached, the cached - * instance will be returned otherwise a new instance will be created. - * - *

Note that, not like {@link #inject(Object)} (Object)} this method will NOT increment - * reference count for the injectable object with the same type and qualifier.

- * @param type the type of the object - * @param qualifier the qualifier of the injected object. Null is allowed if no qualifier is specified - * @return The cached object or a new instance matching the type and qualifier - * @throws MvcGraphException throw if exception occurs during getting the instance + * Same as {@link #use(Class, Annotation, Consumer)} except using un-qualified injectable type. + * @param type The type of the injectable instance + * @param consumer Consume to use the instance */ - public T get(Class type, Annotation qualifier) { + public void use(Class type, Consumer consumer) { try { - return graph.get(type, qualifier, Inject.class); - } catch (ProviderMissingException e) { - throw new MvcGraphException(e.getMessage(), e); - } catch (ProvideException e) { + graph.use(type, Inject.class, consumer); + } catch (PokeException e) { throw new MvcGraphException(e.getMessage(), e); - } catch (CircularDependenciesException e) { + } + } + + /** + * Use an injectable instance in the scope of {@link Consumer#consume(Object)} without injecting + * it as a field of an object. This method will automatically retain the instance before + * {@link Consumer#consume(Object)} is called and released after it's returned. As a result, + * it doesn't hold the instance like the field marked by {@link Inject} that will retain the + * reference of the instance until {@link #release(Object)} is called. However, in the + * scope of {@link Consumer#consume(Object)} the instance will be held. + *

For example,

+ *
+        interface Os {
+        }
+
+        static class DeviceComponent extends Component {
+            @Provides
+            @Singleton
+            public Os provide() {
+                return new Os(){
+                };
+            }
+        }
+    
+        class Device {
+            @Inject
+            private Os os;
+        }
+
+        mvcGraph.register(new DeviceComponent());
+
+        //OsReferenceCount = 0
+        mvcGraph.use(Os.class, null, new Consumer() {
+            @Override
+            public void consume(Os instance) {
+                //First time to create the instance.
+                //OsReferenceCount = 1
+            }
+        });
+        //Reference count decremented by use method automatically
+        //OsReferenceCount = 0
+
+        final Device device = new Device();
+        mvcGraph.inject(device);  //OsReferenceCount = 1
+        //New instance created and cached
+
+        mvcGraph.use(Os.class, null, new Consumer() {
+            @Override
+            public void consume(Os instance) {
+                //Since reference count is greater than 0, cached instance will be reused
+                //OsReferenceCount = 2
+                Assert.assertTrue(device.os == instance);
+            }
+        });
+        //Reference count decremented by use method automatically
+        //OsReferenceCount = 1
+
+        mvcGraph.release(device);  //OsReferenceCount = 0
+        //Last instance released, so next time a new instance will be created
+
+        mvcGraph.use(Os.class, null, new Consumer() {
+            @Override
+            public void consume(Os instance) {
+                //OsReferenceCount = 1
+                //Since the cached instance is cleared, the new instance is a newly created one.
+                Assert.assertTrue(device.os != instance);
+            }
+        });
+        //Reference count decremented by use method automatically
+        //OsReferenceCount = 0
+
+        mvcGraph.use(Os.class, null, new Consumer() {
+            @Override
+            public void consume(Os instance) {
+                //OsReferenceCount = 1
+                //Since the cached instance is cleared, the new instance is a newly created one.
+                Assert.assertTrue(device.os != instance);
+            }
+        });
+        //Reference count decremented by use method automatically
+        //OsReferenceCount = 0
+        //Cached instance cleared again
+
+        mvcGraph.use(Os.class, null, new Consumer() {
+            @Override
+            public void consume(Os instance) {
+                //OsReferenceCount = 1
+                mvcGraph.inject(device);
+                //Injection will reuse the cached instance and increment the reference count
+                //OsReferenceCount = 2
+
+                //Since the cached instance is cleared, the new instance is a newly created one.
+                Assert.assertTrue(device.os == instance);
+            }
+        });
+        //Reference count decremented by use method automatically
+        //OsReferenceCount = 1
+
+        mvcGraph.release(device);  //OsReferenceCount = 0
+     * 
+ * @param type The type of the injectable instance + * @param qualifier Qualifier for the injectable instance + * @param consumer Consume to use the instance + * @throws MvcGraphException throw when there are exceptions during the consumption of the instance + */ + public void use(Class type, Annotation qualifier, Consumer consumer) { + try { + graph.use(type, qualifier, Inject.class, consumer); + } catch (PokeException e) { throw new MvcGraphException(e.getMessage(), e); } } @@ -392,14 +493,12 @@ public MvcProvider(List stateManagedObjects, Class type, Class< public T createInstance() throws ProvideException { final T newInstance = (T) super.createInstance(); - if (newInstance instanceof BaseController) { + if (newInstance instanceof BaseControllerImpl) { registerOnInjectedListener(new OnInjectedListener() { @Override public void onInjected(Object object) { - if (object instanceof BaseController) { - BaseController controller = (BaseController) object; - controller.init(); - } + BaseControllerImpl controller = (BaseControllerImpl) object; + controller.onConstruct(); unregisterOnInjectedListener(this); } }); diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/BaseController.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/BaseController.java index eeb4362..f4b88ac 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/BaseController.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/BaseController.java @@ -34,12 +34,6 @@ public interface BaseController { */ MODEL getModel(); - /** - * Initialized the controller and create an empty model. If a specific model needs to be bound - * to this controller use {@link #bindModel(Object, Object)} - */ - void init(); - /** * Bind a prepared non-null model to the controller * @param sender Who wants to bind it diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/BaseControllerImpl.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/BaseControllerImpl.java index 9579baf..f029107 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/BaseControllerImpl.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/BaseControllerImpl.java @@ -60,11 +60,17 @@ interface AndroidPoster { private MODEL model; - @Override - public void init() { + /** + * Called when the controller is constructed. Note that it could be called either when the + * controller is instantiated for the first time or restored by views. + * + *

The model of the controller will be instantiated by model's default no-argument constructor. + * However, if the controller needs to be restored, a new instance of model restored by + * {@link #restoreState(Object)} will replace the model created here.

+ */ + public void onConstruct() { model = createModelInstance(); eventBusC2C.register(this); - onInitialized(); } private MODEL createModelInstance() { @@ -80,14 +86,8 @@ private MODEL createModelInstance() { } /** - * Called when the controller is newly initialized. - */ - protected void onInitialized() { - } - - /** - * Called when the controller is disposed. When the controller is not referenced any more this - * should be called. + * Called when the controller is disposed. This occurs when the controller is de-referenced and + * not retained by any objects. */ @Override public void onDisposed() { @@ -143,10 +143,8 @@ final public Class getStateType() { * Method of {@link StateManaged} that allows {@link StateKeeper} to save and get the state of * which is also the model the controller. *

- * Note that if the controller doesn't need to get its state saved and restored - * automatically. e.g. The controller always loads resource from remote services so that - * its state can be thought persisted by the remote services when {@link #getModelClassType()} - * returns null, the method will have no effect. + * Note that if the controller doesn't need its state saved and restored automatically return + * null in {@link #getModelClassType()} and then this method will have no effect. *

* * @param restoredState The restored state by {@link StateKeeper} that will be bound to the @@ -157,6 +155,13 @@ final public void restoreState(MODEL restoredState) { if (getModelClassType() != null) { bindModel(this, restoredState); } + onRestored(); + } + + /** + * Called when the controller is restored after {@link #restoreState(Object)} is called. + */ + public void onRestored() { } @Override diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java index 7da131a..77c4b5f 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java @@ -17,11 +17,13 @@ package com.shipdream.lib.android.mvc; import com.shipdream.lib.poke.Component; +import com.shipdream.lib.poke.Consumer; import com.shipdream.lib.poke.Graph; +import com.shipdream.lib.poke.Provider.OnFreedListener; +import com.shipdream.lib.poke.Provides; import com.shipdream.lib.poke.ScopeCache; import com.shipdream.lib.poke.exception.ProvideException; import com.shipdream.lib.poke.exception.ProviderConflictException; -import com.shipdream.lib.poke.Provider.OnFreedListener; import org.junit.Assert; import org.junit.Before; @@ -29,10 +31,18 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.lang.annotation.Annotation; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; +import javax.inject.Inject; +import javax.inject.Qualifier; +import javax.inject.Singleton; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; @@ -66,6 +76,225 @@ protected ExecutorService createExecutorService() { }); } + interface Os { + } + + @Qualifier + @Documented + @Retention(RUNTIME) + @interface Apple { + } + + @Qualifier + @Documented + @Retention(RUNTIME) + @interface Google { + } + + static class iOS implements Os { + + } + + static class Android implements Os { + + } + + static class DeviceComponent extends Component { + @Provides + @Singleton + public Os provide() { + return new Android(); + } + + @Provides + @Singleton + @Apple + public Os provideIos() { + return new iOS(); + } + + @Provides + @Singleton + @Google + public Os provideAndroid() { + return new Android(); + } + } + + class Device { + @Inject + private Os android; + + @Inject + @Apple + private Os os; + } + + @Test + public void use_method_should_retain_and_release_instance_without_qualifier_correctly() { + mvcGraph.register(new DeviceComponent()); + + //OsReferenceCount = 0 + mvcGraph.use(Os.class, new Consumer() { + @Override + public void consume(Os instance) { + //First time to create the instance. + //OsReferenceCount = 1 + Assert.assertTrue(instance instanceof Android); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + + final Device device = new Device(); + mvcGraph.inject(device); //OsReferenceCount = 1 + //New instance created and cached + + mvcGraph.use(Os.class, new Consumer() { + @Override + public void consume(Os instance) { + //Since reference count is greater than 0, cached instance will be reused + //OsReferenceCount = 2 + Assert.assertTrue(device.android == instance); + Assert.assertTrue(instance instanceof Android); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 1 + + mvcGraph.release(device); //OsReferenceCount = 0 + //Last instance released, so next time a new instance will be created + + mvcGraph.use(Os.class, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.android != instance); + Assert.assertTrue(instance instanceof Android); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + + mvcGraph.use(Os.class, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.android != instance); + Assert.assertTrue(instance instanceof Android); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + //Cached instance cleared again + + mvcGraph.use(Os.class, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + mvcGraph.inject(device); + //Injection will reuse the cached instance and increment the reference count + //OsReferenceCount = 2 + + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.android == instance); + Assert.assertTrue(instance instanceof Android); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 1 + + mvcGraph.release(device); //OsReferenceCount = 0 + } + + @Test + public void use_method_should_retain_and_release_instance_correctly() { + mvcGraph.register(new DeviceComponent()); + + @Apple + class NeedIoS { + + } + + Annotation iosQualifier = NeedIoS.class.getAnnotation(Apple.class); + + //OsReferenceCount = 0 + mvcGraph.use(Os.class, iosQualifier, new Consumer() { + @Override + public void consume(Os instance) { + //First time to create the instance. + //OsReferenceCount = 1 + Assert.assertTrue(instance instanceof iOS); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + + final Device device = new Device(); + mvcGraph.inject(device); //OsReferenceCount = 1 + //New instance created and cached + + mvcGraph.use(Os.class, iosQualifier, new Consumer() { + @Override + public void consume(Os instance) { + //Since reference count is greater than 0, cached instance will be reused + //OsReferenceCount = 2 + Assert.assertTrue(device.os == instance); + Assert.assertTrue(instance instanceof iOS); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 1 + + mvcGraph.release(device); //OsReferenceCount = 0 + //Last instance released, so next time a new instance will be created + + mvcGraph.use(Os.class, iosQualifier, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.os != instance); + Assert.assertTrue(instance instanceof iOS); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + + mvcGraph.use(Os.class, iosQualifier, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.os != instance); + Assert.assertTrue(instance instanceof iOS); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 0 + //Cached instance cleared again + + mvcGraph.use(Os.class, iosQualifier, new Consumer() { + @Override + public void consume(Os instance) { + //OsReferenceCount = 1 + mvcGraph.inject(device); + //Injection will reuse the cached instance and increment the reference count + //OsReferenceCount = 2 + + //Since the cached instance is cleared, the new instance is a newly created one. + Assert.assertTrue(device.os == instance); + Assert.assertTrue(instance instanceof iOS); + } + }); + //Reference count decremented by use method automatically + //OsReferenceCount = 1 + + mvcGraph.release(device); //OsReferenceCount = 0 + } + @Test public void should_delegate_mvc_graph_properly() throws ProvideException, ProviderConflictException { // Arrange diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseNavigationControllerTest.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseNavigationControllerTest.java index a57ab11..fe9daba 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseNavigationControllerTest.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseNavigationControllerTest.java @@ -21,13 +21,13 @@ import org.junit.Before; public class BaseNavigationControllerTest extends BaseControllerTest{ - protected NavigationController navigationController; + protected NavigationControllerImpl navigationController; @Before public void setUp() throws Exception { super.setUp(); navigationController = new NavigationControllerImpl(); graph.inject(navigationController); - navigationController.init(); + navigationController.onConstruct(); } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/TestRunAsyncTask.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/TestRunAsyncTask.java index f411dcf..7f00e18 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/TestRunAsyncTask.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/TestRunAsyncTask.java @@ -53,7 +53,7 @@ public void setUp() throws Exception { controller = new MyControllerImpl(); graph.inject(controller); - controller.init(); + controller.onConstruct(); eventMonitor = mock(EventMonitor.class); eventBusC2V.register(eventMonitor); diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestBaseControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestBaseControllerImpl.java index 7ef5c22..15b996b 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestBaseControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestBaseControllerImpl.java @@ -118,10 +118,10 @@ public void should_be_able_to_send_and_receive_c2c_events() throws Exception { Controller1 c1 = new Controller1(); graph.inject(c1); - c1.init(); + c1.onConstruct(); Controller2 c2 = new Controller2(); graph.inject(c2); - c2.init(); + c2.onConstruct(); c2.proxy = proxy; Event myEvent = new Event(this); @@ -151,7 +151,7 @@ public void should_log_exception_when_posting_c2c_events_to_null_eventBus() thro TestController controller = new TestController(); graph.inject(controller); - controller.init(); + controller.onConstruct(); controller.setLogger(loggerMock); controller.eventBusC2C = null; @@ -171,7 +171,7 @@ public void should_log_exception_when_posting_c2v_events_to_null_eventBus() thro TestController controller = new TestController(); graph.inject(controller); - controller.init(); + controller.onConstruct(); controller.setLogger(loggerMock); controller.mEventBusC2V = null; @@ -199,6 +199,6 @@ protected Class getModelClassType() { public void should_throw_out_runtime_exception_when_unable_to_create_model_instance() throws Exception { BadController controller = new BadController(); graph.inject(controller); - controller.init(); + controller.onConstruct(); } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestControllerSimpleInject.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestControllerSimpleInject.java index d9d17ff..90bd1f5 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestControllerSimpleInject.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestControllerSimpleInject.java @@ -123,9 +123,9 @@ public void testOnDisposeShouldBeCalledWhenControllerReleased() throws Exception graph.register(new LifeCycleTestControllerComponent(lifeCycleProxy)); TestLifCycleView testView = new TestLifCycleView(); - verify(lifeCycleProxy, times(0)).initCalled(); + verify(lifeCycleProxy, times(0)).onConstructCalled(); graph.inject(testView); - verify(lifeCycleProxy, times(1)).initCalled(); + verify(lifeCycleProxy, times(1)).onConstructCalled(); verify(lifeCycleProxy, times(0)).disposeCalled(); graph.release(testView); diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/LifeCycleTestController.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/LifeCycleTestController.java index db1a782..dd20ceb 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/LifeCycleTestController.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/LifeCycleTestController.java @@ -20,7 +20,7 @@ public interface LifeCycleTestController extends BaseController { interface Proxy { - void initCalled(); + void onConstructCalled(); void disposeCalled(); } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/LifeCycleTestControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/LifeCycleTestControllerImpl.java index b1ed954..3c2f94a 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/LifeCycleTestControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/LifeCycleTestControllerImpl.java @@ -31,9 +31,9 @@ public Class getModelClassType() { } @Override - public void onInitialized() { - super.onInitialized(); - proxy.initCalled(); + public void onConstruct() { + super.onConstruct(); + proxy.onConstructCalled(); } @Override diff --git a/library/android-mvc-test/build.gradle b/library/android-mvc-test/build.gradle index f7215b1..fdabf7a 100644 --- a/library/android-mvc-test/build.gradle +++ b/library/android-mvc-test/build.gradle @@ -23,9 +23,9 @@ dependencies { compile rootProject.lib.logbackAndroidClassic // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' + androidTestCompile 'com.android.support.test:runner:0.4' + androidTestCompile 'com.android.support.test:rules:0.4' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' } diff --git a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java new file mode 100644 index 0000000..43d81fd --- /dev/null +++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java @@ -0,0 +1,73 @@ +/* + * Copyright 2015 Kejun Xia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.shipdream.lib.android.mvc.view.eventv2v; + +import com.shipdream.lib.android.mvc.view.BaseTestCase; +import com.shipdream.lib.android.mvc.view.eventv2v.controller.V2VTestController; +import com.shipdream.lib.android.mvc.view.test.R; + +import org.junit.Test; + +import javax.inject.Inject; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +public class TestV2VEvents extends BaseTestCase { + @Inject + private V2VTestController v2VTestController; + + public TestV2VEvents() { + super(EventBusV2VActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + waitTest(); + } + + @Test + public void should_be_able_to_send_and_receive_v2v_events_among_fragments_services_and_dialogFragments() throws Throwable { + onView(withId(R.id.fragment_mvc_v2v_text)).check(matches(withText("Initial Text"))); + + onView(withId(R.id.fragment_mvc_v2v_btnService)).perform(click()); + + onView(withId(R.id.fragment_mvc_v2v_text)).check(matches(withText("Updated By Service"))); + + onView(withId(R.id.fragment_mvc_v2v_btnDialog)).perform(click()); + + onView(withId(R.id.fragment_mvc_v2v_dialog_text)).check(matches(withText("Initial Dialog Text"))); + + v2VTestController.updateDialogButton(this, "Updated By Under Fragment via V2V event"); + + onView(withId(R.id.fragment_mvc_v2v_dialog_text)).check(matches(withText("Updated By Under Fragment via V2V event"))); + + onView(withId(R.id.fragment_mvc_v2v_dialog_button)).perform(click()); + + onView(withId(R.id.fragment_mvc_v2v_text)).check(matches(withText("Dialog Closed"))); + } + +} diff --git a/library/android-mvc-test/src/main/AndroidManifest.xml b/library/android-mvc-test/src/main/AndroidManifest.xml index a52de66..ae10a4d 100644 --- a/library/android-mvc-test/src/main/AndroidManifest.xml +++ b/library/android-mvc-test/src/main/AndroidManifest.xml @@ -45,6 +45,12 @@ + + + + + diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VActivity.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VActivity.java new file mode 100644 index 0000000..5f75203 --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VActivity.java @@ -0,0 +1,63 @@ +/* + * Copyright 2015 Kejun Xia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.shipdream.lib.android.mvc.view.eventv2v; + +import android.os.Bundle; +import android.view.View; + +import com.shipdream.lib.android.mvc.view.MvcActivity; +import com.shipdream.lib.android.mvc.view.MvcFragment; + +public class EventBusV2VActivity extends MvcActivity { + + @Override + protected Class mapNavigationFragment(String locationId) { + return EventBusV2VFragment.class; + } + + @Override + protected Class getDelegateFragmentClass() { + return HomeFragment.class; + } + + public static class HomeFragment extends DelegateFragment { + private boolean onViewStateRestoredCalled = false; + + @Override + protected void onStartUp() { + getNavigationController().navigateTo(this, "TestFragment", null); + } + + @Override + public void onViewReady(View view, Bundle savedInstanceState, Reason reason) { + super.onViewReady(view, savedInstanceState, reason); + + if (reason.isRestored()) { + if (!onViewStateRestoredCalled) { + throw new IllegalStateException("When activity is restoring, onViewReady must be called after onViewStateRestored to guarantee all state of this fragment is ready to use."); + } + } + } + + @Override + public void onViewStateRestored(Bundle savedInstanceState) { + onViewStateRestoredCalled = true; + super.onViewStateRestored(savedInstanceState); + } + } + +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VDialogFragment.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VDialogFragment.java new file mode 100644 index 0000000..ffe20e9 --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VDialogFragment.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Kejun Xia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.shipdream.lib.android.mvc.view.eventv2v; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.shipdream.lib.android.mvc.view.MvcDialogFragment; +import com.shipdream.lib.android.mvc.view.test.R; + +public class EventBusV2VDialogFragment extends MvcDialogFragment { + private TextView textView; + private View button; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_mvc_v2v_dialog, container); + textView = (TextView) view.findViewById(R.id.fragment_mvc_v2v_dialog_text); + button = view.findViewById(R.id.fragment_mvc_v2v_dialog_button); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + postEventV2V(new Events.OnFragmentTextChanged(v, "Dialog Closed")); + dismiss(); + } + }); + return view; + } + + private void onEvent(Events.OnDialogButtonChanged onButtonUpdated) { + textView.setText(onButtonUpdated.getText()); + } +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VFragment.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VFragment.java new file mode 100644 index 0000000..10a6bad --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VFragment.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 Kejun Xia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.shipdream.lib.android.mvc.view.eventv2v; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.shipdream.lib.android.mvc.view.MvcFragment; +import com.shipdream.lib.android.mvc.view.eventv2v.controller.V2VTestController; +import com.shipdream.lib.android.mvc.view.test.R; + +public class EventBusV2VFragment extends MvcFragment { + private TextView textView; + private View buttonDialog; + private View buttonService; + + @Override + protected int getLayoutResId() { + return R.layout.fragment_mvc_v2v; + } + + @Override + public void onViewReady(View view, Bundle savedInstanceState, Reason reason) { + super.onViewReady(view, savedInstanceState, reason); + + textView = (TextView) view.findViewById(R.id.fragment_mvc_v2v_text); + + buttonDialog = view.findViewById(R.id.fragment_mvc_v2v_btnDialog); + buttonDialog.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final EventBusV2VDialogFragment cityDialog = new EventBusV2VDialogFragment(); + cityDialog.show(getFragmentManager(), "EventBusV2VDialogFragment"); + } + }); + + buttonService = view.findViewById(R.id.fragment_mvc_v2v_btnService); + buttonService.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), EventBusV2VService.class); + getActivity().startService(intent); + } + }); + } + + private void onEvent(Events.OnFragmentTextChanged event) { + textView.setText(event.getText()); + } + + private void onEvent(V2VTestController.EventC2V.OnButtonUpdated onButtonUpdated) { + postEventV2V(new Events.OnDialogButtonChanged(onButtonUpdated.getSender(), onButtonUpdated.getText())); + } + +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VService.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VService.java new file mode 100644 index 0000000..e8606fd --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/EventBusV2VService.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Kejun Xia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.shipdream.lib.android.mvc.view.eventv2v; + +import android.content.Intent; +import android.os.IBinder; + +import com.shipdream.lib.android.mvc.view.MvcService; + +public class EventBusV2VService extends MvcService { + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + super.onStartCommand(intent, flags, startId); + postEventV2V(new Events.OnFragmentTextChanged(this, "Updated By Service")); + return START_STICKY; + } +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/Events.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/Events.java new file mode 100644 index 0000000..7bee1de --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/Events.java @@ -0,0 +1,30 @@ +package com.shipdream.lib.android.mvc.view.eventv2v; + +import com.shipdream.lib.android.mvc.event.BaseEventV2V; + +public interface Events { + abstract class OnTextChanged extends BaseEventV2V { + private final String text; + protected OnTextChanged(Object sender, String text) { + super(sender); + this.text = text; + } + + public String getText() { + return text; + } + } + + class OnFragmentTextChanged extends OnTextChanged { + protected OnFragmentTextChanged(Object sender, String text) { + super(sender, text); + } + } + + class OnDialogButtonChanged extends OnTextChanged { + protected OnDialogButtonChanged(Object sender, String text) { + super(sender, text); + } + } + +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/V2VTestController.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/V2VTestController.java new file mode 100644 index 0000000..bb2cdb5 --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/V2VTestController.java @@ -0,0 +1,23 @@ +package com.shipdream.lib.android.mvc.view.eventv2v.controller; + +import com.shipdream.lib.android.mvc.controller.BaseController; +import com.shipdream.lib.android.mvc.event.BaseEventC2V; + +public interface V2VTestController extends BaseController { + void updateDialogButton(Object sender, String text); + + interface EventC2V { + class OnButtonUpdated extends BaseEventC2V { + private final String text; + + public OnButtonUpdated(Object sender, String text) { + super(sender); + this.text = text; + } + + public String getText() { + return text; + } + } + } +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/internal/V2VTestControllerImpl.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/internal/V2VTestControllerImpl.java new file mode 100644 index 0000000..21d4719 --- /dev/null +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/eventv2v/controller/internal/V2VTestControllerImpl.java @@ -0,0 +1,16 @@ +package com.shipdream.lib.android.mvc.view.eventv2v.controller.internal; + +import com.shipdream.lib.android.mvc.controller.internal.BaseControllerImpl; +import com.shipdream.lib.android.mvc.view.eventv2v.controller.V2VTestController; + +public class V2VTestControllerImpl extends BaseControllerImpl implements V2VTestController{ + @Override + protected Class getModelClassType() { + return null; + } + + @Override + public void updateDialogButton(Object sender, String text) { + postC2VEvent(new EventC2V.OnButtonUpdated(sender, text)); + } +} diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerAImpl.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerAImpl.java index 63d2bad..1e82fdb 100644 --- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerAImpl.java +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerAImpl.java @@ -30,8 +30,8 @@ public Class getModelClassType() { } @Override - protected void onInitialized() { - super.onInitialized(); + public void onConstruct() { + super.onConstruct(); getModel().setTags(new ArrayList()); } diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerBImpl.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerBImpl.java index 9c048c2..ecc429a 100644 --- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerBImpl.java +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerBImpl.java @@ -30,8 +30,8 @@ public Class getModelClassType() { } @Override - protected void onInitialized() { - super.onInitialized(); + public void onConstruct() { + super.onConstruct(); getModel().setTags(new ArrayList()); } diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerCImpl.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerCImpl.java index b1ba546..9306ccd 100644 --- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerCImpl.java +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/injection/controller/internal/ControllerCImpl.java @@ -30,8 +30,8 @@ public Class getModelClassType() { } @Override - protected void onInitialized() { - super.onInitialized(); + public void onConstruct() { + super.onConstruct(); getModel().setTags(new ArrayList()); } diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/ViewPagerHomeFragment.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/ViewPagerHomeFragment.java index 28d8791..89f2051 100644 --- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/ViewPagerHomeFragment.java +++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/ViewPagerHomeFragment.java @@ -3,7 +3,7 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; @@ -86,7 +86,7 @@ public void onDestroy() { super.onDestroy(); } - private class PagerAdapter extends FragmentStatePagerAdapter { + private class PagerAdapter extends FragmentPagerAdapter { private Class[] tabs = new Class[]{ TabFragmentA.class, TabFragmentB.class, diff --git a/library/android-mvc-test/src/main/res/layout/fragment_mvc_v2v.xml b/library/android-mvc-test/src/main/res/layout/fragment_mvc_v2v.xml new file mode 100644 index 0000000..ed1dc31 --- /dev/null +++ b/library/android-mvc-test/src/main/res/layout/fragment_mvc_v2v.xml @@ -0,0 +1,48 @@ + + + + + + + + + +