Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Tskhovrebov committed Jan 8, 2018
2 parents ced094e + 9464fae commit 98b1ff2
Show file tree
Hide file tree
Showing 35 changed files with 579 additions and 373 deletions.
22 changes: 22 additions & 0 deletions LICENCE
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2017 Konstantin Tskhovrebov (@terrakok)
and Vasili Chyrvon (@Jeevuz)

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.
47 changes: 25 additions & 22 deletions README.md
Expand Up @@ -21,9 +21,9 @@ It was designed to be used with the MVP pattern (try [Moxy](https://github.com/A
+ functionality is simple to extend
+ suitable for Unit Testing

## Version 2.+
## Additional features
+ easy screen result subscription
+ predefined navigator ready for setup transition animation
+ predefined navigator ready for setup transition animation
**See the sample application**

## How to add
Expand Down Expand Up @@ -89,21 +89,21 @@ public class SamplePresenter extends Presenter<SampleView> {
Router converts the navigation call to the set of Commands and sends them to CommandBuffer.

CommandBuffer checks whether there are _"active"_ Navigator:
If yes, it passes the commands to the Navigator. Navigator will process them to achive the desired transition.
If no, then CommandBuffer saves the commands in a queue, and will apply them as soon as new _"active"_ Navigator will appear.
- If yes, it passes the commands to the Navigator. Navigator will process them to achive the desired transition.
- If no, then CommandBuffer saves the commands in a queue, and will apply them as soon as new _"active"_ Navigator will appear.

```java
protected void executeCommand(Command command) {
if (navigator != null) {
navigator.applyCommand(command);
} else {
pendingCommands.add(command);
void executeCommands(Command[] commands) {
if (navigator != null) {
navigator.applyCommands(commands);
} else {
pendingCommands.add(commands);
}
}
}
```

Navigator processes the navigation commands. Usually it is an anonymous class inside the Activity.
Activity provides Navigator to the CommandBuffer in _onResume_ and removes it in _onPause_.
Navigator processes the navigation commands. Usually it is an anonymous class inside the Activity.
Activity provides Navigator to the CommandBuffer in _onResume_ and removes it in _onPause_.

**Attention**: Use _onResumeFragments()_ with FragmentActivity ([more info](https://developer.android.com/reference/android/support/v4/app/FragmentActivity.html#onResume()))

Expand All @@ -130,24 +130,24 @@ private Navigator navigator = new Navigator() {

## Navigation commands
This commands set will fulfill the needs of the most applications. But if you need something special - just add it!
+ Forward - Opens new screen
+ Forward - Opens new screen
![](https://habrastorage.org/files/862/77e/b20/86277eb20b574dae8307ac4f64b0f090.png)
+ Back - Rolls back the last transition
+ Back - Rolls back the last transition
![](https://habrastorage.org/files/059/b63/2d3/059b632d3a7c4515a534b9e5e881c8f0.png)
+ BackTo - Rolls back to the needed screen in the screens chain
+ BackTo - Rolls back to the needed screen in the screens chain
![](https://habrastorage.org/files/a45/4f4/c34/a454f4c340764632ad0669014ad5550d.png)
+ Replace - Replaces the current screen
+ Replace - Replaces the current screen
![](https://habrastorage.org/files/4ae/95c/fee/4ae95cfee4c04f038ad17d358ab08d07.png)
+ SystemMessage - Shows system message (Alert, Toast, Snack, etc.)
+ SystemMessage - Shows system message (Alert, Toast, Snack, etc.)
![](https://habrastorage.org/files/6e7/1a6/4ed/6e71a64edec04079bf33faa7ab39606f.png)

## Predefined navigators
The library provides predefined navigators for _Fragments_ to use inside _Activity_.
To use, just provide it with the container and _FragmentManager_ and override few simple methods.
The library provides predefined navigators for _Fragments_ to use inside _Activity_.
To use, just provide it with the container and _FragmentManager_ and override few simple methods.
```java
private Navigator navigator = new SupportAppNavigator(this, R.id.container) {
@Override
protected Intent createActivityIntent(String screenKey, Object data) {
protected Intent createActivityIntent(Context context, String screenKey, Object data) {
return null;
}

Expand Down Expand Up @@ -185,7 +185,10 @@ To see how to add, initialize and use the library and predefined navigators chec

## License
```
The MIT License (MIT)
MIT License
Copyright (c) 2017 Konstantin Tskhovrebov (@terrakok)
and Vasili Chyrvon (@Jeevuz)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -204,4 +207,4 @@ 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.
```
```
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'

// For the library uploading to the Bintray
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Fri Mar 10 17:09:31 MSK 2017
#Sat Dec 23 00:31:04 MSK 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Expand Up @@ -15,7 +15,7 @@ ext {
bintrayName = 'cicerone'
publishedGroupId = 'ru.terrakok.cicerone'
artifact = 'cicerone'
libraryVersion = '2.1.0'
libraryVersion = '3.0.0'
gitUrl = 'https://github.com/terrakok/Cicerone'
allLicenses = ['MIT']
}
Expand Down
17 changes: 8 additions & 9 deletions library/src/main/java/ru/terrakok/cicerone/BaseRouter.java
@@ -1,12 +1,11 @@
/*
* Created by Konstantin Tskhovrebov (aka @terrakok)
*/

package ru.terrakok.cicerone;

import ru.terrakok.cicerone.commands.Command;

/**
* Created by Konstantin Tckhovrebov (aka @terrakok)
* on 12.10.16
*/

/**
* BaseRouter is an abstract class to implement high-level navigation.
* Extend it to add needed transition methods.
Expand All @@ -23,11 +22,11 @@ CommandBuffer getCommandBuffer() {
}

/**
* Sends navigation command to {@link CommandBuffer}.
* Sends navigation command array to {@link CommandBuffer}.
*
* @param command navigation command to execute
* @param commands navigation command array to execute
*/
protected void executeCommand(Command command) {
commandBuffer.executeCommand(command);
protected void executeCommands(Command... commands) {
commandBuffer.executeCommands(commands);
}
}
9 changes: 4 additions & 5 deletions library/src/main/java/ru/terrakok/cicerone/Cicerone.java
@@ -1,10 +1,9 @@
package ru.terrakok.cicerone;

/**
* Created by Konstantin Tckhovrebov (aka @terrakok)
* on 11.10.16
/*
* Created by Konstantin Tskhovrebov (aka @terrakok)
*/

package ru.terrakok.cicerone;

/**
* Cicerone is the holder for other library components.
* To use it, instantiate it using one of the {@link #create()} methods.
Expand Down
23 changes: 11 additions & 12 deletions library/src/main/java/ru/terrakok/cicerone/CommandBuffer.java
@@ -1,29 +1,28 @@
/*
* Created by Konstantin Tskhovrebov (aka @terrakok)
*/

package ru.terrakok.cicerone;

import java.util.LinkedList;
import java.util.Queue;

import ru.terrakok.cicerone.commands.Command;

/**
* Created by Konstantin Tckhovrebov (aka @terrakok)
* on 12.10.16
*/

/**
* Passes navigation command to an active {@link Navigator}
* or stores it in the pending commands queue to pass it later.
*/
class CommandBuffer implements NavigatorHolder {
private Navigator navigator;
private Queue<Command> pendingCommands = new LinkedList<>();
private Queue<Command[]> pendingCommands = new LinkedList<>();

@Override
public void setNavigator(Navigator navigator) {
this.navigator = navigator;
while (!pendingCommands.isEmpty()) {
if (navigator != null) {
executeCommand(pendingCommands.poll());
executeCommands(pendingCommands.poll());
} else break;
}
}
Expand All @@ -34,15 +33,15 @@ public void removeNavigator() {
}

/**
* Passes {@code command} to the {@link Navigator} if it available.
* Passes {@code commands} to the {@link Navigator} if it available.
* Else puts it to the pending commands queue to pass it later.
* @param command navigation command
* @param commands navigation command array
*/
public void executeCommand(Command command) {
void executeCommands(Command[] commands) {
if (navigator != null) {
navigator.applyCommand(command);
navigator.applyCommands(commands);
} else {
pendingCommands.add(command);
pendingCommands.add(commands);
}
}
}
13 changes: 6 additions & 7 deletions library/src/main/java/ru/terrakok/cicerone/Navigator.java
@@ -1,12 +1,11 @@
/*
* Created by Konstantin Tskhovrebov (aka @terrakok)
*/

package ru.terrakok.cicerone;

import ru.terrakok.cicerone.commands.Command;

/**
* Created by Konstantin Tckhovrebov (aka @terrakok)
* on 11.10.16
*/

/**
* The low-level navigation interface.
* Navigator is the one who actually performs any transition.
Expand All @@ -16,7 +15,7 @@ public interface Navigator {
/**
* Performs transition described by the navigation command
*
* @param command the navigation command to apply
* @param commands the navigation command array to apply per single transaction
*/
void applyCommand(Command command);
void applyCommands(Command[] commands);
}
@@ -1,10 +1,9 @@
package ru.terrakok.cicerone;

/**
* Created by Konstantin Tckhovrebov (aka @terrakok)
* on 11.10.16
/*
* Created by Konstantin Tskhovrebov (aka @terrakok)
*/

package ru.terrakok.cicerone;

/**
* Navigator holder interface.
* Use it to connect a {@link Navigator} to the {@link Cicerone}.
Expand Down

0 comments on commit 98b1ff2

Please sign in to comment.