Skip to content

Commit

Permalink
Merge pull request #121 from nhaarman/transparent-navigator
Browse files Browse the repository at this point in the history
ConcurrentPairNavigator
  • Loading branch information
nhaarman authored Apr 7, 2019
2 parents 7ef9824 + e40452e commit 3903eb5
Show file tree
Hide file tree
Showing 35 changed files with 2,982 additions and 13 deletions.
9 changes: 5 additions & 4 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
:ext-acorn-android-timber:lint \
:ext-acorn-android-lifecycle:lint \
\
:samples:hello-world:lintRelease \
:samples:hello-concurrentpairnavigator:lintRelease \
:samples:hello-navigation:lintRelease \
:samples:hello-staterestoration:lintRelease \
:samples:hello-startactivity:lintRelease \
:samples:hello-sharedata:lintRelease \
:samples:hello-viewfactory:lintRelease \
:samples:hello-startactivity:lintRelease \
:samples:hello-staterestoration:lintRelease \
:samples:hello-transitionanimation:lintRelease \
:samples:hello-viewfactory:lintRelease \
:samples:hello-world:lintRelease \
\
:samples:notes-app:android:lintRelease \
\
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
**.log

*.orig
*.attach_*

.idea/assetWizardSettings.xml
.idea/caches/*
Expand Down
2 changes: 2 additions & 0 deletions .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions ext/acorn/acorn-experimental/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id("org.jetbrains.kotlin.jvm")
id("org.gradle.java-library")

id("org.jetbrains.dokka")
id("org.gradle.maven-publish")
id("signing")
}

dependencies {
api project(":acorn")
api project(":ext-acorn")

implementation "org.jetbrains.kotlin:kotlin-stdlib"

compileOnly "androidx.annotation:annotation"

testImplementation "com.nhaarman:expect.kt"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testRuntime "org.junit.jupiter:junit-jupiter-engine"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = ["-Xuse-experimental=kotlin.Experimental"]
}
}
2 changes: 2 additions & 0 deletions ext/acorn/acorn-experimental/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
groupId=com.nhaarman.acorn.ext
artifactId=acorn-experimental
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2018 Niek Haarman
*
* 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.nhaarman.acorn.navigation.experimental

import com.nhaarman.acorn.presentation.Container
import com.nhaarman.acorn.presentation.RestorableContainer
import com.nhaarman.acorn.presentation.SavableContainer
import com.nhaarman.acorn.state.ContainerState
import com.nhaarman.acorn.state.get

/**
* A [Container] that combines two Containers into one.
*
* This interface is used in conjunction with [ConcurrentPairNavigator].
*/
@ExperimentalConcurrentPairNavigator
interface CombinedContainer : RestorableContainer {

val firstContainer: Container
val secondContainer: Container

override fun saveInstanceState(): ContainerState {
return ContainerState().also {
it["first"] = (firstContainer as? SavableContainer)?.saveInstanceState()
it["second"] = (secondContainer as? SavableContainer)?.saveInstanceState()
}
}

override fun restoreInstanceState(bundle: ContainerState) {
bundle.get<ContainerState>("first")?.let {
(firstContainer as? RestorableContainer)?.restoreInstanceState(it)
}

bundle.get<ContainerState>("second")?.let {
(secondContainer as? RestorableContainer)?.restoreInstanceState(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2018 Niek Haarman
*
* 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.nhaarman.acorn.navigation.experimental

import com.nhaarman.acorn.presentation.Container
import com.nhaarman.acorn.presentation.Scene
import com.nhaarman.acorn.presentation.SceneKey

/**
* A [Scene] that combines two Scenes into one.
* The key of this Scene is taken from [secondScene].
*
* This class is used in conjunction with [ConcurrentPairNavigator].
*/
@ExperimentalConcurrentPairNavigator
class CombinedScene(
val firstScene: Scene<out Container>,
val secondScene: Scene<out Container>
) : Scene<CombinedContainer> {

override val key: SceneKey
get() = secondScene.key

override fun onStart() {
}

@Suppress("UNCHECKED_CAST")
override fun attach(v: CombinedContainer) {
(firstScene as Scene<Container>).attach(v.firstContainer)
(secondScene as Scene<Container>).attach(v.secondContainer)
}

@Suppress("UNCHECKED_CAST")
override fun detach(v: CombinedContainer) {
(secondScene as Scene<Container>).detach(v.secondContainer)
(firstScene as Scene<Container>).detach(v.firstContainer)
}

override fun onStop() {
}

override fun onDestroy() {
}
}
Loading

0 comments on commit 3903eb5

Please sign in to comment.