Skip to content

🌎 a simple tool for checking internet connection with observable or without observable.

License

Notifications You must be signed in to change notification settings

muhammadisa/Lifemark

Repository files navigation

Welcome to Lifemark 👋

Version License: MIT documentation: yes maintained: yes

Short introduction, this is very simple internet checker, you can execute a function when the device disconnected and otherwise, you can check is connected to the internet for once on execution.

Demo

Install

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

implementation 'com.github.muhammadisa:lifemark:1.0.1'

Contribute?

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

Need Example?

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

Simple Usage

  1. Forever Checking

    val networkConnection = Lifemark(applicationContext)
    networkConnection.ObservableNetworkCondition()
    	.observe(this@MainActivity, Observer { isConnected ->
    	if (isConnected) {
            // do something when device connected to internet
    	} else {
            // do something when device disconnected to internet
    	}
    })
  2. Checking for once execution

    val networkConnection = Lifemark(applicationContext)
    if(networkConnection.isNetworkConnected()){
        // do something when device connected to internet
    }else{
        // do something when device disconnected to internet
    }
Full Example
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val networkConnection = Lifemark(applicationContext)

        // Forever Checking example
        networkConnection.ObservableNetworkCondition()
            .observe(this@MainActivity, Observer { isConnected ->
                if (isConnected) {
                    disconnected_layout.visibility = View.GONE
                    connected_layout.visibility = View.VISIBLE
                } else {
                    connected_layout.visibility = View.GONE
                    disconnected_layout.visibility = View.VISIBLE
                }
            })

        if (networkConnection.isNetworkConnected()) {
            // do something when device connected to internet
            Log.d("INTERNET_CHECKER", "true")
        } else {
            // do something when device disconnected to internet
            Log.d("INTERNET_CHECKER", "false")
        }
    }

}

Author

👤 Dimas Prasetya

👤 Muhammad Isa Wijaya Kusuma

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator