Coder Social home page Coder Social logo

zacsweers / conductor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bluelinelabs/conductor

0.0 3.0 0.0 413 KB

A small, yet full-featured framework that allows building View-based Android applications

License: Apache License 2.0

Shell 0.36% Java 99.64%

conductor's Introduction

Travis Build Android Arsenal

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:1.1.4'

// If you want the components that go along with
// Android's support libraries (currently just a PagerAdapter):
compile 'com.bluelinelabs:conductor-support:1.1.4'

// If you want RxJava/RxAndroid lifecycle support:
compile 'com.bluelinelabs:conductor-rxlifecycle:1.1.4'

SNAPSHOT:

compile 'com.bluelinelabs:conductor:1.1.5-SNAPSHOT'
compile 'com.bluelinelabs:conductor-support:1.1.5-SNAPSHOT'
compile 'com.bluelinelabs:conductor-rxlifecycle:1.1.5-SNAPSHOT'

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 mRouter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

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

        mRouter = Conductor.attachRouter(this, container, savedInstanceState);
        if (!mRouter.hasRootController()) {
            mRouter.setRoot(new HomeController());
        }
    }

    @Override
    public void onBackPressed() {
        if (!mRouter.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:

![Controller Lifecycle](docs/Controller Lifecycle.jpg)

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 Controllers

addChildController can be called on a Controller in order to add nested Controllers. Child Controllers will receive all lifecycle callbacks that parents get.

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.

conductor's People

Contributors

adipascu avatar erickuck avatar ravidsrk avatar sockeqwe avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.