This is powerful android framework

Overview

FlairFramework

alt text

Kotlin 1.3.71 Download Codacy BadgeAwesome Kotlin Badge

This is an android framework for build complex application with different architectures (MVC ready/MVP/MVVM/MVI ets). It's create on top of MVC pattern with powerful event system, constructor injection module and property delegation, also it support multi-core instances and animation changes between views (see example project for more information). The FlairFramework is easy to use, it's light-weight, extensible, flexible and it's has more simplier view lifecycle than Fragments and Activities

The start point for initialize framework is declare 'flair' instance in onCreate method in MainApplication file. But u can initialize framework in any part of your project such as MainActivity or any Context implementations

val flairCoreInstance = flair {
        registerCommand<MyCommand>(eventName) { MyCommand() }
        registerProxy<MyProxy> { MyProxy() }
        registerMediator<MyMediator> { MyMediator() }
    }
    // you can define more than one core instance of flair by given the name
val flairSecondCore = flair(SECOND_CORE_NAME) {}

The second point or using 'Flair' is attach created core to single Activity class and root layout container (but u can no specify any root container and 'Flair' take it for you automatically as activity.window.decorView.findViewById(android.R.id.content)). Important thing: only one activity can be stored in one core of FlairFramework

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val showingAnimation = LinearAnimator()
        flair().attach(this).showLastOrExistMediator<MyMediator>(showingAnimation)
        // or 
        // val rootContainer = frameLayout()
        // flair().attach(this, rootContainer).retrieveMediator<MyMediator>().show()
    }
}

Components:

  1. 'flair' instance is a simple IFacade singleton instance as core functionality point
  2. SimpleCommand instances is a command pattern realisation. You can manipulate proxy objects from it's instance as like usecases by siquence one command to notification like registerCommand<MyCommand>(YOUR_EVENT_NAME) { MyCommand() }
  3. MacroCommands can combine more than one SimpleCommand and execute it one by one
  4. Proxy objects is a complex object that store data to manipulate with, it's like repository for ur network calls or database
  5. Mediator is a simple view-hierarchy handler class, it's store and manage life cycle of your view components such as AnkoComponents or xml-layout files. Also it support view backstack storage.
  6. Also you has LinearAnimator.kt for create simple view animation changes such as HorizontalAnimation, or u can extends LinearAnimator and create your own realisation.
  7. All components of a FlairFramework are linked together by a powerful messaging system. You can notify every part of your system by calling sendNotification(event, data) and subscribe on event by calling registerObserver(event) { INotification -> } in IMediator or execute another SimpleCommand (see example above). Mediator can notify commands, commands can notify mediators and another commands, proxy can notify mediators and another commands.

Mediators can handle notification by

class MyMediator : Mediator() {
  // called when medaitor is registered
  override fun onRegister() {
      // register notification for this IMediator instance
      registerObserver(eventName:String) {
            // event handler
      }
      sendNotification(eventName)
  }
  
  // the way to create UI
  override fun createLayout(context: Context): View = UserAuthUI().createView(AnkoContext.create(context, this)) 
  // or you can inflate you custom xml layout
  // override fun createLayout(context: Context): View = inflateView(R.layout.simple_layout) 
  
  class UserAuthUI : AnkoComponent<MyMediator> {
    override fun createView(ui: AnkoContext<MyMediator>) = with(ui) {
        verticalLayout {
            lparams(matchParent, matchParent)
            textView("HELLO WORLD")
        }
    }
  }
}

Proxy object can recieve notification by linked commands as usecases

class MyProxy : Proxy<String>("data_to_store_in_proxy") {
    fun handleNotification() {
        Low.d("HELLO FROM PROXY")
    }
}
//the command that controls the proxy
class MyCommand : SimpleCommand() {
    val myProxy by proxyLazy<MyProxy>()
    override fun execute(notification: INotification) {
         myProxy.handleNotification()
         // or you can use inline functions
         // proxy<MyProxy>().handleNotification()
    }
}

Register all components of Flair framework (Mediators, Proxies, Command) in any part of your application by calling lazy functions or inline functions like proxy(), proxyLazy(), mediator(), mediatorLazy() from reflection module since 1.5.+

You can use powerful feature from kotlin lang like lazy val instantiating, this is an example with custom constructor parameters. Important note: that since version 1.5.+ you need to add

class MyProxyWithParams(mediator:MyMediator) : Proxy<MyMediator>(mediator) {
    override fun onRegister() {
        super.onRegister()
        data?.showFuncyMVPHandler()
    }
}

class MyMediator : Mediator() {
  // lazy proxy initialization with params
  val proxy:MyProxyWithParams by proxyLazy(this)
  // or
  // val proxy by proxyLazy<MyProxyWithParams>(this)
  
  fun showFuncyMVPHandler(){
     println("HELLO FROM PROXY TO MEDIATOR")
  }
}

Since verson 1.1.3 added new extension functions

fun IMediator.startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?= null)
fun IMediator.requestPermissions(permissions: Array<String>, requestCode: Int)
fun IMediator.checkSelfPermission(permissionToCheck:String):Int
fun IMediator.shouldShowRequestPermissionRationale(permission: String): Boolean

and they callbacks:

class MyMediator : Mediator() {
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            // do what ever you want with result data
    }
    
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
          // check if permission granted or not 
    }
}

Since version 1.1.4 you can use FlairPagerAdapter for control viewPager with mediators

viewPager?.adapter = FlairPagerAdapter(
                listOf(mediator<PageOneMediator>(), mediator<PageTwoMediator>(), mediator<PageThreeMediator>()),
                listOf("TabOne", "TabTwo", "TabThree"))
tabLayout?.setupWithViewPager(viewPager)
        
        
class PageOneMediator : Mediator() {
// or you can inflate your view from xml by calling inflateView(R.layout.simple_layout)
    override fun createLayout(context: Context): View = with(context) {
        verticalLayout {
            lparams(matchParent, matchParent)

            textView("THIS IS A PAGE ONE MEDIATOR") {
                textSize = 14f
                textColor = Color.GREEN
            }.lparams {
                gravity = Gravity.CENTER_HORIZONTAL
            }
        }
    }
}

Since version 1.5.0 - there are many new features and changes in framework:

  • The core version is under com.rasalexman.flaircore package and you need to add new packageimplementation 'com.rasalexman.flaircore:flaircore:1.5.+' into your build.gradle file
  • The reflection module included by implementing com.rasalexman.flairreflect:flairreflect:1.5.x and has all the reflection library features like constructor injection, lazy initialization and all the features that was at pre 1.5.+ (1.x.y).
  • Added new animations FadeAnimator, NextLinearAnimator, BackLinearAnimator.
  • Turned minSdkVersion = 19 )

See the sample project app for more complex information. Also code base has good comments and docs on every functions

Maven:

// Core
<dependency>
  <groupId>com.rasalexman.flaircore</groupId>
  <artifactId>flaircore</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
</dependency>

// reflection module
<dependency>
  <groupId>com.rasalexman.flairreflect</groupId>
  <artifactId>flairreflect</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
</dependency>

// coroutines module
<dependency>
	<groupId>com.rasalexman.flaircoutines</groupId>
	<artifactId>flaircoroutines</artifactId>
	<version>x.y.z</version>
	<type>pom</type>
</dependency>

Gradle:

// standart multicore version (without reflection)
implementation 'com.rasalexman.flaircore:flaircore:2.y.z'

// reflection module (for use constructor injections and property injection)
implementation 'com.rasalexman.flairreflect:flairreflect:2.y.z'

// coroutines module 
implementation 'com.rasalexman.flaircoutines:flaircoroutines:2.y.z'

Changelog

  • 2.0.0:
  1. Separate code packages to core functionality and extensions in package com.rasalexman.flaircore.ext.*
  2. IMediator.mediatorName is not a optional for better performance
  3. IProxy.data is not optional anymore but you can support optional like object : Proxy<String?>(null) {}
  4. All HashMap storages now changed to androidx.collection.ArrayMap
  5. Reduce memory leaks when call IFacade.remove() and clear core data
  6. IFacade.attach now take an activity: FragmentActivity as parameter

  • 1.5.7 - Code refactoring, less library size, changes data structures
  • 1.5.4 - Migration to AndroidX and new coroutines 1.3.3
  • 1.5.2 - Added new module flaircoroutines with Async task manager and coroutines manager
  • 1.5.1 - Added AppCompatActivity to View.attachActivity(...) with activity fragmentManager.
  • 1.5.0:
  1. Separate FlairFramework packages to core and reflection modules. Now core module weight is less then 125 Kb and you don't need to worry about reflection library in your proguard file!!!
  2. Add example with GOOGLE LiveData
  3. minSdkVersion come back to 17
  4. IMediator.isAddToBackStack - new property that means: does this mediator need to be added in backstack if you want to organize your own backstack)
  5. Added new animations - FadeAnimator, NextLinearAnimator, BackLinearAnimator.
  6. Many bug fixes and code improvements

  • 1.2.5
  1. fix bug with IView.checkSelfPermission(permissionToCheck: String)
  2. update kotlin version to 1.2.70
  • 1.2.4
  1. added some useful extension functions
  2. Model is final class now
  • 1.2.3:
  1. fixed bug in IView.hideMediator when pop curent Mediator after animation changed
  2. added hashBackButton:Boolean to ToolbarMediator
  3. minSdkVersion 19
  4. split inner classes from com.rasalexman.flairframework.core.animation.* to AnimationPreDrawListener, BaseAnimationListenerAdapter and added abstract class BaseAnimator
  5. changed MutableMap to ArrayMap for memory improvements
  6. View.currentActivity is WeakReference
  7. changed MacroCommand.initializeMacroCommand from constructor to IController.registerCommand
  8. added IMediator.onAnimationStart and IMediator.onAnimationFinish
  9. added IMediator.removeMediator
  10. Docs added, plus a lot of memory improvements and code refactoring.
  • 1.2.0:
  1. Change flair package name to com.rasalexman.flairframework
  2. Added IMediator.startActivity(intent:Intend, bundle:Bundle? = null) for start another activity from mediators

  • 1.1.9 - added IMediator.removeObserver and IMediator.removeAllObservers to manually remove notification observers from mediator instance
  • 1.1.8 - Added bundle argument to IMediator, added one more lifecyrcle fun onPrepareView()
  • 1.1.7 - Added hardware back button support (see example in app)
  • 1.1.6 - fixed rotation bug with menu creation, many improvements
  • 1.1.5 - fix bug in View.kt clearAll()
  • 1.1.4 - added com.mincor.flairframework.common.adapters.FlairPagerAdapter
  • 1.1.3 - extension functions for permissions and activity

License

MIT License

Copyright (c) 2018 Aleksandr Minkin ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

You might also like...
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

A framework for writing composable parsers based on Kotlin Coroutines.

Parsus A framework for writing composable parsers based on Kotlin Coroutines. val booleanGrammar = object : GrammarBooleanExpression() { val ws

Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing functionality and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.), inspired by Badoos RIBs fork of the Uber RIBs framework
Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing functionality and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.), inspired by Badoos RIBs fork of the Uber RIBs framework

Decompose Please see the project website for documentation and APIs. Decompose is a Kotlin Multiplatform library for breaking down your code into life

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

General purpose parsing framework. Simplify parsing of text

General purpose parsing framework. Simplify parsing of text. Allows capture complex nested formats with simple and human-readable syntax.

Framework for quickly creating connected applications in Kotlin with minimal effort
Framework for quickly creating connected applications in Kotlin with minimal effort

Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. import io.ktor.server.n

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

A sample application that build with combine use Clean Architecture framework and Github API
A sample application that build with combine use Clean Architecture framework and Github API

The Github Example Introduction This is a sample application that build with combine use Clean Architecture framework and Github API (https://develope

A modular object storage framework for Kotlin multiplatform projects.

ObjectStore A modular object storage framework for Kotlin multiplatform projects. Usage ObjectStore provides a simple key/value storage interface whic

Comments
  • can't build flair project

    can't build flair project

    I have cloned flair repo and trying to build the project but it seems something missing from repo. In the flaircore module apply from: 'deploy.gradle' the deploy.gradle is missing so I can't build the project.

    opened by sh3lan93 3
Releases(2.0.1)
  • 2.0.1(Apr 6, 2020)

    1. Separate code packages to core functionality and extensions in package com.rasalexman.flaircore.ext.*
    2. IMediator.mediatorName is not a optional for better performance
    3. IProxy.data is not optional anymore but you can support optional like object : Proxy<String?>(null) {}
    4. All HashMap storages now changed to androidx.collection.ArrayMap
    5. Reduce memory leaks when call IFacade.remove() and clear core data
    6. IFacade.attach now take an activity: FragmentActivity as parameter

    Migration Guide: Change import com.rasalexman.flaircore.interfaces to import com.rasalexman.flaircore.ext

    Source code(tar.gz)
    Source code(zip)
  • 1.5.7(Apr 6, 2020)

  • 1.5.4(Jan 31, 2020)

  • 1.5.2(Jan 10, 2019)

  • 1.5.1(Dec 24, 2018)

  • 1.5.0(Dec 17, 2018)

    • Separate FlairFramework packages to core and reflection modules. Now core module weight is less then 125 Kb and you don't need to worry about reflection library in your proguard file!!!
    • Added example with GOOGLE LiveData (https://developer.android.com/topic/libraries/architecture/livedata)
    • minSdkVersion come back to 17
    • IMediator.isAddToBackStack - new property that means: does this mediator need to be added in backstack if you want to organize your own backstack)
    • Added new animations - FadeAnimator, NextLinearAnimator, BackLinearAnimator.
    • Many bug fixes and code improvements
    Source code(tar.gz)
    Source code(zip)
  • 1.2.5(Sep 20, 2018)

  • 1.2.4(Aug 21, 2018)

  • 1.2.3(Aug 17, 2018)

    • fixed bug in IView.hideMediator when pop curent Mediator after animation changed
    • added hashBackButton:Boolean to ToolbarMediator
    • minSdkVersion 19
    • split inner classes from com.rasalexman.flairframework.core.animation.* to AnimationPreDrawListener, BaseAnimationListenerAdapter and added abstract class BaseAnimator
    • changed MutableMap to ArrayMap for memory improvements
    • View.currentActivity is WeakReference
    • changed MacroCommand.initializeMacroCommand from constructor to IController.registerCommand
    • added IMediator.onAnimationStart and IMediator.onAnimationFinish
    • added IMediator.removeMediator

    Docs added, plus a lot of memory improvements and code refactoring.

    Source code(tar.gz)
    Source code(zip)
  • 1.2.2(Aug 13, 2018)

  • 1.2.0(Aug 9, 2018)

    • Change flair package name to com.rasalexman.flairframework
    • Added IMediator.startActivity(intent:Intend, bundle:Bundle? = null) for start another activity from mediators
    Source code(tar.gz)
    Source code(zip)
  • 1.1.9(Aug 6, 2018)

    • added IMediator.removeObserver and IMediator.removeAllObservers to manually remove notification observers from mediator instance
    • refactor IMediator.registerListObservers
    Source code(tar.gz)
    Source code(zip)
  • 1.1.8(Aug 5, 2018)

  • 1.1.7(Aug 4, 2018)

  • 1.1.6(Aug 3, 2018)

    1. IMediator.onAddedView and IMediator.onRemovedView now take view:View as a parameter
    2. fix bug with rotation and menu initialization
    3. improvement of work
    Source code(tar.gz)
    Source code(zip)
  • 1.1.5(Jul 29, 2018)

  • 1.1.4(Jul 29, 2018)

    Added support to use PagerAdapter with IMediator views by FlairPagerAdapter contained in a new package of flairframework called common/adapters see example project to know more

    Source code(tar.gz)
    Source code(zip)
  • v1.1.3(Jul 17, 2018)

    added new functionality

    • fun IMediator.startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?= null)
    • fun IMediator.requestPermissions(permissions: Array, requestCode: Int)
    • fun IMediator.checkSelfPermission(permissionToCheck:String):Int
    • fun IMediator.shouldShowRequestPermissionRationale(permission: String): Boolean
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 11, 2018)

    • inline INotifier core variables
    • refactor INotifier and IMediator
    • rename function from proxy to proxyLazy
    • add inline IMediator.showMediator function
    • changed examples
    Source code(tar.gz)
    Source code(zip)
Owner
Alexandr Minkin
Lead Software Developer - Kotlin - Swift - Java - C#
Alexandr Minkin
A powerful tool (iOS & Android) that focuses on mobile operation behavior!

DiDiPrism,中文名:小桔棱镜,是一款专注于移动端操作行为的工具,涵盖APP操作回放、操作检测、以及数据可视化能力。我们在整个方案的实现过程中沉淀出了一套技术框架,希望可以逐步开源出来帮助更多人,同时也希望棱镜在大家的合力下能够更快的成长。 它有哪些亮点? 零入侵 业务代码无需任何适配。 高可

DiDi 1.6k Dec 22, 2022
A lightweight, simple, smart and powerful Android routing library.

RxRouter Read this in other languages: 中文, English A lightweight, simple, smart and powerful Android routing library. Getting started Setting up the d

Season 323 Nov 10, 2022
Runtime Mobile Security (RMS) 📱🔥 - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) ?? ?? by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Mobile Security 2k Dec 20, 2022
A powerful Minecraft Server Software coming from the future

Mirai A powerful Minecraft Server Software coming from the future Mirai is ❗ under heavy development ❗ and contributions are welcome! Features 30% fas

Etil 354 Dec 30, 2022
⏰ A powerful and simple-to-use guilded wrapper made in Kotlin.

⏰ guilded-kt [WIP] A powerful yet simple-to-use guilded wrapper made entirely in Kotlin with supporting multiplatform. Take a look at an example of th

Gabriel 13 Jul 30, 2022
🎲 A powerful and simple-to-use guilded wrapper made in Kotlin.

?? deck [WIP] Deck is a powerful yet simple-to-use guilded wrapper made entirely in Kotlin with support to multiplatform. Implementating In case you'r

Gabriel 13 Jul 30, 2022
Kauth - Open-source powerful minecraft authorization plugin

KAuth KAuth is a minecraft plugin for offline-mode authorization on your server.

Viktor 1 Feb 17, 2022
Android MVVM framework write in kotlin, develop Android has never been so fun.

KBinding 中文版 Android MVVM framework write in kotlin, base on anko, simple but powerful. It depends on my another project AutoAdapter(A library for sim

Benny 413 Dec 5, 2022
Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One - Cross Platform Native Apps with Java or Kotlin Codename One is a mobile first cross platform environment for Java and Kotlin developers

Codename One 1.4k Jan 9, 2023
Ivy FRP is a Functional Reactive Programming framework for declarative-style programming for Android

FRP (Functional Reactive Programming) framework for declarative-style programming for Andorid. :rocket: (compatible with Jetpack Compose)

null 8 Nov 24, 2022