Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jdk:

env:
- TERM=dumb
- GRADLE_OPTS="-Xmx512m -XX:MaxPermSize=512m"

after_success:
- ./gradlew coveralls
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ injection. A concrete class can be injected straight away.
* Register providers to Graph's root component rather than to graph itself.
* Managers listen to eventBusC
* New lifecycle MvcFragment.onPopAway
* Uplift support library to 24.0.0 and remove all hack for issue reported https://code.google.com/p/android/issues/detail?id=197271

Version:2.3
* New navigation method that allow configuring the location not pushed to back stack
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apply plugin: 'jacoco'

// Top-level build file where you can add configuration options common to all sub-projects/modules.
def log4jVersion = '1.7.6'
def logbackAndroidVersion = '1.1.1-4'
def logbackAndroidVersion = '1.1.1-5'

buildscript {
repositories {
Expand Down Expand Up @@ -83,7 +83,7 @@ ext {
androidMinSdkVersion = 14
androidCompileSdkVersion = 23
androidBuildToolVersion = "23.0.3"
supportLibVersion = "23.4.0"
supportLibVersion = "24.0.0"
androidTargetSdkVersion = androidCompileSdkVersion
lib = [
intelljAnnoatations: 'com.intellij:annotations:12.0',
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@

org.gradle.daemon=true
org.gradle.parallel=true

org.gradle.jvmargs=-Xmx2048M
org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m
2 changes: 1 addition & 1 deletion library/android-mvc-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {
compile project(':library:poke')

compile rootProject.lib.slf4jApi
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.code.gson:gson:2.7'

testCompile rootProject.ext.lib.junit
testCompile rootProject.ext.lib.mokito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,24 @@ protected <RESULT> Task.Monitor<RESULT> runTask(ExecutorService executorService,
final Task<RESULT> task, final Task.Callback<RESULT> callback) {
final Task.Monitor<RESULT> monitor = new Task.Monitor(task, uiThreadRunner, callback);

if (monitor.getState() == Task.Monitor.State.CANCELED) {
return null;
}

monitor.setState(Task.Monitor.State.STARTED);

if (callback != null) {
callback.onStarted();
}

Future<Void> future = executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
if (monitor.getState() == Task.Monitor.State.CANCELED) {
return null;
}

monitor.setState(Task.Monitor.State.STARTED);

if (callback != null) {
uiThreadRunner.post(new Runnable() {
@Override
public void run() {
callback.onStarted();
}
});
}

try {
final RESULT result = task.execute(monitor);

Expand All @@ -195,13 +200,13 @@ public void run() {
}
}
} catch (final Exception e) {
if (e instanceof MvcGraph.Exception) {
if (e instanceof MvcGraphException) {
//Injection exception will always be thrown out since it's a development
//time error
uiThreadRunner.post(new Runnable() {
@Override
public void run() {
throw new IllegalStateException(e);
throw new RuntimeException(e);
}
});
}
Expand All @@ -219,8 +224,13 @@ public void run() {
uiThreadRunner.post(new Runnable() {
@Override
public void run() {
callback.onException(e);
callback.onFinally();
try {
callback.onException(e);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
callback.onFinally();
}
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;

//TODO: documents
/**
* A component manages injectable objects. It is able to locate implementation class automatically by
* <ul>
* <ui>The injecting class is a concrete class and has empty constructor</ui>
* <ui>The injecting class is an interface or abstract class and there is concrete class is named
* with suffix "impl" and sitting in the subpackage "internal" which is at the
* same level of the interface or abstract. For instance, the interface is
* a.b.c.Car and there is an concrete class at a.b.c.internal.CarImpl</ui>
* <ui>The injecting class is registered by {@link #register(Object)} or {@link #register(Provider)}</ui>
* </ul>
*/
public class MvcComponent extends Component {
private Logger logger = LoggerFactory.getLogger(getClass());
public MvcComponent(String name) {
Expand Down Expand Up @@ -51,11 +61,11 @@ public <T> Provider<T> findProvider(final Class<T> type, Annotation qualifier) t
|| provider.getQualifier() != null) {
String msg;
if (qualifier == null) {
msg = String.format("Can't find implementation class for %s. Make sure class %s exists, or its implementation is registered to graph's root component",
type.getName(), getClassName(type));
msg = String.format("Can't find implementation class for %s. Make sure class %s without qualifier %s exists, or its implementation is registered to graph's root component.",
type.getName(), getClassName(type), provider.getQualifier().toString());
} else {
msg = String.format("Can't find implementation class for %s. Make sure class %s exists, or its implementation is registered to graph's root component",
type.getName(), getClassName(type) + "@" + qualifier.toString());
msg = String.format("Can't find implementation class for %s. Make sure class %s with qualifier %s exists, or its implementation is registered to graph's root component.",
type.getName(), getClassName(type), qualifier.toString());
}
throw new ProviderMissingException(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@
public class MvcGraph {
final Logger logger = LoggerFactory.getLogger(getClass());

public static class Exception extends RuntimeException {
public Exception(String s) {
super(s);
}

public Exception(String message, Throwable cause) {
super(message, cause);
}
}

UiThreadRunner uiThreadRunner;
Graph graph;

Expand Down Expand Up @@ -89,6 +79,9 @@ public <T> void onDisposed(Provider<T> 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);
}

Expand All @@ -98,13 +91,19 @@ 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);
}

/**
* 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();
}

Expand All @@ -119,7 +118,7 @@ public void clearMonitors() {
public <T> T reference(Class<T> type, Annotation qualifier)
throws ProviderMissingException, ProvideException, CircularDependenciesException {
if (!uiThreadRunner.isOnUiThread()) {
throw new IllegalStateException("Cannot reference an instance from Non-UiThread");
throw new MvcGraphException("Cannot reference an instance from Non-UiThread");
}
return graph.reference(type, qualifier, Inject.class);
}
Expand All @@ -134,7 +133,7 @@ public <T> T reference(Class<T> type, Annotation qualifier)
public <T> void dereference(T instance, Class<T> type, Annotation qualifier)
throws ProviderMissingException {
if (!uiThreadRunner.isOnUiThread()) {
throw new IllegalStateException("Cannot dereference an instance from Non-UiThread");
throw new MvcGraphException("Cannot dereference an instance from Non-UiThread");
}
graph.dereference(instance, type, qualifier, Inject.class);
}
Expand All @@ -146,12 +145,12 @@ public <T> void dereference(T instance, Class<T> type, Annotation qualifier)
*/
public <T> void use(final Class<T> type, final Consumer<T> consumer) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot use an instance from Non-UiThread");
throw new MvcGraphException("Cannot use an instance from Non-UiThread");
}
try {
graph.use(type, Inject.class, consumer);
} catch (PokeException e) {
throw new Exception(e.getMessage(), e);
throw new MvcGraphException(e.getMessage(), e);
}
}

Expand Down Expand Up @@ -264,16 +263,16 @@ public void consume(Os instance) {
* @param type The type of the injectable instance
* @param qualifier Qualifier for the injectable instance
* @param consumer Consume to use the instance
* @throws Exception throw when there are exceptions during the consumption of the instance
* @throws MvcGraphException throw when there are exceptions during the consumption of the instance
*/
public <T> void use(final Class<T> type, final Annotation qualifier, final Consumer<T> consumer) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot use an instance from Non-UiThread");
throw new MvcGraphException("Cannot use an instance from Non-UiThread");
}
try {
graph.use(type, qualifier, Inject.class, consumer);
} catch (PokeException e) {
throw new Exception(e.getMessage(), e);
throw new MvcGraphException(e.getMessage(), e);
}
}

Expand All @@ -285,12 +284,12 @@ public <T> void use(final Class<T> type, final Annotation qualifier, final Consu
*/
public void inject(Object target) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot inject an instance from Non-UiThread");
throw new MvcGraphException("Cannot inject an instance from Non-UiThread");
}
try {
graph.inject(target, Inject.class);
} catch (PokeException e) {
throw new Exception(e.getMessage(), e);
throw new MvcGraphException(e.getMessage(), e);
}
}

Expand All @@ -303,12 +302,12 @@ public void inject(Object target) {
*/
public void release(Object target) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot release an instance from Non-UiThread");
throw new MvcGraphException("Cannot release an instance from Non-UiThread");
}
try {
graph.release(target, Inject.class);
} catch (ProviderMissingException e) {
throw new Exception(e.getMessage(), e);
throw new MvcGraphException(e.getMessage(), e);
}
}

Expand All @@ -319,12 +318,15 @@ public void release(Object target) {
*/
public void setRootComponent(MvcComponent component) throws Graph.IllegalRootComponentException {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot set root component from Non-UiThread");
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();
}

Expand All @@ -335,7 +337,7 @@ public MvcComponent getRootComponent() {
*/
public void registerDereferencedListener(Provider.DereferenceListener onProviderFreedListener) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot register dereference listener from Non-UiThread");
throw new MvcGraphException("Cannot register dereference listener from Non-UiThread");
}
graph.registerDereferencedListener(onProviderFreedListener);
}
Expand All @@ -348,7 +350,7 @@ public void registerDereferencedListener(Provider.DereferenceListener onProvider
*/
public void unregisterDereferencedListener(Provider.DereferenceListener onProviderFreedListener) {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot unregister dereference listener from Non-UiThread");
throw new MvcGraphException("Cannot unregister dereference listener from Non-UiThread");
}
graph.unregisterDereferencedListener(onProviderFreedListener);
}
Expand All @@ -359,7 +361,7 @@ public void unregisterDereferencedListener(Provider.DereferenceListener onProvid
*/
public void clearDereferencedListeners() {
if (!uiThreadRunner.isOnUiThread()) {
throw new Exception("Cannot clear dereference listeners from Non-UiThread");
throw new MvcGraphException("Cannot clear dereference listeners from Non-UiThread");
}
graph.clearDereferencedListeners();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.shipdream.lib.android.mvc;

public class MvcGraphException extends RuntimeException {
public MvcGraphException(String s) {
super(s);
}

public MvcGraphException(String message, Throwable cause) {
super(message, cause);
}
}
Loading