diff --git a/.travis.yml b/.travis.yml
index a8107c6..21c1e63 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,7 +10,7 @@ android:
- build-tools-23.0.3
# The SDK version used to compile your project
- - android-23
+ - android-24
# Additional components
- extra-google-m2repository
@@ -31,7 +31,7 @@ android:
script: "./gradlew build"
jdk:
- - oraclejdk7
+ - oraclejdk8
env:
- TERM=dumb
diff --git a/ChangeLog.md b/ChangeLog.md
index b1542d9..4d376af 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,4 +1,8 @@
-Version: 3.0
+Version: 3.0.1
+* Fix issue that interim navigation pages are not popped out on back navgation correctly
+* Uplift target compile SDK to 24.
+
+Version: 3.0.0
* View and Controller are one to one mapped
* FragmentController introduced that is bound with the same lifecycle as MvcFragment. It is easier to act as a presenter of fragment
* Able to post actions to ui thread from controllers by protected uiThreadRunner field
diff --git a/README.md b/README.md
index e519599..cb2a686 100644
--- a/README.md
+++ b/README.md
@@ -1,198 +1,169 @@
# AndroidMvc Framework
[](https://travis-ci.org/kejunxia/AndroidMvc)
[](https://coveralls.io/r/kejunxia/AndroidMvc)
-[](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion)
-[](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc)
-
-## Overview
-- **View**: Fragments that to caputre user interaction and reflect view model managed by controller. More broadyly it can be anything included in Android SDK including notification, activity, services etc that users can see and touch.
-- **Controller**: The abstraction of a view/fragment. Define methods to be consumered by the view and then fire events back to the view to notify it update its UI. So views and controllers are one to one relation. Every view has and only has one controller.
-- **Model**: Represents the state of view. Can be thought as ViewModel in MVVM pattern. Each controller has a model. So model-controller is one to one relation so does model-controller-view.
-- **Service**: Data access layer below controller. Provides interface for controllers/managers to access data from database/clound api/sharedPreferences etc. It hides details of data tansportation so it can be easiy swapped by different data source as well as easily mocked in unit tests.
-- **Manager**: What about controllers have shared logic? Break shared code out into managers. If managers need to access data. Inject services into managers.
-
-See the illustration below
-
-
+[](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion)
## Features
- - Easy to apply MVC/MVVM pattern for Android development
- - Event driven
- - Easy testing for controllers running directly on JVM without Android dependency
+
+ - Easy to implement MVC/MVP/MVVM pattern for Android development
+ - Enhanced Android life cycles - e.g. when view needs to refresh when being brought back to foreground but not on rotation, onResume() is not specific to differentiate the two scenarios. Android mvc framework provides more granular life cycles
+ - All fragment life cycles are mapped into controllers thus logic in life cycles are testable on JVM
+ - Easy navigation between pages. Navigation is done in controllers instead of views so navigation can be unit tested on JVM
+ - Easy unit test on JVM since controllers don't depend on any Android APIs
+ - Built in event bus. Event bus also automatically guarantees post event view events on the UI thread
+ - Automatically save and restore instance state. You don't have to touch onSaveInstance and onCreate(savedInstanceState) with countless key-value pairs, it's all managed by the framework.
- [Dependency injection with Poke to make mock easy](https://github.com/kejunxia/AndroidMvc/tree/master/library/poke)
- - Manage navigation by NavigationController which is also testable
- - Improved Fragment life cycles - e.g. Differentiate why view is created: 1. Reason.isNewInstance(), 2. Reason.isFirstTime(), 3. Reason.isRestored(), 4 Reason.isRotated()
- - Automatically save restore instance state
+ - Well tested - non-Android components are tested as the test coverage shown above (over 90%). For Android dependent module "android-mvc", it's tested by real emulator with [this UI test module](https://github.com/kejunxia/AndroidMvc/tree/master/library/android-mvc-test), even with "Don't Keep Activities" turned on in dev options to guarantee your app doesn't crash due to loss of instance state after it's killed by OS in the background!
-## Samples
- - **[Counter](https://docs.google.com/uc?authuser=0&id=0BwcZml9gnwoZRS1pYURMMVRzdHM&export=download)** - A simple sample demonstrates how to use the framework including dependency injection, event bus, unit testing, navigation and etc.
-
- See [**Source code** here](https://github.com/kejunxia/AndroidMvc/tree/master/samples/simple) and download [**Sample APK** here](https://docs.google.com/uc?authuser=0&id=0BwcZml9gnwoZRS1pYURMMVRzdHM&export=download)
-
-
- - **[Note](https://docs.google.com/uc?authuser=0&id=0BwcZml9gnwoZOHcxZFI3Z0ZGUUk&export=download)** - A more complex sample to make notes and query weathers with slide menu and also demonstrates how consume network resources ([public weather API](http://openweathermap.org/api)) and test the async task without depending on Android SDK on pure JVM.
+## Code quick glance
- See [**Source code** here](https://github.com/kejunxia/AndroidMvc/tree/master/samples/note) and download [**Sample APK** here](https://docs.google.com/uc?authuser=0&id=0BwcZml9gnwoZOHcxZFI3Z0ZGUUk&export=download)
+Let's take a quick glance how to use the framework to **navigate** between screens first, more details will be discussed later.
-## Download
-The library is currently released to both
-* jCenter [](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion)
-* Maven Central [](https://maven-badges.herokuapp.com/maven-central/com.shipdream/android-mvc)
+The sample code can be found in [Here](https://github.com/kejunxia/AndroidMvc/tree/master/samples/simple-mvc).
+It is a simple counter app that has a master page and detail page. This 2 pages are represented by two fragments
-**Maven:**
-```xml
-
- com.shipdream
- android-mvc
- [LatestVersion]
-
-```
+- CounterMasterScreen paired with CounterMasterController
+- CounterDetailScreen paired with CounterDetailController
-**Gradle:**
-```groovy
-compile "com.shipdream:android-mvc:[LatestVersion]"
-```
-
-## Dependency injection with reference count
-[See the documentation of Poke](https://github.com/kejunxia/AndroidMvc/tree/master/library/poke)
-
-#### Code snippets:
-- **View**:
+#### Controller
+In CounterMasterController, to navigate simply call
```java
-public class WeatherListFragment extends BaseFragment {
- private Button buttonRefresh;
- private ProgressDialog progressDialog;
-
- @Inject
- private WeatherController weatherController;
-
- @Override
- public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
- super.onViewReady(view, savedInstanceState, reason);
-
- buttonRefresh = (Button) view.findViewById(R.id.fragment_weather_list_buttonRefresh);
- buttonRefresh.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- weatherController.updateAllCities(view);
- }
- });
-
- //Automatically update weathers of all cities on first creation.
- if (reason.isFirstTime()) {
- weatherController.updateAllCities(this);
- }
- }
-
- public void onEvent(WeatherController.EventC2V.OnWeathersUpdateBegan event) {
- ...
- progressDialog.show();
- }
-
- public void onEvent(WeatherController.EventC2V.OnWeathersUpdated event) {
- updateList();
- if (progressDialog != null) {
- progressDialog.dismiss();
- }
- }
+public void goToDetailView(Object sender) {
+ //Navigate to CounterDetailController which is paired by CounterDetailScreen
+ navigationManager.navigate(sender).to(CounterDetailController.class);
}
```
-- **Controller**:
+
+#### View
+In CounterMasterScreen call the navigation method wrapped by the controller
```java
-public class WeatherControllerImpl extends BaseControllerImpl implements
- WeatherController{
- static final String PREF_KEY_WEATHER_CITIES = "PrefKey:Weather:Cities";
- private Gson gson = new Gson();
-
- @Inject
- private WeatherService weatherService;
-
- @Inject
- private PreferenceService preferenceService;
-
- @Override
- public Class modelType() {
- return WeatherModel.class;
- }
-
- @Override
- public void updateAllCities(final Object sender) {
- if(getModel().getWeatherWatchlist().size() == 0) {
- String cities = gson.toJson(getModel().getWeatherWatchlist());
- preferenceService.edit().putString(PREF_KEY_WEATHER_CITIES, cities).apply();
- postEvent2V(new EventC2V.OnWeathersUpdated(sender));
- } else {
- postEvent2V(new EventC2V.OnWeathersUpdateBegan(sender));
-
- runAsyncTask(sender, new AsyncTask() {
- @Override
- public void execute() throws Exception {
- List ids = new ArrayList<>();
- for(WeatherModel.City city : getModel().getWeatherWatchlist().keySet()) {
- ids.add(city.id());
- }
- for (WeatherInfo weatherInfo : weatherService.getWeathers(ids).getList()) {
- getModel().getWeatherWatchlist().put(findCityById(weatherInfo.getId()), weatherInfo);
- }
-
- String cities = gson.toJson(getModel().getWeatherWatchlist());
- preferenceService.edit().putString(PREF_KEY_WEATHER_CITIES, cities).apply();
- //Weather updated, post successful event
- postEvent2V(new EventC2V.OnWeathersUpdated(sender));
- }
- }, new AsyncExceptionHandler() {
- @Override
- public void handleException(Exception exception) {
- //Weather failed, post error event
- postEvent2V(new EventC2V.OnWeathersUpdateFailed(sender, exception));
- }
- });
+buttonGoToDetailScreen.setOnClickListener(
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //Use counterController to manage navigation to make navigation testable
+ controller.goToDetailView(v);
}
- }
+ });
+```
- private WeatherModel.City findCityById(int id) {
- for(int i = 0; i < WeatherModel.City.values().length; i++) {
- if (WeatherModel.City.values()[i].id() == id) {
- return WeatherModel.City.values()[i];
- }
- }
- return null;
- }
+In CounterDetailScreen
+```java
+@Override
+public void update() {
+ /**
+ * Controller will call update() whenever the controller thinks the state of the screen
+ * changes. So just bind the state of the controller to this screen then the screen is always
+ * reflecting the latest state/model of the controller
+ */
+ display.setText(controller.getCount());
}
```
-- **Service**:
+
+#### Unit test
+
```java
-//Just a sample, you can use anything to access cloud api e.g. Retrofit
-public class WeatherServiceImpl implements WeatherService{
- private final static String APPKEY = "123213123123213213123213";
- private OkHttpClient httpClient;
- private Gson gson;
- private Logger logger = LoggerFactory.getLogger(getClass());
-
- public WeatherServiceImpl() {
- httpClient = new OkHttpClient();
- gson = new Gson();
- }
-
- @Override
- public WeatherListResponse getWeathers(List ids) throws IOException {
- String idsStr = "";
- for (Integer id : ids) {
- if (!idsStr.isEmpty()) {
- idsStr += ", ";
- }
- idsStr += String.valueOf(id);
- }
- String url = String.format("http://api.openweathermap.org/data/2.5/group?id=%s&appId=%s",
- URLEncoder.encode(idsStr, "UTF-8"), APPKEY);
- Request request = new Request.Builder()
- .url(url)
- .get()
- .build();
- Response resp = httpClient.newCall(request).execute();
- String responseStr = resp.body().string();
- logger.debug("Weather Service Response: {}", responseStr);
- return gson.fromJson(responseStr, WeatherListResponse.class);
- }
-}
+//Act: navigate to MasterScreen
+navigationManager.navigate(this).to(CounterMasterController.class);
+
+//Verify: location should be changed to MasterScreen
+Assert.assertEquals(CounterMasterController.class.getName(),
+ navigationManager.getModel().getCurrentLocation().getLocationId());
+
+//Act: navigate to DetailScreen
+controller.goToDetailScreen(this);
+
+//Verify: Current location should be at the view paired with CounterDetailController
+Assert.assertEquals(CounterDetailController.class.getName(),
+ navigationManager.getModel().getCurrentLocation().getLocationId());
```
+
+
+## Division between Views and Controllers
+
+- **View**: Mainly fragments that bind user interactions to controllers such as tap, long press and etc.
+Views reflect the model managed by their controllers.
+- **Controller**: Controllers expose methods to its view peer to capture user inputs. Once the state
+of the controller changes, the controller needs to notify its view the update. Usually by calling
+view.update() or post an event to its view.
+- **Model**: Represents the state of view and managed by the controller. It can be accessed by
+controller.getModel(). But only read it to bind the model to views but don't modify the model from
+views. Modification of model should only be done by controller.
+- **Manager**: What about controllers have shared logic? Break shared code out into managers.
+If managers need to access data. Inject services into managers. Managers can be thought as partial
+controllers serve multiple views through the controllers depending on them.
+- **Service**: Services are below controller used to access data such as SharedPreferences,
+database, cloud API, files and etc. It provides abstraction for controllers or managers that can be
+easily mocked in unit tests for controllers. They the data access layer can be replaced quickly.
+For example, when some resources are removed from local data to remote data, just simply replace
+the services implementation to access web api instead of database or sharedPreferences.
+
+See the illustration below
+
+
+
+## How to use
+
+To enforce you don't write Android dependent functions into controllers to make unit tests harder,
+you can separate your Android project into 2 modules:
+
+- **app**: View layer - a lean module depending on Android API only bind model to Android UI and
+pass user interactions to core module. This module should include lib **"android-mvc"** explained
+in download section below. This module includes:
+ - Activities, Fragments, Views, Android Services and anything as views depending on Android API
+ - Implementations of abstract contract defined in core module that depending on Android API.
+ For example, a SharedPreferenceImpl that depends on Android context object.
+- **core**: Controller layer - also includes model, managers and services. It's a module doesn't
+have any Android dependency so can be tested straight away on JVM. This module should include lib
+**"android-mvc-core"** explained in download section below. This module includes:
+ - Controllers
+ - Models
+ - Managers - shared by controllers
+ - Data services. When a service needs Android API it can be defined as an interface and
+ implemented in app module. For example, define an interface SharedPreference to save and get data
+ from Android preference. So in core module, the interface can be easily to be mocked for
+ controllers or managers to provide mocked shared preference in unit tests.
+
+However, separating the android project into two modules as above is not necessary. They for sure
+can be merged into one module and just depend on lib **"android-mvc"**, which has already included
+**"android-mvc-core"**. But in this way, you may accidentally write android dependent functions into
+controller to make mocking harder in controller unit tests.
+
+See the chart below as an example of how to separate the modules. Also check out the
+**[Sample Code](https://github.com/kejunxia/AndroidMvc/tree/SampleWithInterimFragment/samples/simple)**
+
+
+
+## Download
+---
+Here is the the latest version number in jCenter
+
+[](https://bintray.com/kejunxia/maven/android-mvc/_latestVersion)
+
+**Maven:**
+- lib **android-mvc**
+ ```xml
+
+ com.shipdream
+ android-mvc
+ [LatestVersion]
+
+ ```
+- lib **android-mvc-core**
+ ```xml
+
+ com.shipdream
+ android-mvc-core
+ [LatestVersion]
+
+ ```
+
+**Gradle:**
+- lib **android-mvc**
+ ```groovy
+ compile "com.shipdream:android-mvc:[LatestVersion]"
+ ```
+- lib **android-mvc-core**
+ ```groovy
+ compile "com.shipdream:android-mvc-core:[LatestVersion]"
+ ```
diff --git a/build.gradle b/build.gradle
index 3569d40..bd74820 100644
--- a/build.gradle
+++ b/build.gradle
@@ -74,14 +74,14 @@ ext {
version = [
major: 3,
minor: 0,
- patch : 0
+ patch : 1
]
libGroup = 'com.shipdream'
libVersion = "${version.major}.${version.minor}.${version.patch}"
shouldPublish = false
androidMinSdkVersion = 14
- androidCompileSdkVersion = 23
+ androidCompileSdkVersion = 24
androidBuildToolVersion = "23.0.3"
supportLibVersion = "24.0.0"
androidTargetSdkVersion = androidCompileSdkVersion
diff --git a/documents/imgs/Android-Mvc-Pattern.jpg b/documents/imgs/Android-Mvc-Pattern.jpg
deleted file mode 100644
index 9bd6d0c..0000000
Binary files a/documents/imgs/Android-Mvc-Pattern.jpg and /dev/null differ
diff --git a/extension/service-core/build.gradle b/extension/service-core/build.gradle
index 583403e..8399315 100644
--- a/extension/service-core/build.gradle
+++ b/extension/service-core/build.gradle
@@ -15,7 +15,7 @@
*/
plugins {
- id "com.jfrog.bintray" version "1.4"
+ id "com.jfrog.bintray" version "1.7"
}
apply plugin: 'java'
diff --git a/library/android-mvc-core/build.gradle b/library/android-mvc-core/build.gradle
index 7b27d95..af9ea25 100644
--- a/library/android-mvc-core/build.gradle
+++ b/library/android-mvc-core/build.gradle
@@ -15,7 +15,7 @@
*/
plugins {
- id "com.jfrog.bintray" version "1.4"
+ id "com.jfrog.bintray" version "1.7"
}
apply plugin: 'java'
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Controller.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Controller.java
index 8462bfa..5c0a38f 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Controller.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Controller.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.event.bus.EventBus;
@@ -14,7 +30,46 @@
import javax.inject.Inject;
/**
- * Abstract view controller. Presenter will subscribe to {@link EventBusC}
+ *
+ * A controller is a delegate of a Android view. It holds a {@link UiView} that needs to be implemented
+ * by the corresponding Android view. Whenever the controller changes its model, it calls {@link UiView#update()}
+ * to update the view. Be careful when you are calling {@link UiView#update()} on the non-UI thread,
+ * because in this case, it needs to use {@link #uiThreadRunner} to post a runnable wrapping
+ * {@link UiView#update()} to ensure the view is updated on UI thread. Use {@link #runTask(Task)} to
+ * run heavy actions, especially network calls, on non-UI thread.
+ *
+ *
+ *
+ * In the above way the controller works as a presenter in MVP pattern. If you prefer MVVM pattern.
+ * You can define events and {@link #postEvent(Object)} to the view. Since {@link #postEvent(Object)}
+ * guarantees the event is posted onto UI thread, you don't need to worry about on which thread the
+ * event is posted.
+ *
+ *
+ *
+ * When some code needs to run on non-UI thread, use {@link #runTask(Task)},
+ * {@link #runTask(Task, Task.Callback)} to run it on a different thread. Make sure if
+ * {@link UiView#update()} needs to be called in scope of @link Task#execute(Task.Monitor)} use
+ * {@link #uiThreadRunner} to post back to UI thread.
+ *
+ *
+ *
+ * The controller has 4 injected fields. They can be replaced by providing special or mocking objects
+ * in unit tests.
+ *
+ *
a {@link EventBus} annotated by {@link EventBusC} to receive events from managers and other non ui components
+ *
a {@link EventBus} annotated by {@link EventBusV} to send event to Android views
+ *
a {@link ExecutorService} that runs {@link Task} via {@link #runTask(Task)} on non-UI thread.
+ * by default, it has a fixed thread tool at size 10. You can inject a mocked {@link ExecutorService}
+ * that runs everything on the main thread in your Unit Tests to avoid multi-thread complexity.
+ *
a protected {@link UiThreadRunner} to post a {@link Runnable} onto UI thread. Make sure
+ * use it to {@link UiView#update()} view inside method block {@link Task#execute(Task.Monitor)}
+ * which is run on non-UI thread. It's NOT necessary to use it in callback methods in
+ * {@link Task.Callback} since the framework has already guaranteed it.
+ * In non-Android environment, typically in unit tests, the framework will also provide a default
+ * uiThreadRunner that runs everything on the same thread as the caller's.
+ *
+ *
* @param The view model of the controller.
*/
public abstract class Controller extends Bean {
@@ -22,14 +77,14 @@ public abstract class Controller extends Bean
@Inject
@EventBusC
- private EventBus eventBus2C;
+ private EventBus eventBusC;
@Inject
@EventBusV
- private EventBus eventBus2V;
+ private EventBus eventBusV;
@Inject
- protected ExecutorService executorService;
+ private ExecutorService executorService;
@Inject
protected UiThreadRunner uiThreadRunner;
@@ -51,7 +106,7 @@ public void onCreated() {
uiThreadRunner = Mvc.graph().uiThreadRunner;
}
- eventBus2C.register(this);
+ eventBusC.register(this);
}
/**
@@ -61,7 +116,7 @@ public void onCreated() {
@Override
public void onDestroy() {
super.onDestroy();
- eventBus2C.unregister(this);
+ eventBusC.unregister(this);
}
/**
@@ -254,16 +309,63 @@ public void run() {
}
/**
+ *
* Post the event to views. It automatically guarantees the event will be received
- * and run on UI thread of Android
+ * and run on UI thread of Android.
+ *
+ *
+ *
+ * The event will be captured by views or any objects registered to {@link EventBus} annotated
+ * by {@link EventBusV} and has corresponding method named onEvent() with single parameter with
+ * the same type of the event. For example
+ *
+ *
+ * public class OnTextChangedEvent {
+ * private String text;
+ *
+ * public OnTextChangedEvent(String text) {
+ * this.text = text;
+ * }
+ *
+ * public String getText() {
+ * return text;
+ * }
+ * }
+ *
+ * public class SomeView {
+ * @ Inject
+ * @ EventBusV
+ * private EventBus eventBusV;
+ *
+ * private TextView textView;
+ *
+ * public class SomeView() {
+ * //This is just needed when you have a view not inheriting MvcFragment, MvcService or etc.
+ * //In MvcFragment or MvcService will register to the event bus in onCreate automatically.
+ * eventBusV.register(this);
+ * }
+ *
+ * public void onEvent(OnTextChangedEvent onTextChangedEvent) {
+ * textView.setText(onTextChangedEvent.getText());
+ * }
+ * }
+ *
+ * public class SomeController{
+ * private void func() {
+ * postEvent(new OnTextChangedEvent("Controller Wants to change text"));
+ * }
+ * }
+ *
+ *
* @param eventV The event
*/
protected void postEvent(final Object eventV) {
uiThreadRunner.post(new Runnable() {
@Override
public void run() {
- eventBus2V.post(eventV);
+ eventBusV.post(eventV);
}
});
}
+
}
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Forwarder.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Forwarder.java
index d75fffe..dad3443 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Forwarder.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Forwarder.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 org.jetbrains.annotations.NotNull;
@@ -5,8 +21,10 @@
/**
* Configuration of forwarding navigation by setting
*
- *
{@link #setInterim(boolean)}
- *
{@link #clearTo(String)}
+ *
{@link #setInterim(boolean)} indicating whether the location currently navigating to will
+ * be an interim in the navigation history, which means when {@link Navigator#back()} is called
+ * the interim locations will be skipped.
+ *
{@link #clearTo(Class)}
*
{@link #clearAll()}
*
*/
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/FragmentController.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/FragmentController.java
index e4cbe94..a50e9a0 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/FragmentController.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/FragmentController.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 abstract class FragmentController extends Controller{
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Manager.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Manager.java
index 55f268f..0abd2c1 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Manager.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Manager.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;
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcComponent.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcComponent.java
index fbead97..9ab8f6e 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcComponent.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcComponent.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.Component;
@@ -26,6 +42,11 @@
*/
public class MvcComponent extends Component {
private Logger logger = LoggerFactory.getLogger(getClass());
+
+ /**
+ * Name of the component
+ * @param name
+ */
public MvcComponent(String name) {
super(name);
}
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java
index 802b20d..f401d40 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraph.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.Component;
@@ -79,9 +95,6 @@ public void onDisposed(Provider provider, T instance) {
* @param monitor The monitor
*/
public void registerMonitor(Graph.Monitor monitor) {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot register mvc graph monitor from Non-UiThread");
- }
graph.registerMonitor(monitor);
}
@@ -91,9 +104,6 @@ public void registerMonitor(Graph.Monitor monitor) {
* @param monitor The monitor
*/
public void unregisterMonitor(Graph.Monitor monitor) {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot unregister mvc graph monitor from Non-UiThread");
- }
graph.unregisterMonitor(monitor);
}
@@ -101,9 +111,6 @@ public void unregisterMonitor(Graph.Monitor monitor) {
* Clear {@link Graph.Monitor} which will be called the graph is about to inject or release an object
*/
public void clearMonitors() {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot clear mvc graph monitors from Non-UiThread");
- }
graph.clearMonitors();
}
@@ -317,16 +324,10 @@ public void release(Object target) {
* @param component The root {@link Component} of this graph.
*/
public void setRootComponent(MvcComponent component) throws Graph.IllegalRootComponentException {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot set root component from Non-UiThread");
- }
graph.setRootComponent(component);
}
public MvcComponent getRootComponent() {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot getRootComponent() from Non-UiThread");
- }
return (MvcComponent) graph.getRootComponent();
}
@@ -336,9 +337,6 @@ public MvcComponent getRootComponent() {
* @param onProviderFreedListener The listener
*/
public void registerDereferencedListener(Provider.DereferenceListener onProviderFreedListener) {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot register dereference listener from Non-UiThread");
- }
graph.registerDereferencedListener(onProviderFreedListener);
}
@@ -349,9 +347,6 @@ public void registerDereferencedListener(Provider.DereferenceListener onProvider
* @param onProviderFreedListener The listener
*/
public void unregisterDereferencedListener(Provider.DereferenceListener onProviderFreedListener) {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot unregister dereference listener from Non-UiThread");
- }
graph.unregisterDereferencedListener(onProviderFreedListener);
}
@@ -360,9 +355,6 @@ public void unregisterDereferencedListener(Provider.DereferenceListener onProvid
* instance of an injected contract is freed.
*/
public void clearDereferencedListeners() {
- if (!uiThreadRunner.isOnUiThread()) {
- throw new MvcGraphException("Cannot clear dereference listeners from Non-UiThread");
- }
graph.clearDereferencedListeners();
}
}
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java
index 7ed0c32..8f1409f 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/MvcGraphException.java
+++ b/library/android-mvc-core/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-core/src/main/java/com/shipdream/lib/android/mvc/Navigator.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Navigator.java
index 3b02e1a..2d02dac 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Navigator.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Navigator.java
@@ -297,9 +297,21 @@ private void doNavigateTo(@NotNull Class extends Controller> controllerClass,
}
/**
- * Navigates one step back. If current location is null it doesn't take any effect otherwise
+ *
+ * Navigates one step back. However, if the previous location is an interim location, it keeps
+ * seeking backward to the first non-interim navigation location. Interim locations are set when
+ * forward navigate to them by
+ *
+ *
+ * navigationManager.navigate(this).to(SomeController.class, new Forwarder().setInterim(true));
+ *
+ *
+ *
+ *
+ * If current location is null it doesn't take any effect otherwise
* raises a {@link NavigationManager.Event.OnLocationBack} event when there is a previous
* location.
+ *
*/
public void back() {
NavLocation currentLoc = navigationManager.getModel().getCurrentLocation();
@@ -309,14 +321,20 @@ public void back() {
}
NavLocation previousLoc = currentLoc.getPreviousLocation();
+
+ boolean needFastRewind = false;
while (previousLoc != null && previousLoc.isInterim()) {
previousLoc = previousLoc.getPreviousLocation();
+ needFastRewind = true;
}
- navigationManager.getModel().setCurrentLocation(previousLoc);
-
- navigateEvent = new NavigationManager.Event.OnLocationBack(sender, currentLoc, previousLoc, false, this);
- go();
+ if (needFastRewind) {
+ navigateBackToLoc(previousLoc == null ? null : previousLoc.getLocationId());
+ } else {
+ navigationManager.getModel().setCurrentLocation(previousLoc);
+ navigateEvent = new NavigationManager.Event.OnLocationBack(sender, currentLoc, previousLoc, false, this);
+ go();
+ }
}
/**
@@ -328,6 +346,11 @@ public void back() {
* @param controllerClass the controller class type
*/
public void back(Class extends Controller> controllerClass) {
+ String toLocationId = controllerClass == null ? null : controllerClass.getName();
+ navigateBackToLoc(toLocationId);
+ }
+
+ private void navigateBackToLoc(String toLocationId) {
NavLocation currentLoc = navigationManager.getModel().getCurrentLocation();
if (currentLoc == null) {
navigationManager.logger.warn("Current location should never be null before navigating backwards.");
@@ -342,8 +365,6 @@ public void back(Class extends Controller> controllerClass) {
boolean success = false;
NavLocation previousLoc = currentLoc;
- String toLocationId = controllerClass == null ? null : controllerClass.getName();
-
if (toLocationId == null) {
success = true;
}
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Orientation.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Orientation.java
index 6714c5a..7288089 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Orientation.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Orientation.java
@@ -1,9 +1,24 @@
+/*
+ * 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;
/**
- * Created by kejun on 20/06/2016.
+ * Orientation of device screen
*/
-
public enum Orientation {
UNSPECIFIED,
LANDSCAPE,
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Reason.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Reason.java
index cc0e6b6..615b45a 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Reason.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/Reason.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;
/**
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/TestUtil.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/TestUtil.java
index 1dc4039..ba1b2c9 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/TestUtil.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/TestUtil.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;
/**
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiThreadRunner.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiThreadRunner.java
index 8d0c620..a1dbf3e 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiThreadRunner.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiThreadRunner.java
@@ -1,5 +1,24 @@
+/*
+ * 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;
+/**
+ * UiThreadRunner abstracts methods able to post actions to Android UI thread.
+ */
public interface UiThreadRunner {
/**
* Indicates whether current thread is UI thread.
@@ -8,13 +27,15 @@ public interface UiThreadRunner {
boolean isOnUiThread();
/**
- * Post the runnable to run on Android UI thread
+ * Post the runnable to run on Android UI thread. In Android app, when the caller is not
+ * currently on UI thread, it will be posted to the UI thread to be run in next main loop.
+ * Otherwise, it will be run immediately.
* @param runnable
*/
void post(Runnable runnable);
/**
- * Post the runnable to run on Android UI thread
+ * Post the runnable to run on Android UI thread with the given delay.
* @param runnable
*/
void postDelayed(Runnable runnable, long delayMs);
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiView.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiView.java
index a2ef891..48c2f6e 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiView.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/UiView.java
@@ -1,15 +1,62 @@
+/*
+ * 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;
/**
- * UiView represents android views. Call it Ui-View not to conflict with android.view.View and
- * simplify imports
+ *
+ * UiView represents android views. It has a single method {@link #update()}. Every {@link Controller}
+ * holds an instance of {@link UiView} which is implemented by the controller's corresponding
+ * concrete view. Whenever the {@link Controller} updates its state, usually it's model, the controller
+ * needs to call {@link UiView}.{@link #update()}.
+ *
+ *
+ *
+ * Usually this is enough for most Android views since as long as the concrete view implements
+ * {@link UiView}.{@link #update()} by binding the full controller model to the view, it guarantees the view's
+ * graphics is always in sync with the controller's model. However, if the model of a controller is
+ * large and sometimes only very limited part of the model changes, you may not always want to call
+ * {@link UiView}.{@link #update()} to rebind the entire model to the view if performance becomes a concern.
+ *
+ *
+ *
+ * In this case, define a custom view interface extending {@link UiView} with extra method to allow
+ * controllers updating specific part of the view. For example,
+ *
+ *
+ *
+ * public interface PageView extends UiView {
+ * /**
+ * * Let the controller of the page view just update the title instead calling {@link UiView}.{@link #update()}
+ * * to update the whole page.
+ * * @param title The title of the page.
+ * * /
+ * void updateTitle(String title);
+ * }
+ *
*/
public interface UiView {
/**
* When a view is requested to update itself, it should read it's controller's model by
* {@link Controller#getModel()} to bind the data to the view.
*
- *
Do NOT change values of model from view but only from controllers.
+ *
It will be automatically called when a view is ready to shown. Controllers should call this
+ * method when they updated their model.
+ *
+ *
Do NOT change values of model from view but only from controllers.
*/
void update();
}
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java
index 2869172..29daaa7 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusC.java
@@ -16,6 +16,8 @@
package com.shipdream.lib.android.mvc.event.bus.annotation;
+import com.shipdream.lib.android.mvc.event.bus.EventBus;
+
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -23,8 +25,10 @@
import javax.inject.Qualifier;
/**
- * 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.
+ * Indicates the annotated event bus is for events to core components such as controllers, managers
+ * or core services. To receive or send events to Android views use {@link EventBusV} to qualify the
+ * injecting {@link EventBus}. Events through the event bus annotated by this annotation will be
+ * received on the same thread as the caller who posts them.
*/
@Qualifier
@Documented
diff --git a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java
index 0501854..fecf462 100644
--- a/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java
+++ b/library/android-mvc-core/src/main/java/com/shipdream/lib/android/mvc/event/bus/annotation/EventBusV.java
@@ -16,6 +16,8 @@
package com.shipdream.lib.android.mvc.event.bus.annotation;
+import com.shipdream.lib.android.mvc.event.bus.EventBus;
+
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -23,9 +25,15 @@
import javax.inject.Qualifier;
/**
- * 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.
+ * Indicates the annotated event bus is for events sent to Android views. To send or receive events
+ * for core components such as controllers, managers, core services, use {@link EventBusC} to annotate
+ * the injecting {@link EventBus}.
+ *
+ *
+ * In Android app events through the event bus annotated by this annotation will be guaranteed to be
+ * received on Android's UI thread automatically.
+ *
+ *
*/
@Qualifier
@Documented
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestController.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestController.java
index 5d0e639..605b6c8 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestController.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestController.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.event.bus.EventBus;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestFragmentController.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestFragmentController.java
index 4602385..8ad49ba 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestFragmentController.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestFragmentController.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 org.junit.Assert;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcComponent.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcComponent.java
index 985d215..cd9616d 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcComponent.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcComponent.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.inject.test.Phone;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java
index ce42cf6..03e94b8 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestMvcGraph.java
@@ -417,56 +417,56 @@ public void should_throw_exception_when_mvc_graph_release_on_non_main_thread() {
graph.release(this);
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_set_rootComponent_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.setRootComponent(new MvcComponent(""));
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_get_rootComponent_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.getRootComponent();
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_register_deferenceListener_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.registerDereferencedListener(mock(Provider.DereferenceListener.class));
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_unregister_deferenceListener_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.unregisterDereferencedListener(mock(Provider.DereferenceListener.class));
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_clear_deferenceListeners_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.clearDereferencedListeners();
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_register_monitor_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.registerMonitor(mock(Graph.Monitor.class));
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_unregister_monitor_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
graph.unregisterMonitor(mock(Graph.Monitor.class));
}
- @Test(expected = MvcGraphException.class)
+ @Test
public void should_throw_exception_when_mvc_graph_clear_monitors_on_non_main_thread() throws Graph.IllegalRootComponentException {
graph.uiThreadRunner = mock(UiThreadRunner.class);
when(graph.uiThreadRunner.isOnUiThread()).thenReturn(false);
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestNavigationManager.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestNavigationManager.java
index 938dc59..27744ac 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestNavigationManager.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestNavigationManager.java
@@ -324,7 +324,7 @@ public void should_skip_interim_location_on_back_navigation() throws Exception {
NavLocation currentLoc = navigationManager.getModel().getCurrentLocation();
assertEquals(currentLoc.getLocationId(), locId4.getName());
- Assert.assertFalse(event.getValue().isFastRewind());
+ Assert.assertTrue(event.getValue().isFastRewind());
}
@Test
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestOrientation.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestOrientation.java
index 424714b..74fe22f 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestOrientation.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestOrientation.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 org.junit.Test;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestReason.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestReason.java
index 1f3bc35..ba05416 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestReason.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestReason.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 org.junit.Assert;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestTestUtil.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestTestUtil.java
index 5cd0f47..7fb5510 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestTestUtil.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/TestTestUtil.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 org.junit.Assert;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Phone.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Phone.java
index cceccf1..dd7253b 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Phone.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Phone.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.test;
public interface Phone {
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Robot.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Robot.java
index 1a5822a..e540867 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Robot.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Robot.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.test;
public interface Robot {
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Smart.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Smart.java
index 428e684..b54c1f2 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Smart.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/Smart.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.test;
import java.lang.annotation.Retention;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/PhoneImpl.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/PhoneImpl.java
index 9b9d982..b866b50 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/PhoneImpl.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/PhoneImpl.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.test.internal;
import com.shipdream.lib.android.mvc.inject.test.Smart;
diff --git a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/RobotImpl.java b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/RobotImpl.java
index 53b9dec..54ba134 100644
--- a/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/RobotImpl.java
+++ b/library/android-mvc-core/src/test/java/com/shipdream/lib/android/mvc/inject/test/internal/RobotImpl.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.test.internal;
public class RobotImpl {
diff --git a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/BaseTestCase.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/BaseTestCase.java
index ba8b802..3ea4fed 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/BaseTestCase.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/BaseTestCase.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.
@@ -235,25 +235,21 @@ public void tearDown() throws Exception {
if (activity != null) {
activity.finish();
- }
-
- instrumentation.runOnMainSync(new Runnable() {
- @Override
- public void run() {
- Mvc.graph().release(BaseTestCase.this);
- try {
- Mvc.graph().getRootComponent().detach(component);
- } catch (Component.MismatchDetachException e) {
- e.printStackTrace();
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Mvc.graph().release(BaseTestCase.this);
+ try {
+ Mvc.graph().getRootComponent().getCache().clear();
+ Mvc.graph().getRootComponent().detach(component);
+ } catch (Component.MismatchDetachException e) {
+ e.printStackTrace();
+ }
}
+ });
+ }
- }
- });
super.tearDown();
-
- Mvc.graph().getRootComponent().getCache().clear();
-
- eventBusV.unregister(this);
}
protected void navTo(final Class cls) {
diff --git a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycle.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycle.java
index 345eb8d..393e80d 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycle.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycle.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycleValidator.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycleValidator.java
index 09feff0..08442f4 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycleValidator.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/LifeCycleValidator.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java
index 1059431..e695f0a 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/eventv2v/TestV2VEvents.java
@@ -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/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectedStateManagedObjects.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectedStateManagedObjects.java
index d2b4067..cecc031 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectedStateManagedObjects.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectedStateManagedObjects.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycle.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycle.java
index 2556bb1..3ebbc7b 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycle.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycle.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycleForRootFragment.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycleForRootFragment.java
index b748e19..f9cfcc4 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycleForRootFragment.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/injection/TestInjectionAndLifeCycleForRootFragment.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/BaseTestCaseLifeCycle.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/BaseTestCaseLifeCycle.java
index e1d3131..d665c6d 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/BaseTestCaseLifeCycle.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/BaseTestCaseLifeCycle.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestBackButtonPress.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestBackButtonPress.java
index 3b002c9..adec447 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestBackButtonPress.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestBackButtonPress.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestCase.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestCase.java
index 5d26a26..d88b18f 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestCase.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/KeepActivitiesLifeCycleTestCase.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/NotKeepActivitiesLifeCycleTestCase.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/NotKeepActivitiesLifeCycleTestCase.java
index a0ee808..cd51812 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/NotKeepActivitiesLifeCycleTestCase.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/lifecycle/NotKeepActivitiesLifeCycleTestCase.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-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationAndInjection.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationAndInjection.java
index 6445b0b..6d5460a 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationAndInjection.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationAndInjection.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.
@@ -414,6 +414,7 @@ public void test_should_release_and_inject_properly_on_single_step_back_navigati
navigateBackByFragment();
//quit
waitTest();
+ Thread.sleep(500);
Assert.assertEquals(activity.fragAInjectCount, 0);
Assert.assertEquals(activity.fragAReleaseCount, 1);
Assert.assertEquals(activity.fragBInjectCount, 0);
diff --git a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationBasic.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationBasic.java
index 5820a04..58ed33f 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationBasic.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationBasic.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.
@@ -229,6 +229,8 @@ public void testShouldReleaseInjectionsAfterFragmentsArePoppedOut() throws Throw
@Test
public void testNavigateAmongFragments() throws Throwable {
+ waitTest();
+
testNavigateToB();
rotateMainActivity(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
@@ -477,7 +479,7 @@ public void test_should_be_able_to_skip_interim_item_with_clear_history_nav_loca
onView(withText(NavFragmentD.class.getSimpleName())).check(matches(isDisplayed()));
navigateBackByFragment();
- onView(withText(NavFragmentA.class.getSimpleName())).check(matches(isDisplayed()));
+ onView(withText(NavFragmentB.class.getSimpleName())).check(matches(isDisplayed()));
}
@Test
diff --git a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationFromController.java b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationFromController.java
index d55788b..1d28cb2 100644
--- a/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationFromController.java
+++ b/library/android-mvc-test/src/androidTest/java/com/shipdream/lib/android/mvc/view/nav/TestCaseNavigationFromController.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,14 +16,21 @@
package com.shipdream.lib.android.mvc.view.nav;
+import android.support.v4.app.FragmentManager;
+
import com.shipdream.lib.android.mvc.BaseTestCase;
-import com.shipdream.lib.android.mvc.Mvc;
+import com.shipdream.lib.android.mvc.Forwarder;
import com.shipdream.lib.android.mvc.MvcComponent;
import com.shipdream.lib.android.mvc.NavigationManager;
import com.shipdream.lib.android.mvc.Preparer;
import com.shipdream.lib.android.mvc.view.injection.controller.ControllerA;
+import com.shipdream.lib.android.mvc.view.injection.controller.ControllerB;
+import com.shipdream.lib.android.mvc.view.injection.controller.ControllerC;
+import com.shipdream.lib.android.mvc.view.injection.controller.ControllerD;
import com.shipdream.lib.poke.Provides;
+import junit.framework.Assert;
+
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -36,6 +43,7 @@
import javax.inject.Singleton;
import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@@ -51,7 +59,7 @@ public class TestCaseNavigationFromController extends BaseTestCase proxies = new CopyOnWriteArrayList<>();;
+ public DelegateFragment getDelegateFragment() {
+ return delegateFragment;
+ }
+
public void addProxy(Proxy proxy) {
synchronized (proxies) {
proxies.add(proxy);
diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/nav/NavFragment.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/nav/NavFragment.java
index 27d3fe2..0d479f1 100644
--- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/nav/NavFragment.java
+++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/nav/NavFragment.java
@@ -20,6 +20,7 @@
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
+import android.widget.TextView;
import com.shipdream.lib.android.mvc.Controller;
import com.shipdream.lib.android.mvc.Forwarder;
@@ -33,6 +34,8 @@
public abstract class NavFragment extends MvcFragment {
private Button next;
private Button clear;
+ private TextView textView;
+
@Inject
private NavigationManager navigationManager;
@@ -49,6 +52,9 @@ protected int getLayoutResId() {
public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
super.onViewReady(view, savedInstanceState, reason);
+ textView = (TextView) view.findViewById(R.id.text);
+ textView.setText(getClass().getSimpleName());
+
next = (Button) view.findViewById(R.id.button_next);
next.setOnClickListener(new View.OnClickListener() {
@Override
@@ -73,7 +79,7 @@ public void onClick(View view) {
public void onResume() {
super.onResume();
Toolbar toolbar = (Toolbar) getView().findViewById(R.id.toolbar);
- toolbar.setTitle(getClass().getSimpleName());
+ toolbar.setTitle("Page: " + getClass().getSimpleName());
}
@Override
diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/FirstFragmentController.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/FirstFragmentController.java
index ed50658..82c8956 100644
--- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/FirstFragmentController.java
+++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/FirstFragmentController.java
@@ -1,10 +1,23 @@
+/*
+ * 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.view.viewpager.controller;
import com.shipdream.lib.android.mvc.FragmentController;
-/**
- * Created by kejun on 6/13/2016.
- */
public class FirstFragmentController extends FragmentController {
@Override
public Class modelType() {
diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/HomeController.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/HomeController.java
index 51e2a01..e80514c 100644
--- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/HomeController.java
+++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/HomeController.java
@@ -1,10 +1,23 @@
+/*
+ * 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.view.viewpager.controller;
import com.shipdream.lib.android.mvc.FragmentController;
-/**
- * Created by kejun on 6/13/2016.
- */
public class HomeController extends FragmentController {
@Override
public Class modelType() {
diff --git a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/SecondFragmentController.java b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/SecondFragmentController.java
index be43f7a..d2edb5f 100644
--- a/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/SecondFragmentController.java
+++ b/library/android-mvc-test/src/main/java/com/shipdream/lib/android/mvc/view/viewpager/controller/SecondFragmentController.java
@@ -1,10 +1,23 @@
+/*
+ * 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.view.viewpager.controller;
import com.shipdream.lib.android.mvc.FragmentController;
-/**
- * Created by kejun on 6/13/2016.
- */
public class SecondFragmentController extends FragmentController {
@Override
public Class modelType() {
diff --git a/library/android-mvc-test/src/main/res/layout/fragment_mvc_test_nav.xml b/library/android-mvc-test/src/main/res/layout/fragment_mvc_test_nav.xml
index 731a03e..f3319e7 100644
--- a/library/android-mvc-test/src/main/res/layout/fragment_mvc_test_nav.xml
+++ b/library/android-mvc-test/src/main/res/layout/fragment_mvc_test_nav.xml
@@ -37,6 +37,12 @@
android:layout_height="match_parent"
android:orientation="vertical">
+
+