Skip to content

Commit

Permalink
Merge pull request #63 from kejunxia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kejunxia committed Sep 19, 2016
2 parents bd9de8b + 6450cca commit 196d6e3
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 60 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
@@ -1,3 +1,9 @@
Version: 3.1.1
* Add MvcDialog and deprecate MvcDialogFragment
* Better description for injection errors for fragments and services
* Allow controllers to send events to other controllers and managers
* Uplift Android support library to 24.2.0

Version: 3.1.0
* Uplift Android Support Library to 24.1.1

Expand Down
7 changes: 3 additions & 4 deletions build.gradle
Expand Up @@ -29,7 +29,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
classpath 'com.android.tools.build:gradle:2.2.0-rc1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

Expand Down Expand Up @@ -74,7 +74,7 @@ ext {
version = [
major: 3,
minor: 1,
patch : 0
patch : 1
]
libGroup = 'com.shipdream'
libVersion = "${version.major}.${version.minor}.${version.patch}"
Expand All @@ -83,12 +83,11 @@ ext {
androidMinSdkVersion = 14
androidCompileSdkVersion = 24
androidBuildToolVersion = "23.0.3"
supportLibVersion = "24.1.1"
supportLibVersion = "24.2.0"
androidTargetSdkVersion = androidCompileSdkVersion
lib = [
intelljAnnoatations: 'com.intellij:annotations:12.0',
androidMinSdk: 'com.google.android:android:4.0.1.2',
androidSupportLib: "com.android.support:appcompat-v7:$supportLibVersion",
junit: 'junit:junit:4.12',
mokito: 'org.mockito:mockito-core:1.9.5',
slf4jApi: "org.slf4j:slf4j-api:$log4jVersion",
Expand Down
Expand Up @@ -308,6 +308,80 @@ public void run() {
return monitor;
}

/**
* <p>
* Post the event to views. It automatically guarantees the event will be received
* and run on UI thread of Android.
* </p>
*
* <p>
* 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
* </p>
* <pre>
* 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"));
* }
* }
* </pre>
*
* @param event2V The event
* @deprecated Use {@link #postEvent2V(Object)} instead
*/
protected void postEvent(final Object event2V) {
postEvent2V(event2V);
}

/**
* <p>
* Post the event to other core components such as controllers and managers. Event will be
* captured on the thread of the invoker.
* </p>
*
* <p>
* The event will be captured by {@link Controller}s, {@link Manager}s or others registered to
* {@link EventBus} annotated by {@link EventBusC} and has corresponding method named onEvent()
* with single parameter with the same type of the event. For example
* </p>
*
* @param event2C The event to other {@link Controller}s, {@link Manager}s
*/
protected void postEvent2C(final Object event2C) {
eventBusC.post(event2C);
}

/**
* <p>
* Post the event to views. It automatically guarantees the event will be received
Expand Down Expand Up @@ -359,8 +433,7 @@ public void run() {
*
* @param eventV The event
*/
protected void postEvent(final Object eventV) {
protected void postEvent2V(final Object eventV) {
eventBusV.post(eventV);
}

}
Expand Up @@ -17,6 +17,7 @@
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.annotation.EventBusV;
import com.shipdream.lib.poke.Provides;

Expand All @@ -34,7 +35,6 @@

public class TestController extends BaseTest{
private UiThreadRunner uiThreadRunner;
private EventBus eventBusV;

@Override
@Before
Expand All @@ -50,6 +50,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
}).when(uiThreadRunner).post(any(Runnable.class));

eventBusC = mock(EventBus.class);

eventBusV = mock(EventBus.class);

MvcComponent component = new MvcComponent("");
Expand All @@ -59,17 +61,23 @@ UiThreadRunner uiThreadRunner() {
return uiThreadRunner;
}

@Provides
@EventBusC
EventBus eventBus2C() {
return eventBusC;
}

@Provides
@EventBusV
EventBus eventBus() {
EventBus eventBus2V() {
return eventBusV;
}
});
graph.getRootComponent().attach(component, true);
}

@Test
public void should_post_event_to_event2v_channel() throws Exception {
public void should_post_event_to_event2v_channel_old() throws Exception {
Controller controller = new Controller() {
@Override
public Class modelType() {
Expand All @@ -84,6 +92,38 @@ public Class modelType() {
verify(eventBusV).post(eq(event));
}

@Test
public void should_post_event_to_event2v_channel() throws Exception {
Controller controller = new Controller() {
@Override
public Class modelType() {
return null;
}
};
graph.inject(controller);

String event = ";";
controller.postEvent2V(event);

verify(eventBusV).post(eq(event));
}

@Test
public void should_post_event_to_event2c_channel() throws Exception {
Controller controller = new Controller() {
@Override
public Class modelType() {
return null;
}
};
graph.inject(controller);

String event = ";";
controller.postEvent2C(event);

verify(eventBusC).post(eq(event));
}

@Test
public void should_post_wrapped_MvcGraphException_when_run_async_task() {
Controller controller = new Controller() {
Expand Down
Expand Up @@ -52,34 +52,34 @@ class CountMonitor implements Graph.Monitor {
int fragDReleaseCount = 0;

@Override
public void onInject(Object target) {
public void onInject(Object intoTarget) {
synchronized (this) {
if (valid) {
if (target instanceof NavFragmentA) {
if (intoTarget instanceof NavFragmentA) {
fragAInjectCount++;
} else if (target instanceof NavFragmentB) {
} else if (intoTarget instanceof NavFragmentB) {
fragBInjectCount++;
} else if (target instanceof NavFragmentC) {
} else if (intoTarget instanceof NavFragmentC) {
fragCInjectCount++;
} else if (target instanceof NavFragmentD) {
} else if (intoTarget instanceof NavFragmentD) {
fragDInjectCount++;
}
}
}
}

@Override
public void onRelease(Object target) {
public void onRelease(Object fromTarget) {

synchronized (this) {
if (valid) {
if (target instanceof NavFragmentA) {
if (fromTarget instanceof NavFragmentA) {
fragAReleaseCount++;
} else if (target instanceof NavFragmentB) {
} else if (fromTarget instanceof NavFragmentB) {
fragBReleaseCount++;
} else if (target instanceof NavFragmentC) {
} else if (fromTarget instanceof NavFragmentC) {
fragCReleaseCount++;
} else if (target instanceof NavFragmentD) {
} else if (fromTarget instanceof NavFragmentD) {
fragDReleaseCount++;
}
}
Expand Down Expand Up @@ -184,9 +184,9 @@ class WaitMonitor extends CountMonitor {
boolean released = false;

@Override
public void onRelease(Object target) {
super.onRelease(target);
if (target instanceof NavFragmentA) {
public void onRelease(Object fromTarget) {
super.onRelease(fromTarget);
if (fromTarget instanceof NavFragmentA) {
released = true;
synchronized (this) {
notify();
Expand Down Expand Up @@ -453,9 +453,9 @@ class WaitMonitor extends CountMonitor {
boolean released = false;

@Override
public void onRelease(Object target) {
super.onRelease(target);
if (target instanceof NavFragmentA) {
public void onRelease(Object fromTarget) {
super.onRelease(fromTarget);
if (fromTarget instanceof NavFragmentA) {
released = true;
synchronized (this) {
notify();
Expand Down
2 changes: 1 addition & 1 deletion library/android-mvc/build.gradle
Expand Up @@ -23,7 +23,7 @@ apply plugin: 'com.github.dcendents.android-maven'

dependencies {
compile project(':library:android-mvc-core')
compile rootProject.lib.androidSupportLib
compile "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
}

android {
Expand Down
Expand Up @@ -320,7 +320,6 @@ public void onViewStateRestored(Bundle savedInstanceState) {
Bundle mvcOutState = savedInstanceState.getBundle(MVC_STATE_BUNDLE_KEY);
long ts = System.currentTimeMillis();

//TODO: if its rotation, consider not restore since the fragment is retained
MvcStateKeeperHolder.restoreState(mvcOutState);
logger.trace("Restored state of all active controllers, {}ms used.", System.currentTimeMillis() - ts);

Expand Down

0 comments on commit 196d6e3

Please sign in to comment.