Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Allowing to implement RosiePresenter.View interfaces in base Fragments or Activity classes #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion rosie/src/main/java/com/karumi/rosie/view/RosiePresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,31 @@ private Class<?> getViewInterfaceClass() {
interfaceClass = interfaceCandidate;
}
}
return interfaceClass;
if (interfaceClass != null) {
return interfaceClass;
} else {
return getViewInterfaceSuperClass(this.view.getClass());
}
}

private Class<?> getViewInterfaceSuperClass(Class<?> currentClass) {
Class<?> interfaceClass = null;
Class<?> superClass = currentClass.getSuperclass();
Class<?>[] interfaces = superClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
Class<?> interfaceCandidate = interfaces[i];
if (RosiePresenter.View.class.isAssignableFrom(interfaceCandidate)) {
interfaceClass = interfaceCandidate;
}
}
if (interfaceClass != null) {
return interfaceClass;
} else {
return getViewInterfaceSuperClass(superClass);
}
}


private void registerGlobalErrorCallback() {
if (shouldRegisterGlobalErrorCallbacks) {
for (OnErrorCallback onErrorCallback : globalOnErrorCallbacks) {
Expand Down