diff --git a/ChangeLog.md b/ChangeLog.md index d1a987c..037c6df 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,6 @@ +Version:2.0.0 +Simplified event and event bus structure. + Version:1.6.0 * Add BaseManagerImpl. Logic and data shared by multiple controllers can be put into managers and injected into controllers. * Delegate fragment's onViewReady lifecycle will be called after state of all controllers are restored if activity is killed by OS diff --git a/build.gradle b/build.gradle index b5e2b9a..7b5fb28 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,8 +72,8 @@ ext { siteUrl = 'https://github.com/kejunxia/AndroidMvc' // Homepage URL of the library gitUrl = 'https://github.com/kejunxia/AndroidMvc.git' // Git repository URL version = [ - major: 1, - minor: 6, + major: 2, + minor: 0, patch : 0 ] libGroup = 'com.shipdream' diff --git a/extension/build.gradle b/extension/build.gradle index 7d1f16d..2b66a46 100644 --- a/extension/build.gradle +++ b/extension/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/build.gradle b/extension/service-core/build.gradle index afda7c8..583403e 100644 --- a/extension/service-core/build.gradle +++ b/extension/service-core/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/AssetService.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/AssetService.java index e683115..5dbd8fe 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/AssetService.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/AssetService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/NetworkService.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/NetworkService.java index 69f9ab6..28db1d6 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/NetworkService.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/NetworkService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/PreferenceService.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/PreferenceService.java index 29bd05b..cf921d6 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/PreferenceService.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/PreferenceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/AssetServiceImpl.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/AssetServiceImpl.java index 496affa..8ff6904 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/AssetServiceImpl.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/AssetServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/NetworkServiceImpl.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/NetworkServiceImpl.java index 00773da..70446a0 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/NetworkServiceImpl.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/NetworkServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/PreferenceServiceImpl.java b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/PreferenceServiceImpl.java index 038ebbb..1a87f52 100644 --- a/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/PreferenceServiceImpl.java +++ b/extension/service-core/src/main/java/com/shipdream/lib/android/mvc/service/internal/PreferenceServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-core/src/test/java/com/shipdream/lib/android/mvc/service/internal/TestPreferencesServiceImpl.java b/extension/service-core/src/test/java/com/shipdream/lib/android/mvc/service/internal/TestPreferencesServiceImpl.java index cad7d01..5e95f26 100644 --- a/extension/service-core/src/test/java/com/shipdream/lib/android/mvc/service/internal/TestPreferencesServiceImpl.java +++ b/extension/service-core/src/test/java/com/shipdream/lib/android/mvc/service/internal/TestPreferencesServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/build.gradle b/extension/service-mediastore/build.gradle index 69033e0..8b8c255 100644 --- a/extension/service-mediastore/build.gradle +++ b/extension/service-mediastore/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MediaStoreService.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MediaStoreService.java index 53fc8fd..b907c23 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MediaStoreService.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MediaStoreService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MimeTypes.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MimeTypes.java index 9ebe4a7..20b747b 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MimeTypes.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/MimeTypes.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ImageDTO.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ImageDTO.java index 8589fc4..e14055c 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ImageDTO.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ImageDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/MediaDTO.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/MediaDTO.java index ac19294..556dbe2 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/MediaDTO.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/MediaDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ThumbnailDTO.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ThumbnailDTO.java index c2e0083..55bb903 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ThumbnailDTO.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/ThumbnailDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VideoDTO.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VideoDTO.java index 828bc1c..b5b829e 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VideoDTO.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VideoDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VisualMediaDTO.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VisualMediaDTO.java index 75651c9..ffceabb 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VisualMediaDTO.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/dto/VisualMediaDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/internal/MediaStoreServiceImpl.java b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/internal/MediaStoreServiceImpl.java index c7deb0f..770a86e 100644 --- a/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/internal/MediaStoreServiceImpl.java +++ b/extension/service-mediastore/src/main/java/com/shipdream/lib/android/mvc/service/internal/MediaStoreServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/gradle.properties b/gradle.properties index 8b28e42..dec1873 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # -# Copyright 2015 Kejun Xia +# Copyright 2016 Kejun Xia # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 83e4ce0..ee002c4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ # -# Copyright 2015 Kejun Xia +# Copyright 2016 Kejun Xia # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/build.gradle b/library/android-mvc-controller/build.gradle index 00c5867..75bf346 100644 --- a/library/android-mvc-controller/build.gradle +++ b/library/android-mvc-controller/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Constructable.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Constructable.java deleted file mode 100644 index a3c7f07..0000000 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Constructable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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; - -/** - * Object has callback on construction - */ -public interface Constructable { - /** - * Execute onConstruct logic of given object - */ - void onConstruct(); -} 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 index 9caa5cb..a8233e3 100644 --- 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 @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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; import com.shipdream.lib.poke.exception.PokeException; diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateKeeper.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/ModelKeeper.java similarity index 54% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateKeeper.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/ModelKeeper.java index 19c6cab..7883a10 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateKeeper.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/ModelKeeper.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,24 +17,24 @@ package com.shipdream.lib.android.mvc; /** - * StateKeeper can save state of objects implementing {@link StateManaged} into it. The state can + * ModelKeeper can save model of objects implementing {@link MvcBean} into it. The model can * be got back from the keeper later on. */ -public interface StateKeeper { +public interface ModelKeeper { /** - * Save state into this {@link StateKeeper} - * @param state The state to save - * @param type The class type of the state + * Save model into this {@link ModelKeeper} + * @param model The model to save + * @param type The class type of the model * @param */ - void saveState(T state, Class type); + void saveModel(T model, Class type); /** - * Get saved state from the keeper - * @param type The class type of the state + * Retrieves model + * @param type The class type of the model * @param - * @return null if the state with the given type has not been saved or a null state was saved, - * otherwise state saved previously + * @return null if the model with the given type has not been saved or a null model was saved, + * otherwise returns model saved previously */ - T getState(Class type); + T retrieveModel(Class type); } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcBean.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcBean.java new file mode 100644 index 0000000..af02a00 --- /dev/null +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcBean.java @@ -0,0 +1,108 @@ +/* + * Copyright 2016 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; + +import com.shipdream.lib.poke.util.ReflectUtils; + +public abstract class MvcBean { + private MODEL model; + + /** + * Bind model to MvcBean + * @param model non-null model + * @throws IllegalArgumentException thrown when null is being bound + */ + public void bindModel(MODEL model) { + if (model == null) { + throw new IllegalArgumentException("Can't bind null model explicitly."); + } else { + this.model = model; + } + } + + /** + * Called when the MvcBean is injected for the first time or restored when a new instance of + * this MvcBean needs to be instantiated. + * + *

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

+ */ + public void onConstruct() { + model = instantiateModel(); + } + + private MODEL instantiateModel() { + Class type = modelType(); + if (type == null) { + return null; + } else { + try { + return new ReflectUtils.newObjectByType<>(type).newInstance(); + } catch (Exception e) { + throw new RuntimeException("Fail to instantiate model by its default constructor"); + } + } + } + + /** + * Called when the MvcBean is disposed. This occurs when the MvcBean is de-referenced and + * not retained by any other objects. + */ + public void onDisposed() { + } + + /** + * Model represents the state of this MvcBean. + * @return Null if the MvcBean doesn't need to get its model saved and restored automatically. + */ + public MODEL getModel() { + return model; + } + + /** + * Provides the type class of the model. + * @return Implementing class should return the type class of the model that will be used by + * this MvcBean to instantiate its model in {@link #onConstruct()} and restores model in + * {@link #restoreModel(Object)}. Returning null is allowed which means this MvcBean doesn't + * have a model needs to be automatically saved and restored. + */ + public abstract Class modelType(); + + /** + * Restores the model of this MvcBean. + *

+ * Note that when {@link #modelType()} returns null, this method will have no effect. + *

+ * + * @param restoredModel The restored model by {@link ModelKeeper} that will be rebound to the + * MvcBean. + */ + public void restoreModel(MODEL restoredModel) { + if (modelType() != null) { + this.model = restoredModel; + onRestored(); + } + } + + /** + * Called after {@link #restoreModel(Object)} is called only when {@link #modelType()} returns + * a non-null type class. + */ + public void onRestored() { + } +} 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 e58786b..a191975 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,14 @@ package com.shipdream.lib.android.mvc; -import com.shipdream.lib.android.mvc.controller.BaseController; import com.shipdream.lib.android.mvc.controller.NavigationController; import com.shipdream.lib.android.mvc.controller.internal.AsyncTask; import com.shipdream.lib.android.mvc.controller.internal.BaseControllerImpl; import com.shipdream.lib.android.mvc.controller.internal.Navigator; import com.shipdream.lib.android.mvc.controller.internal.Preparer; import com.shipdream.lib.android.mvc.event.bus.EventBus; -import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2C; -import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2V; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusV; import com.shipdream.lib.android.mvc.event.bus.internal.EventBusImpl; import com.shipdream.lib.poke.Component; import com.shipdream.lib.poke.Consumer; @@ -89,7 +88,7 @@ public class MvcGraph { private Logger logger = LoggerFactory.getLogger(getClass()); ScopeCache singletonScopeCache; DefaultProviderFinder defaultProviderFinder; - List stateManagedObjects = new ArrayList<>(); + List mvcBeans = new ArrayList<>(); //Composite graph to hide methods Graph graph; @@ -109,16 +108,12 @@ public void onFreed(Provider provider) { if (obj != null) { //When the cached instance is still there free and dispose it. - if (obj instanceof StateManaged) { - stateManagedObjects.remove(obj); - } - - if (obj instanceof Disposable) { - ((Disposable) obj).onDisposed(); - } + if (obj instanceof MvcBean) { + MvcBean bean = (MvcBean) obj; + bean.onDisposed(); + mvcBeans.remove(obj); - if (obj instanceof BaseControllerImpl) { - logger.trace("--Controller freed - '{}'.", + logger.trace("--MvcBean freed - '{}'.", obj.getClass().getSimpleName()); } } @@ -326,9 +321,9 @@ public void consume(Os instance) { * *

Note that, if navigation is involved in {@link Consumer#consume(Object)}, though the * instance injected is still held until consume method returns, the injected instance may - * loose its state when the next fragment is loaded. This is because Android doesn't load + * loose its model when the next fragment is loaded. This is because Android doesn't load * fragment immediately by fragment manager, instead navigation will be done in the future main - * loop. Therefore, if the state of an injected instance needs to be carried to the next fragment + * loop. Therefore, if the model of an injected instance needs to be carried to the next fragment * navigated to, use {@link NavigationController#navigate(Object)}.{@link Navigator#with(Class, Annotation, Preparer)}

* * @param type The type of the injectable instance @@ -396,29 +391,29 @@ public void unregister(Component component) { } /** - * Save state of all injected objects - * @param stateKeeper The state keeper to manage the state + * Save model of all injected objects + * @param modelKeeper The model keeper managing the model */ - public void saveAllStates(StateKeeper stateKeeper) { - int size = stateManagedObjects.size(); + public void saveAllModels(ModelKeeper modelKeeper) { + int size = mvcBeans.size(); for (int i = 0; i < size; i++) { - StateManaged obj = stateManagedObjects.get(i); - stateKeeper.saveState(obj.getState(), obj.getStateType()); + MvcBean bean = mvcBeans.get(i); + modelKeeper.saveModel(bean.getModel(), bean.modelType()); } } /** - * Restore state of all injected objects - * @param stateKeeper The state keeper to manage the state + * Restore model of all injected objects + * @param modelKeeper The model keeper managing the model */ @SuppressWarnings("unchecked") - public void restoreAllStates(StateKeeper stateKeeper) { - int size = stateManagedObjects.size(); + public void restoreAllModels(ModelKeeper modelKeeper) { + int size = mvcBeans.size(); for (int i = 0; i < size; i++) { - StateManaged obj = stateManagedObjects.get(i); - Object state = stateKeeper.getState(obj.getStateType()); - if(state != null) { - stateManagedObjects.get(i).restoreState(state); + MvcBean bean = mvcBeans.get(i); + Object model = modelKeeper.retrieveModel(bean.modelType()); + if(model != null) { + mvcBeans.get(i).restoreModel(model); } } } @@ -429,21 +424,21 @@ public void restoreAllStates(StateKeeper stateKeeper) { public abstract static class BaseDependencies { /** * Create a new instance of EventBus for events among controllers. This event bus will be - * injected into fields annotated by {@link EventBusC2C}. + * injected into fields annotated by {@link EventBusC}. * * @return The event bus */ - protected EventBus createEventBusC2C() { + protected EventBus createEventBusC() { return new EventBusImpl(); } /** - * Create a new instance of EventBus for events from controllers to views. This event bus - * will be injected into fields annotated by {@link EventBusC2V}. + * Create a new instance of EventBus for events posted to views. This event bus + * will be injected into fields annotated by {@link EventBusV}. * * @return The event bus */ - protected EventBus createEventBusC2V() { + protected EventBus createEventBusV() { return new EventBusImpl(); } @@ -474,17 +469,17 @@ public __Component(ScopeCache scopeCache, BaseDependencies baseDependencies) { } @Provides - @EventBusC2C + @EventBusC @Singleton - public EventBus providesIEventBusC2C() { - return baseDependencies.createEventBusC2C(); + public EventBus providesEventBusC() { + return baseDependencies.createEventBusC(); } @Provides - @EventBusC2V + @EventBusV @Singleton - public EventBus providesIEventBusC2V() { - return baseDependencies.createEventBusC2V(); + public EventBus providesEventBusV() { + return baseDependencies.createEventBusV(); } @Provides @@ -520,7 +515,7 @@ public Provider findProvider(Class type, Annotation qualifier) throws impClass = type; } - provider = new MvcProvider<>(mvcGraph.stateManagedObjects, type, impClass); + provider = new MvcProvider<>(mvcGraph.mvcBeans, type, impClass); provider.setScopeCache(defaultImplClassLocator.getScopeCache()); providers.put(type, provider); } catch (ImplClassNotFoundException e) { @@ -534,11 +529,11 @@ public Provider findProvider(Class type, Annotation qualifier) throws private static class MvcProvider extends ProviderByClassType { private final Logger logger = LoggerFactory.getLogger(MvcGraph.class); - private List stateManagedObjects; + private List mvcBeans; - public MvcProvider(List stateManagedObjects, Class type, Class implementationClass) { + public MvcProvider(List mvcBeans, Class type, Class implementationClass) { super(type, implementationClass); - this.stateManagedObjects = stateManagedObjects; + this.mvcBeans = mvcBeans; } @SuppressWarnings("unchecked") @@ -549,23 +544,19 @@ public T createInstance() throws ProvideException { registerOnInjectedListener(new OnInjectedListener() { @Override public void onInjected(Object object) { - if (object instanceof Constructable) { - Constructable constructable = (Constructable) object; - constructable.onConstruct(); - } - unregisterOnInjectedListener(this); + if (object instanceof MvcBean) { + MvcBean bean = (MvcBean) object; + bean.onConstruct(); - if (logger.isTraceEnabled()) { - if (object instanceof BaseController) { - logger.trace("++Controller injected - '{}'.", - object.getClass().getSimpleName()); - } + logger.trace("++MvcBean injected - '{}'.", + object.getClass().getSimpleName()); } + unregisterOnInjectedListener(this); } }); - if (newInstance instanceof StateManaged) { - stateManagedObjects.add((StateManaged) newInstance); + if (newInstance instanceof MvcBean) { + mvcBeans.add((MvcBean) newInstance); } return newInstance; diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java index 2200c80..944be4d 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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; public class MvcGraphException extends RuntimeException { diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/NavLocation.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/NavLocation.java index fbc0d3a..dd57c38 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/NavLocation.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/NavLocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateManaged.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateManaged.java deleted file mode 100644 index 9800a33..0000000 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/StateManaged.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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; - -/** - * Indicates the object implemented this interface needs to get its state managed. Its state could - * be saved and restored by {@link StateKeeper} - * @param - */ -public interface StateManaged { - /** - * @return The class type of the state - */ - Class getStateType(); - - /** - * @return The state of the object implementing {@link StateManaged} - */ - T getState(); - - /** - * Restores the state of the object implementing {@link StateManaged} - * @param restoredState The restored state that will be applied to the object implementing {@link StateManaged} - */ - void restoreState(T restoredState); -} diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/__MvcGraphHelper.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/__MvcGraphHelper.java index 09cd3eb..6114c94 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/__MvcGraphHelper.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/__MvcGraphHelper.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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; import com.shipdream.lib.android.mvc.controller.NavigationController; 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 5aa8808..cdfef4c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,30 +16,50 @@ package com.shipdream.lib.android.mvc.controller; +import com.shipdream.lib.android.mvc.manager.BaseManagerImpl; + /** - * Base controller interface. + *

+ * Base controller interface. A controller is a proxy between an Android view and core business + * logic. The model of a controller represents the state of the view that the controller is tied to. + * All UI interactions captured by a view should be translated into method calls that the + * corresponding controller understands. Once the method finishes the process and updates model, it + * sends an event back to notify the view. Then view updates based on the updated model or the data + * encapsulated in the event. + *

+ *

+ * Model of the controller will be saved and restored automatically by the MvcFramework. So at any + * time the view can update its state based on the date retrieved from {@link #getModel()} + *

+ * + *

+ * All logic should be abstracted into controller from view as much as possible result in easier + * unit testing. When multiple controllers share same logic and model, the shared logic could be + * broken out into a shared manager. For example, a common scenario is multiple app pages need to + * access the current logged in user status, therefore the corresponding controllers could refer + * to an AccountManager which manages the logged in user. See {@link BaseManagerImpl}. + * + *

*/ public interface BaseController { - /** * Gets the model which represents the state of the controller. Don't change any values of * the model by its setter methods inside a view. A view should only read the values of the * model of the controller through its getters. It's controllers' responsibility to change it's * own model with the bossiness logic in the controller. * - * @return null when the controller doesn't need to get its state saved and restored + * @return null when the controller doesn't need to get its model 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. Otherwise return the instance of the - * model whose state will be automatically saved and restored. + * its model can be thought persisted by the remote services. Otherwise return the instance of the + * model whose model will be automatically saved and restored. */ MODEL getModel(); /** - * Bind a prepared non-null model to the controller + * Binds a non-null model to the controller * @param sender Who wants to bind it * @param model The model to bind to this controller. CANNOT be NULL otherwise a runtime * exception will be thrown */ void bindModel(Object sender, MODEL model); - } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/NavigationController.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/NavigationController.java index 395983f..e2322f6 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/NavigationController.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/NavigationController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ import com.shipdream.lib.android.mvc.MvcGraph; import com.shipdream.lib.android.mvc.NavLocation; import com.shipdream.lib.android.mvc.controller.internal.Navigator; -import com.shipdream.lib.android.mvc.event.BaseEventC2C; -import com.shipdream.lib.android.mvc.event.ValueChangeEventC2V; +import com.shipdream.lib.android.mvc.event.BaseEventC; +import com.shipdream.lib.android.mvc.event.ValueChangeEventV; import com.shipdream.lib.poke.Consumer; /** @@ -127,10 +127,10 @@ public interface NavigationController extends BaseController { + abstract class OnLocationChanged extends ValueChangeEventV { private final Navigator navigator; public OnLocationChanged(Object sender, NavLocation lastValue, NavLocation currentValue, @@ -215,7 +215,7 @@ interface EventC2C { * *

This is a good point to notify controllers to clear the their state.

*/ - class OnAppExit extends BaseEventC2C { + class OnAppExit extends BaseEventC { public OnAppExit(Object sender) { super(sender); } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncExceptionHandler.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncExceptionHandler.java index 26236fd..019c0e0 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncExceptionHandler.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncTask.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncTask.java index 9ceb6b5..94e5be2 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncTask.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/AsyncTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 95b68fb..fd75b96 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,14 @@ package com.shipdream.lib.android.mvc.controller.internal; -import com.shipdream.lib.android.mvc.Constructable; -import com.shipdream.lib.android.mvc.Disposable; -import com.shipdream.lib.android.mvc.StateKeeper; -import com.shipdream.lib.android.mvc.StateManaged; +import com.shipdream.lib.android.mvc.MvcBean; import com.shipdream.lib.android.mvc.controller.BaseController; -import com.shipdream.lib.android.mvc.event.BaseEventC2C; -import com.shipdream.lib.android.mvc.event.BaseEventC2V; +import com.shipdream.lib.android.mvc.event.BaseEventC; +import com.shipdream.lib.android.mvc.event.BaseEventV; import com.shipdream.lib.android.mvc.event.bus.EventBus; -import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2C; -import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2V; -import com.shipdream.lib.poke.util.ReflectUtils; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusV; +import com.shipdream.lib.android.mvc.manager.BaseManagerImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,54 +34,40 @@ import javax.inject.Inject; /** - * Base controller implementation. + * Base controller implementation implements {@link BaseController}. A controller is responsible to + * manage the corresponding view. When multiple controllers have shared logic or data, break them + * out into a manager extending {@link BaseManagerImpl}. For example, a common scenario is multiple + * controllers can share an AccountManager and monitor the account change events. */ -public abstract class BaseControllerImpl implements BaseController, - StateManaged, Constructable, Disposable { +public abstract class BaseControllerImpl extends MvcBean implements BaseController { interface AndroidPoster { - void post(EventBus eventBusC2V, BaseEventC2V eventC2V); + void post(EventBus eventBusV, BaseEventV eventV); } static AndroidPoster androidPoster; protected Logger logger = LoggerFactory.getLogger(getClass()); @Inject - @EventBusC2V - EventBus mEventBusC2V; + @EventBusV + EventBus eventBus2V; @Inject - @EventBusC2C - EventBus eventBusC2C; + @EventBusC + EventBus eventBus2C; @Inject ExecutorService executorService; - private MODEL model; - /** * 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.

+ *

The model of the controller will be instantiated by model's default no-argument + * constructor here whe {@link #modelType()} doesn't return null.

*/ public void onConstruct() { - model = createModelInstance(); - eventBusC2C.register(this); - } - - private MODEL createModelInstance() { - Class type = getStateType(); - if (type == null) { - return null; - } else { - try { - return new ReflectUtils.newObjectByType<>(type).newInstance(); - } catch (Exception e) { - throw new RuntimeException("Fail to instantiate state by its default constructor"); - } - } + super.onConstruct(); + eventBus2C.register(this); } /** @@ -93,121 +76,62 @@ private MODEL createModelInstance() { */ @Override public void onDisposed() { - eventBusC2C.unregister(this); - logger.trace("-Event bus unregistered for Controller - '{}'.", getClass().getName()); - } - - /** - * Model represents the state of view that this controller is managing. - * @return @return Null if the controller doesn't need to get its state saved and restored - * automatically when {@link #getModelClassType()} returns null. Otherwise the model. - */ - @Override - public MODEL getModel() { - return model; + super.onDisposed(); + eventBus2C.unregister(this); } - /** - * Method of {@link StateManaged} that allows {@link StateKeeper} to save and get the state of - * which is also the model the controller. - * - * @return Null if the controller doesn't need to get its state saved and restored - * automatically. Otherwise same as {@link #getModel()} - */ @Override - final public MODEL getState() { - return model; + public void bindModel(Object sender, MODEL model) { + super.bindModel(model); } /** - * Subclass should override this method to provide the class type of the model of the controller. - * - * @return null when the controller doesn't need to get its state saved and restored - * automatically by view. e.g. The controller always loads resource from remote services so that - * its state can be thought managed by the remote services. Otherwise returns the class type - */ - protected abstract Class getModelClassType(); - - /** - * Method of {@link StateManaged} that allows {@link StateKeeper} to save and get the state of - * which is also the model the controller. - * - * @return The class type of the model of the controller + * Model represents the state of the view this controller is managing. + * @return Null if the controller doesn't need to get its model saved and restored automatically + * when {@link #modelType()} returns null. */ @Override - final public Class getStateType() { - return getModelClassType(); + public MODEL getModel() { + return super.getModel(); } /** - * 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 its state saved and restored automatically return - * null in {@link #getModelClassType()} and then this method will have no effect. - *

+ * Post an event to other controllers. The event will be posted on the same thread that the + * caller is running on. * - * @param restoredState The restored state by {@link StateKeeper} that will be bound to the - * controller on the view referencing the controller is restored. - */ - @Override - 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. + * @param event event to controllers */ - public void onRestored() { - } - - @Override - public void bindModel(Object sender, MODEL model) { - if (model == null) { - throw new IllegalArgumentException("Can't bind a null model to a controller explicitly."); + protected void postControllerEvent(final BaseEventC event) { + if (eventBus2C != null) { + eventBus2C.post(event); + } else { + logger.warn("Trying to post event {} to EventBusC which is null", event.getClass().getName()); } - this.model = model; } /** - * Help function to post the event to views on + * Post an event to views on *
    *
  • Android main thread -- when detected android OS. Note that, if the caller is on main thread, event will be * execute immediately on the main thread. Otherwise it will be post to the main thread message queue.
  • *
  • Same thread of caller -- if on usual JVM
  • *
* - * @param eventC2V Controller to View event to be broadcast + * @param event event to views */ - protected void postC2VEvent(final BaseEventC2V eventC2V) { + protected void postViewEvent(final BaseEventV event) { if (androidPoster != null) { //Run on android OS - androidPoster.post(mEventBusC2V, eventC2V); + androidPoster.post(eventBus2V, event); } else { - if (mEventBusC2V != null) { - mEventBusC2V.post(eventC2V); + if (eventBus2V != null) { + eventBus2V.post(event); } else { - logger.warn("Trying to post event {} to EventBusC2V which is null", eventC2V.getClass().getName()); + logger.warn("Trying to post event {} to EventBusV which is null", event.getClass().getName()); } } } - /** - * Help function to post events to other controllers - * - * @param eventC2C Controller to Controller event to be broadcast - */ - protected void postC2CEvent(final BaseEventC2C eventC2C) { - if (eventBusC2C != null) { - eventBusC2C.post(eventC2C); - } else { - logger.warn("Trying to post event {} to EventBusC2C which is null", eventC2C.getClass().getName()); - } - } - /** * Run async task on the default ExecutorService injected as a field of this class. Exceptions * occur during running the task will be suppressed but logged at warning level. Be careful, diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/NavigationControllerImpl.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/NavigationControllerImpl.java index fadda8f..2e6a9c2 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/NavigationControllerImpl.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/NavigationControllerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.shipdream.lib.android.mvc.controller.internal; -import com.shipdream.lib.android.mvc.NavLocation; import com.shipdream.lib.android.mvc.controller.NavigationController; /** @@ -27,7 +26,7 @@ public class NavigationControllerImpl extends BaseControllerImpl getModelClassType() { + public Class modelType() { return NavigationController.Model.class; } @@ -55,5 +54,4 @@ public void navigateBack(Object sender) { public void navigateBack(Object sender, String toLocationId) { navigate(sender).back(toLocationId); } - } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Navigator.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Navigator.java index be1519a..a2c8206 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Navigator.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Navigator.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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.controller.internal; import com.shipdream.lib.android.mvc.Injector; @@ -360,7 +376,7 @@ public Navigator onSettled(OnSettled onSettled) { private void go() { if (navigateEvent != null) { - navigationController.postC2VEvent(navigateEvent); + navigationController.postViewEvent(navigateEvent); if (navigateEvent instanceof NavigationController.EventC2V.OnLocationForward) { String lastLocId = navigateEvent.getLastValue() == null ? null @@ -410,7 +426,7 @@ void __destroy() { private void checkAppExit(Object sender) { NavLocation curLocation = navigationController.getModel().getCurrentLocation(); if (curLocation == null) { - navigationController.postC2CEvent(new NavigationController.EventC2C.OnAppExit(sender)); + navigationController.postControllerEvent(new NavigationController.EventC2C.OnAppExit(sender)); } } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Preparer.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Preparer.java index e8eefb0..d666efa 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Preparer.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/controller/internal/Preparer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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.controller.internal; /** diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEvent.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEvent.java index 4ea250a..2a39637 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEvent.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,25 @@ public abstract class BaseEvent { private final Object sender; + /** + * Construct an event + * @param sender Who initially sent the request that triggers this event + */ public BaseEvent(Object sender) { this.sender = sender; } + /** + * Gets the sender that tracks who initially sends a command leading to trigger this event. It's + * useful when the origin of the event is important. For example, in a login controller there is + * a login function - login(sender). It could be called by a button click operation or an + * automatic call on app start up. Then the event handler may needs to handle the successful + * login differently based on different login requesters when sender is useful to differentiate + * these scenarios. + * + * @return Who initially sent the request that triggers this event. + */ public Object getSender(){ return sender; } - } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2C.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC.java similarity index 73% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2C.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC.java index 06a1bb6..5c5ae7c 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2C.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,12 @@ /** * Base event from controllers to controllers. */ -public abstract class BaseEventC2C extends BaseEvent{ - public BaseEventC2C(Object sender) { +public abstract class BaseEventC extends BaseEvent{ + /** + * Construct a controller event + * @param sender Who initially sent the request that triggers this event + */ + public BaseEventC(Object sender) { super(sender); } } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2V.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV.java similarity index 74% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2V.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV.java index 033871c..00dc6b0 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventC2V.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,12 @@ /** * Base event from controllers to views. */ -public abstract class BaseEventC2V extends BaseEvent{ - public BaseEventC2V(Object sender) { +public abstract class BaseEventV extends BaseEvent{ + /** + * Construct a view event + * @param sender Who initially sent the request that triggers this event + */ + public BaseEventV(Object sender) { super(sender); } } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV2V.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV2V.java deleted file mode 100644 index 1f39274..0000000 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/BaseEventV2V.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.event; - -/** - * Base event from views to views. - */ -public abstract class BaseEventV2V extends BaseEvent{ - public BaseEventV2V(Object sender) { - super(sender); - } -} diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2C.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC.java similarity index 85% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2C.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC.java index 316762b..1677f71 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2C.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ * Value change c2c event. * @param The type fo the value */ -public class ValueChangeEventC2C extends BaseEventC2C{ +public class ValueChangeEventC extends BaseEventC { private final T lastValue; private final T currentValue; - public ValueChangeEventC2C(Object sender, T lastValue, T currentValue) { + public ValueChangeEventC(Object sender, T lastValue, T currentValue) { super(sender); this.lastValue = lastValue; this.currentValue = currentValue; diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2V.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV.java similarity index 85% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2V.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV.java index 358bc2a..c7eb140 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventC2V.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ * Value change c2v event. * @param The type fo the value */ -public class ValueChangeEventC2V extends BaseEventC2V{ +public class ValueChangeEventV extends BaseEventV { private final T lastValue; private final T currentValue; - public ValueChangeEventC2V(Object sender, T lastValue, T currentValue) { + public ValueChangeEventV(Object sender, T lastValue, T currentValue) { super(sender); this.lastValue = lastValue; this.currentValue = currentValue; diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV2V.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV2V.java deleted file mode 100644 index 57ec370..0000000 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/ValueChangeEventV2V.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.event; - -/** - * Value change v2v event. - * @param The type fo the value - */ -public class ValueChangeEventV2V extends BaseEventV2V{ - private final T lastValue; - private final T currentValue; - - public ValueChangeEventV2V(Object sender, T lastValue, T currentValue) { - super(sender); - this.lastValue = lastValue; - this.currentValue = currentValue; - } - - public T getLastValue(){ - return lastValue; - } - - public T getCurrentValue(){ - return currentValue; - } -} diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/EventBus.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/EventBus.java index b82994f..ce978a8 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/EventBus.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/EventBus.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2C.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java similarity index 76% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2C.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java index fe0791a..2869172 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2C.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,12 +23,11 @@ import javax.inject.Qualifier; /** - * Indicates the annotated event bus is for communication among controllers. Events through the - * event bus annotated by this annotation will be received on the same thread as the caller who - * posts them. + * Indicates the annotated event bus is for events to controllers. Events through the event bus + * annotated by this annotation will be received on the same thread as the caller who posts them. */ @Qualifier @Documented @Retention(RetentionPolicy.RUNTIME) -public @interface EventBusC2C { +public @interface EventBusC { } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2V.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java similarity index 86% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2V.java rename to library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java index 14ca6ca..0501854 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC2V.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,12 +23,12 @@ import javax.inject.Qualifier; /** - * Indicates the annotated event bus is for communication from controllers to views. On Android + * Indicates the annotated event bus is for events sent to views. On Android * events through the event bus annotated by this annotation will be guaranteed to be received on * Android's UI thread automatically. */ @Qualifier @Documented @Retention(RetentionPolicy.RUNTIME) -public @interface EventBusC2V { +public @interface EventBusV { } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/internal/EventBusImpl.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/internal/EventBusImpl.java index d2b882e..1511595 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/internal/EventBusImpl.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/event/bus/internal/EventBusImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,14 +107,16 @@ public void post(Object event) { try { entry.getValue().invoke(entry.getKey(), event); } catch (IllegalAccessException e) { - logger.warn(e.getMessage(), e); + //This should never happen since setAccessible has already opened the access + throw new RuntimeException("Not able to post event - " + + event.getClass().getName() + " due to IllegalAccessException: " + e.getMessage(), e); } catch (InvocationTargetException e) { String msg = e.getMessage(); if (msg == null || msg.isEmpty() && e.getCause() != null) { msg = e.getCause().getMessage(); } throw new RuntimeException("Not able to post event - " - + event.getClass().getName() + " due to error: " + msg, e.getCause()); + + event.getClass().getName() + " due to error: " + msg, e); } } } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/manager/BaseManagerImpl.java b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/manager/BaseManagerImpl.java index aece31f..e57a8f6 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/manager/BaseManagerImpl.java +++ b/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/manager/BaseManagerImpl.java @@ -1,106 +1,57 @@ +/* + * Copyright 2016 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.manager; -import com.shipdream.lib.android.mvc.Constructable; -import com.shipdream.lib.android.mvc.Disposable; -import com.shipdream.lib.android.mvc.StateKeeper; -import com.shipdream.lib.android.mvc.StateManaged; -import com.shipdream.lib.poke.util.ReflectUtils; +import com.shipdream.lib.android.mvc.MvcBean; +import com.shipdream.lib.android.mvc.event.BaseEventC; +import com.shipdream.lib.android.mvc.event.bus.EventBus; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; /** - * Abstract manager with state that needs to be managed. A stateful manager can be shared by multiple - * controllers. For example, LoginManager is an good example that will manage the state of logged in - * user. The log in user object usually is a part of the state to remember the logged in user. + * Abstract manager with model that needs to be managed. A manager can be shared by multiple + * controllers. A LoginManager is an good example that manages the state of logged in user. * *

- * Managers should only be serving controllers and not visible to views. + * Managers should only be serving controllers and not visible to views. Managers can post events + * to controllers to notify the state change in the shared manager. *

*/ -public abstract class BaseManagerImpl implements StateManaged, - Constructable, Disposable { - private STATE state; +public abstract class BaseManagerImpl extends MvcBean { + protected Logger logger = LoggerFactory.getLogger(getClass()); - /** - * Bind state to this manager. - * @param state non-null state - * @throws IllegalArgumentException thrown when null is being bound - */ - public void bindState(STATE state) { - if (state == null) { - throw new IllegalArgumentException("Can't bind a null state to a manage explicitly."); - } - this.state = state; - } + @Inject + @EventBusC + private EventBus eventBus2C; /** - * Called when the manager is injected for the first time or restored when a new instance of - * this manager needs to be instantiated. + * Post an event to other controllers. Event will be posted on the same thread as the caller. * - *

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

+ * @param event event to controllers */ - public void onConstruct() { - state = createModelInstance(); - } - - private STATE createModelInstance() { - Class type = getStateType(); - if (type == null) { - return null; + protected void postControllerEvent(final BaseEventC event) { + if (eventBus2C != null) { + eventBus2C.post(event); } else { - try { - return new ReflectUtils.newObjectByType<>(type).newInstance(); - } catch (Exception e) { - throw new RuntimeException("Fail to instantiate state by its default constructor"); - } + logger.warn("Trying to post event {} to EventBusC which is null", event.getClass().getName()); } } - - /** - * Called when the manager is disposed. This occurs when the manager is de-referenced and - * not retained by any other objects. - */ - @Override - public void onDisposed() { - } - - /** - * @return Null if the manager doesn't need to get its state saved and restored automatically. - */ - @Override - final public STATE getState() { - return state; - } - - /** - * @return The class type of the state of the controller that will be used by this manager to - * instantiate its state in {@link #onConstruct()} - */ - @Override - abstract public Class getStateType(); - - /** - * Restore the state of the manager. - *

- * Note that if the manager doesn't need its state saved and restored automatically and return - * null in {@link #getStateType()}, then this method will have no effect. - *

- * - * @param restoredState The restored state by {@link StateKeeper} that will be bound to the - * manager when the views of app are restored. - */ - @Override - final public void restoreState(STATE restoredState) { - if (getStateType() != null) { - bindState(restoredState); - } - onRestored(); - } - - /** - * Called when the manager is restored after {@link #restoreState(Object)} is called. - */ - public void onRestored() { - } - } diff --git a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Disposable.java b/library/android-mvc-controller/src/test/java/android/Phone.java similarity index 72% rename from library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Disposable.java rename to library/android-mvc-controller/src/test/java/android/Phone.java index 0c29a13..d83229c 100644 --- a/library/android-mvc-controller/src/main/java/com/shipdream/lib/android/mvc/Disposable.java +++ b/library/android-mvc-controller/src/test/java/android/Phone.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,10 @@ * limitations under the License. */ -package com.shipdream.lib.android.mvc; +package android; /** - * Object has callback on disposal + * Created by kejun on 1/20/2016. */ -public interface Disposable { - /** - * Execute onDisposed logic of given object - */ - void onDisposed(); +public class Phone { } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestInjector.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestInjector.java index 3477571..8afd16f 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestInjector.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestInjector.java @@ -1,17 +1,32 @@ +/* + * Copyright 2016 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; import com.shipdream.lib.android.mvc.event.bus.EventBus; -import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC2C; -import com.shipdream.lib.android.mvc.event.bus.internal.EventBusImpl; -import com.shipdream.lib.poke.Component; -import com.shipdream.lib.poke.Provides; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusV; import org.junit.After; +import org.junit.Assert; import org.junit.Test; import java.util.concurrent.ExecutorService; -import javax.inject.Singleton; +import javax.inject.Inject; import static org.mockito.Mockito.mock; @@ -26,30 +41,44 @@ public void should_raise_exception_when_getting_mvc_graph_before_configuring_it( Injector.getGraph(); } - static class Comp extends Component { - @Provides - @EventBusC2C - @Singleton - public EventBus providesIEventBusC2C() { - return new EventBusImpl(); - } - } - - @Test(expected = RuntimeException.class) - public void should_raise_runtime_exception_when_exception_occurring_when_configuring_mvc_graph_by_injector() { - MvcGraph.BaseDependencies baseDependencies = new MvcGraph.BaseDependencies() { + @Test + public void should_return_all_cahced_instances_by___MvcGraphHelper() { + Injector.configGraph(new MvcGraph.BaseDependencies() { @Override protected ExecutorService createExecutorService() { return mock(ExecutorService.class); } - }; + }); + Assert.assertEquals(0, __MvcGraphHelper.getAllCachedInstances(Injector.getGraph()).size()); - Injector.configGraph(baseDependencies); + class View1 { + @Inject + @EventBusC + EventBus eventBus; + } - //Register component providing duplicate instances - Injector.getGraph().register(new Comp()); + View1 v1 = new View1(); + Injector.getGraph().inject(v1); + Assert.assertEquals(1, __MvcGraphHelper.getAllCachedInstances(Injector.getGraph()).size()); + + class View2 { + @Inject + @EventBusC + EventBus eventBus; + } + + View2 v2 = new View2(); + Injector.getGraph().inject(v2); + Assert.assertEquals(1, __MvcGraphHelper.getAllCachedInstances(Injector.getGraph()).size()); + + class View3 { + @Inject + @EventBusV + EventBus eventBus; + } - //Exception should be raised here - Injector.configGraph(baseDependencies); + View3 v3 = new View3(); + Injector.getGraph().inject(v3); + Assert.assertEquals(2, __MvcGraphHelper.getAllCachedInstances(Injector.getGraph()).size()); } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestManagerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestManagerImpl.java new file mode 100644 index 0000000..c83f159 --- /dev/null +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestManagerImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright 2016 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; + +import com.shipdream.lib.android.mvc.event.BaseEventC; +import com.shipdream.lib.android.mvc.event.bus.EventBus; +import com.shipdream.lib.android.mvc.manager.BaseManagerImpl; + +import org.junit.After; +import org.junit.Test; + +import java.util.concurrent.ExecutorService; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class TestManagerImpl { + @After + public void tearDown() throws Exception { + Injector.mvcGraph = null; + } + + @Test + public void should_not_crash_when_manager_post_event_even_without_registering_controller_event_bus() { + class MyManager extends BaseManagerImpl { + void doPost(){ + postControllerEvent(mock(BaseEventC.class)); + } + + @Override + public Class modelType() { + return null; + } + }; + + MyManager myManager = new MyManager(); + //Haven't registered controller event yet, but should not throw exception but just log + myManager.doPost(); + } + + @Test + public void should_be_able_to_post_events_to_controller_event_bus_from_manager() { + class MyEvent extends BaseEventC{ + public MyEvent(Object sender) { + super(sender); + } + } + + final MyEvent myEvent = mock(MyEvent.class); + + class MyManager extends BaseManagerImpl { + void doPost(){ + postControllerEvent(myEvent); + } + + @Override + public Class modelType() { + return null; + } + } + + final EventBus bus = mock(EventBus.class); + + Injector.configGraph(new MvcGraph.BaseDependencies() { + @Override + protected EventBus createEventBusC() { + return bus; + } + + @Override + protected ExecutorService createExecutorService() { + return null; + } + }); + + MyManager myManager = new MyManager(); + Injector.getGraph().inject(myManager); + + verify(bus, times(0)).post(anyObject()); + + myManager.doPost(); + + verify(bus, times(1)).post(myEvent); + } +} diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcBean.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcBean.java new file mode 100644 index 0000000..73af695 --- /dev/null +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcBean.java @@ -0,0 +1,186 @@ +/* + * Copyright 2016 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; + +import org.junit.Assert; +import org.junit.Test; + +public class TestMvcBean { + @Test(expected = IllegalArgumentException.class) + public void should_throw_exception_when_bind_null_to_a_mvcBean() { + MvcBean mvcBean = new MvcBean() { + @Override + public Class modelType() { + return String.class; + } + }; + + mvcBean.bindModel(null); + } + + @Test + public void should_rebind_state_after_restoring_mvcBean() { + MvcBean mvcBean = new MvcBean() { + + @Override + public Class modelType() { + return String.class; + } + }; + + Assert.assertNull(mvcBean.getModel()); + + mvcBean.restoreModel("A"); + + Assert.assertEquals("A", mvcBean.getModel()); + } + + @Test + public void should_call_on_restore_call_back_after_a_stateful_mvcBean_is_restored() { + class MyMvcBean extends MvcBean { + private boolean called = false; + + @Override + public Class modelType() { + return String.class; + } + + @Override + public void onRestored() { + super.onRestored(); + called = true; + } + }; + + MyMvcBean mvcBean = new MyMvcBean(); + + Assert.assertFalse(mvcBean.called); + + mvcBean.restoreModel("A"); + + Assert.assertTrue(mvcBean.called); + } + + @Test + public void should_not_call_on_restore_call_back_after_a_non_stateful_mvcBean_is_restored() { + class MyMvcBean extends MvcBean { + private boolean called = false; + + @Override + public Class modelType() { + return null; + } + + @Override + public void onRestored() { + super.onRestored(); + called = true; + } + }; + + MyMvcBean mvcBean = new MyMvcBean(); + + Assert.assertFalse(mvcBean.called); + + mvcBean.restoreModel("A"); + + Assert.assertFalse(mvcBean.called); + } + + public void should_create_state_instance_on_construct_when_the_state_type_is_specified_for_a_mvcBean() { + class MyMvcBean extends MvcBean { + @Override + public Class modelType() { + return String.class; + } + }; + MyMvcBean mvcBean = new MyMvcBean(); + + Assert.assertNull(mvcBean.getModel()); + + mvcBean.onConstruct(); + + Assert.assertNotNull(mvcBean.getModel()); + } + + public void should_NOT_create_state_instance_on_construct_when_the_state_type_is_null_for_a_mvcBean() { + class MyMvcBean extends MvcBean { + @Override + public Class modelType() { + return null; + } + }; + MyMvcBean mvcBean = new MyMvcBean(); + + Assert.assertNull(mvcBean.getModel()); + + mvcBean.onConstruct(); + + Assert.assertNull(mvcBean.getModel()); + } + + @Test(expected = RuntimeException.class) + public void should_throw_exception_out_when_creating_state_failed() { + class BadClass { + {int x = 1 / 0;} + } + + class MyMvcBean extends MvcBean { + @Override + public Class modelType() { + return BadClass.class; + } + }; + + MyMvcBean mvcBean = new MyMvcBean(); + + mvcBean.onConstruct(); + } + + @Test(expected = IllegalArgumentException.class) + public void should_throw_exception_when_binding_null_to_stateful_mvcBean() { + class MyMvcBean extends MvcBean { + @Override + public Class modelType() { + return String.class; + } + }; + + MyMvcBean mvcBean = new MyMvcBean(); + + mvcBean.bindModel(null); + } + + @Test + public void should_be_able_to_successfully_bind_state_to_stateful_mvcBean() { + class MyMvcBean extends MvcBean { + @Override + public Class modelType() { + return String.class; + } + }; + + MyMvcBean mvcBean = new MyMvcBean(); + + Assert.assertNotEquals("B", mvcBean.getModel()); + + mvcBean.bindModel("B"); + + Assert.assertEquals("B", mvcBean.getModel()); + } + +} 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 15c713a..efc0838 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -380,35 +380,35 @@ public void should_be_able_to_hijack_singleton_cache() @Test public void should_be_able_save_and_restore_state_correctly() throws ProvideException, ProviderConflictException { - final StateManaged stateManagedMock = mock(StateManaged.class); + MvcBean mvcBeanMock = mock(MvcBean.class); Object mockState = mock(Object.class); - when(stateManagedMock.getState()).thenReturn(mockState); - when(stateManagedMock.getStateType()).thenReturn(Object.class); + when(mvcBeanMock.getModel()).thenReturn(mockState); + when(mvcBeanMock.modelType()).thenReturn(Object.class); - List stateManagedList = new ArrayList(); - stateManagedList.add(stateManagedMock); - mvcGraph.stateManagedObjects = stateManagedList; + List mvcBeans = new ArrayList(); + mvcBeans.add(mvcBeanMock); + mvcGraph.mvcBeans = mvcBeans; - final StateKeeper stateKeeperMock = mock(StateKeeper.class); + final ModelKeeper modelKeeperMock = mock(ModelKeeper.class); // Act - mvcGraph.saveAllStates(stateKeeperMock); + mvcGraph.saveAllModels(modelKeeperMock); // Verify - verify(stateManagedMock, times(1)).getState(); - verify(stateManagedMock, times(1)).getStateType(); - verify(stateKeeperMock).saveState(eq(mockState), eq(Object.class)); + verify(mvcBeanMock, times(1)).getModel(); + verify(mvcBeanMock, times(1)).modelType(); + verify(modelKeeperMock).saveModel(eq(mockState), eq(Object.class)); // Arrange - reset(stateKeeperMock); + reset(modelKeeperMock); Object stateMock = mock(Object.class); - when(stateKeeperMock.getState(eq(Object.class))).thenReturn(stateMock); + when(modelKeeperMock.retrieveModel(eq(Object.class))).thenReturn(stateMock); - mvcGraph.restoreAllStates(stateKeeperMock); + mvcGraph.restoreAllModels(modelKeeperMock); // Verify - verify(stateManagedMock).restoreState(eq(stateMock)); + verify(mvcBeanMock).restoreModel(eq(stateMock)); } interface UnimplementedInterface{} diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraphHelper.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraphHelper.java new file mode 100644 index 0000000..d5bc2b0 --- /dev/null +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraphHelper.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 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; + +import com.shipdream.lib.android.mvc.event.bus.EventBus; +import com.shipdream.lib.android.mvc.event.bus.annotation.EventBusC; +import com.shipdream.lib.android.mvc.event.bus.internal.EventBusImpl; +import com.shipdream.lib.poke.Component; +import com.shipdream.lib.poke.Provides; + +import org.junit.After; +import org.junit.Test; + +import java.util.concurrent.ExecutorService; + +import javax.inject.Singleton; + +import static org.mockito.Mockito.mock; + +public class TestMvcGraphHelper { + @After + public void tearDown() throws Exception { + Injector.mvcGraph = null; + } + + @Test(expected = RuntimeException.class) + public void should_raise_exception_when_getting_mvc_graph_before_configuring_it() { + Injector.getGraph(); + } + + static class Comp extends Component { + @Provides + @EventBusC + @Singleton + public EventBus providesIEventBusC() { + return new EventBusImpl(); + } + } + + @Test(expected = RuntimeException.class) + public void should_raise_runtime_exception_when_exception_occurrs_by_configuring_mvc_graph_dependencies() { + Injector.getGraph().register(new Component() { + @Provides + @EventBusC + @Singleton + public EventBus providesIEventBusC() { + return mock(EventBus.class); + } + }); + + //Register an event bus that will raise a duplicate registering exception when register the + //BaseDependencies + + MvcGraph.BaseDependencies baseDependencies = new MvcGraph.BaseDependencies() { + @Override + protected ExecutorService createExecutorService() { + return mock(ExecutorService.class); + } + }; + + Injector.configGraph(baseDependencies); + } + + @Test(expected = RuntimeException.class) + public void should_raise_runtime_exception_when_exception_occurrs_by_configuring_mvc_graph_by_injector() { + MvcGraph.BaseDependencies baseDependencies = new MvcGraph.BaseDependencies() { + @Override + protected ExecutorService createExecutorService() { + return mock(ExecutorService.class); + } + }; + + Injector.configGraph(baseDependencies); + + //Register component providing duplicate instances + Injector.getGraph().register(new Comp()); + + //Exception should be raised here + Injector.configGraph(baseDependencies); + } +} diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseControllerTest.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseControllerTest.java index 02aa5b2..a559d71 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseControllerTest.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/BaseControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,24 +33,24 @@ import static org.mockito.Mockito.mock; public class BaseControllerTest { - protected EventBus eventBusC2C; - protected EventBus eventBusC2V; + protected EventBus eventBusC; + protected EventBus eventBusV; protected ExecutorService executorService; private void prepareGraph() { - eventBusC2C = new EventBusImpl(); - eventBusC2V = new EventBusImpl(); + eventBusC = new EventBusImpl(); + eventBusV = new EventBusImpl(); executorService = mock(ExecutorService.class); Injector.configGraph(new MvcGraph.BaseDependencies() { @Override - public EventBus createEventBusC2C() { - return eventBusC2C; + public EventBus createEventBusC() { + return eventBusC; } @Override - public EventBus createEventBusC2V() { - return eventBusC2V; + public EventBus createEventBusV() { + return eventBusV; } @Override @@ -88,13 +88,13 @@ public ControllerDependencies(BaseControllerTest baseControllerTest) { } @Override - public EventBus createEventBusC2C() { - return baseControllerTest.eventBusC2C; + public EventBus createEventBusC() { + return baseControllerTest.eventBusC; } @Override - public EventBus createEventBusC2V() { - return baseControllerTest.eventBusC2V; + public EventBus createEventBusV() { + return baseControllerTest.eventBusV; } @Override 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 fe9daba..56aa421 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 7f00e18..8352326 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public void onEvent(MyControllerImpl.ResourceLoadCanceled event) {} private MyControllerImpl controller; private EventMonitor eventMonitor; - private static final long WAIT_DURATION = MyControllerImpl.LONG_TASK_DURATION + 1000; + private static final long WAIT_DURATION = MyControllerImpl.LONG_TASK_DURATION + 100; @Before public void setUp() throws Exception { @@ -56,7 +56,7 @@ public void setUp() throws Exception { controller.onConstruct(); eventMonitor = mock(EventMonitor.class); - eventBusC2V.register(eventMonitor); + eventBusV.register(eventMonitor); } @Test diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/MyControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/MyControllerImpl.java index 034a4a9..6a1cac6 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/MyControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/MyControllerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.shipdream.lib.android.mvc.controller.internal; -import com.shipdream.lib.android.mvc.event.BaseEventC2V; +import com.shipdream.lib.android.mvc.event.BaseEventV; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -40,7 +40,7 @@ public Logger getLogger() { } @Override - public Class getModelClassType() { + public Class modelType() { return null; } @@ -49,7 +49,7 @@ public AsyncTask loadHeavyResourceSuccessfullyWithoutErrorHandlerWithDefaultExec @Override public void execute() throws Exception { Thread.sleep(LONG_TASK_DURATION); - postC2VEvent(new ResourceLoaded(sender)); + postViewEvent(new ResourceLoaded(sender)); } }); } @@ -69,7 +69,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Override public void execute() throws Exception { Thread.sleep(LONG_TASK_DURATION); - postC2VEvent(new ResourceLoaded(sender)); + postViewEvent(new ResourceLoaded(sender)); } }); } @@ -79,12 +79,12 @@ public AsyncTask loadHeavyResourceSuccessfullyWithErrorHandler(final Object send @Override public void execute() throws Exception { Thread.sleep(LONG_TASK_DURATION); - postC2VEvent(new ResourceLoaded(sender)); + postViewEvent(new ResourceLoaded(sender)); } }, new AsyncExceptionHandler() { @Override public void handleException(Exception exception) { - postC2VEvent(new ResourceLoadFailed(sender, exception)); + postViewEvent(new ResourceLoadFailed(sender, exception)); } }); } @@ -108,7 +108,7 @@ public void execute() throws Exception { }, new AsyncExceptionHandler() { @Override public void handleException(Exception exception) { - postC2VEvent(new ResourceLoadFailed(sender, exception)); + postViewEvent(new ResourceLoadFailed(sender, exception)); } }); } @@ -120,9 +120,9 @@ public AsyncTask loadHeavyResourceAndCancel(final Object sender) { public void execute() throws Exception { Thread.sleep(LONG_TASK_DURATION); if (getState() == State.CANCELED) { - postC2VEvent(new ResourceLoadCanceled(sender)); + postViewEvent(new ResourceLoadCanceled(sender)); } else { - postC2VEvent(new ResourceLoaded(sender)); + postViewEvent(new ResourceLoaded(sender)); } } }; @@ -131,26 +131,26 @@ public void execute() throws Exception { new AsyncExceptionHandler() { @Override public void handleException(Exception exception) { - postC2VEvent(new ResourceLoadFailed(sender, exception)); + postViewEvent(new ResourceLoadFailed(sender, exception)); } }); return asyncTask; } - public static class ResourceLoaded extends BaseEventC2V { + public static class ResourceLoaded extends BaseEventV { public ResourceLoaded(Object sender) { super(sender); } } - public static class ResourceLoadCanceled extends BaseEventC2V { + public static class ResourceLoadCanceled extends BaseEventV { public ResourceLoadCanceled(Object sender) { super(sender); } } - public static class ResourceLoadFailed extends BaseEventC2V { + public static class ResourceLoadFailed extends BaseEventV { private final Exception exception; public ResourceLoadFailed(Object sender, Exception exception) { 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 c408aef..d9b5f6c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ import com.shipdream.lib.android.mvc.controller.BaseControllerTest; import com.shipdream.lib.android.mvc.controller.NavigationController; -import com.shipdream.lib.android.mvc.event.BaseEventC2C; -import com.shipdream.lib.android.mvc.event.BaseEventC2V; +import com.shipdream.lib.android.mvc.event.BaseEventC; +import com.shipdream.lib.android.mvc.event.BaseEventV; import org.junit.Assert; import org.junit.Test; @@ -37,8 +37,8 @@ public class TestBaseControllerImpl extends BaseControllerTest { public void should_return_getState_and_getStateType_correctly() throws Exception { NavigationControllerImpl navigationController = new NavigationControllerImpl(); - Assert.assertTrue(navigationController.getModel() == navigationController.getState()); - Assert.assertTrue(navigationController.getStateType() == navigationController.getModelClassType()); + Assert.assertTrue(navigationController.getModel() == navigationController.getModel()); + Assert.assertTrue(navigationController.modelType() == navigationController.modelType()); } @Test @@ -48,13 +48,13 @@ public void should_rebind_model_on_restoration_when_state_class_type_is_NOT_null NavigationController.Model restoreState = mock(NavigationController.Model.class); Assert.assertNotEquals(restoreState, navigationController.getModel()); - navigationController.restoreState(restoreState); + navigationController.restoreModel(restoreState); Assert.assertEquals(restoreState, navigationController.getModel()); } class StatelessController extends BaseControllerImpl { @Override - protected Class getModelClassType() { + public Class modelType() { return null; } } @@ -63,10 +63,10 @@ protected Class getModelClassType() { public void should_rebind_model_on_restoration_when_state_class_type_is_null() throws Exception { StatelessController controller = new StatelessController(); //Pre-verify - Assert.assertNull(controller.getModelClassType()); + Assert.assertNull(controller.modelType()); Assert.assertNull(controller.getModel()); - controller.restoreState("Non-Null State"); + controller.restoreModel("Non-Null State"); Assert.assertNull(controller.getModel()); } @@ -77,7 +77,7 @@ public void should_throw_exception_on_binding_null_model() throws Exception { navigationController.bindModel(this, null); } - class Event extends BaseEventC2C { + class Event extends BaseEventC { public Event(Object sender) { super(sender); } @@ -85,12 +85,12 @@ public Event(Object sender) { static class Controller1 extends BaseControllerImpl { @Override - protected Class getModelClassType() { + public Class modelType() { return null; } - void postMyEvent(BaseEventC2C e) { - postC2CEvent(e); + void postMyEvent(BaseEventC e) { + postControllerEvent(e); } } @@ -102,7 +102,7 @@ interface EventProxy { EventProxy proxy; @Override - protected Class getModelClassType() { + public Class modelType() { return null; } @@ -135,7 +135,7 @@ public void should_be_able_to_send_and_receive_c2c_events() throws Exception { class TestController extends BaseControllerImpl { @Override - protected Class getModelClassType() { + public Class modelType() { return null; } @@ -153,12 +153,12 @@ public void should_log_exception_when_posting_c2c_events_to_null_eventBus() thro graph.inject(controller); controller.onConstruct(); controller.setLogger(loggerMock); - controller.eventBusC2C = null; + controller.eventBus2C = null; - BaseEventC2C event = new BaseEventC2C(this){}; + BaseEventC event = new BaseEventC(this){}; //Act - controller.postC2CEvent(event); + controller.postControllerEvent(event); //Assert verify(loggerMock).warn(anyString(), anyVararg()); @@ -173,12 +173,12 @@ public void should_log_exception_when_posting_c2v_events_to_null_eventBus() thro graph.inject(controller); controller.onConstruct(); controller.setLogger(loggerMock); - controller.mEventBusC2V = null; + controller.eventBus2V = null; - BaseEventC2V event = new BaseEventC2V(this){}; + BaseEventV event = new BaseEventV(this){}; //Act - controller.postC2VEvent(event); + controller.postViewEvent(event); //Assert verify(loggerMock).warn(anyString(), anyVararg()); @@ -190,7 +190,7 @@ private PrivateModel() {} class BadController extends BaseControllerImpl { @Override - protected Class getModelClassType() { + public Class modelType() { return PrivateModel.class; } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestControllerInjectionByComponent.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestControllerInjectionByComponent.java index 628a8ab..869e353 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestControllerInjectionByComponent.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestControllerInjectionByComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestNavigationController.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestNavigationController.java index 3544540..fbc166b 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestNavigationController.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/controller/internal/TestNavigationController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.internal.matchers.Null; import org.slf4j.Logger; import java.lang.annotation.Annotation; @@ -136,7 +135,7 @@ public void shouldClearAllNavigationHistory() throws Exception { public void shouldBeAbleToNavigateBackOneByOne() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); prepareLocationHistory(); @@ -198,7 +197,7 @@ public void shouldBeAbleToNavigateBackOneByOne() throws Exception { public void shouldBeAbleToNavigateBackToGivenLocation() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); prepareLocationHistory(); @@ -221,7 +220,7 @@ public void shouldBeAbleToNavigateBackToGivenLocation() throws Exception { public void shouldBeAbleToNavigateBackToFirstLocation() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); prepareLocationHistory(); @@ -250,7 +249,7 @@ public void onEvent(NavigationController.EventC2C.OnAppExit event) {} = ArgumentCaptor.forClass(NavigationController.EventC2C.OnAppExit.class); AppExitListener exitListener = mock(AppExitListener.class); - eventBusC2C.register(exitListener); + eventBusC.register(exitListener); prepareLocationHistory(); @@ -279,7 +278,7 @@ public void onEvent(NavigationController.EventC2C.OnAppExit event) {} = ArgumentCaptor.forClass(NavigationController.EventC2C.OnAppExit.class); AppExitListener exitListener = mock(AppExitListener.class); - eventBusC2C.register(exitListener); + eventBusC.register(exitListener); prepareLocationHistory(); @@ -295,7 +294,7 @@ public void onEvent(NavigationController.EventC2C.OnAppExit event) {} public void should_not_raise_navigate_back_event_when_navigate_to_first_location_from_the_first_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); navigationController.navigateTo(this, locId1); @@ -312,7 +311,7 @@ public void should_not_raise_navigate_back_event_when_navigate_to_first_location public void should_not_raise_navigate_back_event_when_navigate_to_unknown_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); prepareLocationHistory(); @@ -329,7 +328,7 @@ public void should_not_raise_navigate_back_event_when_navigate_to_unknown_locati public void should_not_raise_navigate_back_event_when_fast_back_navigate_from_null_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); - eventBusC2V.register(backListener); + eventBusV.register(backListener); // Arrange navigationController.navigateBack(this, "any location"); @@ -642,7 +641,7 @@ public void should_invoke_on_settled_when_navigation_is_done() throws Exception private ForwardListener prepareLocationHistory() { //mock the subscriber ForwardListener forwardListener = mock(ForwardListener.class); - eventBusC2V.register(forwardListener); + eventBusV.register(forwardListener); navigationController.navigateTo(this, locId1); diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/TestEvent.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/TestEvent.java index 438e8ca..4fb4fb0 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/TestEvent.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/TestEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ public void should_return_past_and_current_value_given_in_constructor_for_ValueC String v1 = "v1"; String v2 = "v2"; Object sender = new Object(); - ValueChangeEventC2C eventC2C = new ValueChangeEventC2C(sender, v1, v2); + ValueChangeEventC eventC2C = new ValueChangeEventC(sender, v1, v2); Assert.assertEquals(sender, eventC2C.getSender()); Assert.assertEquals(v1, eventC2C.getLastValue()); @@ -38,7 +38,7 @@ public void should_return_past_and_current_value_given_in_constructor_for_ValueC String v1 = "v1"; String v2 = "v2"; Object sender = new Object(); - ValueChangeEventC2V eventC2V = new ValueChangeEventC2V(sender, v1, v2); + ValueChangeEventV eventC2V = new ValueChangeEventV(sender, v1, v2); Assert.assertEquals(sender, eventC2V.getSender()); Assert.assertEquals(v1, eventC2V.getLastValue()); @@ -50,7 +50,7 @@ public void should_return_past_and_current_value_given_in_constructor_for_ValueC String v1 = "v1"; String v2 = "v2"; Object sender = new Object(); - ValueChangeEventV2V eventV2V = new ValueChangeEventV2V(sender, v1, v2); + ValueChangeEventV eventV2V = new ValueChangeEventV(sender, v1, v2); Assert.assertEquals(sender, eventV2V.getSender()); Assert.assertEquals(v1, eventV2V.getLastValue()); diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/bus/internal/TestEventBus.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/bus/internal/TestEventBus.java index 604249b..1597e8a 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/bus/internal/TestEventBus.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/event/bus/internal/TestEventBus.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,14 @@ package com.shipdream.lib.android.mvc.event.bus.internal; import org.junit.Assert; - import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -51,6 +54,105 @@ public void shouldThrowIllegalArgumentExceptionToPostNullEvent() { eventBus.post(null); } + @Test + public void should_subscribers_methods_inherited_from_system_classes() { + //Arrange + class Event1{} + class Event2{} + class Event3{} + + //Test java.xxx + class Subscriber extends java.io.InputStream{ + public void onEvent(Event1 event1) { + } + + @Override + public int read() throws IOException { + return 0; + } + } + + Subscriber sub = new Subscriber(); + + //Action + EventBusImpl eventBus1 = new EventBusImpl(); + eventBus1.register(sub); + + //Assert + Assert.assertEquals(eventBus1.subscribers.size(), 1); + Assert.assertTrue(eventBus1.subscribers.keySet().contains(Event1.class)); + + eventBus1.unregister(sub); + Assert.assertEquals(eventBus1.subscribers.size(), 0); + + //Test javax.xxx + class Subscriber2 extends javax.naming.Binding { + public Subscriber2(String name, Object obj) { + super(name, obj); + } + + public void onEvent(Event1 event1) { + } + } + Subscriber2 sub2 = new Subscriber2("", ""); + + //Action + EventBusImpl eventBus2 = new EventBusImpl(); + eventBus2.register(sub2); + + //Assert + Assert.assertEquals(eventBus2.subscribers.size(), 1); + Assert.assertTrue(eventBus2.subscribers.keySet().contains(Event1.class)); + + eventBus2.unregister(sub2); + Assert.assertEquals(eventBus2.subscribers.size(), 0); + + //Test android.xxx + class Subscriber3 extends android.Phone{ + public void onEvent(Event2 event2) { + } + public void onEvent(Event3 event3) { + } + } + Subscriber3 sub3 = new Subscriber3(); + + EventBusImpl eventBus3 = new EventBusImpl(); + eventBus3.register(sub3); + + Assert.assertEquals(eventBus3.subscribers.size(), 2); + Assert.assertTrue(eventBus3.subscribers.keySet().contains(Event2.class)); + Assert.assertTrue(eventBus3.subscribers.keySet().contains(Event3.class)); + + eventBus3.unregister(sub3); + Assert.assertEquals(eventBus3.subscribers.size(), 0); + } + + @Test + public void should_throw_runtime_exception_when_posting_event_encounters_illegalAccessException() { + //Arrange + class Event1{} + + //Test java.xxx + class Subscriber{ + void onEvent(Event1 event1) { + throw new RuntimeException("Opps..."); + } + } + Subscriber sub = new Subscriber(); + + //Action + EventBusImpl eventBus = new EventBusImpl(); + eventBus.register(sub); + + try { + eventBus.post(new Event1()); + + fail("Should caught InvocationTargetException"); + } catch (RuntimeException e) { + Assert.assertTrue(e.getCause() instanceof InvocationTargetException); + } + } + @Test public void shouldBeAbleToRegisterEventsForSingleSubscriber() { //Arrange diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseControllerDependencies.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseControllerDependencies.java index 5b1d168..c74fc42 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseControllerDependencies.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseControllerDependencies.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseTestCases.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseTestCases.java index 5ab507f..3221dc9 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseTestCases.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/BaseTestCases.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 8491cec..c2f4907 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestInjectCustomControllerDependencies.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestInjectCustomControllerDependencies.java index 1d39312..35b2f95 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestInjectCustomControllerDependencies.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestInjectCustomControllerDependencies.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestOverridesControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestOverridesControllerImpl.java index 11a7555..d567ca9 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestOverridesControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/TestOverridesControllerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ public String print() { return printContent; } @Override - public Class getModelClassType() { + public Class modelType() { return null; } @Override diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/AndroidPart.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/AndroidPart.java index ba9d6cd..f4bb3fb 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/AndroidPart.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/AndroidPart.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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.inject.testNameMapping.controller; public interface AndroidPart { 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 dd20ceb..d9cfbaa 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/MissingImplController.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/MissingImplController.java index 04cd752..b60e347 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/MissingImplController.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/MissingImplController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintController.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintController.java index 4f9a68e..bd4f283 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintController.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintModel.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintModel.java index c6526c7..c22585f 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintModel.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrintModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrinterController2.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrinterController2.java index 14b6175..5d1c75a 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrinterController2.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/PrinterController2.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerController.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerController.java index 1ee5f85..d7295f1 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerController.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerModel.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerModel.java index c8b357b..291f229 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerModel.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/TimerModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/AndroidPartImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/AndroidPartImpl.java index 0065359..588a32c 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/AndroidPartImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/AndroidPartImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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.inject.testNameMapping.controller.internal; import com.shipdream.lib.android.mvc.inject.testNameMapping.controller.AndroidPart; 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 3c2f94a..b320c97 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ public class LifeCycleTestControllerImpl extends BaseControllerImpl implements L private Proxy proxy; @Override - public Class getModelClassType() { + public Class modelType() { return null; } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrintControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrintControllerImpl.java index f452995..49d2913 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrintControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrintControllerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ public String print() { @SuppressWarnings("unchecked") @Override - public Class getModelClassType() { + public Class modelType() { return PrintModel.class; } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrinterController2Impl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrinterController2Impl.java index c242e7f..c1ae4f2 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrinterController2Impl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/PrinterController2Impl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public InkManager getInkManager() { } @Override - public Class getModelClassType() { + public Class modelType() { return PrintModel.class; } } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/TimerControllerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/TimerControllerImpl.java index ef86b39..14a8e45 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/TimerControllerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/controller/internal/TimerControllerImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 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.inject.testNameMapping.controller.internal; import com.shipdream.lib.android.mvc.controller.internal.BaseControllerImpl; @@ -6,7 +22,7 @@ public class TimerControllerImpl extends BaseControllerImpl implements TimerController{ @Override - protected Class getModelClassType() { + public Class modelType() { return TimerModel.class; } diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/InkManager.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/InkManager.java index b903208..33541fd 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/InkManager.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/InkManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/internal/InkManagerImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/internal/InkManagerImpl.java index 516049a..1383afb 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/internal/InkManagerImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/manager/internal/InkManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/Cartridge.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/Cartridge.java index f43ec6f..9e6b39c 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/Cartridge.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/Cartridge.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/internal/CartridgeImpl.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/internal/CartridgeImpl.java index 7acc771..0f7f739 100644 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/internal/CartridgeImpl.java +++ b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/inject/testNameMapping/service/internal/CartridgeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/manager/TestStatefulManager.java b/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/manager/TestStatefulManager.java deleted file mode 100644 index 3816e5e..0000000 --- a/library/android-mvc-controller/src/test/java/com/shipdream/lib/android/mvc/manager/TestStatefulManager.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.shipdream.lib.android.mvc.manager; - -import org.junit.Assert; -import org.junit.Test; - -public class TestStatefulManager { - @Test(expected = IllegalArgumentException.class) - public void should_throw_exception_when_bind_null_to_stateful_manager() { - BaseManagerImpl manager = new BaseManagerImpl() { - @Override - public Class getStateType() { - return String.class; - } - }; - - manager.bindState(null); - } - - @Test - public void should_rebind_state_after_restoring_manager() { - BaseManagerImpl manager = new BaseManagerImpl() { - - @Override - public Class getStateType() { - return String.class; - } - }; - - Assert.assertNull(manager.getState()); - - manager.restoreState("A"); - - Assert.assertEquals("A", manager.getState()); - } - - @Test - public void should_call_on_restore_call_back_after_manager_is_restored() { - class MyManager extends BaseManagerImpl { - private boolean called = false; - - @Override - public Class getStateType() { - return String.class; - } - - @Override - public void onRestored() { - super.onRestored(); - called = true; - } - }; - - MyManager manager = new MyManager(); - - Assert.assertFalse(manager.called); - - manager.restoreState("A"); - - Assert.assertTrue(manager.called); - } - - public void should_create_state_instance_on_construct_when_the_state_type_is_specified_for_a_stateful_manager() { - class MyManager extends BaseManagerImpl { - @Override - public Class getStateType() { - return String.class; - } - }; - MyManager manager = new MyManager(); - - Assert.assertNull(manager.getState()); - - manager.onConstruct(); - - Assert.assertNotNull(manager.getState()); - } - - public void should_NOT_create_state_instance_on_construct_when_the_state_type_is_null_for_a_stateful_manager() { - class MyManager extends BaseManagerImpl { - @Override - public Class getStateType() { - return null; - } - }; - MyManager manager = new MyManager(); - - Assert.assertNull(manager.getState()); - - manager.onConstruct(); - - Assert.assertNull(manager.getState()); - } - - @Test(expected = RuntimeException.class) - public void should_throw_excpetion_out_when_creating_state_failed() { - class BadClass { - {int x = 1 / 0;} - } - - class MyManager extends BaseManagerImpl { - @Override - public Class getStateType() { - return BadClass.class; - } - }; - - MyManager manager = new MyManager(); - - manager.onConstruct(); - } - - @Test(expected = IllegalArgumentException.class) - public void should_throw_excpetion_when_binding_null_to_stateful_manager() { - class MyManager extends BaseManagerImpl { - @Override - public Class getStateType() { - return String.class; - } - }; - - MyManager manager = new MyManager(); - - manager.bindState(null); - } - - @Test - public void should_be_able_to_successfully_bind_state_to_stateful_manager() { - class MyManager extends BaseManagerImpl { - @Override - public Class getStateType() { - return String.class; - } - }; - - MyManager manager = new MyManager(); - - Assert.assertNotEquals("B", manager.getState()); - - manager.bindState("B"); - - Assert.assertEquals("B", manager.getState()); - } - -} diff --git a/library/android-mvc-test/build.gradle b/library/android-mvc-test/build.gradle index 9284fe3..789b1df 100644 --- a/library/android-mvc-test/build.gradle +++ b/library/android-mvc-test/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/android-mvc-test/src/main/AndroidManifest.xml b/library/android-mvc-test/src/main/AndroidManifest.xml index ac2e652..9be077d 100644 --- a/library/android-mvc-test/src/main/AndroidManifest.xml +++ b/library/android-mvc-test/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/NoteApp.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/NoteApp.java index 08adf4d..5c4dfa5 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/NoteApp.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/NoteApp.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/activity/MainActivity.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/activity/MainActivity.java index 1d16585..508a084 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/activity/MainActivity.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/activity/MainActivity.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/BaseFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/BaseFragment.java index 50dfbf4..ee6bb77 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/BaseFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/BaseFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/MainFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/MainFragment.java index 4ecff72..6188606 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/MainFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/MainFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteCreateFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteCreateFragment.java index 8e3bf5b..6287556 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteCreateFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteCreateFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteDetailFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteDetailFragment.java index ea09a5b..1f17af8 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteDetailFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteDetailFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteListFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteListFragment.java index f2a0689..093f446 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteListFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteTabletLandscape.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteTabletLandscape.java index 9a73c62..c2a865e 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteTabletLandscape.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/NoteTabletLandscape.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherCityListFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherCityListFragment.java index beb5eb2..947bf0f 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherCityListFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherCityListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; -import com.shipdream.lib.android.mvc.event.BaseEventV2V; +import com.shipdream.lib.android.mvc.event.BaseEventV; import com.shipdream.lib.android.mvc.samples.note.R; import com.shipdream.lib.android.mvc.samples.note.controller.WeatherController; import com.shipdream.lib.android.mvc.samples.note.model.WeatherModel; @@ -106,7 +106,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { buttonOK.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - postEventV2V(new EventV2V.OnOkButtonClicked(v)); + postToViews(new EventV2V.OnOkButtonClicked(v)); } }); @@ -145,7 +145,7 @@ private void updateList() { } public static class EventV2V { - public static class OnOkButtonClicked extends BaseEventV2V { + public static class OnOkButtonClicked extends BaseEventV { protected OnOkButtonClicked(Object sender) { super(sender); } diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherListFragment.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherListFragment.java index 5ce4cb9..8bb0e60 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherListFragment.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/fragment/WeatherListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/internal/PreferenceServiceImpl.java b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/internal/PreferenceServiceImpl.java index 7e0a73d..3a00f5d 100644 --- a/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/internal/PreferenceServiceImpl.java +++ b/samples/note/android/src/main/java/com/shipdream/lib/android/mvc/samples/note/view/internal/PreferenceServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Kejun Xia + * Copyright 2016 Kejun Xia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/note/android/src/main/res/drawable/nav_item.xml b/samples/note/android/src/main/res/drawable/nav_item.xml index 0dcbae7..0e19b94 100644 --- a/samples/note/android/src/main/res/drawable/nav_item.xml +++ b/samples/note/android/src/main/res/drawable/nav_item.xml @@ -1,6 +1,6 @@