Skip to content

Commit

Permalink
0.6.0: Simple Stack is now a library
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Jan 23, 2017
1 parent 3cdd557 commit a12529a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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())) {
Expand Down
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

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
}
}

allprojects {
repositories {
mavenCentral()
jcenter()
maven { url "https://clojars.org/repo/" }
maven { url "https://jitpack.io" }
}
}

Expand Down
29 changes: 28 additions & 1 deletion simple-stack/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'


android {
compileSdkVersion 25
Expand All @@ -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 {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a12529a

Please sign in to comment.