diff --git a/CHANGELOG.md b/CHANGELOG.md index 992f0147..5707dde7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +-Simple Stack 0.6.0 (2017-01-23) +--------------------------------- +- **Simple Stack is now a library!** +- Added `BackstackDelegate.getBackstack()` for convenience over `Backstack.get(this)` in Activity + -Simple Stack 0.5.1 (2017-01-23) --------------------------------- - Added `Bundleable` interface to allow saving view's state to Bundle diff --git a/README.md b/README.md index 0bc1a997..14f76433 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Simple Stack Demo +# Simple Stack This is a simple backstack implementation that will serve as basis for a series of Medium articles. @@ -8,6 +8,10 @@ This is a simple backstack implementation that will serve as basis for a series - [Part 4: Persisting view-state when using a custom backstack](https://medium.com/@Zhuinden/persisting-view-state-when-using-a-custom-backstack-creating-a-flow-like-backstack-part-4-5e0ba00ed80c#.ktath328c) - [Part 5: Hiding Activity-lifecycle integration inside Delegate class](https://medium.com/@Zhuinden/hiding-the-backstacks-activity-lifecycle-integration-in-a-delegate-class-creating-a-flow-like-695fe16338ff#.w3i1pnmj2) +It is theoretically based on Flow 0.9, mixed with some aspects taken from Flow 1.0-alpha; but written from scratch. + +The core concept was simplicity: maybe it should try to do less. In fact, even less than less. + ## What is it? Currently it's the following files: @@ -45,6 +49,30 @@ The backstack also allows navigation between the states, and enables handling th Also provides delegate class that hides Activity lifecycle integration, and manages view state persistence. +## Using Simple Stack + +In order to use Simple Stack, you need to add jitpack to your project root gradle: + + buildscript { + repositories { + // ... + maven { url "https://jitpack.io" } + } + // ... + } + allprojects { + repositories { + // ... + maven { url "https://jitpack.io" } + } + // ... + } + + +and add the compile dependency to your module level gradle. + + compile 'com.github.Zhuinden:simple-stack:0.6.0' + ## How does it work? The backstack must be initialized with at least one initial state, and a state changer must be set when it is able to handle the state change. @@ -53,6 +81,8 @@ Setting a state changer begins an `initialization` (in Flow terms, a bootstrap t Afterwards, the backstack operators allow changing between states. +But `BackstackDelegate` is provided as a convenience class to hide the Activity lifecycle integration and state persistence. + ``` java public class MainActivity extends AppCompatActivity @@ -113,6 +143,7 @@ public class MainActivity return super.getSystemService(name); } + // StateChanger implementation @Override public void handleStateChange(StateChange stateChange, Callback completionCallback) { if(stateChange.topNewState().equals(stateChange.topPreviousState())) { diff --git a/build.gradle b/build.gradle index 74b2ab0d..93fe790c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,11 +2,14 @@ buildscript { repositories { + mavenCentral() jcenter() + maven { url "https://clojars.org/repo/" } + maven { url "https://jitpack.io" } } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' - + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -14,7 +17,10 @@ buildscript { allprojects { repositories { + mavenCentral() jcenter() + maven { url "https://clojars.org/repo/" } + maven { url "https://jitpack.io" } } } diff --git a/simple-stack/build.gradle b/simple-stack/build.gradle index 95c2ce1a..f0e39d41 100644 --- a/simple-stack/build.gradle +++ b/simple-stack/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.library' +apply plugin: 'com.github.dcendents.android-maven' + android { compileSdkVersion 25 @@ -7,7 +9,7 @@ android { minSdkVersion 14 targetSdkVersion 25 versionCode 1 - versionName "1.0" + versionName "0.6.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -25,5 +27,30 @@ dependencies { testCompile 'org.assertj:assertj-core:1.7.1' testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.robolectric:robolectric:3.0' + testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' androidTestCompile 'junit:junit:4.12' } + +// build a jar with source files +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.sourceFiles + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += configurations.compile +} + +// build a jar with javadoc +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar + archives javadocJar +} \ No newline at end of file diff --git a/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java b/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java index 52a2fb96..0a882896 100644 --- a/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java +++ b/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java @@ -92,6 +92,15 @@ public Backstack getSystemService(String name) { return null; } + // ----- get backstack + + public Backstack getBackstack() { + if(backstack == null) { + throw new IllegalStateException("The backstack within the delegate must be initialized by `onCreate()`"); + } + return backstack; + } + // ----- viewstate persistence public void persistViewToState(View view) {