Navigator

General

Category
Free
Tag
Navigation
License
Apache License, Version 2.0
Registered
Nov 30, 2017
Favorites
1
Link
https://github.com/ShabanKamell/Navigator
See also
SmoothBottomBar
Router
CardDrawer
Router
flowless

Additional

Language
Kotlin
Version
N/A
Created
Nov 11, 2017
Updated
Dec 16, 2019 (Retired)
Owner
Shaban Kamel (ShabanKamell)
Contributor
Shaban Kamel (ShabanKamell)
1
Activity
Badge
Generate
Download
Source code

Android Navigator

A simple wrapper for Android navigation that helps you get rid of a lot of boilerplate code.

Install

Gradle:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

dependencies {
       implementation 'com.github.ShabanKamell:Navigator:x.y.z'
}

(Please replace x, y and z with the latest version numbers: )

Usage

Modular Navigation

Navigator supports Fragment/Activity navigation

Activity

// Declare Addresable Activity
object Profile: AddressableActivity {
     override val className: String = "com.sha.navigator.profile.ProfileActivity"
}
// start Activity
ActivityModuleNavigator(this, packageName).navigate(Profile)

Fragment

// Declare Addresable Fragment
object Profile: AddressableFragment {
     override val className: String = "com.sha.navigator.profile.ProfileFragment"
}
// Add Fragment
FragmentModuleNavigator(this).add(Profile)
// OR Replace Fragment
FragmentModuleNavigator(this).replace(Profile)

Fragment Navigation

Replace Fragment

 FragmentNavigator(this).replace(ExampleFragment.newInstance()

Add Fragment

 FragmentNavigator(this).add(ExampleFragment.newInstance())

Show DialogFragment

 FragmentNavigator(this).showDialogFragment(CustomerDialogFragment.newInstance())

Where's FrameLayout's ID?

FrameLayout's ID can be Provided with 2 ways:

1- Pass in FragmentNavigator Contstructor

   FragmentNavigator(this, R.id.mainFrame)

2- Provide only once in Application class or anywhere

In this case, you don't have to pass the ID in the constructor in every call.

class SampleApp : Application() {
    override fun onCreate() {
        super.onCreate()
        NavigatorOptions.frameLayoutId = R.id.mainFrame
    }
}

Note: Passing the ID in the constructor will override the ID of NavigatorOptions only this call and won't change NavigatorOptions's ID.

Activity Navigation

Navigate to Activity

 new ActivityNavigator(this).navigate(ExampleActivity.class);

Start Activity For Result

 ActivityNavigator(this).navigate(ExampleActivity::class.java)

With Parcelable

ActivityNavigator(this)
                    .withParcelable(Parcels.wrap(Message()), "message")
                    .navigate(ExampleActivity::class.java)

With Flags

  ActivityNavigator(this)  
        .withFlags(new Flags().newTask().singleTop())
        .navigate(ExampleActivity.class)
        
        // OR
        
  ActivityNavigator(this)  
        .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK, Intent.FLAG_ACTIVITY_SINGLE_TOP)
        .navigate(ExampleActivity.class)

Open App In Google Play

  ActivityNavigator(this).openInGooglePlay()

Open Camera

  ActivityNavigator(this).openCamera(2)

Open Settings

  ActivityNavigator(this).navigateToSettings()

Show Route In Google Map

 new ActivityNavigator(this).showRouteInGoogleMap(  
        25.095549,  // from lat
        29.644703,  // from lng
        24.457151,  // to lat
        27.184841   // to lng
  );

See 'sample' module for the full code.

Credit

Plaid Modular Navigation

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.