All Projects → terrakok → Cicerone

terrakok / Cicerone

Licence: other
🚦 Cicerone is a lightweight library that makes the navigation in an Android app easy.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Cicerone

Brick
🧱 Brick - Multiplatform navigation library for Compose.
Stars: ✭ 33 (-98.59%)
Mutual labels:  navigation, multistack
Alligator
Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way.
Stars: ✭ 287 (-87.76%)
Mutual labels:  navigation, fragments
BottomNavArchDemo
The demo project for Bottom Navigation with Navigation Architecture Components article
Stars: ✭ 53 (-97.74%)
Mutual labels:  bottom-navigation, jetpack-navigation
navigator
Annotation processor that eliminates navigation and Bundle boilerplate
Stars: ✭ 13 (-99.45%)
Mutual labels:  fragments, navigation
Bubble Navigation
🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.
Stars: ✭ 1,537 (-34.46%)
Mutual labels:  navigation, bottom-navigation
Jetpack Mvvm Best Practice
是 难得一见 的 Jetpack MVVM 最佳实践!在 以简驭繁 的代码中,对 视图控制器 乃至 标准化开发模式 形成正确、深入的理解!
Stars: ✭ 6,950 (+196.38%)
Mutual labels:  navigation, jetpack-navigation
drawer-with-bottom-navigation-architecture
Sample android kotlin project with both drawer and bottom navigation together
Stars: ✭ 42 (-98.21%)
Mutual labels:  navigation, bottom-navigation
Flowr
FlowR is a wrapper class around the Fragment Manager.
Stars: ✭ 123 (-94.75%)
Mutual labels:  navigation, fragments
Fragnav
An Android library for managing multiple stacks of fragments
Stars: ✭ 1,379 (-41.19%)
Mutual labels:  navigation, fragments
Simple Stack
[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
Stars: ✭ 1,012 (-56.84%)
Mutual labels:  navigation, fragments
Flownav
Annotation processor that provides better navigation on android multi-modules projects 🛳.
Stars: ✭ 122 (-94.8%)
Mutual labels:  navigation, fragments
Scene
Android Single Activity Applications framework without Fragment.
Stars: ✭ 1,793 (-23.54%)
Mutual labels:  navigation, fragments
Motion
Navigation and insight in Go
Stars: ✭ 163 (-93.05%)
Mutual labels:  navigation
The Movie Db Kotlin
The Movie DB app using Kotlin with updated Android features
Stars: ✭ 176 (-92.49%)
Mutual labels:  navigation
Expandingpager
ExpandingPager is a card peek/pop controller
Stars: ✭ 1,906 (-18.72%)
Mutual labels:  fragments
Gallerit
A sample Android gallery to search images posted on Reddit built using modern Android development tools (Architecture Components, MVVM, Coroutines, Flow, Navigation, Retrofit, Room, Koin)
Stars: ✭ 153 (-93.48%)
Mutual labels:  navigation
Arouter
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Stars: ✭ 13,587 (+479.4%)
Mutual labels:  navigation
Marine Api
Java Marine API - NMEA 0183 library for Java
Stars: ✭ 174 (-92.58%)
Mutual labels:  navigation
Jquery Navobile
A jQuery plugin that makes mobile navigation easy.
Stars: ✭ 157 (-93.3%)
Mutual labels:  navigation
Locationsimulator
MacOS 10.15 / 11.0 application to spoof your iOS / iPadOS or iPhoneSimulator device location. WatchOS and TvOS are partially supported.
Stars: ✭ 157 (-93.3%)
Mutual labels:  navigation

Cicerone

Maven Central License: MIT

Android Arsenal Android Weekly Android Weekly

Power navigation Multibackstack Result listeners

Cicerone (means - a guide, one who conducts sightseers) is a lightweight library that makes the navigation in an Android app easy.
It was designed to be used with the MVP/MVVM/MVI patterns but will work great with any architecture.

Main advantages

  • is not tied to Fragments
  • not a framework (very lightweight)
  • short navigation calls (no builders)
  • static typed checks for screen parameters!
  • lifecycle-safe!
  • functionality is simple to extend
  • suitable for Unit Testing

Additional features

  • opening several screens inside single call (for example: deeplink)
  • provides FragmentFactory if it needed
  • add or replace strategy for opening next screen (see router.navigateTo last parameter)
  • implementation of parallel navigation (Instagram like)
  • predefined navigator ready for Single-Activity apps
  • predefined navigator ready for setup transition animation

How to add

Add the dependency in your build.gradle:

dependencies {
    //Cicerone
    implementation("com.github.terrakok:cicerone:X.X.X")
}

Initialize the library (for example in your Application class):

class App : Application() {
    private val cicerone = Cicerone.create()
    val router get() = cicerone.router
    val navigatorHolder get() = cicerone.getNavigatorHolder()

    override fun onCreate() {
        super.onCreate()
        INSTANCE = this
    }

    companion object {
        internal lateinit var INSTANCE: App
            private set
    }
}

How it works?

CiceroneDiagram.png

Presenter calls navigation method of Router.

class SamplePresenter(
    private val router: Router
) : Presenter<SampleView>() {

    fun onOpenNewScreen() {
        router.navigateTo(SomeScreen())
    }

    fun onBackPressed() {
        router.exit()
    }
}

Router converts the navigation call to the set of Commands and sends them to CommandBuffer.

CommandBuffer checks whether there are "active" Navigator:

  • If yes, it passes the commands to the Navigator. Navigator will process them to achive the desired transition.
  • If no, then CommandBuffer saves the commands in a queue, and will apply them as soon as new "active" Navigator will appear.
fun executeCommands(commands: Array<out Command>) {
    navigator?.applyCommands(commands) ?: pendingCommands.add(commands)
}

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

Attention: Use onResumeFragments() with FragmentActivity (more info)

private val navigator = AppNavigator(this, R.id.container)

override fun onResumeFragments() {
    super.onResumeFragments()
    navigatorHolder.setNavigator(navigator)
}

override fun onPause() {
    navigatorHolder.removeNavigator()
    super.onPause()
}

Navigation commands

This commands set will fulfill the needs of the most applications. But if you need something special - just add it!

  • Forward - Opens new screen
  • Back - Rolls back the last transition
  • BackTo - Rolls back to the needed screen in the screens chain
  • Replace - Replaces the current screen

Predefined navigator

The library provides predefined navigator for Fragments and Activity. To use, just provide it with the container and FragmentManager.

private val navigator = AppNavigator(this, R.id.container)

Custom navigator can be useful sometimes:

private val navigator = object : AppNavigator(this, R.id.container) {
    override fun setupFragmentTransaction(
        screen: FragmentScreen,
        fragmentTransaction: FragmentTransaction,
        currentFragment: Fragment?,
        nextFragment: Fragment
    ) {
        //setup your animation
    }

    override fun applyCommands(commands: Array<out Command>) {
        hideKeyboard()
        super.applyCommands(commands)
    }
}

Screens

Describe your screens as you like e.g. create Kotlin object with all application screens:

object Screens {
    fun Main() = FragmentScreen { MainFragment() }
    fun AddressSearch() = FragmentScreen { AddressSearchFragment() }
    fun Profile(userId: Long) = FragmentScreen("Profile_$userId") { ProfileFragment(userId) }
    fun Browser(url: String) = ActivityScreen { Intent(Intent.ACTION_VIEW, Uri.parse(url))  }
}

Additional you can use FragmentFactory for creating your screens:

fun SomeScreen() = FragmentScreen { factory: FragmentFactory -> ... }

Screen parameters and result listener

//you have to specify screen parameters via new FragmentScreen creation
fun SelectPhoto(resultKey: String) = FragmentScreen {
    SelectPhotoFragment.getNewInstance(resultKey)
}
//listen result
fun onSelectPhotoClicked() {
    router.setResultListener(RESULT_KEY) { data ->
        view.showPhoto(data as Bitmap)
    }
    router.navigateTo(SelectPhoto(RESULT_KEY))
}

//send result
fun onPhotoClick(photo: Bitmap) {
    router.sendResult(resultKey, photoRes)
    router.exit()
}

Sample

To see how to add, initialize and use the library and predefined navigators see sample project
(thank you @Javernaut for support new library version and migrate sample project to Kotlin!)

For more complex use case check out the GitFox (Android GitLab client)

Applications with Cicerone inside

Яндекс.Еда — доставка еды/продуктов. Food delivery
Kaspersky Internet Security
Delivery Club – Доставка еды и продуктов
Поиск работы на hh. Вакансии рядом с домом
Whisk: Recipe Saver, Meal Planner & Grocery List
Мой Beeline (Казахстан)
Mercuryo Bitcoin Cryptowallet
ЧекСкан - кэшбэк за чеки, цены и акции в магазинах
RSS Reader для Вести.Ru
EPAM Connect
Consumer Reports: Product Reviews & Ratings
Zakaz.ru

Participants

  • idea and code - Konstantin Tskhovrebov (@terrakok)
  • architecture advice, documentation and publication - Vasili Chyrvon (@Jeevuz)

License

MIT License

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].