flipper

Flipper is a simple and useful tool to deal with feature toggles

License

License

MIT
GroupId

GroupId

com.redmadrobot
ArtifactId

ArtifactId

flipper
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

flipper
Flipper is a simple and useful tool to deal with feature toggles
Project URL

Project URL

https://github.com/RedMadRobot/flipper
Source Code Management

Source Code Management

https://github.com/RedMadRobot/flipper

Download flipper

How to add to project

<!-- https://jarcasting.com/artifacts/com.redmadrobot/flipper/ -->
<dependency>
    <groupId>com.redmadrobot</groupId>
    <artifactId>flipper</artifactId>
    <version>2.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.redmadrobot/flipper/
implementation 'com.redmadrobot:flipper:2.0.1'
// https://jarcasting.com/artifacts/com.redmadrobot/flipper/
implementation ("com.redmadrobot:flipper:2.0.1")
'com.redmadrobot:flipper:aar:2.0.1'
<dependency org="com.redmadrobot" name="flipper" rev="2.0.1">
  <artifact name="flipper" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.redmadrobot', module='flipper', version='2.0.1')
)
libraryDependencies += "com.redmadrobot" % "flipper" % "2.0.1"
[com.redmadrobot/flipper "2.0.1"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.32

Project Modules

There are no modules declared in this project.

Flipper

Android Weekly API Build Status Maven Central

Flipper is a simple and useful tool to deal with feature toggles. It's not some secret weapon but rather a set of best practices to work with flipping features in your application, which is shipped as a library.

Quick start

Add this library to your gradle config

implementation 'com.redmadrobot:flipper:1.0.6'

Create a class with a description of features

object Features {

    object Feature1 : Feature() {
        override val id = "Feature1"
    }
}

Create some simplest configuration describing which features are enabled and which features are disabled:

class HardcodedConfig : FlipperConfig {
    private val features = mapOf(
        Features.Feature1.id to true
    )

    override fun featureIsEnabled(feature: Feature): Boolean {
        return features[feature.id] ?: false
    }
}

If you want to manage your features with Firebase, look at this config example.

Init the library in your Application class

ToggleRouter.init(HardcodedConfig())

Choose the necessary "feature edge" and place a toggle point (flipper point in this library terms).

val feature1Button = (Button) findViewById(R.id.feature1_button)

feature1Button.flipperPoint(Features.Feature1)

...

feature1Button.setOnClickListener { openFeature1Screen() }

Run and enjoy!

Library components

  • Feature: base class for all your feature objects. You have to provide a unique identifier for each such object.
  • ToggleRouter: features orchestrator based on some variant of the configuration
  • FlipperConfig: base class for your variant of the feature toggle configuration
  • flipperPoint: Kotlin extension function which you should place at the edge of your feature

More information about the "feature edges"

When it comes to Android application, you have only three ways of transition between features.

  • tap on the view (swipe like a special case)
  • tap on the menu item
  • an external event driven by business logic

In fact, all components that trigger transitions are the edges of the features. So, to prevent transition between features, we've got to disable the border component. You can do it using extension functions on View and MenuItem or a top-level function with flipping code blocks.

Some examples

with(feature4_button) {
    setOnClickListener { findNavController().navigate(Feature1FragmentDirections.toFeature4()) }
    flipperPoint(Features.Feature4)
}
with(bottom_nav.menu) {
    findItem(R.id.feature1).flipperPoint(Features.Feature1)
    findItem(R.id.feature2).flipperPoint(Features.Feature2)
    findItem(R.id.feature3).flipperPoint(Features.Feature3)
}
flipperPoint(Features.Feature1) {
    Log.d("Flipper", "I'll appear only when feature1 is enabled.")
}
if(flipperPointIsEnabled(Features.Feature1)) {
    Log.d("Flipper", "Feature1 is enabled.")
} else {
    Log.d("Flipper", "Feature1 is disabled.")
}

Further reading

There is an almost "classic" article about feature toggles Feature Toggles (aka Feature Flags). You can read it to know more about this library underline concepts.

Feedback

In case you have faced any bug or have a useful suggestion for improvement of this library, feel free to create an issue.

LICENSE

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

com.redmadrobot

red_mad_robot

knows its onions in mobile application development

Versions

Version
2.0.1
2.0.0