Giter Club home page Giter Club logo

orion's Introduction

Welcome to Orion ๐Ÿ‘‹

Version License: MIT documentation: yes maintained: yes

Short introduction, this is very simple tool for navigate between activities using deep link

Install

For installation just add this code in your app build.gradle file

implementation 'com.github.muhammadisa:orion:1.0.0'

Contribute?

Read the terms https://github.com/muhammadisa/orion/blob/master/CONTRIBUTING.md

Need Example?

Just click this link https://github.com/muhammadisa/orion/tree/master/example/src/main/java/com/xoxoer/example

Simple Usage

  1. add this new string inside your strings.xml
    <string name="app_domain">yourapp</string>
  2. set link for your activity inside AndroidManifest.xml

    <activity android:name=".YourDesiredActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
    
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
    
            <data
                  android:host="your.desired.activity"
                  android:scheme="@string/app_domain" />
        </intent-filter>
    </activity>
  3. create Route class

    object InitialRouteName {
        // replace this with your initial route name
        const val FIRST = "first"
        const val SECOND = "second"
        const val THIRD = "third"
    }
    
    class Route internal constructor(
        context: Context,
        private val initial: String
    ) : Orion(), OrionContract {
    
        init {
            super.init(context)
        }
    
        // get string from string resource for app domain
        override val appDomain: String = context.getString(R.string.app_domain)
    
        override val routes: Map<String, Uri> = mapOf(
            // deep link format : appdomain://your.desired.activity
            // exmaple
            FIRST to Uri.parse("$appDomain://first.act"),
            SECOND to Uri.parse("$appDomain://second.act"),
            THIRD to Uri.parse("$appDomain://third.act")
        )
    
        fun navigate() {
            super.navigate(routes[initial] ?: error(""))
        }
    
        fun navigate(extraKey: String, extra: Any) {
            val uri = routes[initial] ?: error("")
            super.navigate(uri, extraKey, extra)
        }
    
        fun navigateNoHistory() {
            super.navigateNoHistory(routes[initial] ?: error(""))
        }
    
    }
  4. final usage

    class MainActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            button_first.setOnClickListener {
                // normal navigate
                Route(it.context, FIRST).navigate()
            }
    
            button_second.setOnClickListener {
                // navigate with extra data parcelable
                Route(it.context, SECOND).navigate("MESSAGE", Message(
                    "MainActivity",
                    "Hello, navigating with deeplink and orion"
                ))
            }
    
            button_third.setOnClickListener {
                // navigate without back to previous activity
                Route(it.context, THIRD).navigateNoHistory()
            }
    
        }
    
    }

Author

๐Ÿ‘ค Muhammad Isa Wijaya Kusuma

Show your support

Give a โญ๏ธ if this project helped you!


This README was generated with โค๏ธ by readme-md-generator

orion's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.