GraphFlow


Source link: https://github.com/saantiaguilera/android-api-graph_flow

GraphFlow

GraphFlow is a lightweight library for designing 'logic based' UI flows. You create a graph of nodes logically connected where each node represents a UI renderable object (fragment/view/whatever).

Minimum api level

Per module:

  • :core: 9
  • :fragments: 9
  • :views: 14
  • :conductor: 16

This library was heavily influenced by a Reddit Post

Setup

Add dependencies in your build.gradle

dependencies {

// Core library.
compile "com.saantiaguilera.graphflow:core:<latest_version>"

// For using it with fragments. Brings support-fragments
compile "com.saantiaguilera.graphflow:fragments:<latest_version>"

// For using it with views
compile "com.saantiaguilera.graphflow:views:<latest_version>"

// For using it with conductor
compile "com.saantiaguilera.graphflow:conductor:<latest_version>" 
}

Usage

  1. Create a Graph with nodes and connections. Lets say we have a signup application where:

    a. You set your name

    b. You set your age

    c. If you are <18 you validate something, else skips this

    d. You set your email

  // For this example I'll be using the View component (using fragments its the same but MView.class -> MFragment.class
// Create the type of graph, for this example we use a shipped in DirectedAcyclicGraph
Graph graph = new DirectedAcyclicGraph();

 // Create the name input node
Node nameNode = new Node(NameInputView.class, new NodeSelector() {

  @Override
  public boolean select(@Nullable final Bundle args) {

 return true; // Always pick it, its the root?
  
}

}
);

// Create the age input node
Node ageNode = new Node(AgeInputView.class, new NodeSelector() {

  @Override
  public boolean select(@Nullable final Bundle args) {

 return true; // Always pick it if coming from the name.
  
}

}
);

// Create the under 18 input node
Node underEighteenNode = new Node(UnderEighteenView.class, new NodeSelector() {

  @Override
  public boolean select(@Nullable final Bundle args) {

 return args.getInteger("age") < 18;
  
}

}
);

// Create the email input node
Node emailNode = new Node(EmailInputView.class, new NodeSelector() {

  @Override
  public boolean select(@Nullable final Bundle args) {

 return true; // Always pick, doesnt matter from where you come
  
}

}
);

 // Add the nodes to the graph, the order doesnt mind, when connected the shape will be formed.
graph.add(emailNode);

graph.add(underEighteenNode);

graph.add(ageNode);

graph.add(nameNode);

 // Connect them as we want. We will do it like this:
// Name --> age --> underEighteen --> email
//

  \_________________/
graph.connect(name, age);

graph.connect(age, underEighteen);

graph.connect(age, email);

graph.connect(underEighteen, email);

// Graph done!
  1. Create a node switcher! Node switcher is the class in charge of switching a node for another and make them "rendereable"
  // Following the example, we will use a NodeViewSwitcher. If using fragments it would be the same with NodeFragmentSwitcher
NodeSwitcher<View> nodeSwitcher = new NodeViewSwitcher(activityContext, R.id.viewgroup_container_id);
  1. Finally, create a router and start using it!
  router = Router.<View>create()
  .with(graph)
  .switcher(nodeSwitcher)
  .build();

Router

The router is the class in charge of managing the whole graph flow. The router provides a lot of useful methods:

  • fromRoot: Starts the graph from the root node. The root node is considered the only point with no incoming edges and >1 outgoing edges.

  • addOnNodeCommitListener: Adds a listener that will be triggered everytime we move from one node to another.

  • removeOnNodeCommitListener: Removes a listener, since they are kept as strong references.

  • next: Moves to the immediate node in the graph that fulfills the bundle params

  • back: Moves to the previous node

  • jump: Jumps to a given node

Proguard

This library supports proguard transitively, no need to add extra rules :)

Contributing

Feel free to submit me issues or fork it and do pull requests with changes!

Resources

Blorm is a field validation lib for android.

A syntax highlighting view, powered by highlight.js, for Android.

Highly customizable and lightweight library that allows you to create a button with animation effect similar to Twitter's heart animation.

An OkHttp interceptor which shows logs from OkHttp request and response data by shaking your device.

Featured helps you to split activity or fragment code into truly decoupled, testable and maintainable features.

A library to work with gregorian lunar calendar.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes