├── .gitignore ├── CODEOWNERS ├── LICENSE ├── README.md ├── bintray.gradle ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── install.gradle ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── kotlin │ └── io │ └── fluent │ ├── Hub.kt │ ├── Job.kt │ ├── State.kt │ ├── StateType.kt │ ├── Store.kt │ └── View.kt ├── rx-library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── io │ │ └── fluent │ │ └── rx │ │ ├── RxHub.kt │ │ ├── RxJob.kt │ │ └── RxStore.kt │ └── res │ └── values │ └── strings.xml ├── samples └── RxFirebaseLogin │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── proguard-rules.pro │ └── src │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── br │ │ │ └── com │ │ │ └── rsicarelli │ │ │ └── rxfirebaselogin │ │ │ ├── App.kt │ │ │ ├── feature │ │ │ └── login │ │ │ │ ├── LoginActivity.kt │ │ │ │ ├── LoginHub.kt │ │ │ │ ├── LoginModule.kt │ │ │ │ ├── LoginState.kt │ │ │ │ ├── LoginView.kt │ │ │ │ ├── google │ │ │ │ ├── GoogleFirebaseAuth.kt │ │ │ │ └── GoogleLogin.kt │ │ │ │ └── jobs │ │ │ │ ├── DoGoogleLoginJob.kt │ │ │ │ └── RequestGoogleLoginJob.kt │ │ │ └── infra │ │ │ └── di │ │ │ ├── ActivityScoped.kt │ │ │ ├── component │ │ │ └── ApplicationComponent.kt │ │ │ └── module │ │ │ ├── ActivityBuilderModule.kt │ │ │ └── ApplicationModule.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_login.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── br │ └── com │ └── rsicarelli │ └── rxfirebaselogin │ └── feature │ └── login │ └── jobs │ ├── DoGoogleLoginJobTest.kt │ └── RequestGoogleLoginJobTest.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | 39 | # Keystore files 40 | *.jks 41 | 42 | # External native build folder generated in Android Studio 2.2 and later 43 | .externalNativeBuild 44 | 45 | # Google Services (e.g. APIs or Firebase) 46 | google-services.json 47 | 48 | # Freeline 49 | freeline.py 50 | freeline/ 51 | freeline_project_description.json 52 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # These owners will be the default owners for everything in the repo. 5 | * @ftgoncalves @rsicarelli @rodrigohenriques -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Fluent 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Fluent 3 | 4 | Fluent is a lightweight framework that helps you to create an entirely Android Application following SOLID pattern with a unidirectional flow using reactive concepts or not. 5 | 6 | The main concepts in this architecture are: `State`, `View`, `Store`, `Job` and `Hub` 7 | 8 | --- 9 | >![fluent diagram](https://image.ibb.co/cAXPhH/Screen_Shot_2018_04_11_at_12_09_41.png) 10 | --- 11 | 12 | ## Download 13 | 14 | You have to add Fluent maven repository to your project 15 | ```groovy 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 |    maven { url 'http://dl.bintray.com/fluentio/maven' } 21 | } 22 | } 23 | ``` 24 | 25 | 26 | Then you'll be able to download Fluent dependencies 27 | ```groovy 28 | implementation 'io.fluent:library:0.2.0' 29 | implementation 'io.fluent:rx-library:0.2.0' 30 | ``` 31 | 32 | 33 | ## Concept Explanation 34 | 35 | ### View 36 | 37 | The `View` class is the entry point of your Fluent flow. Basically, you need to expose all the events (or streams) that the `Hub` class needs to connect with some `Job`. 38 | 39 | You need to create your own specialized `View `class for each view of your application. 40 | 41 | A regular implementation of your `View`: 42 | 43 | ```kotlin 44 | interface LoginView : View { 45 | fun doLoginClicks(): UserCredentials 46 | } 47 | ``` 48 | 49 | Note that the `View` class is the reference to your screen itself and you should attach your screen `State` as well. 50 | 51 | Your `Activity`, `Fragment` or `Custom View` needs to implement your `View` class: 52 | 53 | ```kotlin 54 | class LoginActivity : AppCompatActivity(), LoginView { 55 | override fun bind(newState: LoginState) { ... } 56 | } 57 | ``` 58 | 59 | > For convenience, the Fluent framework already provides the `bind()` function. It is just a helper function to reduce the boilerplate. 60 | 61 | >See how to implement [with rx](#view---reactive-way) and [without rx](#view---non-reactive-way) 62 | 63 | ### State 64 | 65 | The `State` represents some state of your screen. In order to reduce inconsistency from your `View`, the `State` is an object who represents the entire state which you view should react. 66 | 67 | Note that your view's state should be a `data class`, which means that your `View` should not have more than one single `State`. 68 | 69 | It is a good practice that each of your screens has your own `State` class. 70 | Fluent already provides the `type()` function so you can easily retrieve the type of your view's state. 71 | 72 | By default, every `State` has a `StateType` which represents the type of your view state. 73 | 74 | #### StateType 75 | 76 | The `StateType` is class that you can create the different states of your view. 77 | The Fluent framework already provides four default StateType, which is: `Initial`, `Loading`, `Success` and `Error`. 78 | 79 | You can easily create your own StateType inheriting the StateType class: 80 | 81 | ```kotlin 82 | class LoginStateType : StateType() { 83 | object Refreshing : StateType() 84 | class Error(val message: String) : StateType() 85 | } 86 | ``` 87 | 88 | ### Store 89 | 90 | Responsible for handle all the new States. It is the only way to update the View state. 91 | It receives all the possible states of a `View` so you don't need to worry, because we take care about statefulness and performance. 92 | 93 | >See how to implement [with rx](#rxstore) and [without rx](#store---non-reactive-way) 94 | 95 | ### Job 96 | 97 | A job is a little piece of work which might look like an atomic operation. It can be network calls, database operations, third-party libraries or even a view-lifecycle handling. 98 | 99 | It's the only place where you can generate new states and push them to the `Store`. 100 | 101 | >See how to implement [with rx](#rxjob) and [without rx](#job---non-reactive-way) 102 | 103 | ### Hub 104 | 105 | The `Hub` is maybe the most important and disruptive layer of this framework. 106 | For each new `View` events, your `Hub` should connect with some `Job`. 107 | 108 | It is responsible to `connect()` the `View` and the `Job`'s layers. 109 | 110 | You can combine and/or filter actions before performing the `Job` itself. It acts kind like a bridge binding user actions with the use cases. 111 | 112 | >See how to implement [with rx](#rxhub) and [without rx](#hub---non-reactive-way) 113 | 114 | 115 | ## Implementing in a non Reactive Way 116 | 117 | ### View - Non Reactive Way 118 | `//TODO` 119 | Too be filled 120 | 121 | ### Store - Non Reactive Way 122 | `//TODO` 123 | Too be filled 124 | 125 | ### Job - Non Reactive Way 126 | `//TODO` 127 | Too be filled 128 | 129 | ### Hub - Non Reactive Way 130 | `//TODO` 131 | Too be filled 132 | 133 | ## Implementing in a Reactive way 134 | 135 | Besides Fluent can be used with callbacks, Fluent can be more charming with Reactive Extensions, following the Reactive Manifesto 136 | 137 | ### View - Reactive Way 138 | 139 | Stay aware to think in a way to declare all the user's actions and screen's actions related as `Observable`. 140 | 141 | ```kotlin 142 | interface LoginView : View { 143 | fun doLoginClicks(): Observable 144 | fun activityResults(): Observable> 145 | } 146 | ``` 147 | 148 | ### RxStore 149 | > `RxStore` is an implementation of `Store` that works with Reactive Extensions 150 | 151 | It requires an initial `State`. You can use the `stateChanges()` to start receiving new states: 152 | 153 | ```kotlin 154 | RxStore(SomeState()).stateChanges() 155 | .observeOn(mainThread) 156 | .subscribe { newState -> bind(newState) } 157 | ``` 158 | 159 | The stream created by it can be handled inside the `View` implementation. 160 | 161 | ```kotlin 162 | override fun onCreate(savedInstanceState: Bundle?) { 163 | super.onCreate(savedInstanceState) 164 | setContentView(R.layout.activity_login) 165 | 166 | store.stateChanges() 167 | .observeOn(AndroidSchedulers.mainThread()) 168 | .subscribe { bind(it) } 169 | } 170 | 171 | override fun bind(newState: LoginState) { 172 | when (newState.type) { 173 | StateType.Success -> success() 174 | StateType.Error -> error() 175 | StateType.Loading -> loading() 176 | } 177 | } 178 | ``` 179 | 180 | 181 | ### RxJob 182 | > `RxJob` is an implementation of `Job` that works with Reactive Extensions 183 | 184 | 185 | The RxJob have the `bind()` function, which returns a `Completable` class. Since Fluent is a unidirectional flow, your `Job` should complete or not. 186 | 187 | You just need to inherit your use case class from `RxJob` (specifying the type of the input parameter) and override the `bind(input: T):Completable` method with the properly work. 188 | 189 | >You must handle all the possible edge cases into your job. You should not allow your job to throw an exception back to the `Hub`. 190 | 191 | ```kotlin 192 | class DoGoogleLoginJob @Inject constructor( 193 | private val store: RxStore, 194 | private val firebase: GoogleFirebaseAuth) : RxJob() { 195 | 196 | override fun bind(input: Intent): Completable { 197 | return firebase.firebaseAuthWith(intent = input) 198 | .doOnSubscribe { store.update { setType(StateType.Loading) } } 199 | .doOnSuccess { store.update { setType(StateType.Success) } } 200 | .doOnError { store.update { setType(StateType.Error) } } 201 | .toCompletable() 202 | .onErrorComplete() 203 | } 204 | } 205 | ``` 206 | 207 | > In this example we are injecting the local parameters `store` and `firebase` with [dagger](https://github.com/google/dagger) we strong recommend that. 208 | 209 | ### RxHub 210 | > `RxHub` is an implementation of `Hub` that works with Reactive Extensions 211 | 212 | The `RxHub` contains functions to easily connects your `View` events source to your `RxJob`'s. 213 | 214 | You connect the `View` and the `RxJob`'s layers through the operator `bind(job: RxJob)`(that's why all of your `View`'s methods needs to return an `Observable`). 215 | 216 | After that just need to inherit the class `RxHub`(specifying the `View` it will connect with) and override the `connect(view: T)` method with the binds to `RxJobs` you need. 217 | 218 | We have already implemented the `disconnect()` method to release resources by disposing all the bound jobs. 219 | 220 | ```kotlin 221 | class LoginHub @Inject constructor( 222 | private val doGoogleLoginJob: RxJob, 223 | private val requestGoogleLoginJob: RxJob) : RxHub() { 224 | 225 | override fun connect(view: LoginView) { 226 | view.doLoginClicks() 227 | .bind(requestGoogleLoginJob) 228 | 229 | view.activityResults() 230 | .filter { it.first == GoogleLogin.GOOGLE_REQUEST } 231 | .map { it.second } 232 | .bind(doGoogleLoginJob) 233 | } 234 | } 235 | ``` 236 | 237 | And finally that's how you connect and disconnect your `View` to the `Hub` 238 | 239 | ```kotlin 240 | override fun onCreate(savedInstanceState: Bundle?) { 241 | super.onCreate(savedInstanceState) 242 | setContentView(R.layout.activity_login) 243 | 244 | ... 245 | hub.connect(this) 246 | } 247 | 248 | override fun onDestroy() { 249 | super.onDestroy() 250 | hub.disconnect() 251 | } 252 | ``` 253 | 254 | --- 255 | 256 | We are looking forward to improving this framework. If you have some feedback, comments, questions or if you want to contribute, join us at our [Slack group](https://join.slack.com/t/fluent-io/shared_invite/enQtMzQ3MDY3Njk0MjI3LTZkMjU0Y2Q3ZTA2NWQ0OTE4ZjFiZmQxNzJlMTYxNjIwODBjYmJhOGRlYzRhNGY5NmNjZTVhMTIzMTJhNzEwYTY) 257 | 258 | 259 | ## Next Steps: 260 | * Library icon 261 | * Non-reactive samples 262 | * More reactive samples 263 | * Improve documentation with callbacks (non-reactive) 264 | * Fluent for iOS (Swift) 265 | 266 | --- 267 | 268 | ## License 269 | 270 | ``` 271 | Copyright 2018 fluentio Team 272 | 273 | Licensed under the Apache License, Version 2.0 (the "License"); 274 | you may not use this file except in compliance with the License. 275 | You may obtain a copy of the License at 276 | 277 | http://www.apache.org/licenses/LICENSE-2.0 278 | 279 | Unless required by applicable law or agreed to in writing, software 280 | distributed under the License is distributed on an "AS IS" BASIS, 281 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 282 | See the License for the specific language governing permissions and 283 | limitations under the License. 284 | ``` 285 | -------------------------------------------------------------------------------- /bintray.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = libraryVersion 4 | 5 | /* 6 | * Comment the following part if you only want to distribute .aar files. 7 | * (For example, your source code is obfuscated by Proguard and is not shown to outsite developers) 8 | * Without source code .jar files, you only can publish on bintray respository but not jcenter. 9 | */ 10 | 11 | /*--------------------------------*/ 12 | if (project.hasProperty("android")) { 13 | task sourcesJar(type: Jar) { 14 | classifier = 'sources' 15 | from android.sourceSets.main.java.srcDirs 16 | } 17 | 18 | if (project.hasProperty("kotlin")) { //Kotlin libraries 19 | task javadoc(type: Javadoc, dependsOn: dokka) { 20 | 21 | } 22 | } else { 23 | task javadoc(type: Javadoc) { 24 | source = android.sourceSets.main.java.srcDirs 25 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 26 | } 27 | } 28 | } else { // Java libraries 29 | task sourcesJar(type: Jar, dependsOn: classes) { 30 | classifier = 'sources' 31 | from sourceSets.main.allSource 32 | } 33 | } 34 | 35 | task javadocJar(type: Jar, dependsOn: javadoc) { 36 | classifier = 'javadoc' 37 | from javadoc.destinationDir 38 | } 39 | 40 | artifacts { 41 | archives javadocJar 42 | archives sourcesJar 43 | } 44 | /*--------------------------------*/ 45 | 46 | // Bintray 47 | Properties properties = new Properties() 48 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 49 | 50 | bintray { 51 | user = properties.getProperty("bintray.user") 52 | key = properties.getProperty("bintray.apikey") 53 | 54 | configurations = ['archives'] 55 | pkg { 56 | repo = bintrayRepo 57 | name = bintrayName 58 | desc = libraryDescription 59 | userOrg = organization // If the repository is hosted by an organization instead of personal account. 60 | websiteUrl = siteUrl 61 | vcsUrl = gitUrl 62 | licenses = allLicenses 63 | publish = true 64 | publicDownloadNumbers = true 65 | version { 66 | desc = libraryDescription 67 | gpg { 68 | sign = true 69 | passphrase = properties.getProperty("bintray.gpg.password") 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.30' 5 | 6 | Properties properties = new Properties() 7 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 8 | 9 | ext { 10 | bintrayRepo = 'maven' 11 | bintrayName = 'fluent' 12 | 13 | publishedGroupId = 'io.fluent' 14 | 15 | siteUrl = 'https://github.com/fluentio' 16 | gitUrl = 'https://github.com/fluentio/Fluent.git' 17 | 18 | libraryVersion = '0.2.1' 19 | 20 | developerId = properties.getProperty("user.id") 21 | developerName = properties.getProperty("user.name") 22 | developerEmail = properties.getProperty("user.email") 23 | organization = 'fluentio' 24 | 25 | licenseName = 'The Apache Software License, Version 2.0' //Example for license 26 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 27 | allLicenses = ["Apache-2.0"] 28 | } 29 | 30 | repositories { 31 | google() 32 | jcenter() 33 | } 34 | dependencies { 35 | classpath 'com.android.tools.build:gradle:3.0.1' 36 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 37 | 38 | classpath 'com.google.gms:google-services:3.1.1' 39 | // NOTE: Do not place your application dependencies here; they belong 40 | // in the individual module build.gradle files 41 | // Two necessary plugins 42 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 43 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 44 | } 45 | } 46 | 47 | allprojects { 48 | repositories { 49 | google() 50 | jcenter() 51 | } 52 | } 53 | 54 | task clean(type: Delete) { 55 | delete rootProject.buildDir 56 | } 57 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 09 20:51:18 BRT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /install.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = publishedGroupId // Maven Group ID for the artifact 4 | 5 | install { 6 | repositories.mavenInstaller { 7 | // This generates POM.xml with proper parameters 8 | pom.project { 9 | packaging 'aar' 10 | groupId publishedGroupId 11 | artifactId artifact 12 | 13 | // Add your description here 14 | name libraryName 15 | description libraryDescription 16 | url siteUrl 17 | 18 | // Set your license 19 | licenses { 20 | license { 21 | name licenseName 22 | url licenseUrl 23 | } 24 | } 25 | developers { 26 | developer { 27 | id developerId 28 | name developerName 29 | email developerEmail 30 | } 31 | } 32 | scm { 33 | connection gitUrl 34 | developerConnection gitUrl 35 | url siteUrl 36 | 37 | } 38 | } 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'kotlin' 2 | 3 | dependencies { 4 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 5 | testImplementation 'junit:junit:4.12' 6 | } 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | ext { 13 | libraryName = 'library' 14 | artifact = 'library' 15 | libraryDescription = 'Remove inconsistency of your view. Go Fluent' 16 | } 17 | 18 | apply from: '../install.gradle' 19 | apply from: '../bintray.gradle' 20 | 21 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/Hub.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | interface Hub { 4 | fun connect(view: V) 5 | 6 | fun disconnect() 7 | } 8 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/Job.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | interface Job { 4 | fun run(input: T) 5 | } 6 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/State.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | interface State { 4 | fun type(): StateType 5 | } 6 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/StateType.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | open class StateType { 4 | object Initial : StateType() 5 | object Loading : StateType() 6 | object Success : StateType() 7 | object Error : StateType() 8 | } 9 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/Store.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | interface Store { 4 | fun update(newState: T) 5 | 6 | fun state(): T 7 | } 8 | -------------------------------------------------------------------------------- /library/src/main/kotlin/io/fluent/View.kt: -------------------------------------------------------------------------------- 1 | package io.fluent 2 | 3 | interface View { 4 | fun bind(newState: T) 5 | } 6 | -------------------------------------------------------------------------------- /rx-library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /rx-library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'kotlin' 2 | 3 | dependencies { 4 | implementation project(':library') 5 | implementation "io.reactivex.rxjava2:rxjava:2.1.7" 6 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 7 | 8 | testImplementation 'junit:junit:4.12' 9 | } 10 | 11 | ext { 12 | libraryName = 'rx-library' 13 | artifact = 'rx-library' 14 | libraryDescription = 'Reactive extensions for Fluent library' 15 | } 16 | 17 | apply from: '../install.gradle' 18 | apply from: '../bintray.gradle' 19 | -------------------------------------------------------------------------------- /rx-library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /rx-library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /rx-library/src/main/kotlin/io/fluent/rx/RxHub.kt: -------------------------------------------------------------------------------- 1 | package io.fluent.rx 2 | 3 | import io.fluent.Hub 4 | import io.reactivex.Completable 5 | import io.reactivex.Flowable 6 | import io.reactivex.Maybe 7 | import io.reactivex.Observable 8 | import io.reactivex.Single 9 | import io.reactivex.disposables.CompositeDisposable 10 | import io.reactivex.disposables.Disposable 11 | 12 | abstract class RxHub : Hub { 13 | private val compositeDisposable = CompositeDisposable() 14 | 15 | override fun disconnect() { 16 | compositeDisposable.clear() 17 | } 18 | 19 | fun Disposable.compose() = compositeDisposable.add(this) 20 | 21 | fun Observable.subscribeAndCompose() = subscribe().compose() 22 | 23 | fun Completable.subscribeAndCompose() = subscribe().compose() 24 | 25 | fun Single.subscribeAndCompose() = subscribe().compose() 26 | 27 | fun Maybe.subscribeAndCompose() = subscribe().compose() 28 | 29 | fun Flowable.subscribeAndCompose() = subscribe().compose() 30 | 31 | fun Observable.bind(job: RxJob) = 32 | this.flatMapCompletable { job.bind(it) } 33 | .subscribeAndCompose() 34 | 35 | fun Single.bind(job: RxJob) = 36 | this.flatMapCompletable { job.bind(it) } 37 | .subscribeAndCompose() 38 | 39 | fun Maybe.bind(job: RxJob) = 40 | this.flatMapCompletable { job.bind(it) } 41 | .subscribeAndCompose() 42 | 43 | fun Flowable.bind(job: RxJob) = 44 | this.flatMapCompletable { job.bind(it) } 45 | .subscribeAndCompose() 46 | 47 | fun Observable.bind(vararg jobs: RxJob) = 48 | this.flatMapCompletable { value -> 49 | jobs.map { it.bind(value) } 50 | .fold(Completable.complete()) { acc, next -> acc.andThen(next) } 51 | }.subscribeAndCompose() 52 | 53 | fun Single.bind(vararg jobs: RxJob) = 54 | this.flatMapCompletable { value -> 55 | jobs.map { it.bind(value) } 56 | .fold(Completable.complete()) { acc, next -> acc.andThen(next) } 57 | }.subscribeAndCompose() 58 | 59 | fun Maybe.bind(vararg jobs: RxJob) = 60 | this.flatMapCompletable { value -> 61 | jobs.map { it.bind(value) } 62 | .fold(Completable.complete()) { acc, next -> acc.andThen(next) } 63 | }.subscribeAndCompose() 64 | 65 | fun Flowable.bind(vararg jobs: RxJob) = 66 | this.flatMapCompletable { value -> 67 | jobs.map { it.bind(value) } 68 | .fold(Completable.complete()) { acc, next -> acc.andThen(next) } 69 | }.subscribeAndCompose() 70 | } -------------------------------------------------------------------------------- /rx-library/src/main/kotlin/io/fluent/rx/RxJob.kt: -------------------------------------------------------------------------------- 1 | package io.fluent.rx 2 | 3 | import io.fluent.Job 4 | import io.reactivex.Completable 5 | 6 | abstract class RxJob : Job { 7 | override fun run(input: T) { 8 | bind(input).blockingGet() 9 | } 10 | 11 | abstract fun bind(input: T): Completable 12 | } 13 | -------------------------------------------------------------------------------- /rx-library/src/main/kotlin/io/fluent/rx/RxStore.kt: -------------------------------------------------------------------------------- 1 | package io.fluent.rx 2 | 3 | import io.fluent.State 4 | import io.fluent.Store 5 | import io.reactivex.Observable 6 | import io.reactivex.subjects.BehaviorSubject 7 | import kotlin.properties.Delegates 8 | 9 | open class RxStore(initialState: T) : Store{ 10 | private val publisher = BehaviorSubject.create() 11 | 12 | private var currentState by Delegates.observable(initialState) { _, _, newState -> 13 | publisher.onNext(newState) 14 | } 15 | 16 | @Synchronized 17 | open override fun update(newState: T) { 18 | currentState = newState 19 | } 20 | 21 | open override fun state() = currentState 22 | 23 | @Synchronized 24 | open fun update(block: T.() -> T) { 25 | currentState = state().block() 26 | } 27 | 28 | fun stateChanges(): Observable = publisher 29 | } 30 | -------------------------------------------------------------------------------- /rx-library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | rx 3 | 4 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | 6 | android { 7 | compileSdkVersion 27 8 | 9 | defaultConfig { 10 | applicationId "br.com.rsicarelli.rxfirebaselogin" 11 | minSdkVersion 16 12 | targetSdkVersion 27 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | sourceSets { 28 | main.java.srcDirs += 'src/main/kotlin' 29 | test.java.srcDirs += 'src/test/kotlin' 30 | } 31 | 32 | testOptions { 33 | unitTests.returnDefaultValues = true 34 | } 35 | } 36 | 37 | dependencies { 38 | implementation project(":library") 39 | implementation project(":rx-library") 40 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 41 | implementation 'com.android.support:appcompat-v7:27.1.0' 42 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 43 | 44 | implementation "com.google.dagger:dagger:2.14.1" 45 | implementation "com.google.dagger:dagger-android:2.14.1" 46 | implementation "com.google.dagger:dagger-android-support:2.14.1" 47 | kapt "com.google.dagger:dagger-compiler:2.14.1" 48 | kapt "com.google.dagger:dagger-android-processor:2.14.1" 49 | 50 | implementation "io.reactivex.rxjava2:rxjava:2.1.7" 51 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' 52 | implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0' 53 | 54 | implementation 'com.jakewharton.timber:timber:4.6.0' 55 | 56 | implementation 'com.google.firebase:firebase-core:11.8.0' 57 | implementation 'com.google.firebase:firebase-auth:11.8.0' 58 | implementation 'com.google.android.gms:play-services-auth:11.8.0' 59 | 60 | testImplementation 'junit:junit:4.12' 61 | testImplementation "org.mockito:mockito-core:2.16.0" 62 | testImplementation "com.nhaarman:mockito-kotlin:1.5.0" 63 | 64 | 65 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 66 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 67 | } 68 | 69 | apply plugin: 'com.google.gms.google-services' 70 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 13 16:08:40 BRT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/App.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin 2 | 3 | import br.com.rsicarelli.rxfirebaselogin.infra.di.component.ApplicationComponent 4 | import br.com.rsicarelli.rxfirebaselogin.infra.di.component.DaggerApplicationComponent 5 | import dagger.android.AndroidInjector 6 | import dagger.android.support.DaggerApplication 7 | import timber.log.Timber 8 | 9 | class App : DaggerApplication() { 10 | override fun applicationInjector(): AndroidInjector { 11 | applicationComponent = DaggerApplicationComponent.builder() 12 | .application(this) 13 | .build() 14 | 15 | applicationComponent.inject(this) 16 | 17 | return applicationComponent 18 | } 19 | 20 | override fun onCreate() { 21 | super.onCreate() 22 | Timber.plant(Timber.DebugTree()) 23 | } 24 | 25 | companion object { 26 | lateinit var applicationComponent: ApplicationComponent 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/LoginActivity.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.view.View 6 | import android.widget.Toast 7 | import br.com.rsicarelli.rxfirebaselogin.R 8 | import com.jakewharton.rxbinding2.view.RxView 9 | import dagger.android.support.DaggerAppCompatActivity 10 | import io.fluent.StateType 11 | import io.fluent.rx.RxHub 12 | import io.fluent.rx.RxStore 13 | import io.reactivex.Observable 14 | import io.reactivex.android.schedulers.AndroidSchedulers 15 | import io.reactivex.subjects.PublishSubject 16 | import kotlinx.android.synthetic.main.activity_login.googleSignIn 17 | import kotlinx.android.synthetic.main.activity_login.loading 18 | import timber.log.Timber 19 | import javax.inject.Inject 20 | 21 | 22 | class LoginActivity : DaggerAppCompatActivity(), LoginView { 23 | @Inject 24 | lateinit var hub: RxHub<@JvmSuppressWildcards LoginView> 25 | 26 | @Inject 27 | lateinit var store: RxStore 28 | 29 | private val activityResultDispatcher = PublishSubject.create>() 30 | 31 | override fun doLoginClicks(): Observable = RxView.clicks(googleSignIn).map { } 32 | 33 | override fun activityResults(): Observable> = activityResultDispatcher 34 | 35 | override fun onCreate(savedInstanceState: Bundle?) { 36 | super.onCreate(savedInstanceState) 37 | setContentView(R.layout.activity_login) 38 | 39 | store.stateChanges() 40 | .observeOn(AndroidSchedulers.mainThread()) 41 | .subscribe { bind(it) } 42 | 43 | Timber.d(store.toString()) 44 | 45 | hub.connect(this) 46 | } 47 | 48 | override fun onDestroy() { 49 | super.onDestroy() 50 | hub.disconnect() 51 | } 52 | 53 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 54 | super.onActivityResult(requestCode, resultCode, data) 55 | data?.let { 56 | activityResultDispatcher.onNext(requestCode to data) 57 | } 58 | } 59 | 60 | override fun bind(newState: LoginState) { 61 | when (newState.type) { 62 | StateType.Success -> success() 63 | StateType.Error -> error() 64 | StateType.Loading -> loading() 65 | } 66 | } 67 | 68 | private fun success() { 69 | loading.gone() 70 | Toast.makeText(this, "It works", Toast.LENGTH_LONG).show() 71 | } 72 | 73 | private fun error() { 74 | loading.gone() 75 | Toast.makeText(this, "Something goes wrong! :(", Toast.LENGTH_LONG).show() 76 | } 77 | 78 | private fun loading() { 79 | loading.show() 80 | } 81 | 82 | private fun View.show() { 83 | this.visibility = View.VISIBLE 84 | } 85 | 86 | private fun View.gone() { 87 | this.visibility = View.GONE 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/LoginHub.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.GoogleLogin 5 | import io.fluent.rx.RxHub 6 | import io.fluent.rx.RxJob 7 | import javax.inject.Inject 8 | 9 | class LoginHub @Inject constructor( 10 | private val doGoogleLoginJob: RxJob<@JvmSuppressWildcards Intent>, 11 | private val requestGoogleLoginJob: RxJob<@JvmSuppressWildcards Unit> 12 | ) : RxHub() { 13 | 14 | override fun connect(view: LoginView) { 15 | view.doLoginClicks() 16 | .bind(requestGoogleLoginJob) 17 | 18 | view.activityResults() 19 | .filter { it.first == GoogleLogin.GOOGLE_REQUEST } 20 | .map { it.second } 21 | .bind(doGoogleLoginJob) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/LoginModule.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.jobs.DoGoogleLoginJob 5 | import br.com.rsicarelli.rxfirebaselogin.feature.login.jobs.RequestGoogleLoginJob 6 | import dagger.Module 7 | import dagger.Provides 8 | import io.fluent.rx.RxHub 9 | import io.fluent.rx.RxJob 10 | import io.fluent.rx.RxStore 11 | 12 | @Module 13 | class LoginModule { 14 | 15 | @Provides 16 | fun providesLoginActivity(activity: LoginActivity): LoginView = activity 17 | 18 | @Provides 19 | fun providesLoginStore() = RxStore(LoginState()) 20 | 21 | @Provides 22 | fun providesDoGoogleLoginJob(doGoogleLoginJob: DoGoogleLoginJob): RxJob { 23 | return doGoogleLoginJob 24 | } 25 | 26 | @Provides 27 | fun providesRequestGoogleLoginJob(requestGoogleLoginJob: RequestGoogleLoginJob): RxJob { 28 | return requestGoogleLoginJob 29 | } 30 | 31 | @Provides 32 | fun providesLoginHub(loginHub: LoginHub): RxHub { 33 | return loginHub 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/LoginState.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login 2 | 3 | import io.fluent.State 4 | import io.fluent.StateType 5 | 6 | data class LoginState( 7 | val type: StateType = StateType.Initial 8 | ) : State { 9 | 10 | override fun type() = type 11 | 12 | fun setType(newType: StateType) = copy(type = newType) 13 | } 14 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/LoginView.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login 2 | 3 | import android.content.Intent 4 | import io.fluent.View 5 | import io.reactivex.Observable 6 | 7 | interface LoginView : View { 8 | fun doLoginClicks(): Observable 9 | fun activityResults(): Observable> 10 | } 11 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/google/GoogleFirebaseAuth.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.google 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginActivity 5 | import com.google.firebase.auth.FirebaseAuth 6 | import com.google.firebase.auth.GoogleAuthProvider 7 | import io.reactivex.Single 8 | import timber.log.Timber 9 | import javax.inject.Inject 10 | 11 | open class GoogleFirebaseAuth @Inject constructor( 12 | private val activity: LoginActivity, 13 | private val googleLogin: GoogleLogin 14 | ) { 15 | 16 | open fun firebaseAuthWith(intent: Intent): Single { 17 | return Single.create({ emitter -> 18 | val accountFromIntent = googleLogin.getAccountFromIntent(intent) 19 | val auth = FirebaseAuth.getInstance() 20 | val credential = GoogleAuthProvider.getCredential(accountFromIntent.idToken, null) 21 | 22 | auth.signInWithCredential(credential).addOnCompleteListener(activity, { task -> 23 | if (task.isSuccessful) { 24 | auth.currentUser?.let { 25 | emitter.onSuccess(User(it.email)) 26 | } 27 | } else { 28 | task.exception?.let { 29 | Timber.e(it) 30 | emitter.onError(it) 31 | } 32 | } 33 | }) 34 | }) 35 | } 36 | 37 | } 38 | 39 | data class User( 40 | val email: String? 41 | ) 42 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/google/GoogleLogin.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.google 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.R 5 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginActivity 6 | import com.google.android.gms.auth.api.signin.GoogleSignIn 7 | import com.google.android.gms.auth.api.signin.GoogleSignInAccount 8 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions 9 | import com.google.android.gms.common.api.ApiException 10 | import io.reactivex.Completable 11 | import javax.inject.Inject 12 | 13 | open class GoogleLogin @Inject constructor( 14 | private val activity: LoginActivity 15 | ) { 16 | 17 | private val gso by lazy { 18 | GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 19 | .requestIdToken(activity.getString(R.string.default_web_client_id)) 20 | .requestEmail() 21 | .build() 22 | } 23 | 24 | private val googleSignInClient by lazy { 25 | GoogleSignIn.getClient(activity, gso) 26 | } 27 | 28 | open fun startActivityForResult(): Completable { 29 | return Completable.fromAction { 30 | activity.startActivityForResult(googleSignInClient.signInIntent, GOOGLE_REQUEST) 31 | } 32 | } 33 | 34 | open fun getAccountFromIntent(intent: Intent): GoogleSignInAccount { 35 | return GoogleSignIn.getSignedInAccountFromIntent(intent).getResult(ApiException::class.java) 36 | } 37 | 38 | companion object { 39 | const val GOOGLE_REQUEST = 1234 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/jobs/DoGoogleLoginJob.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.jobs 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginState 5 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.GoogleFirebaseAuth 6 | import io.fluent.StateType 7 | import io.fluent.rx.RxJob 8 | import io.fluent.rx.RxStore 9 | import io.reactivex.Completable 10 | import javax.inject.Inject 11 | 12 | class DoGoogleLoginJob @Inject constructor( 13 | private val store: RxStore, 14 | private val firebase: GoogleFirebaseAuth 15 | ) : RxJob() { 16 | 17 | override fun bind(input: Intent): Completable { 18 | return firebase.firebaseAuthWith(intent = input) 19 | .doOnSubscribe { store.update { setType(StateType.Loading) } } 20 | .doOnSuccess { store.update { setType(StateType.Success) } } 21 | .doOnError { store.update { setType(StateType.Error) } } 22 | .toCompletable() 23 | .onErrorComplete() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/feature/login/jobs/RequestGoogleLoginJob.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.jobs 2 | 3 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.GoogleLogin 4 | import io.fluent.rx.RxJob 5 | import io.reactivex.Completable 6 | import javax.inject.Inject 7 | 8 | class RequestGoogleLoginJob @Inject constructor( 9 | private val googleLogin: GoogleLogin 10 | ) : RxJob() { 11 | 12 | override fun bind(input: Unit): Completable { 13 | return googleLogin.startActivityForResult() 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/infra/di/ActivityScoped.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.infra.di 2 | 3 | import javax.inject.Scope 4 | 5 | @Scope 6 | @Retention(AnnotationRetention.RUNTIME) 7 | annotation class ActivityScoped 8 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/infra/di/component/ApplicationComponent.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.infra.di.component 2 | 3 | import android.app.Application 4 | import br.com.rsicarelli.rxfirebaselogin.App 5 | import br.com.rsicarelli.rxfirebaselogin.infra.di.module.ActivityBuilderModule 6 | import br.com.rsicarelli.rxfirebaselogin.infra.di.module.ApplicationModule 7 | import dagger.BindsInstance 8 | import dagger.Component 9 | import dagger.android.AndroidInjector 10 | import dagger.android.support.AndroidSupportInjectionModule 11 | import javax.inject.Singleton 12 | 13 | @Singleton 14 | @Component(modules = [ 15 | (AndroidSupportInjectionModule::class), 16 | (ApplicationModule::class), 17 | (ActivityBuilderModule::class) 18 | ]) 19 | interface ApplicationComponent : AndroidInjector { 20 | 21 | @Component.Builder 22 | interface Builder { 23 | @BindsInstance 24 | fun application(application: Application): Builder 25 | 26 | fun build(): ApplicationComponent 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/infra/di/module/ActivityBuilderModule.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.infra.di.module 2 | 3 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginActivity 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginModule 5 | import br.com.rsicarelli.rxfirebaselogin.infra.di.ActivityScoped 6 | import dagger.Module 7 | import dagger.android.ContributesAndroidInjector 8 | 9 | @Module 10 | abstract class ActivityBuilderModule { 11 | 12 | @ActivityScoped 13 | @ContributesAndroidInjector(modules = [(LoginModule::class)]) 14 | internal abstract fun loginActivity(): LoginActivity 15 | } 16 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/kotlin/br/com/rsicarelli/rxfirebaselogin/infra/di/module/ApplicationModule.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.infra.di.module 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import dagger.Binds 6 | import dagger.Module 7 | 8 | @Module 9 | abstract class ApplicationModule { 10 | 11 | @Binds 12 | abstract fun provideContext(application: Application): Context 13 | } 14 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 21 | 22 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluentio/Fluent/43607b6b48d1ad870a752b3836ceaa3fb1172d25/samples/RxFirebaseLogin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RxFirebaseLogin 3 | 4 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/test/java/br/com/rsicarelli/rxfirebaselogin/feature/login/jobs/DoGoogleLoginJobTest.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.jobs 2 | 3 | import android.content.Intent 4 | import br.com.rsicarelli.rxfirebaselogin.feature.login.LoginState 5 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.GoogleFirebaseAuth 6 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.User 7 | import com.nhaarman.mockito_kotlin.whenever 8 | import io.fluent.StateType 9 | import io.fluent.rx.RxStore 10 | import io.reactivex.Single 11 | import org.junit.Test 12 | import org.junit.runner.RunWith 13 | import org.mockito.InjectMocks 14 | import org.mockito.Mock 15 | import org.mockito.Spy 16 | import org.mockito.junit.MockitoJUnitRunner 17 | 18 | @RunWith(MockitoJUnitRunner::class) 19 | class DoGoogleLoginJobTest { 20 | 21 | @Spy 22 | var store: RxStore = RxStore(LoginState()) 23 | 24 | @Mock 25 | lateinit var intent: Intent 26 | 27 | @Mock 28 | lateinit var firebase: GoogleFirebaseAuth 29 | 30 | @InjectMocks 31 | lateinit var target: DoGoogleLoginJob 32 | 33 | @Test 34 | fun success_WithUser_ShouldDoLogin() { 35 | withUser { 36 | target.bind(intent) 37 | .test() 38 | .assertComplete() 39 | .assertNoErrors() 40 | 41 | store.stateChanges() 42 | .test() 43 | .assertValue { it.type == StateType.Success } 44 | } 45 | } 46 | 47 | @Test 48 | fun error_WithoutUser_ShouldNotDoLogin() { 49 | withError { 50 | target.bind(intent) 51 | .test() 52 | .assertComplete() 53 | .assertNoErrors() 54 | 55 | store.stateChanges() 56 | .test() 57 | .assertValue { it.type == StateType.Error } 58 | } 59 | } 60 | 61 | private fun withUser(action: () -> Unit) { 62 | whenever(firebase.firebaseAuthWith(intent)).thenReturn(Single.just(User("a@a.com"))) 63 | action() 64 | } 65 | 66 | private fun withError(action: () -> Unit) { 67 | whenever(firebase.firebaseAuthWith(intent)).thenReturn(Single.error(Exception())) 68 | action() 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /samples/RxFirebaseLogin/src/test/java/br/com/rsicarelli/rxfirebaselogin/feature/login/jobs/RequestGoogleLoginJobTest.kt: -------------------------------------------------------------------------------- 1 | package br.com.rsicarelli.rxfirebaselogin.feature.login.jobs 2 | 3 | import br.com.rsicarelli.rxfirebaselogin.feature.login.google.GoogleLogin 4 | import com.nhaarman.mockito_kotlin.whenever 5 | import io.reactivex.Completable 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.mockito.InjectMocks 9 | import org.mockito.Mock 10 | import org.mockito.junit.MockitoJUnitRunner 11 | 12 | @RunWith(MockitoJUnitRunner::class) 13 | class RequestGoogleLoginJobTest { 14 | 15 | @Mock 16 | lateinit var googleLogin: GoogleLogin 17 | 18 | @InjectMocks 19 | lateinit var target: RequestGoogleLoginJob 20 | 21 | @Test 22 | fun startForResult_ShouldStartActivityForResult() { 23 | whenever(googleLogin.startActivityForResult()).thenReturn(Completable.complete()) 24 | 25 | target.bind(Unit) 26 | .test() 27 | .assertComplete() 28 | .assertNoErrors() 29 | } 30 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':rx-library', ':samples:RxFirebaseLogin' 2 | --------------------------------------------------------------------------------