Conductor


Source link: https://github.com/bluelinelabs/Conductor

Conductor

A small, yet full-featured framework that allows building View-based Android applications. Conductor provides a light-weight wrapper around standard Android Views that does just about everything you'd want:

Conductor
🎉 Easy integration
☝? Single Activity apps without using Fragments
♻? Simple but powerful lifecycle management
🚋 Navigation and backstack handling
🔀 Beautiful transitions between views
💾 State persistence
☎? Callbacks for onActivityResult, onRequestPermissionsResult, etc
🏤 MVP / MVVM / VIPER / MVC ready

Conductor is architecture-agnostic and does not try to force any design decisions on the developer. We here at BlueLine Labs tend to use either MVP or MVVM, but it would work equally well with standard MVC or whatever else you want to throw at it.

Installation

compile 'com.bluelinelabs:conductor:2.1.4'  // If you want the components that go along with // Android's support libraries (currently just a PagerAdapter): compile 'com.bluelinelabs:conductor-support:2.1.4'  // If you want RxJava lifecycle support: compile 'com.bluelinelabs:conductor-rxlifecycle:2.1.4'  // If you want RxJava2 lifecycle support: compile 'com.bluelinelabs:conductor-rxlifecycle2:2.1.4'  // If you want RxJava2 Autodispose support: compile 'com.bluelinelabs:conductor-autodispose:2.1.4'  // If you want Controllers that are Lifecycle-aware (architecture components): compile 'com.bluelinelabs:conductor-archlifecycle:0.1.1'

SNAPSHOT

Just use 2.1.5-SNAPSHOT as your version number in any of the dependencies above and add the url to the snapshot repository:

allprojects {

repositories {

  maven {
 url "https://oss.sonatype.org/content/repositories/snapshots/" 
}

}
 
}

Components to Know

Conductor Components
Controller The Controller is the View wrapper that will give you all of your lifecycle management features. Think of it as a lighter-weight and more predictable Fragment alternative with an easier to manage lifecycle.
Router A Router implements navigation and backstack handling for Controllers. Router objects are attached to Activity/containing ViewGroup pairs. Routers do not directly render or push Views to the container ViewGroup, but instead defer this responsibility to the ControllerChangeHandler specified in a given transaction.
ControllerChangeHandler ControllerChangeHandlers are responsible for swapping the View for one Controller to the View of another. They can be useful for performing animations and transitions between Controllers. Several default ControllerChangeHandlers are included.
ControllerTransaction Transactions are used to define data about adding Controllers. RouterControllerTransactions are used to push a Controller to a Router with specified ControllerChangeHandlers, while ChildControllerTransactions are used to add child Controllers.

Getting Started

Minimal Activity implementation

public class MainActivity extends Activity {

private Router router;

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 setContentView(R.layout.activity_main);

 ViewGroup container = (ViewGroup)findViewById(R.id.controller_container);

 router = Conductor.attachRouter(this, container, savedInstanceState);

if (!router.hasRootController()) {

 router.setRoot(RouterTransaction.with(new HomeController()));

}

  
}

@Override
  public void onBackPressed() {

if (!router.handleBack()) {

 super.onBackPressed();

}

  
}
  
}

Minimal Controller implementation

public class HomeController extends Controller {

@Override
  protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {

View view = inflater.inflate(R.layout.controller_home, container, false);

((TextView)view.findViewById(R.id.tv_title)).setText("Hello World");

return view;
  
}
  
}

Sample Project

Demo app - Shows how to use all basic and most advanced functions of Conductor.

Controller Lifecycle

The lifecycle of a Controller is significantly simpler to understand than that of a Fragment. A lifecycle diagram is shown below:

Advanced Topics

Retain View Modes

setRetainViewMode can be called on a Controller with one of two values: RELEASE_DETACH, which will release the Controller's view as soon as it is detached from the screen (saves memory), or RETAIN_DETACH, which will ensure that a Controller holds on to its view, even if it's not currently shown on the screen (good for views that are expensive to re-create).

Custom Change Handlers

ControllerChangeHandler can be subclassed in order to perform different functions when changing between two Controllers. Two convenience ControllerChangeHandler subclasses are included to cover most basic needs: AnimatorChangeHandler, which will use an Animator object to transition between two views, and TransitionChangeHandler, which will use Lollipop's Transition framework for transitioning between views.

Child Routers & Controllers

getChildRouter can be called on a Controller in order to get a nested Router into which child Controllers can be pushed. This enables creating advanced layouts, such as Master/Detail.

RxJava Lifecycle

If the RxLifecycle dependency has been added, there is an RxController available that can be used along with the standard RxLifecycle library. There is also a ControllerLifecycleProvider available if you do not wish to use this subclass.

License

Copyright 2016 BlueLine Labs, Inc.  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. 

Resources

A night model lib to change app's night theme easy. You do not need to restart Activity.

A messaging library for Android.

A cool customizable loading animation with Dots.

A simple and easy-to-use scroll number widget.

Simple implementations of a EditText widgets, which can help to visualise inputted text. Classes are inherited from AppCompatEditText.

FSquaDRA is a tool for detection of repackaged Android applications. The approach is based on the idea that repackaged applications want to maintain "look and feel" of the originals.

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