diff --git a/.ops/publishing-base.gradle b/.ops/publishing-base.gradle index 78dc7aa9..5540c7e4 100644 --- a/.ops/publishing-base.gradle +++ b/.ops/publishing-base.gradle @@ -24,6 +24,14 @@ publishing { publications { maven(MavenPublication) { + versionMapping { + usage("java-api") { + fromResolutionResult() + } + usage("java-runtime") { + fromResolutionResult() + } + } version = git.versionName() diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/AcornActivityDelegate.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/AcornActivityDelegate.kt index 49b13eb6..73a80fa8 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/AcornActivityDelegate.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/AcornActivityDelegate.kt @@ -81,10 +81,8 @@ class AcornActivityDelegate private constructor( dispatcher.onUIVisible() } - // We suppress the unused parameter to keep a uniform API. - @Suppress("UNUSED_PARAMETER") fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - dispatcher.onActivityResult(resultCode, data) + dispatcher.onActivityResult(requestCode, resultCode, data) } fun onBackPressed(): Boolean { diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/AcornSceneDispatcher.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/AcornSceneDispatcher.kt index 7c211a4e..3f695f20 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/AcornSceneDispatcher.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/AcornSceneDispatcher.kt @@ -75,8 +75,8 @@ class AcornSceneDispatcher internal constructor( return uiHandler.onBackPressed() } - override fun onActivityResult(resultCode: Int, data: Intent?) { - activityHandler.onActivityResult(resultCode, data) + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + activityHandler.onActivityResult(requestCode, resultCode, data) } override fun saveInstanceState(): SavedState { diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/SceneDispatcher.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/SceneDispatcher.kt index c80ef227..319a231b 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/SceneDispatcher.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/SceneDispatcher.kt @@ -66,7 +66,7 @@ interface SceneDispatcher { * To be invoked when the [Activity] receives an invocation to its * [Activity.onActivityResult] method. */ - fun onActivityResult(resultCode: Int, data: Intent?) + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) /** * Saves any state for this [SceneDispatcher]. diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/ActivityHandler.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/ActivityHandler.kt index 840e59ee..f6045ad2 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/ActivityHandler.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/ActivityHandler.kt @@ -31,7 +31,7 @@ internal interface ActivityHandler { fun withoutScene() - fun onActivityResult(resultCode: Int, data: Intent?) + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) fun saveInstanceState(): SavedState } diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandler.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandler.kt index 521c811e..eba1dd85 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandler.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandler.kt @@ -59,10 +59,19 @@ internal class DefaultActivityHandler( lastScene = scene lastActivityController = activityController + scene.forceAttach(activityController) + val intent = activityController.createIntent() + if (intent != null) { + v("ActivityHandler", "Starting Intent: $intent.") + callback.startForResult(intent) + scene.forceDetach(activityController) + return + } - v("ActivityHandler", "Starting Intent: $intent.") - callback.startForResult(intent) + v("ActivityHandler", "Starting ActivityController $activityController") + activityController.start() + scene.forceDetach(activityController) } override fun withoutScene() { @@ -73,8 +82,8 @@ internal class DefaultActivityHandler( } } - override fun onActivityResult(resultCode: Int, data: Intent?) { - d("ActivityHandler", "Activity result: resultCode=$resultCode, data=$data") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + d("ActivityHandler", "Activity result: requestCode=$requestCode, resultCode=$resultCode, data=$data") val scene = lastScene val activityController = lastActivityController @@ -90,7 +99,7 @@ internal class DefaultActivityHandler( scene.forceAttach(activityController) v("ActivityHandler", "Notifying ActivityController of result.") - activityController.onResult(resultCode, data) + activityController.onResult(requestCode, resultCode, data) v("ActivityHandler", "Detaching container from $scene.") scene.forceDetach(activityController) diff --git a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/presentation/ActivityController.kt b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/presentation/ActivityController.kt index 5baa472e..60a87365 100644 --- a/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/presentation/ActivityController.kt +++ b/ext/acorn-android/src/main/java/com/nhaarman/acorn/android/presentation/ActivityController.kt @@ -23,17 +23,53 @@ import com.nhaarman.acorn.presentation.Scene /** * A [Container] specialization that can be used to dispatch [Scene]s as Activities. + * + * Implementers must either implement [createIntent] or [start]. */ interface ActivityController : Container { /** * Creates the [Intent] that can be used to start the [Activity]. + * + * Override this function if you simply want to build an Intent + * and don't worry about anything else. Use [start] if you want + * to have more control. + */ + fun createIntent(): Intent? { + return null + } + + /** + * Starts the designated Activity. + * + * Override this function to start the Activity. To be able to + * call [Activity.startActivityForResult], implementers are + * responsible to deliver the receiving Activity instance. + * + * Implementations should invoke [Activity.startActivityForResult] + * rather than [Activity.startActivity], to ensure Acorn is notified + * when the Activity has finished. + * + * If you simply want to provide an Intent that should be started + * for you, override [createIntent]. + */ + fun start() { + error("Either override createIntent() or start() to start an Activity.") + } + + /** + * Called when the [Activity] started with the [Intent] provided by + * [createIntent] finishes. */ - fun createIntent(): Intent + fun onResult(resultCode: Int, data: Intent?) { + error("You must override onResult") + } /** * Called when the [Activity] started with the [Intent] provided by * [createIntent] finishes. */ - fun onResult(resultCode: Int, data: Intent?) + fun onResult(requestCode: Int, resultCode: Int, data: Intent?) { + onResult(resultCode, data) + } } diff --git a/ext/acorn-android/src/test/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandlerTest.kt b/ext/acorn-android/src/test/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandlerTest.kt index 89954075..0ed62464 100644 --- a/ext/acorn-android/src/test/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandlerTest.kt +++ b/ext/acorn-android/src/test/java/com/nhaarman/acorn/android/dispatching/internal/DefaultActivityHandlerTest.kt @@ -205,7 +205,7 @@ internal class DefaultActivityHandlerTest { activityHandler.withScene(scene, activityController) /* When */ - activityHandler.onActivityResult(3, null) + activityHandler.onActivityResult(42, 3, null) /* Then */ inOrder(scene, activityController) { @@ -232,7 +232,7 @@ internal class DefaultActivityHandlerTest { activityHandler.withScene(scene, activityController) /* When */ - activityHandler.onActivityResult(3, null) + activityHandler.onActivityResult(42, 3, null) /* Then */ inOrder(scene, activityController) {