Naviganto


Source link: https://github.com/FireZenk/Naviganto

Naviganto

A small routing library for Android

GRADLE:

 repositories {

 ...

 maven {
 url 'https://github.com/FireZenk/maven-repo/raw/master/'
}
  
}
  dependencies {

 ...
 provided 'javax.annotation:javax.annotation-api:1.2'
 provided 'com.squareup:javapoet:1.8.0'
  def NVersion = '3.0.1'
 compile "org.firezenk.naviganto:annotations:$NVersion"
 compile "org.firezenk.naviganto:processor:$NVersion"
 compile "org.firezenk.naviganto:library:$NVersion"  
}

DESCRIPTION:

Naviganto consists of 5 main classes:

  • Naviganto which is in charge of navigate between views ( Activity or View).
  • Route that contains the desired route.
  • @RoutableActivity and @RoutableView to use auto-routes.
  • Routable the interface that is implemented for each of our custom Routes.

Additionally, two custom exceptions are provided for make the debugging easier:

  • ParameterNotFoundException launched when not found a path parameter that we need.
  • NotEnoughParametersException which is launched if the route has not received all the necessary parameters.

USAGE

1. Route to the target view

There are two cases when using the router:

  • Route to a another Activity
  • Route to a different View inside the Activity
// Navigate to another Activity; Bundle for custom routes or Object[] for auto-routes Naviganto.get().routeTo(this, new Route<>(DetailRoute.class, bundle));
  // Or if you need a result for your previous Activity Naviganto.get().routeTo(this, new Route<>(DetailRoute.class, bundle, requestCode));
// Navigate to a View; Bundle for custom routes or Object[] for auto-routes Naviganto.get().routeTo(this, new Route<>(ProductRoute.class, bundle, placeholder));
  // Or if you need a result for your previous Activity Naviganto.get().routeTo(this, new Route<>(ProductRoute.class, bundle, placeholder, requestCode));

As we can see the only difference is that if we need to navigate to a View, we need to serve a placeholder. Besides this, in our Activity have to specify the following (to enable "back button" navigation):

@Override public void onBackPressed() {
  if (!Naviganto.get().back(this))
super.onBackPressed();
 
}

In all the above cases should be understood this as Context

2. Mark the target view as Route

Finally, to implement a route, there are two ways to use this library since version 2.0:

1 - Use auto-routes (remember to rebuild to generate the routes):

@RoutableActivity(params = {
...
}
, requestCode = ...) // for Activities {
parameter types separated by commas
}
, define requestCode as -1 if you don't need it (generates SomeActivityRoute.java) public class SomeActivity extends AppCompatActivity {
  
}
  @RoutableView(params = {
...
}
, requestCode = ...) // for Views {
Parameter types separated by commas
}
, define requestCode as -1 if you don't need it (generates SomeViewRoute.java) class SomeView extends FrameLayout {
  
}

2 - Or implement your custom routes from the Routable like this:

public class MyCustomRoute<C extends Context, B extends Bundle> implements Routable<C, B> {

@Override public void route(@NonNull Context context, @NonNull Bundle parameters, @Nullable Object viewParent)

 throws ParameterNotFoundException, NotEnoughParametersException {

// How to opening our Activity or View  
}
 
}

Sample Auto-route and Routable implementations:

Auto-route for Activity

Implementation for Activity

Auto-route for View

Implementation for View

ADDITIONAL NOTES

  • No, it is not contemplated the use of fragments, although it is possible (using View sample)
  • I recommend to use auto-routes (available since version 2.0) because you can avoid to use Parcelables
  • User .clearHistory() if you need to clear all the navigation history
  • There is some more self documented functions here
  • For more info an samples, see sample module

CHANGES

See CHANGES.md

Resources

A spinning circular loading view; for use when you need to display something when you are loading something off of the main UI thread.

Reduks is a redux-like implementation for kotlin apps, with this you can create, state, actions, reducers, stores and middlewares in an easy way.

A simple animation with tanslation or scale views written in Java.

A reusable fragment to display links to social networks, the Play Store as well as recommendation and support email links. The fragment tries to open installed apps on the user's device first and resorts to the web browser otherwise.

Simple multithread-friendly library for getting latest user locations using RxJava 2.

Easily set up phone authentication leveraging on different auth platform (Firebase, Sinch) of your choice.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes