├── app
├── .gitignore
├── .DS_Store
├── src
│ ├── .DS_Store
│ └── main
│ │ ├── .DS_Store
│ │ ├── res
│ │ ├── 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
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── anim
│ │ │ ├── slide_in.xml
│ │ │ └── slide_out.xml
│ │ ├── drawable
│ │ │ ├── ic_home_black_24dp.xml
│ │ │ ├── ic_dashboard_black_24dp.xml
│ │ │ └── ic_notifications_black_24dp.xml
│ │ ├── layout
│ │ │ ├── fragment_first.xml
│ │ │ ├── fragment_second.xml
│ │ │ ├── fragment_third.xml
│ │ │ ├── activity_secondary.xml
│ │ │ └── activity_main.xml
│ │ └── menu
│ │ │ └── navigation.xml
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── sasd97
│ │ │ └── android_router
│ │ │ ├── FirstFragment.java
│ │ │ ├── ThirdFragment.java
│ │ │ ├── SecondFragment.java
│ │ │ ├── SecondaryActivity.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── lib-router
├── .gitignore
├── .DS_Store
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── sasd97
│ │ │ └── lib_router
│ │ │ ├── satellites
│ │ │ ├── SatelliteTypes.java
│ │ │ ├── Satellite.java
│ │ │ ├── ActivitySatellite.java
│ │ │ ├── ToastSatellite.java
│ │ │ └── FragmentSatellite.java
│ │ │ ├── commands
│ │ │ ├── Command.java
│ │ │ ├── messages
│ │ │ │ ├── MessageCommand.java
│ │ │ │ ├── Message.java
│ │ │ │ └── ShowToast.java
│ │ │ ├── activities
│ │ │ │ ├── Back.java
│ │ │ │ ├── And.java
│ │ │ │ ├── ActivityCommand.java
│ │ │ │ ├── ForwardIntent.java
│ │ │ │ ├── FinishThis.java
│ │ │ │ ├── Start.java
│ │ │ │ └── StartForResult.java
│ │ │ ├── CommandDecorator.java
│ │ │ ├── fragments
│ │ │ │ ├── And.java
│ │ │ │ ├── FragmentCommand.java
│ │ │ │ ├── AddToBackStack.java
│ │ │ │ ├── Add.java
│ │ │ │ ├── WithCustomAnimation.java
│ │ │ │ └── Replace.java
│ │ │ └── providers
│ │ │ │ ├── ProviderCommand.java
│ │ │ │ └── With.java
│ │ │ ├── exceptions
│ │ │ ├── SatelliteNotAttachedException.java
│ │ │ └── CommandNotSupportedException.java
│ │ │ ├── Router.java
│ │ │ └── BaseRouter.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .DS_Store
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── gradlew.bat
├── CODE_OF_CONDUCT.md
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib-router/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib-router'
2 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/.DS_Store
--------------------------------------------------------------------------------
/app/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/.DS_Store
--------------------------------------------------------------------------------
/app/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/.DS_Store
--------------------------------------------------------------------------------
/lib-router/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/lib-router/.DS_Store
--------------------------------------------------------------------------------
/app/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/.DS_Store
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lib-router/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib-router
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/st235/AndroidRouter/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/satellites/SatelliteTypes.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.lib_router.satellites;
2 |
3 | @interface SatelliteTypes {
4 | int ACTIVITY = 0;
5 | int FRAGMENT = 1;
6 | int TOAST = 2;
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Oct 22 00:47:22 MSK 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.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/Command.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands;
5 |
6 | /**
7 | * Navigation command.
8 | */
9 | public interface Command {
10 | }
11 |
--------------------------------------------------------------------------------
/lib-router/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | android-router
3 | SecondaryActivity
4 | Home
5 | Dashboard
6 | Notifications
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_third.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/messages/MessageCommand.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.messages;
5 |
6 | import com.github.sasd97.lib_router.commands.Command;
7 |
8 | /**
9 | * System messages command.
10 | * Can provide messages.
11 | */
12 | public abstract class MessageCommand implements Command {
13 | public abstract Message getMessage();
14 | }
15 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/Back.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.lib_router.commands.activities;
2 |
3 | import android.app.Activity;
4 | import android.support.annotation.NonNull;
5 |
6 | public class Back extends ActivityCommand {
7 |
8 | private Back() {
9 | }
10 |
11 | public static Back back() {
12 | return new Back();
13 | }
14 |
15 | @Override
16 | public void apply(@NonNull Activity activity) {
17 | activity.onBackPressed();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/exceptions/SatelliteNotAttachedException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.exceptions;
5 |
6 | /**
7 | * Throws when router cannot handle passed command by its satellites set.
8 | */
9 | public class SatelliteNotAttachedException extends RuntimeException {
10 |
11 | public SatelliteNotAttachedException() {
12 | super("There is no active satellite attached to router");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/CommandDecorator.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands;
5 |
6 | import android.support.annotation.NonNull;
7 |
8 | /**
9 | * {@link Command} wrapper. Helps chain commands.
10 | * @param command group.
11 | */
12 | public abstract class CommandDecorator implements Command {
13 |
14 | protected T command;
15 |
16 | protected CommandDecorator() {
17 | }
18 |
19 | public CommandDecorator(@NonNull T command) {
20 | this.command = command;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/sasd97/android_router/FirstFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.android_router;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | /**
11 | * Created by alexander on 06/09/2017.
12 | */
13 |
14 | public class FirstFragment extends Fragment {
15 |
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
19 | return inflater.inflate(R.layout.fragment_first, container, false);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/sasd97/android_router/ThirdFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.android_router;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | /**
11 | * Created by alexander on 06/09/2017.
12 | */
13 |
14 | public class ThirdFragment extends Fragment {
15 |
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
19 | return inflater.inflate(R.layout.fragment_third, container, false);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/sasd97/android_router/SecondFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.android_router;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | /**
11 | * Created by alexander on 06/09/2017.
12 | */
13 |
14 | public class SecondFragment extends Fragment {
15 |
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
19 | return inflater.inflate(R.layout.fragment_second, container, false);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/And.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.support.annotation.NonNull;
8 |
9 | public final class And extends ActivityCommand {
10 |
11 | private And(@NonNull ActivityCommand command) {
12 | super(command);
13 | }
14 |
15 | public static And and(@NonNull ActivityCommand command) {
16 | return new And(command);
17 | }
18 |
19 | @Override
20 | public void apply(@NonNull Activity activity) {
21 | command.apply(activity);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/ActivityCommand.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.support.annotation.NonNull;
8 |
9 | import com.github.sasd97.lib_router.commands.CommandDecorator;
10 |
11 | public abstract class ActivityCommand extends CommandDecorator {
12 |
13 | protected ActivityCommand() {
14 | }
15 |
16 | protected ActivityCommand(@NonNull ActivityCommand command) {
17 | super(command);
18 | }
19 |
20 | public abstract void apply(@NonNull Activity activity);
21 | }
22 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/exceptions/CommandNotSupportedException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.exceptions;
5 |
6 | import android.support.annotation.NonNull;
7 |
8 | import java.util.Locale;
9 |
10 | /**
11 | * Throws when satellite try to execute command, which is not applicable to it.
12 | */
13 | public final class CommandNotSupportedException extends RuntimeException {
14 |
15 | public CommandNotSupportedException(@NonNull String group) {
16 | super(
17 | String.format(Locale.US, "Your type is not supported. Command must follow \'%1$s\' group.", group)
18 | );
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/messages/Message.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.messages;
5 |
6 | /**
7 | * Platform independent representation of system messages.
8 | */
9 | public final class Message {
10 |
11 | private int duration;
12 | private String message;
13 |
14 | public int getDuration() {
15 | return duration;
16 | }
17 |
18 | public void setDuration(int duration) {
19 | this.duration = duration;
20 | }
21 |
22 | public String getMessage() {
23 | return message;
24 | }
25 |
26 | public void setMessage(String message) {
27 | this.message = message;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/And.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.s
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.FragmentTransaction;
8 |
9 | public class And extends FragmentCommand {
10 |
11 | private And(@NonNull FragmentCommand command) {
12 | super(command);
13 | }
14 |
15 | public static And and(@NonNull FragmentCommand command) {
16 | return new And(command);
17 | }
18 |
19 | @Override
20 | public FragmentTransaction apply(int containerId, @NonNull FragmentTransaction transaction) {
21 | return command.apply(containerId, transaction);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/FragmentCommand.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.FragmentTransaction;
8 |
9 | import com.github.sasd97.lib_router.commands.CommandDecorator;
10 |
11 | public abstract class FragmentCommand extends CommandDecorator {
12 |
13 | protected FragmentCommand() {
14 | }
15 |
16 | protected FragmentCommand(@NonNull FragmentCommand command) {
17 | super(command);
18 | }
19 |
20 | public abstract FragmentTransaction apply(int containerId,
21 | @NonNull FragmentTransaction transaction);
22 | }
23 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/ForwardIntent.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.content.Intent;
8 | import android.support.annotation.NonNull;
9 |
10 | public final class ForwardIntent extends ActivityCommand {
11 |
12 | private final Intent intent;
13 |
14 | public ForwardIntent(@NonNull Intent intent) {
15 | this.intent = intent;
16 | }
17 |
18 | public static ForwardIntent forwardIntent(@NonNull Intent intent) {
19 | return new ForwardIntent(intent);
20 | }
21 |
22 | @Override
23 | public void apply(@NonNull Activity activity) {
24 | activity.startActivity(intent);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/providers/ProviderCommand.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.providers;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.github.sasd97.lib_router.commands.CommandDecorator;
10 |
11 | /**
12 | * Command which is not navigation, but provides data between navigation frames.
13 | * @param data type.
14 | */
15 | public abstract class ProviderCommand extends CommandDecorator> {
16 |
17 | protected ProviderCommand() { /* default constructor */ }
18 |
19 | protected ProviderCommand(@NonNull ProviderCommand command) {
20 | super(command);
21 | }
22 |
23 | public abstract T getContent(@Nullable T content);
24 | }
25 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/AddToBackStack.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.FragmentTransaction;
9 |
10 | public class AddToBackStack extends FragmentCommand {
11 |
12 | private String tag;
13 |
14 | private AddToBackStack(@Nullable String tag) {
15 | this.tag = tag;
16 | }
17 |
18 | public static AddToBackStack addToBackStack(@Nullable String tag) {
19 | return new AddToBackStack(tag);
20 | }
21 |
22 | @Override
23 | public FragmentTransaction apply(int containerId, @NonNull FragmentTransaction transaction) {
24 | return transaction.addToBackStack(tag);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/FinishThis.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.support.annotation.NonNull;
8 |
9 |
10 | public final class FinishThis extends ActivityCommand {
11 |
12 | private FinishThis() {
13 | super();
14 | }
15 |
16 | private FinishThis(@NonNull ActivityCommand command) {
17 | super(command);
18 | }
19 |
20 | public static FinishThis finishThis() {
21 | return new FinishThis();
22 | }
23 |
24 | public static FinishThis finishThis(@NonNull ActivityCommand command) {
25 | return new FinishThis(command);
26 | }
27 |
28 | @Override
29 | public void apply(@NonNull Activity activity) {
30 | if (command != null) command.apply(activity);
31 | activity.finish();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lib-router/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.novoda:bintray-release:0.8.0'
10 | }
11 | }
12 |
13 | publish {
14 | userOrg = 'st235'
15 | groupId = 'com.github.st235'
16 | artifactId = 'android-router'
17 | publishVersion = '0.1.1'
18 | desc = 'Simple way to make navigation in Android Application.'
19 | website = 'https://github.com/st235/android-router'
20 | }
21 |
22 | android {
23 | compileSdkVersion 28
24 | buildToolsVersion '28.0.3'
25 |
26 | defaultConfig {
27 | minSdkVersion 15
28 | targetSdkVersion 28
29 | versionCode 27
30 | versionName "0.1.1"
31 |
32 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation 'com.android.support:appcompat-v7:28.0.0'
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/alexander/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/lib-router/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/alexander/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/messages/ShowToast.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.messages;
5 |
6 | import android.support.annotation.NonNull;
7 |
8 | public class ShowToast extends MessageCommand {
9 |
10 | private final int duration;
11 |
12 | @NonNull
13 | private final String text;
14 |
15 | private ShowToast(int duration,
16 | @NonNull String text) {
17 | this.text = text;
18 | this.duration = duration;
19 | }
20 |
21 | public static ShowToast showToast(int duration,
22 | @NonNull String text) {
23 | return new ShowToast(duration, text);
24 | }
25 |
26 | @NonNull
27 | @Override
28 | public Message getMessage() {
29 | Message message = new Message();
30 | message.setDuration(duration);
31 | message.setMessage(text);
32 | return message;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_secondary.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/satellites/Satellite.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.satellites;
5 |
6 | import android.support.annotation.NonNull;
7 |
8 | import com.github.sasd97.lib_router.commands.Command;
9 |
10 | /**
11 | * Platform-dependent entity, which works with system navigation framework.
12 | */
13 | public interface Satellite {
14 | /**
15 | * Get current satellite type.
16 | * @return unique id for satellite group (for example, activity group).
17 | */
18 | int getType();
19 |
20 | /**
21 | * Execute passed command by satellite.
22 | * @param command or command chain which contains navigation info.
23 | */
24 | void execute(@NonNull Command command);
25 |
26 | /**
27 | * Checks whether satellite can handle command or not.
28 | * @param command or command chain which contains navigation info.
29 | * @return true if satellite can handle command else otherwise.
30 | */
31 | boolean isApplicable(@NonNull Command command);
32 | }
33 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | ### Hey, hey, hey 🦄
4 |
5 | First off, thank you for considering contributing to Android Router. It's people like you that make Android Router such a great tool.
6 |
7 | >Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests.
8 |
9 | Keep an open mind! Improving documentation, bug triaging, or writing tutorials are all examples of helpful contributions that mean less work for you.
10 |
11 | # Ground Rules
12 |
13 | This section helps you to realize the basics of contributing in our repository.
14 |
15 | * Create issues for any major changes and enhancements that you wish to make. Discuss things transparently and get community feedback.
16 | * Don't add any classes to the codebase unless absolutely needed.
17 | * Keep feature versions as small as possible, preferably one new feature per version.
18 | * Be welcoming to newcomers and encourage diverse new contributors from all backgrounds.
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Alexander Dadukin
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 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/Router.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router;
5 |
6 | import android.support.annotation.NonNull;
7 |
8 | import com.github.sasd97.lib_router.commands.Command;
9 | import com.github.sasd97.lib_router.satellites.Satellite;
10 |
11 | /**
12 | * Platform-independent entity for navigation.
13 | */
14 | public interface Router {
15 | /**
16 | * Execute the navigation command.
17 | * If an appropriate satellite will not be found to execute the command,
18 | * an exception will be thrown.
19 | * @param command or command chain which would be executed by satellite.
20 | */
21 | void pushCommand(@NonNull Command command);
22 |
23 | /**
24 | * Add satellite to handle navigation command group.
25 | * @param satellite - platform-dependent entity, which works with navigation.
26 | */
27 | void addSatellite(@NonNull Satellite satellite);
28 |
29 | /**
30 | * Removes satellite from router to avoid memory leaks.
31 | * @param type - unique id for satellite group.
32 | */
33 | void removeSatellite(int type);
34 | }
35 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion '28.0.3'
6 | defaultConfig {
7 | applicationId "com.github.sasd97.android_router"
8 | minSdkVersion 15
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | implementation project(path: ':lib-router')
29 | implementation 'com.android.support:appcompat-v7:28.0.0'
30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
31 | implementation 'com.android.support:design:28.0.0'
32 | implementation 'com.android.support:support-vector-drawable:28.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | }
35 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/Add.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentTransaction;
9 |
10 | public class Add extends FragmentCommand {
11 |
12 | private Fragment to;
13 |
14 | private Add(@NonNull Fragment to) {
15 | this.to = to;
16 | }
17 |
18 | private Add(@NonNull Fragment to,
19 | @NonNull FragmentCommand command) {
20 | super(command);
21 | this.to = to;
22 | }
23 |
24 | public static Add add(@NonNull Fragment to) {
25 | return new Add(to);
26 | }
27 |
28 | public static Add add(@NonNull Fragment to,
29 | @NonNull FragmentCommand command) {
30 | return new Add(to, command);
31 | }
32 |
33 | @Override
34 | public FragmentTransaction apply(int containerId, @NonNull FragmentTransaction transaction) {
35 | FragmentTransaction t = transaction.add(containerId, to);
36 | return command == null ? t : command.apply(containerId, t);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/providers/With.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.providers;
5 |
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 |
10 | /**
11 | * Packs bundle data.
12 | */
13 | public final class With extends ProviderCommand {
14 |
15 | @Nullable
16 | private final Bundle bundle;
17 |
18 | private With(@NonNull Bundle bundle) {
19 | this.bundle = bundle;
20 | }
21 |
22 | private With(@NonNull ProviderCommand command) {
23 | super(command);
24 | bundle = null;
25 | }
26 |
27 | public static With with(@NonNull Bundle bundle) {
28 | return new With(bundle);
29 | }
30 |
31 | public static With with(@NonNull ProviderCommand command) {
32 | return new With(command);
33 | }
34 |
35 | @Override
36 | public Bundle getContent(@Nullable Bundle bundle) {
37 | if (this.bundle != null) return this.bundle;
38 |
39 | Bundle args = new Bundle();
40 | if (command != null) args = command.getContent(args);
41 | return args;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/Start.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.support.annotation.NonNull;
10 |
11 | import com.github.sasd97.lib_router.commands.providers.ProviderCommand;
12 |
13 | public final class Start extends ActivityCommand {
14 |
15 | private Class> to;
16 | private ProviderCommand command;
17 |
18 | private Start(@NonNull Class> to) {
19 | this.to = to;
20 | }
21 |
22 | private Start(@NonNull Class> to,
23 | @NonNull ProviderCommand command) {
24 | this.to = to;
25 | this.command = command;
26 | }
27 |
28 | public static Start start(@NonNull Class> to) {
29 | return new Start(to);
30 | }
31 |
32 | public static Start start(@NonNull Class> to,
33 | @NonNull ProviderCommand command) {
34 | return new Start(to, command);
35 | }
36 |
37 |
38 | @Override
39 | public void apply(@NonNull Activity activity) {
40 | Intent startIntent = new Intent(activity, to);
41 | if (command != null) startIntent.putExtras(command.getContent(null));
42 | activity.startActivity(startIntent);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/WithCustomAnimation.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.AnimRes;
7 | import android.support.annotation.AnimatorRes;
8 | import android.support.annotation.NonNull;
9 | import android.support.v4.app.FragmentTransaction;
10 |
11 | public class WithCustomAnimation extends FragmentCommand {
12 |
13 | private int startAnimation;
14 | private int endAnimation;
15 |
16 | private WithCustomAnimation(@AnimatorRes @AnimRes int startAnimation,
17 | @AnimatorRes @AnimRes int endAnimation,
18 | @NonNull FragmentCommand command) {
19 | super(command);
20 | this.startAnimation = startAnimation;
21 | this.endAnimation = endAnimation;
22 | }
23 |
24 | public static WithCustomAnimation animate(@AnimatorRes @AnimRes int startAnimation,
25 | @AnimatorRes @AnimRes int endAnimation,
26 | @NonNull FragmentCommand command) {
27 | return new WithCustomAnimation(startAnimation, endAnimation, command);
28 | }
29 |
30 | @Override
31 | public FragmentTransaction apply(int containerId, @NonNull FragmentTransaction transaction) {
32 | FragmentTransaction t = transaction.setCustomAnimations(startAnimation, endAnimation);
33 | return command.apply(containerId, t);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/satellites/ActivitySatellite.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.satellites;
5 |
6 | import android.app.Activity;
7 | import android.support.annotation.NonNull;
8 |
9 | import com.github.sasd97.lib_router.commands.Command;
10 | import com.github.sasd97.lib_router.commands.activities.ActivityCommand;
11 | import com.github.sasd97.lib_router.exceptions.CommandNotSupportedException;
12 |
13 | import java.lang.ref.WeakReference;
14 |
15 | /**
16 | * Satellite which handle activity scope.
17 | */
18 | public final class ActivitySatellite implements Satellite {
19 |
20 | private final WeakReference activityReference;
21 |
22 | public ActivitySatellite(@NonNull Activity activity) {
23 | activityReference = new WeakReference<>(activity);
24 | }
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public int getType() {
31 | return SatelliteTypes.ACTIVITY;
32 | }
33 |
34 | /**
35 | * {@inheritDoc}
36 | */
37 | @Override
38 | public void execute(@NonNull Command command) {
39 | if (!isApplicable(command))
40 | throw new CommandNotSupportedException("Activity group");
41 |
42 | Activity activity = activityReference.get();
43 | if (activity == null) return;
44 | ((ActivityCommand) command).apply(activity);
45 | }
46 |
47 | /**
48 | * {@inheritDoc}
49 | */
50 | @Override
51 | public boolean isApplicable(@NonNull Command command) {
52 | return command instanceof ActivityCommand;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/BaseRouter.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.github.sasd97.lib_router.commands.Command;
10 | import com.github.sasd97.lib_router.exceptions.SatelliteNotAttachedException;
11 | import com.github.sasd97.lib_router.satellites.Satellite;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | /**
17 | * {@inheritDoc}
18 | */
19 | public class BaseRouter implements Router {
20 |
21 | private final Map satellites = new HashMap<>();
22 |
23 | /**
24 | * {@inheritDoc}
25 | */
26 | @Override
27 | public void pushCommand(@NonNull Command command) {
28 | Satellite applicableSatellite = findSatellite(command);
29 | if (applicableSatellite == null) throw new SatelliteNotAttachedException();
30 | applicableSatellite.execute(command);
31 | }
32 |
33 | /**
34 | * {@inheritDoc}
35 | */
36 | @Override
37 | public void addSatellite(@NonNull Satellite satellite) {
38 | satellites.put(satellite.getType(), satellite);
39 | }
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | @Override
45 | public void removeSatellite(int type) {
46 | satellites.remove(type);
47 | }
48 |
49 | @Nullable
50 | private Satellite findSatellite(@NonNull Command command) {
51 | for (Satellite satellite: satellites.values()) {
52 | if (satellite.isApplicable(command)) return satellite;
53 | }
54 |
55 | return null;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/fragments/Replace.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.fragments;
5 |
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentTransaction;
10 |
11 | public class Replace extends FragmentCommand {
12 |
13 | private Fragment to;
14 | private String tag;
15 |
16 | private Replace(@NonNull Fragment to,
17 | @Nullable String tag) {
18 | super();
19 | this.to = to;
20 | this.tag = tag;
21 | }
22 |
23 | private Replace(@NonNull Fragment to,
24 | @Nullable String tag,
25 | @NonNull FragmentCommand command) {
26 | super(command);
27 | this.to = to;
28 | this.tag = tag;
29 | }
30 |
31 | public static Replace replace(@NonNull Fragment to,
32 | @Nullable String tag) {
33 | return new Replace(to, tag);
34 | }
35 |
36 | public static Replace replace(@NonNull Fragment to,
37 | @Nullable String tag,
38 | @NonNull FragmentCommand command) {
39 | return new Replace(to, tag, command);
40 | }
41 |
42 | @Override
43 | public FragmentTransaction apply(int containerId,
44 | @NonNull FragmentTransaction transaction) {
45 | FragmentTransaction current = transaction.replace(containerId, to, tag);
46 | return command == null ? current : command.apply(containerId, current);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/satellites/ToastSatellite.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.satellites;
5 |
6 | import android.content.Context;
7 | import android.support.annotation.NonNull;
8 | import android.widget.Toast;
9 |
10 | import com.github.sasd97.lib_router.commands.Command;
11 | import com.github.sasd97.lib_router.commands.messages.Message;
12 | import com.github.sasd97.lib_router.commands.messages.MessageCommand;
13 | import com.github.sasd97.lib_router.exceptions.CommandNotSupportedException;
14 |
15 | /**
16 | * Satellite which handle toast messages commands.
17 | */
18 | public class ToastSatellite implements Satellite {
19 |
20 | @NonNull
21 | private final Context context;
22 |
23 | public ToastSatellite(@NonNull Context context) {
24 | this.context = context;
25 | }
26 |
27 | /**
28 | * {@inheritDoc}
29 | */
30 | @Override
31 | public int getType() {
32 | return SatelliteTypes.TOAST;
33 | }
34 |
35 | /**
36 | * {@inheritDoc}
37 | */
38 | @Override
39 | public void execute(@NonNull Command command) {
40 | if (!isApplicable(command))
41 | throw new CommandNotSupportedException("Message group");
42 |
43 | MessageCommand messageCommand = (MessageCommand) command;
44 | Message message = messageCommand.getMessage();
45 | Toast.makeText(context, message.getMessage(), message.getDuration()).show();
46 | }
47 |
48 | /**
49 | * {@inheritDoc}
50 | */
51 | @Override
52 | public boolean isApplicable(@NonNull Command command) {
53 | return command instanceof MessageCommand;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/satellites/FragmentSatellite.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.satellites;
5 |
6 | import android.support.annotation.IdRes;
7 | import android.support.annotation.NonNull;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentTransaction;
10 |
11 | import com.github.sasd97.lib_router.commands.Command;
12 | import com.github.sasd97.lib_router.commands.fragments.FragmentCommand;
13 | import com.github.sasd97.lib_router.exceptions.CommandNotSupportedException;
14 |
15 | /**
16 | * Satellite which works with fragment stack.
17 | */
18 | public final class FragmentSatellite implements Satellite {
19 |
20 | @IdRes
21 | private final int containerId;
22 | @NonNull
23 | private final FragmentManager fragmentManager;
24 |
25 | public FragmentSatellite(@IdRes int containerId,
26 | @NonNull FragmentManager fragmentManager) {
27 | this.containerId = containerId;
28 | this.fragmentManager = fragmentManager;
29 | }
30 |
31 | /**
32 | * {@inheritDoc}
33 | */
34 | @Override
35 | public int getType() {
36 | return SatelliteTypes.FRAGMENT;
37 | }
38 |
39 | /**
40 | * {@inheritDoc}
41 | */
42 | @Override
43 | public void execute(@NonNull Command command) {
44 | if (!isApplicable(command))
45 | throw new CommandNotSupportedException("Fragment group");
46 |
47 | FragmentTransaction transaction = fragmentManager.beginTransaction();
48 | transaction = ((FragmentCommand) command).apply(containerId, transaction);
49 | transaction.commit();
50 | }
51 |
52 | /**
53 | * {@inheritDoc}
54 | */
55 | @Override
56 | public boolean isApplicable(@NonNull Command command) {
57 | return command instanceof FragmentCommand;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/lib-router/src/main/java/com/github/sasd97/lib_router/commands/activities/StartForResult.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 by Alexander Dadukin (st235@yandex.ru)
2 | // All rights reserved.
3 |
4 | package com.github.sasd97.lib_router.commands.activities;
5 |
6 | import android.app.Activity;
7 | import android.content.Intent;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.support.annotation.NonNull;
11 |
12 | import com.github.sasd97.lib_router.commands.providers.ProviderCommand;
13 |
14 | public final class StartForResult extends ActivityCommand {
15 |
16 | private Class> to;
17 | private int requestCode;
18 | private Intent wrappedIntent;
19 | private ProviderCommand command;
20 |
21 | private StartForResult(@NonNull Class> to,
22 | int requestCode) {
23 | this.to = to;
24 | this.requestCode = requestCode;
25 | }
26 |
27 | private StartForResult(@NonNull Class> to,
28 | int requestCode,
29 | @NonNull ProviderCommand command) {
30 | this.to = to;
31 | this.command = command;
32 | this.requestCode = requestCode;
33 | }
34 |
35 | private StartForResult(@NonNull Intent intent,
36 | int requestCode) {
37 | this.wrappedIntent = intent;
38 | this.requestCode = requestCode;
39 | }
40 |
41 | public static StartForResult startForResult(@NonNull Class> to,
42 | int requestCode) {
43 | return new StartForResult(to, requestCode);
44 | }
45 |
46 | public static StartForResult startForResult(@NonNull Class> to,
47 | int requestCode,
48 | @NonNull ProviderCommand command) {
49 | return new StartForResult(to, requestCode, command);
50 | }
51 |
52 | public static StartForResult startForResult(@NonNull Intent wrapped,
53 | int requestCode) {
54 | return new StartForResult(wrapped, requestCode);
55 | }
56 |
57 | @Override
58 | public void apply(@NonNull Activity activity) {
59 | Intent startIntent = wrappedIntent != null ?
60 | new Intent(wrappedIntent) : new Intent(activity, to);
61 | if (command != null) startIntent.putExtras(command.getContent(null));
62 | activity.startActivityForResult(startIntent, requestCode);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/sasd97/android_router/SecondaryActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.android_router;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.design.widget.BottomNavigationView;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.MenuItem;
9 | import android.widget.Toast;
10 |
11 | import com.github.sasd97.lib_router.BaseRouter;
12 | import com.github.sasd97.lib_router.Router;
13 | import com.github.sasd97.lib_router.satellites.FragmentSatellite;
14 | import com.github.sasd97.lib_router.satellites.Satellite;
15 | import com.github.sasd97.lib_router.satellites.ToastSatellite;
16 |
17 | import static com.github.sasd97.lib_router.commands.fragments.AddToBackStack.addToBackStack;
18 | import static com.github.sasd97.lib_router.commands.fragments.And.and;
19 | import static com.github.sasd97.lib_router.commands.fragments.Replace.replace;
20 | import static com.github.sasd97.lib_router.commands.fragments.WithCustomAnimation.animate;
21 | import static com.github.sasd97.lib_router.commands.messages.ShowToast.showToast;
22 |
23 | public class SecondaryActivity extends AppCompatActivity {
24 |
25 | private Router router = new BaseRouter();
26 | private Satellite satellite;
27 |
28 | private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
29 | = new BottomNavigationView.OnNavigationItemSelectedListener() {
30 |
31 | @Override
32 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
33 | switch (item.getItemId()) {
34 | case R.id.navigation_home:
35 | router.pushCommand(replace(new FirstFragment(), null, and(addToBackStack(null))));
36 | return true;
37 | case R.id.navigation_dashboard:
38 | router.pushCommand(replace(new SecondFragment(), "tag"));
39 | return true;
40 | case R.id.navigation_notifications:
41 | router.pushCommand(
42 | animate(R.anim.slide_in, R.anim.slide_out, replace(new ThirdFragment(), null))
43 | );
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | };
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_secondary);
55 |
56 | satellite = new FragmentSatellite(R.id.fragmentContainer, getSupportFragmentManager());
57 | router.addSatellite(satellite);
58 | router.addSatellite(new ToastSatellite(this));
59 |
60 | BottomNavigationView navigation = findViewById(R.id.navigation);
61 | navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
62 |
63 | Intent intent = getIntent();
64 | Bundle args = intent.getExtras();
65 |
66 | if (args != null && args.containsKey("args")) {
67 | router.pushCommand(showToast(Toast.LENGTH_SHORT, String.valueOf(args.getInt("args"))));
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at st235@yandex.ru. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/sasd97/android_router/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.sasd97.android_router;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.provider.MediaStore;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.github.sasd97.lib_router.BaseRouter;
12 | import com.github.sasd97.lib_router.Router;
13 | import com.github.sasd97.lib_router.satellites.ActivitySatellite;
14 | import com.github.sasd97.lib_router.satellites.Satellite;
15 | import com.github.sasd97.lib_router.satellites.ToastSatellite;
16 |
17 | import static com.github.sasd97.lib_router.commands.activities.And.and;
18 | import static com.github.sasd97.lib_router.commands.activities.ForwardIntent.forwardIntent;
19 | import static com.github.sasd97.lib_router.commands.activities.FinishThis.finishThis;
20 | import static com.github.sasd97.lib_router.commands.activities.Start.start;
21 | import static com.github.sasd97.lib_router.commands.activities.StartForResult.startForResult;
22 | import static com.github.sasd97.lib_router.commands.messages.ShowToast.showToast;
23 | import static com.github.sasd97.lib_router.commands.providers.With.with;
24 |
25 | public class MainActivity extends AppCompatActivity {
26 |
27 | private Router router = new BaseRouter();
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 |
34 | router.addSatellite(new ActivitySatellite(this));
35 | router.addSatellite(new ToastSatellite(this));
36 |
37 | findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View view) {
40 | router.pushCommand(start(SecondaryActivity.class));
41 | }
42 | });
43 |
44 | findViewById(R.id.nextAndFinish).setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View view) {
47 | router.pushCommand(finishThis(and(start(SecondaryActivity.class))));
48 | }
49 | });
50 |
51 | findViewById(R.id.nextWithArgs).setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View view) {
54 | Bundle args = new Bundle();
55 | args.putInt("args", 1);
56 | router.pushCommand(start(SecondaryActivity.class, with(args)));
57 | }
58 | });
59 |
60 | findViewById(R.id.showMessage).setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View view) {
63 | router.pushCommand(showToast(Toast.LENGTH_SHORT, "Hello world!"));
64 | }
65 | });
66 |
67 | findViewById(R.id.openGallery).setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View view) {
70 | Intent openGallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
71 | router.pushCommand(startForResult(openGallery, 1));
72 | }
73 | });
74 |
75 | findViewById(R.id.sendEmail).setOnClickListener(new View.OnClickListener() {
76 | @Override
77 | public void onClick(View v) {
78 | Intent mail = new Intent(Intent.ACTION_SENDTO);
79 | mail.setData(Uri.parse("mailto:example@google.com?s=hello"));
80 | router.pushCommand(forwardIntent(Intent.createChooser(mail, "Choose email app")));
81 | }
82 | });
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Router
2 |
3 | [  ](https://bintray.com/st235/maven/android-router/_latestVersion)
4 |
5 | ## Installation
6 |
7 | ### Gradle
8 | ```
9 | implementation 'com.github.st235:android-router:0.1.0'
10 | ```
11 |
12 | ### Maven
13 | ```
14 |
15 | com.github.st235
16 | android-router
17 | 0.1.0
18 | pom
19 |
20 | ```
21 |
22 | ## Concepts
23 |
24 | We realized that Android-framework needs its own routing system, but there is
25 | no unified solution or any unified concepts.So we came up with our design pattern.
26 | Routing in Android is not an easy thing. It was suggested to divide all entities into
27 | 2 levels of abstraction: depending on the framework (platform **satellites**) and independent entities - **routers**.
28 |
29 | Platform-specific entities implement specific functions, such as,
30 | system messages handling, showing of dialogs, routing between activities & fragments.
31 |
32 |
33 | ## How to use
34 |
35 | We implemented base router and 2 satellites out of the box.
36 | There are activities and fragments satellites and several following commands.
37 |
38 | First of all, you need to attach **satellite** to **router**.
39 |
40 | ```java
41 | private Router router = new BaseRouter();
42 | private Satellite satellite;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_main);
48 |
49 | satellite = new ActivitySatellite(this);
50 | router.addSatellite(satellite);
51 | }
52 | ```
53 |
54 | ### Available activity commands
55 | - start
56 | - startForResult
57 | - forwardIntent
58 | - finish
59 | - with
60 | - and _(Sugar :candy:)_
61 |
62 | ```java
63 | router.pushCommand(start(SecondaryActivity.class));
64 | ```
65 |
66 | ```java
67 | router.pushCommand(finishThis(and(start(SecondaryActivity.class))));
68 | ```
69 |
70 | ```java
71 | Bundle args = new Bundle();
72 | args.putInt("args", 1);
73 | router.pushCommand(start(SecondaryActivity.class, with(args)));
74 | ```
75 |
76 |
77 | ### Available fragments commands
78 | - addToBackStack
79 | - and _(Sugar :candy:)_
80 | - replace
81 | - add
82 | - animate
83 |
84 | ```java
85 | router.pushCommand(replace(new FirstFragment(), null, and(addToBackStack(null))));
86 | ```
87 |
88 | ### System messages show
89 | - showToast
90 |
91 | ```java
92 | router.pushCommand(showToast(Toast.LENGTH_SHORT, "Hello world!"));
93 | ```
94 |
95 | _Note: You can find all usage examples in app folder._
96 |
97 | ## Extension
98 |
99 | You can extend your own routing system by one of three ways.
100 | The first way is to add new command to existing commands group.
101 |
102 | ### Add command
103 | To add command you need to inherit new one from command group.
104 |
105 | _Example:_
106 | ```java
107 | public final class Start extends ActivityCommand {
108 | ...
109 | }
110 |
111 | public class Replace extends FragmentCommand {
112 | ...
113 | }
114 | ```
115 |
116 | If you need more complex functionality to manipulate command stack
117 | you can create your own __satellite__
118 |
119 | ### Add satellite
120 | To add satellite you need to implement satellite interface
121 |
122 | ```java
123 | public final class ActivitySatellite implements Satellite {
124 | ...
125 | }
126 | ```
127 |
128 | Satellite interface
129 |
130 | ```java
131 | public interface Satellite {
132 | /**
133 | * Get current satellite type.
134 | * @return unique id for satellite group (for example, activity group).
135 | */
136 | int getType();
137 |
138 | /**
139 | * Execute passed command by satellite.
140 | * @param command or command chain which contains navigation info.
141 | */
142 | void execute(@NonNull Command command);
143 |
144 | /**
145 | * Checks whether satellite can handle command or not.
146 | * @param command or command chain which contains navigation info.
147 | * @return true if satellite can handle command else otherwise.
148 | */
149 | boolean isApplicable(@NonNull Command command);
150 | }
151 | ```
152 |
153 | And the last one opportunity to add misc functions to **router** is to write your own custom router.
154 |
155 | ### Add router
156 |
157 | To add router you need to implement router interface
158 |
159 | ```java
160 | public class BaseRouter implements Router {
161 | ...
162 | }
163 | ```
164 |
165 | Router interface
166 |
167 | ```java
168 | public interface Router {
169 | void pushCommand(@NonNull Command command);
170 |
171 | void addSatellite(@NonNull Satellite satellite);
172 | void removeSatellite(@NonNull Satellite satellite);
173 | }
174 | ```
175 |
176 | ## License
177 |
178 | MIT License
179 |
180 | Copyright (c) 2017-present Alexander Dadukin
181 |
182 | Permission is hereby granted, free of charge, to any person obtaining a copy
183 | of this software and associated documentation files (the "Software"), to deal
184 | in the Software without restriction, including without limitation the rights
185 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
186 | copies of the Software, and to permit persons to whom the Software is
187 | furnished to do so, subject to the following conditions:
188 |
189 | The above copyright notice and this permission notice shall be included in all
190 | copies or substantial portions of the Software.
191 |
192 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
193 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
195 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
197 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
198 | SOFTWARE.
199 |
--------------------------------------------------------------------------------